diff --git a/src/main/java/com/atsuishio/superbwarfare/config/server/ExplosionConfig.java b/src/main/java/com/atsuishio/superbwarfare/config/server/ExplosionConfig.java index f9b39978f..31aa89b42 100644 --- a/src/main/java/com/atsuishio/superbwarfare/config/server/ExplosionConfig.java +++ b/src/main/java/com/atsuishio/superbwarfare/config/server/ExplosionConfig.java @@ -6,13 +6,72 @@ public class ExplosionConfig { public static ForgeConfigSpec.IntValue EXPLOSION_PENETRATION_RATIO; + public static ForgeConfigSpec.IntValue RGO_GRENADE_EXPLOSION_DAMAGE; + public static ForgeConfigSpec.IntValue RGO_GRENADE_EXPLOSION_RADIUS; + + public static ForgeConfigSpec.IntValue M67_GRENADE_EXPLOSION_DAMAGE; + public static ForgeConfigSpec.IntValue M67_GRENADE_EXPLOSION_RADIUS; + + public static ForgeConfigSpec.IntValue MORTAR_SHELL_EXPLOSION_DAMAGE; + public static ForgeConfigSpec.IntValue MORTAR_SHELL_EXPLOSION_RADIUS; + + public static ForgeConfigSpec.IntValue DRONE_KAMIKAZE_HIT_DAMAGE; + public static ForgeConfigSpec.IntValue DRONE_KAMIKAZE_EXPLOSION_DAMAGE; + public static ForgeConfigSpec.IntValue DRONE_KAMIKAZE_EXPLOSION_RADIUS; + public static void init(ForgeConfigSpec.Builder builder) { - builder.push("explosion_penetration"); + builder.push("explosion"); builder.comment("The percentage of explosion damage you take behind cover"); EXPLOSION_PENETRATION_RATIO = builder.defineInRange("explosion_destroy", 15, 0, 100); builder.pop(); + + + builder.push("RGO Grenade"); + + builder.comment("The explosion damage of RGO grenade"); + RGO_GRENADE_EXPLOSION_DAMAGE = builder.defineInRange("Rgo grenade explosion damage", 90, 1, 10000000); + + builder.comment("The explosion radius of RGO grenade"); + RGO_GRENADE_EXPLOSION_RADIUS = builder.defineInRange("Rgo grenade explosion radius", 5, 1, 50); + + builder.pop(); + + + builder.push("M67 Grenade"); + + builder.comment("The explosion damage of M67 grenade"); + M67_GRENADE_EXPLOSION_DAMAGE = builder.defineInRange("Rgo grenade explosion damage", 120, 1, 10000000); + + builder.comment("The explosion radius of M67 grenade"); + M67_GRENADE_EXPLOSION_RADIUS = builder.defineInRange("Rgo grenade explosion radius", 6, 1, 50); + + builder.pop(); + + + builder.push("Mortar shell"); + + builder.comment("The explosion damage of Mortar shell"); + MORTAR_SHELL_EXPLOSION_DAMAGE = builder.defineInRange("Rgo grenade explosion damage", 160, 1, 10000000); + + builder.comment("The explosion radius of Mortar shell"); + MORTAR_SHELL_EXPLOSION_RADIUS = builder.defineInRange("Rgo grenade explosion radius", 9, 1, 50); + + builder.pop(); + + builder.push("Drone Kamikaze"); + + builder.comment("The hit damage of Drone Kamikaze"); + DRONE_KAMIKAZE_HIT_DAMAGE = builder.defineInRange("Rgo grenade explosion damage", 300, 1, 10000000); + + builder.comment("The explosion damage of Drone Kamikaze"); + DRONE_KAMIKAZE_EXPLOSION_DAMAGE = builder.defineInRange("Rgo grenade explosion damage", 160, 1, 10000000); + + builder.comment("The explosion radius of Drone Kamikaze"); + DRONE_KAMIKAZE_EXPLOSION_RADIUS = builder.defineInRange("Rgo grenade explosion radius", 9, 1, 50); + + builder.pop(); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/config/server/ExplosionDestroyConfig.java b/src/main/java/com/atsuishio/superbwarfare/config/server/ExplosionDestroyConfig.java index f02074b5d..fba11386d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/config/server/ExplosionDestroyConfig.java +++ b/src/main/java/com/atsuishio/superbwarfare/config/server/ExplosionDestroyConfig.java @@ -7,7 +7,7 @@ public class ExplosionDestroyConfig { public static ForgeConfigSpec.BooleanValue EXPLOSION_DESTROY; public static void init(ForgeConfigSpec.Builder builder) { - builder.push("explosion"); + builder.push("explosion_destroy"); builder.comment("Set TRUE to allow Explosion to destroy blocks"); EXPLOSION_DESTROY = builder.define("explosion_destroy", false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java index 2756e105b..23e889efa 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/ClaymoreEntity.java @@ -4,6 +4,7 @@ import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.tools.CustomExplosion; +import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.ParticleTool; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -40,6 +41,7 @@ import java.util.UUID; public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity, OwnableEntity { protected static final EntityDataAccessor> OWNER_UUID = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.OPTIONAL_UUID); + protected static final EntityDataAccessor LAST_ATTACKER_UUID = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.STRING); public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(ClaymoreEntity.class, EntityDataSerializers.FLOAT); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -55,6 +57,7 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity, @Override protected void defineSynchedData() { this.entityData.define(OWNER_UUID, Optional.empty()); + this.entityData.define(LAST_ATTACKER_UUID, "undefined"); this.entityData.define(HEALTH, 10f); } @@ -83,6 +86,10 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity, amount *= 0.2f; } + if (source.getEntity() != null) { + this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID()); + } + if (this.level() instanceof ServerLevel serverLevel) { ParticleTool.sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 0.2, this.getZ(), 2, 0.02, 0.02, 0.02, 0.1, false); } @@ -108,7 +115,7 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity, @Override public void addAdditionalSaveData(CompoundTag compound) { compound.putFloat("Health", this.entityData.get(HEALTH)); - + compound.putString("LastAttacker", this.entityData.get(LAST_ATTACKER_UUID)); if (this.getOwnerUUID() != null) { compound.putUUID("Owner", this.getOwnerUUID()); } @@ -120,6 +127,10 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity, this.entityData.set(HEALTH, compound.getFloat("Health")); } + if (compound.contains("LastAttacker")) { + this.entityData.set(LAST_ATTACKER_UUID, compound.getString("LastAttacker")); + } + UUID uuid; if (compound.hasUUID("Owner")) { uuid = compound.getUUID("Owner"); @@ -217,8 +228,9 @@ public class ClaymoreEntity extends Entity implements GeoEntity, AnimatedEntity, public void destroy() { if (level() instanceof ServerLevel) { - CustomExplosion explosion = new CustomExplosion(this.level(), null, - ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), null, null), 25.0f, + Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID)); + CustomExplosion explosion = new CustomExplosion(this.level(), attacker, + ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), attacker, attacker), 25.0f, this.getX(), this.getY(), this.getZ(), 5f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java index 1545839eb..66b910246 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/DroneEntity.java @@ -1,5 +1,6 @@ package com.atsuishio.superbwarfare.entity; +import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; import com.atsuishio.superbwarfare.entity.projectile.RgoGrenadeEntity; import com.atsuishio.superbwarfare.init.ModDamageTypes; @@ -10,7 +11,6 @@ import com.atsuishio.superbwarfare.item.Monitor; import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.EntityFindUtil; import com.atsuishio.superbwarfare.tools.ParticleTool; -import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.NonNullList; @@ -48,6 +48,7 @@ import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PlayMessages; import net.minecraftforge.registries.ForgeRegistries; +import org.joml.Vector3f; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animation.AnimatableManager; @@ -173,6 +174,55 @@ public class DroneEntity extends LivingEntity implements GeoEntity { this.entityData.set(ROT_Z, compound.getFloat("rotZ")); } + + public Vector3f getForwardDirection() { + return new Vector3f( + Mth.sin(-getYRot() * ((float) Math.PI / 180)), + 0.0f, + Mth.cos(getYRot() * ((float) Math.PI / 180)) + ).normalize(); + } + + + public Vector3f getRightDirection() { + return new Vector3f( + Mth.cos(-getYRot() * ((float) Math.PI / 180)), + 0.0f, + Mth.sin(getYRot() * ((float) Math.PI / 180)) + ).normalize(); + } + +// if (this.level().isClientSide) { +// +// if (!this.onGround()) { +// // left and right +// float moveX = 0; +// if (Minecraft.getInstance().options.keyLeft.isDown()) { +// moveX = -1; +// } else if (Minecraft.getInstance().options.keyRight.isDown()) { +// moveX = 1; +// } +// +// Vector3f direction = getRightDirection().mul(moveX); +// setDeltaMovement(getDeltaMovement().add(direction.x, direction.y, direction.z)); +// +// // forward and backward +//// direction = getForwardDirection().mul(thrust * pressingInterpolatedZ.getSmooth()); +//// setDeltaMovement(getDeltaMovement().add(direction.x, direction.y, direction.z)); +// } else { +// // up and down +// +// float moveY = 0; +// if (Minecraft.getInstance().options.keyJump.isDown()) { +// moveY = -1; +// } else if (Minecraft.getInstance().options.keyShift.isDown()) { +// moveY = 1; +// } +// +// setDeltaMovement(getDeltaMovement().add(0.0f, moveY, 0.0f)); +// } +// } + @Override public void baseTick() { super.baseTick(); @@ -242,11 +292,13 @@ public class DroneEntity extends LivingEntity implements GeoEntity { Player controller = EntityFindUtil.findPlayer(this.level(), this.entityData.get(CONTROLLER)); if (!this.onGround()) { - this.level().playSound(null, this.getOnPos(), ModSounds.DRONE_SOUND.get(), SoundSource.AMBIENT, 3, 1); if (controller != null) { ItemStack stack = controller.getMainHandItem(); - if (stack.getOrCreateTag().getBoolean("Using") && controller instanceof ServerPlayer serverPlayer) { - SoundTool.playLocalSound(serverPlayer, ModSounds.DRONE_SOUND.get(), 4, 1); + if (stack.getOrCreateTag().getBoolean("Using") && controller.level().isClientSide) { + controller.playSound(ModSounds.DRONE_SOUND.get(), 32, 1); + } + if (!controller.level().isClientSide) { + this.level().playSound(null, this.getOnPos(), ModSounds.DRONE_SOUND.get(), SoundSource.AMBIENT, 3, 1); } controller.setYRot(controller.getYRot() - 5 * this.entityData.get(ROT_X) * Mth.abs(this.entityData.get(MOVE_Z))); } @@ -419,7 +471,7 @@ public class DroneEntity extends LivingEntity implements GeoEntity { public void hitEntityCrash(Player controller, Entity target) { if (lastTickSpeed > 0.2) { if (this.entityData.get(KAMIKAZE) && 6 * lastTickSpeed > this.getHealth()) { - target.hurt(ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, controller), 600); + target.hurt(ModDamageTypes.causeCustomExplosionDamage(this.level().registryAccess(), this, controller), ExplosionConfig.DRONE_KAMIKAZE_HIT_DAMAGE.get()); } target.hurt(ModDamageTypes.causeDroneHitDamage(this.level().registryAccess(), this, controller), (float) (5 * lastTickSpeed)); if (target instanceof Mob mobEntity) { @@ -486,8 +538,8 @@ public class DroneEntity extends LivingEntity implements GeoEntity { private void kamikazeExplosion(Entity source) { CustomExplosion explosion = new CustomExplosion(this.level(), this, - ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), source, source), 125, - this.getX(), this.getY(), this.getZ(), 7.5f, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); + ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), source, source), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_DAMAGE.get(), + this.getX(), this.getY(), this.getZ(), ExplosionConfig.DRONE_KAMIKAZE_EXPLOSION_RADIUS.get(), ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(1); explosion.explode(); net.minecraftforge.event.ForgeEventFactory.onExplosionStart(this.level(), explosion); explosion.finalizeExplosion(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java index a93073aad..5dfa3ffcb 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java @@ -1,13 +1,13 @@ package com.atsuishio.superbwarfare.entity; -import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity; -import com.atsuishio.superbwarfare.init.ModEntities; -import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.ModUtils; import com.atsuishio.superbwarfare.client.gui.RangeHelper; +import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity; +import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModParticleTypes; import com.atsuishio.superbwarfare.init.ModSounds; +import com.atsuishio.superbwarfare.tools.ParticleTool; import net.minecraft.ChatFormatting; import net.minecraft.commands.arguments.EntityAnchorArgument; import net.minecraft.core.BlockPos; @@ -45,8 +45,6 @@ import software.bernie.geckolib.core.animation.RawAnimation; import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; -import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; - public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { public static final EntityDataAccessor FIRE_TIME = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor PITCH = SynchedEntityData.defineId(MortarEntity.class, EntityDataSerializers.FLOAT); @@ -164,7 +162,7 @@ public class MortarEntity extends Entity implements GeoEntity, AnimatedEntity { if (level instanceof ServerLevel server) { MortarShellEntity entityToSpawn = new MortarShellEntity(ModEntities.MORTAR_SHELL.get(), player, level); entityToSpawn.setPos(this.getX(), this.getEyeY(), this.getZ()); - entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 8, (float) 0.9); + entityToSpawn.shoot(this.getLookAngle().x, this.getLookAngle().y, this.getLookAngle().z, 8, (float) 0.3); level.addFreshEntity(entityToSpawn); server.sendParticles(ParticleTypes.CAMPFIRE_COSY_SMOKE, (this.getX() + 3 * this.getLookAngle().x), (this.getY() + 0.1 + 3 * this.getLookAngle().y), (this.getZ() + 3 * this.getLookAngle().z), 8, 0.4, 0.4, 0.4, 0.007); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/model/DroneModel.java b/src/main/java/com/atsuishio/superbwarfare/entity/model/DroneModel.java index 38f484f1a..595d3870f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/model/DroneModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/model/DroneModel.java @@ -6,7 +6,6 @@ import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.tools.EntityFindUtil; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; -import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import software.bernie.geckolib.core.animatable.model.CoreGeoBone; @@ -61,8 +60,8 @@ public class DroneModel extends GeoModel { float times = (float) (0.5f * Math.min(Minecraft.getInstance().getDeltaFrameTime(), 0.8)); - rotX = Mth.lerp(0.5f * times, rotX, animatable.getEntityData().get(ROT_X)); - rotZ = Mth.lerp(0.5f * times, rotZ, animatable.getEntityData().get(ROT_Z)); +// rotX = Mth.lerp(0.5f * times, rotX, animatable.getEntityData().get(ROT_X)); +// rotZ = Mth.lerp(0.5f * times, rotZ, animatable.getEntityData().get(ROT_Z)); main.setRotZ(rotX); main.setRotX(rotZ); @@ -76,7 +75,7 @@ public class DroneModel extends GeoModel { CoreGeoBone wingBL = getAnimationProcessor().getBone("wingBL"); CoreGeoBone wingBR = getAnimationProcessor().getBone("wingBR"); - rotation = (float) Mth.lerp(times, rotation, animatable.onGround() ? 0 : 0.08 - 0.1 * animatable.getEntityData().get(MOVE_Y)); +// rotation = (float) Mth.lerp(times, rotation, animatable.onGround() ? 0 : 0.08 - 0.1 * animatable.getEntityData().get(MOVE_Y)); wingFL.setRotY(wingFL.getRotY() - rotation); wingFR.setRotY(wingFL.getRotY() - rotation); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java index 0435a4846..27dea63b4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/HandGrenadeEntity.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.ModUtils; +import com.atsuishio.superbwarfare.config.server.ExplosionConfig; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; @@ -128,7 +129,7 @@ public class HandGrenadeEntity extends ThrowableItemProjectile { if (this.fuse <= 0) { this.discard(); if (!this.level().isClientSide) { - ProjectileTool.causeCustomExplode(this, 125f, 5f, 1.2f); + ProjectileTool.causeCustomExplode(this, ExplosionConfig.M67_GRENADE_EXPLOSION_DAMAGE.get(), ExplosionConfig.M67_GRENADE_EXPLOSION_RADIUS.get(), 1.2f); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java index db6b6d8c1..8de71e6af 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/MortarShellEntity.java @@ -1,10 +1,11 @@ package com.atsuishio.superbwarfare.entity.projectile; +import com.atsuishio.superbwarfare.config.server.ExplosionConfig; +import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModEntities; +import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ProjectileTool; -import com.atsuishio.superbwarfare.init.ModDamageTypes; -import com.atsuishio.superbwarfare.init.ModItems; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; @@ -26,9 +27,9 @@ import net.minecraftforge.network.PlayMessages; public class MortarShellEntity extends ThrowableItemProjectile { - private float damage = 175f; + private float damage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get(); private int life = 600; - private float radius = 8f; + private float radius = ExplosionConfig.MORTAR_SHELL_EXPLOSION_RADIUS.get(); public MortarShellEntity(EntityType type, Level world) { super(type, world); @@ -61,7 +62,7 @@ public class MortarShellEntity extends ThrowableItemProjectile { if (pCompound.contains("Damage")) { this.damage = pCompound.getFloat("Damage"); } else { - this.damage = 250f; + this.damage = ExplosionConfig.MORTAR_SHELL_EXPLOSION_DAMAGE.get();; } if (pCompound.contains("Life")) { @@ -73,7 +74,7 @@ public class MortarShellEntity extends ThrowableItemProjectile { if (pCompound.contains("Radius")) { this.radius = pCompound.getFloat("Radius"); } else { - this.radius = 12.5f; + this.radius = ExplosionConfig.MORTAR_SHELL_EXPLOSION_RADIUS.get(); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java index b51e25a31..746bac9ec 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RgoGrenadeEntity.java @@ -1,11 +1,15 @@ package com.atsuishio.superbwarfare.entity.projectile; import com.atsuishio.superbwarfare.ModUtils; +import com.atsuishio.superbwarfare.config.server.ExplosionConfig; +import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; import com.atsuishio.superbwarfare.entity.DroneEntity; +import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModEntities; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.network.message.ClientIndicatorMessage; +import com.atsuishio.superbwarfare.tools.CustomExplosion; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.ProjectileTool; import net.minecraft.core.BlockPos; @@ -16,11 +20,13 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; +import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.projectile.ThrowableItemProjectile; import net.minecraft.world.item.Item; +import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BellBlock; import net.minecraft.world.level.block.state.BlockState; @@ -36,6 +42,8 @@ import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache import software.bernie.geckolib.core.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; +import javax.annotation.Nullable; + public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEntity { private int fuse = 80; private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); @@ -78,7 +86,7 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti if (state.getBlock() instanceof BellBlock bell) { bell.attemptToRing(this.level(), resultPos, blockResult.getDirection()); } - ProjectileTool.causeCustomExplode(this, 100f, 4f, 1.2f); + ProjectileTool.causeCustomExplode(this, ExplosionConfig.RGO_GRENADE_EXPLOSION_DAMAGE.get(), ExplosionConfig.RGO_GRENADE_EXPLOSION_RADIUS.get(), 1.2f); break; case ENTITY: @@ -92,7 +100,9 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti } } if (!(entity instanceof DroneEntity)) { - ProjectileTool.causeCustomExplode(this, 100f, 4f, 1.2f); + causeRgoExplode(this, + ModDamageTypes.causeProjectileBoomDamage(this.level().registryAccess(), this, this.getOwner()), + entity, ExplosionConfig.RGO_GRENADE_EXPLOSION_DAMAGE.get(), ExplosionConfig.RGO_GRENADE_EXPLOSION_RADIUS.get(), 1.2f); } break; default: @@ -100,6 +110,16 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti } } + public static void causeRgoExplode(ThrowableItemProjectile projectile, @Nullable DamageSource source, Entity entity, float damage, float radius, float damageMultiplier) { + CustomExplosion explosion = new CustomExplosion(projectile.level(), projectile, source, damage, + entity.getX(), entity.getY(), entity.getZ(), radius, ExplosionDestroyConfig.EXPLOSION_DESTROY.get() ? Explosion.BlockInteraction.DESTROY : Explosion.BlockInteraction.KEEP).setDamageMultiplier(damageMultiplier); + explosion.explode(); + net.minecraftforge.event.ForgeEventFactory.onExplosionStart(projectile.level(), explosion); + explosion.finalizeExplosion(false); + ParticleTool.spawnMediumExplosionParticles(projectile.level(), projectile.position()); + projectile.discard(); + } + @Override public void tick() { super.tick(); @@ -108,7 +128,7 @@ public class RgoGrenadeEntity extends ThrowableItemProjectile implements GeoEnti if (this.fuse <= 0) { this.discard(); if (!this.level().isClientSide) { - ProjectileTool.causeCustomExplode(this, 100f, 4f, 1.2f); + ProjectileTool.causeCustomExplode(this, ExplosionConfig.RGO_GRENADE_EXPLOSION_DAMAGE.get(), ExplosionConfig.RGO_GRENADE_EXPLOSION_RADIUS.get(), 1.2f); } }