diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java index 54050a3ad..78265793b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/MortarEntity.java @@ -24,7 +24,6 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MoverType; @@ -37,7 +36,6 @@ import net.minecraft.world.phys.Vec3; import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PlayMessages; -import org.jetbrains.annotations.NotNull; import org.joml.Math; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; @@ -99,10 +97,8 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, AnimatedEn } @Override - public boolean hurt(DamageSource source, float amount) { - super.hurt(source, amount); - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; + public boolean sendFireStarParticleOnHurt() { + return false; } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java index c47c7fdab..0c8e7b402 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -27,9 +27,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -131,16 +129,6 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli return NetworkHooks.getEntitySpawningPacket(this); } - @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - if (this.level() instanceof ServerLevel serverLevel) { - sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); - } - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; - } - @Override public DamageModifier getDamageModifier() { return super.getDamageModifier() diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java index 00208a2e2..690b442b9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/AnnihilatorEntity.java @@ -24,7 +24,6 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -42,7 +41,6 @@ import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PlayMessages; -import org.jetbrains.annotations.NotNull; import org.joml.Math; import org.joml.Vector3d; import software.bernie.geckolib.animatable.GeoEntity; @@ -57,8 +55,6 @@ import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; import java.util.List; -import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; - public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, ICannonEntity { public static final EntityDataAccessor COOL_DOWN = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.INT); @@ -181,16 +177,6 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, return super.getPassengersRidingOffset() + 0.75; } - @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - if (this.level() instanceof ServerLevel serverLevel) { - sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); - } - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; - } - @Override public DamageModifier getDamageModifier() { return super.getDamageModifier() diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java index d5aee4727..1c3f84b7e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -27,9 +27,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -137,16 +135,6 @@ public class Bmp2Entity extends ContainerMobileEntity implements GeoEntity, ILan return NetworkHooks.getEntitySpawningPacket(this); } - @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - if (this.level() instanceof ServerLevel serverLevel) { - sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); - } - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; - } - @Override public DamageModifier getDamageModifier() { return super.getDamageModifier() diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java index a2d8b40f7..38bc89b58 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java @@ -105,10 +105,15 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { return Mth.lerp(0.6f * tickDelta, pitchO, getBodyPitch()); } + @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - return true; + public boolean sendFireStarParticleOnHurt() { + return false; + } + + @Override + public boolean playHitSoundOnHurt() { + return false; } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java index aa72063a2..1f9e3d4ff 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/LaserTowerEntity.java @@ -22,7 +22,6 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.*; import net.minecraft.world.entity.monster.Enemy; @@ -35,7 +34,6 @@ import net.minecraft.world.phys.HitResult; import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PlayMessages; -import org.jetbrains.annotations.NotNull; import org.joml.Math; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; @@ -142,16 +140,6 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity, return NetworkHooks.getEntitySpawningPacket(this); } - @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - if (this.level() instanceof ServerLevel serverLevel) { - sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 0.8, this.getZ(), 4, 0.1, 0.1, 0.1, 0.2, false); - } - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; - } - @Override public DamageModifier getDamageModifier() { return super.getDamageModifier() diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java index 2217b3304..eda2d2977 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -26,9 +26,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -134,16 +132,6 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IL return NetworkHooks.getEntitySpawningPacket(this); } - @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - if (this.level() instanceof ServerLevel serverLevel) { - sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); - } - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; - } - @Override public DamageModifier getDamageModifier() { return super.getDamageModifier() diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java index 9247bf555..fedf64710 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -26,7 +26,6 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.*; import net.minecraft.world.entity.player.Player; @@ -38,7 +37,6 @@ import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PlayMessages; -import org.jetbrains.annotations.NotNull; import org.joml.Math; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; @@ -52,8 +50,6 @@ import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; import java.util.List; -import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; - public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntity { public static final EntityDataAccessor COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT); @@ -149,16 +145,6 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntit return super.getPassengersRidingOffset() - 0.25; } - @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - if (this.level() instanceof ServerLevel serverLevel) { - sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); - } - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; - } - @Override public DamageModifier getDamageModifier() { return super.getDamageModifier() diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java index 0ddefcd8f..72d7a844a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -26,7 +26,6 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.*; import net.minecraft.world.entity.player.Player; @@ -38,7 +37,6 @@ import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PlayMessages; -import org.jetbrains.annotations.NotNull; import org.joml.Math; import org.joml.Vector3d; import software.bernie.geckolib.animatable.GeoEntity; @@ -53,8 +51,6 @@ import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; import java.util.List; -import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; - public class Mle1934Entity extends VehicleEntity implements GeoEntity, ICannonEntity { public static final EntityDataAccessor COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); @@ -163,16 +159,6 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, ICannonEn return super.getPassengersRidingOffset() - 0.075; } - @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - if (this.level() instanceof ServerLevel serverLevel) { - sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); - } - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; - } - @Override public DamageModifier getDamageModifier() { return super.getDamageModifier() diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java index 1475c2a2c..44cd78077 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -23,9 +23,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -39,7 +37,6 @@ import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PlayMessages; -import org.jetbrains.annotations.NotNull; import org.joml.Math; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; @@ -114,16 +111,6 @@ public class SpeedboatEntity extends ContainerMobileEntity implements GeoEntity, return super.getPassengersRidingOffset() - 0.8; } - @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - if (this.level() instanceof ServerLevel serverLevel) { - sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); - } - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; - } - @Override public DamageModifier getDamageModifier() { return super.getDamageModifier() diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java index 5e443ed56..550ef675e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Tom6Entity.java @@ -27,7 +27,6 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; @@ -97,10 +96,8 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { } @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; + public boolean sendFireStarParticleOnHurt() { + return false; } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java index 3abd0270b..b6fb34690 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/VehicleEntity.java @@ -50,6 +50,8 @@ import org.joml.Vector4f; import java.util.ArrayList; import java.util.List; +import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; + public class VehicleEntity extends Entity { public static final EntityDataAccessor HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT); @@ -155,21 +157,48 @@ public class VehicleEntity extends Entity { @Override public boolean hurt(@NotNull DamageSource source, float amount) { + // 计算减伤后的伤害 float computedAmount = damageModifier.compute(source, amount); this.crash = source.is(ModDamageTypes.VEHICLE_STRIKE); if (source.getEntity() != null) { this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID()); } + + // 受伤打断呼吸回血 if (computedAmount > 0) { lastHurtTick = 0; repairCoolDown = maxRepairCoolDown(); } this.onHurt(computedAmount, source.getEntity(), true); + + // 显示火花粒子效果 + if (this.sendFireStarParticleOnHurt() && this.level() instanceof ServerLevel serverLevel) { + sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 2.5, this.getZ(), 4, 0.2, 0.2, 0.2, 0.2, false); + } + // 播放受击音效 + if (this.playHitSoundOnHurt()) { + this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); + } + return super.hurt(source, computedAmount); } + /** + * 受击时是否显示火花粒子效果 + */ + public boolean sendFireStarParticleOnHurt() { + return true; + } + + /** + * 受击时是否播放受击音效 + */ + public boolean playHitSoundOnHurt() { + return true; + } + protected final DamageModifier damageModifier = this.getDamageModifier(); /** diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java index 0c489ea67..7e5fd6bc5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/WheelChairEntity.java @@ -21,7 +21,6 @@ import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; import net.minecraft.util.Mth; -import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.*; import net.minecraft.world.entity.animal.WaterAnimal; import net.minecraft.world.entity.player.Player; @@ -31,7 +30,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.PlayMessages; -import org.jetbrains.annotations.NotNull; import org.joml.Math; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; @@ -102,12 +100,9 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity { public Packet getAddEntityPacket() { return NetworkHooks.getEntitySpawningPacket(this); } - @Override - public boolean hurt(@NotNull DamageSource source, float amount) { - super.hurt(source, amount); - this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1); - return true; + public boolean sendFireStarParticleOnHurt() { + return false; } @Override