重写载具受击粒子效果和音效播放

This commit is contained in:
Light_Quanta 2025-02-24 04:02:39 +08:00
parent 5a7cdc760e
commit 61fe4148d0
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
13 changed files with 43 additions and 124 deletions

View file

@ -24,7 +24,6 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityDimensions; import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.MoverType;
@ -37,7 +36,6 @@ import net.minecraft.world.phys.Vec3;
import net.minecraftforge.items.ItemHandlerHelper; import net.minecraftforge.items.ItemHandlerHelper;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
import org.jetbrains.annotations.NotNull;
import org.joml.Math; import org.joml.Math;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
@ -99,10 +97,8 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, AnimatedEn
} }
@Override @Override
public boolean hurt(DamageSource source, float amount) { public boolean sendFireStarParticleOnHurt() {
super.hurt(source, amount); return false;
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
return true;
} }
@Override @Override

View file

@ -27,9 +27,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
@ -131,16 +129,6 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
return NetworkHooks.getEntitySpawningPacket(this); 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 @Override
public DamageModifier getDamageModifier() { public DamageModifier getDamageModifier() {
return super.getDamageModifier() return super.getDamageModifier()

View file

@ -24,7 +24,6 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
@ -42,7 +41,6 @@ import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
import org.jetbrains.annotations.NotNull;
import org.joml.Math; import org.joml.Math;
import org.joml.Vector3d; import org.joml.Vector3d;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
@ -57,8 +55,6 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, ICannonEntity { public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(AnnihilatorEntity.class, EntityDataSerializers.INT);
@ -181,16 +177,6 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
return super.getPassengersRidingOffset() + 0.75; 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 @Override
public DamageModifier getDamageModifier() { public DamageModifier getDamageModifier() {
return super.getDamageModifier() return super.getDamageModifier()

View file

@ -27,9 +27,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
@ -137,16 +135,6 @@ public class Bmp2Entity extends ContainerMobileEntity implements GeoEntity, ILan
return NetworkHooks.getEntitySpawningPacket(this); 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 @Override
public DamageModifier getDamageModifier() { public DamageModifier getDamageModifier() {
return super.getDamageModifier() return super.getDamageModifier()

View file

@ -105,10 +105,15 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
return Mth.lerp(0.6f * tickDelta, pitchO, getBodyPitch()); return Mth.lerp(0.6f * tickDelta, pitchO, getBodyPitch());
} }
@Override @Override
public boolean hurt(@NotNull DamageSource source, float amount) { public boolean sendFireStarParticleOnHurt() {
super.hurt(source, amount); return false;
return true; }
@Override
public boolean playHitSoundOnHurt() {
return false;
} }
@Override @Override

View file

@ -22,7 +22,6 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.monster.Enemy; 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.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
import org.jetbrains.annotations.NotNull;
import org.joml.Math; import org.joml.Math;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
@ -142,16 +140,6 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
return NetworkHooks.getEntitySpawningPacket(this); 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 @Override
public DamageModifier getDamageModifier() { public DamageModifier getDamageModifier() {
return super.getDamageModifier() return super.getDamageModifier()

View file

@ -26,9 +26,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
@ -134,16 +132,6 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IL
return NetworkHooks.getEntitySpawningPacket(this); 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 @Override
public DamageModifier getDamageModifier() { public DamageModifier getDamageModifier() {
return super.getDamageModifier() return super.getDamageModifier()

View file

@ -26,7 +26,6 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player; 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.NetworkHooks;
import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
import org.jetbrains.annotations.NotNull;
import org.joml.Math; import org.joml.Math;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; 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.Comparator;
import java.util.List; import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntity { public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mk42Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> 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; 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 @Override
public DamageModifier getDamageModifier() { public DamageModifier getDamageModifier() {
return super.getDamageModifier() return super.getDamageModifier()

View file

@ -26,7 +26,6 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player; 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.NetworkHooks;
import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
import org.jetbrains.annotations.NotNull;
import org.joml.Math; import org.joml.Math;
import org.joml.Vector3d; import org.joml.Vector3d;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
@ -53,8 +51,6 @@ import software.bernie.geckolib.util.GeckoLibUtil;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class Mle1934Entity extends VehicleEntity implements GeoEntity, ICannonEntity { public class Mle1934Entity extends VehicleEntity implements GeoEntity, ICannonEntity {
public static final EntityDataAccessor<Integer> COOL_DOWN = SynchedEntityData.defineId(Mle1934Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor<Integer> 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; 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 @Override
public DamageModifier getDamageModifier() { public DamageModifier getDamageModifier() {
return super.getDamageModifier() return super.getDamageModifier()

View file

@ -23,9 +23,7 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; 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.NetworkHooks;
import net.minecraftforge.network.PacketDistributor; import net.minecraftforge.network.PacketDistributor;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
import org.jetbrains.annotations.NotNull;
import org.joml.Math; import org.joml.Math;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
@ -114,16 +111,6 @@ public class SpeedboatEntity extends ContainerMobileEntity implements GeoEntity,
return super.getPassengersRidingOffset() - 0.8; 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 @Override
public DamageModifier getDamageModifier() { public DamageModifier getDamageModifier() {
return super.getDamageModifier() return super.getDamageModifier()

View file

@ -27,7 +27,6 @@ import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
@ -97,10 +96,8 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
} }
@Override @Override
public boolean hurt(@NotNull DamageSource source, float amount) { public boolean sendFireStarParticleOnHurt() {
super.hurt(source, amount); return false;
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
return true;
} }
@Override @Override

View file

@ -50,6 +50,8 @@ import org.joml.Vector4f;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public class VehicleEntity extends Entity { public class VehicleEntity extends Entity {
public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT);
@ -155,21 +157,48 @@ public class VehicleEntity extends Entity {
@Override @Override
public boolean hurt(@NotNull DamageSource source, float amount) { public boolean hurt(@NotNull DamageSource source, float amount) {
// 计算减伤后的伤害
float computedAmount = damageModifier.compute(source, amount); float computedAmount = damageModifier.compute(source, amount);
this.crash = source.is(ModDamageTypes.VEHICLE_STRIKE); this.crash = source.is(ModDamageTypes.VEHICLE_STRIKE);
if (source.getEntity() != null) { if (source.getEntity() != null) {
this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID()); this.entityData.set(LAST_ATTACKER_UUID, source.getEntity().getStringUUID());
} }
// 受伤打断呼吸回血
if (computedAmount > 0) { if (computedAmount > 0) {
lastHurtTick = 0; lastHurtTick = 0;
repairCoolDown = maxRepairCoolDown(); repairCoolDown = maxRepairCoolDown();
} }
this.onHurt(computedAmount, source.getEntity(), true); 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); return super.hurt(source, computedAmount);
} }
/**
* 受击时是否显示火花粒子效果
*/
public boolean sendFireStarParticleOnHurt() {
return true;
}
/**
* 受击时是否播放受击音效
*/
public boolean playHitSoundOnHurt() {
return true;
}
protected final DamageModifier damageModifier = this.getDamageModifier(); protected final DamageModifier damageModifier = this.getDamageModifier();
/** /**

View file

@ -21,7 +21,6 @@ import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.*; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.animal.WaterAnimal; import net.minecraft.world.entity.animal.WaterAnimal;
import net.minecraft.world.entity.player.Player; 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.minecraft.world.phys.Vec3;
import net.minecraftforge.network.NetworkHooks; import net.minecraftforge.network.NetworkHooks;
import net.minecraftforge.network.PlayMessages; import net.minecraftforge.network.PlayMessages;
import org.jetbrains.annotations.NotNull;
import org.joml.Math; import org.joml.Math;
import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.animatable.GeoEntity;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
@ -102,12 +100,9 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity {
public Packet<ClientGamePacketListener> getAddEntityPacket() { public Packet<ClientGamePacketListener> getAddEntityPacket() {
return NetworkHooks.getEntitySpawningPacket(this); return NetworkHooks.getEntitySpawningPacket(this);
} }
@Override @Override
public boolean hurt(@NotNull DamageSource source, float amount) { public boolean sendFireStarParticleOnHurt() {
super.hurt(source, amount); return false;
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
return true;
} }
@Override @Override