优化载具hurt方法调用

This commit is contained in:
Light_Quanta 2025-02-24 03:48:37 +08:00
parent 50ba7d8bb5
commit 5a7cdc760e
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
13 changed files with 36 additions and 74 deletions

View file

@ -37,6 +37,7 @@ 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,12 +100,8 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, AnimatedEn
@Override
public boolean hurt(DamageSource source, float amount) {
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
amount = this.damageModifier.compute(source, amount);
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
return true;
}

View file

@ -132,16 +132,12 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli
}
@Override
public boolean hurt(DamageSource source, float amount) {
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);
amount = damageModifier.compute(source, amount);
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
return true;
}

View file

@ -42,6 +42,7 @@ 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;
@ -181,16 +182,12 @@ public class AnnihilatorEntity extends EnergyVehicleEntity implements GeoEntity,
}
@Override
public boolean hurt(DamageSource source, float amount) {
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);
amount = damageModifier.compute(source, amount);
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
return true;
}

View file

@ -138,16 +138,12 @@ public class Bmp2Entity extends ContainerMobileEntity implements GeoEntity, ILan
}
@Override
public boolean hurt(DamageSource source, float amount) {
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);
amount = damageModifier.compute(source, amount);
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
return true;
}

View file

@ -106,11 +106,8 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity {
}
@Override
public boolean hurt(DamageSource source, float amount) {
amount = damageModifier.compute(source, amount);
public boolean hurt(@NotNull DamageSource source, float amount) {
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), false);
return true;
}

View file

@ -35,6 +35,7 @@ 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 +143,12 @@ public class LaserTowerEntity extends EnergyVehicleEntity implements GeoEntity,
}
@Override
public boolean hurt(DamageSource source, float amount) {
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);
amount = damageModifier.compute(source, amount);
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
return true;
}

View file

@ -135,16 +135,12 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IL
}
@Override
public boolean hurt(DamageSource source, float amount) {
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);
amount = damageModifier.compute(source, amount);
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
return true;
}

View file

@ -38,6 +38,7 @@ 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;
@ -149,16 +150,12 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, ICannonEntit
}
@Override
public boolean hurt(DamageSource source, float amount) {
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);
amount = damageModifier.compute(source, amount);
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
return true;
}

View file

@ -38,6 +38,7 @@ 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;
@ -163,16 +164,12 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, ICannonEn
}
@Override
public boolean hurt(DamageSource source, float amount) {
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);
amount = damageModifier.compute(source, amount);
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
return true;
}

View file

@ -39,6 +39,7 @@ 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 +115,12 @@ public class SpeedboatEntity extends ContainerMobileEntity implements GeoEntity,
}
@Override
public boolean hurt(DamageSource source, float amount) {
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);
amount = damageModifier.compute(source, amount);
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
return true;
}

View file

@ -97,13 +97,9 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
}
@Override
public boolean hurt(DamageSource source, float amount) {
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
amount = damageModifier.compute(source, amount);
this.hurt(amount, source.getEntity(), true);
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;
}

View file

@ -154,18 +154,20 @@ public class VehicleEntity extends Entity {
}
@Override
public boolean hurt(DamageSource source, float amount) {
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 (amount > 0) {
if (computedAmount > 0) {
lastHurtTick = 0;
repairCoolDown = maxRepairCoolDown();
}
return super.hurt(source, amount);
this.onHurt(computedAmount, source.getEntity(), true);
return super.hurt(source, computedAmount);
}
protected final DamageModifier damageModifier = this.getDamageModifier();
@ -194,7 +196,7 @@ public class VehicleEntity extends Entity {
}
public void hurt(float pHealAmount, Entity attacker, boolean send) {
public void onHurt(float pHealAmount, Entity attacker, boolean send) {
if (this.level() instanceof ServerLevel) {
var holder = Holder.direct(ModSounds.INDICATION_VEHICLE.get());
if (attacker instanceof ServerPlayer player && pHealAmount > 0 && this.getHealth() > 0 && send && !(this instanceof DroneEntity)) {
@ -323,7 +325,7 @@ public class VehicleEntity extends Entity {
if (this.getHealth() <= 0.1 * this.getMaxHealth()) {
// 血量过低时自动扣血
this.hurt(0.1f, attacker, false);
this.onHurt(0.1f, attacker, false);
} else {
// 呼吸回血
if (repairCoolDown == 0) {

View file

@ -31,6 +31,7 @@ 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;
@ -103,13 +104,9 @@ public class WheelChairEntity extends MobileVehicleEntity implements GeoEntity {
}
@Override
public boolean hurt(DamageSource source, float amount) {
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
amount = damageModifier.compute(source, amount);
public boolean hurt(@NotNull DamageSource source, float amount) {
super.hurt(source, amount);
this.hurt(amount, source.getEntity(), true);
this.level().playSound(null, this.getOnPos(), ModSounds.HIT.get(), SoundSource.PLAYERS, 1, 1);
return true;
}