优化DPS发电机DPS计算方法

This commit is contained in:
Light_Quanta 2025-05-20 01:24:44 +08:00
parent dd322621ae
commit 409cf9271f
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959

View file

@ -19,12 +19,10 @@ import net.minecraft.sounds.SoundSource;
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.DamageSource;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.*; import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.ThrownPotion;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
@ -49,6 +47,8 @@ public class DPSGeneratorEntity extends LivingEntity implements GeoEntity {
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private float damageDealt = 0;
public DPSGeneratorEntity(EntityType<DPSGeneratorEntity> type, Level world) { public DPSGeneratorEntity(EntityType<DPSGeneratorEntity> type, Level world) {
super(type, world); super(type, world);
this.noCulling = true; this.noCulling = true;
@ -114,21 +114,11 @@ public class DPSGeneratorEntity extends LivingEntity implements GeoEntity {
} }
@Override @Override
public boolean hurt(DamageSource source, float amount) { public boolean hurt(@NotNull DamageSource source, float amount) {
if (source.is(DamageTypes.IN_FIRE) damageDealt += amount;
|| source.getDirectEntity() instanceof ThrownPotion
|| source.getDirectEntity() instanceof AreaEffectCloud if (this.getHealth() < 0.01) {
|| source.is(DamageTypes.FALL) amount = 0;
|| source.is(DamageTypes.CACTUS)
|| source.is(DamageTypes.DROWN)
|| source.is(DamageTypes.LIGHTNING_BOLT)
|| source.is(DamageTypes.FALLING_ANVIL)
|| source.is(DamageTypes.DRAGON_BREATH)
|| source.is(DamageTypes.WITHER)
|| source.is(DamageTypes.WITHER_SKULL)
|| source.is(DamageTypes.MAGIC)
|| this.entityData.get(DOWN_TIME) > 0) {
return false;
} }
if (!this.level().isClientSide()) { if (!this.level().isClientSide()) {
@ -201,9 +191,9 @@ public class DPSGeneratorEntity extends LivingEntity implements GeoEntity {
// DPS显示 // DPS显示
if (getLastDamageSource() != null) { if (getLastDamageSource() != null) {
var attacker = getLastDamageSource().getEntity(); var attacker = getLastDamageSource().getEntity();
if (attacker instanceof Player player) { if (attacker instanceof Player player && !this.level().isClientSide) {
player.displayClientMessage(Component.translatable("tips.superbwarfare.dps_generator.dps", player.displayClientMessage(Component.translatable("tips.superbwarfare.dps_generator.dps",
FormatTool.format1DZ(damage * Math.pow(2, getGeneratorLevel()))), true); FormatTool.format1DZ(damageDealt)), true);
} }
} }
@ -229,6 +219,7 @@ public class DPSGeneratorEntity extends LivingEntity implements GeoEntity {
} }
} }
this.setHealth(this.getMaxHealth()); this.setHealth(this.getMaxHealth());
damageDealt = 0;
} }
} }