From 535e7a130520ebf567c64b5b71785fb10d29b206 Mon Sep 17 00:00:00 2001 From: Atsuishio <842960157@qq.com> Date: Mon, 12 May 2025 16:43:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0A10=E5=BC=95=E6=93=8E?= =?UTF-8?q?=E7=9D=80=E7=81=AB=E7=89=B9=E6=95=88,A10=E5=92=8C=E5=B0=8F?= =?UTF-8?q?=E9=B8=9F=E6=94=AF=E6=8C=81=E6=89=8B=E5=8A=A8=E6=8C=82=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/A10Entity.java | 103 +++++++++++++++++- .../entity/vehicle/Ah6Entity.java | 17 +++ .../entity/vehicle/base/VehicleEntity.java | 2 +- 3 files changed, 117 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/A10Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/A10Entity.java index a60248106..a695aa41e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/A10Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/A10Entity.java @@ -8,10 +8,7 @@ import com.atsuishio.superbwarfare.entity.projectile.MortarShellEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.*; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.entity.vehicle.weapon.*; -import com.atsuishio.superbwarfare.init.ModDamageTypes; -import com.atsuishio.superbwarfare.init.ModItems; -import com.atsuishio.superbwarfare.init.ModSounds; -import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.*; import com.mojang.math.Axis; @@ -27,13 +24,17 @@ 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.SoundEvents; 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.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -51,6 +52,7 @@ import software.bernie.geckolib.animation.AnimatableManager; import software.bernie.geckolib.util.GeckoLibUtil; import java.util.Comparator; +import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; @@ -181,6 +183,39 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity .reduce(7); } + @Override + public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) { + ItemStack stack = player.getMainHandItem(); + if (stack.getItem() == ModItems.ROCKET_70.get() && this.entityData.get(LOADED_ROCKET) < 28) { + // 装载火箭 + this.entityData.set(LOADED_ROCKET, this.entityData.get(LOADED_ROCKET) + 1); + if (!player.isCreative()) { + stack.shrink(1); + } + this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 2, 1); + return InteractionResult.sidedSuccess(this.level().isClientSide()); + } + if (stack.getItem() == ModItems.MEDIUM_AERIAL_BOMB.get() && this.entityData.get(LOADED_BOMB) < 3) { + // 装载航弹 + this.entityData.set(LOADED_BOMB, this.entityData.get(LOADED_BOMB) + 1); + if (!player.isCreative()) { + stack.shrink(1); + } + this.level().playSound(null, this, ModSounds.BOMB_RELOAD.get(), this.getSoundSource(), 2, 1); + return InteractionResult.sidedSuccess(this.level().isClientSide()); + } + if (stack.getItem() == ModItems.AGM.get() && this.entityData.get(LOADED_MISSILE) < 4) { + // 装载导弹 + this.entityData.set(LOADED_MISSILE, this.entityData.get(LOADED_MISSILE) + 1); + if (!player.isCreative()) { + stack.shrink(1); + } + this.level().playSound(null, this, ModSounds.BOMB_RELOAD.get(), this.getSoundSource(), 2, 1); + return InteractionResult.sidedSuccess(this.level().isClientSide()); + } + return super.interact(player, hand); + } + @Override public void baseTick() { lockingTargetO = getTargetUuid(); @@ -244,6 +279,66 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity this.refreshDimensions(); } + @Override + public void lowHealthWarning() { + Matrix4f transform = this.getVehicleTransform(1); + if (this.getHealth() <= 0.4 * this.getMaxHealth()) { + List entities = getPlayer(level()); + for (var e : entities) { + if (e instanceof ServerPlayer player) { + if (player.level() instanceof ServerLevel serverLevel) { + Vector4f position = transformPosition(transform, -1.603125f, 0.875f, -5.0625f); + sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true); + } + } + } + } + + if (this.level() instanceof ServerLevel serverLevel) { + if (this.getHealth() <= 0.25 * this.getMaxHealth()) { + playLowHealthParticle(serverLevel); + } + if (this.getHealth() <= 0.15 * this.getMaxHealth()) { + playLowHealthParticle(serverLevel); + } + } + + if (this.getHealth() <= 0.1 * this.getMaxHealth()) { + List entities = getPlayer(level()); + for (var e : entities) { + if (e instanceof ServerPlayer player) { + if (player.level() instanceof ServerLevel serverLevel) { + Vector4f position = transformPosition(transform, -1.603125f, 0.875f, -5.0625f); + sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true); + sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true); + sendParticle(serverLevel, ParticleTypes.FLAME, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true); + sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true); + Vector4f position2 = transformPosition(transform, 1.603125f, 0.875f, -5.0625f); + sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, position2.x, position2.y, position2.z, 5, 0.25, 0.25, 0.25, 0, true); + sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, position2.x, position2.y, position2.z, 5, 0.25, 0.25, 0.25, 0, true); + sendParticle(serverLevel, ParticleTypes.FLAME, position2.x, position2.y, position2.z, 5, 0.25, 0.25, 0.25, 0, true); + sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), position2.x, position2.y, position2.z, 5, 0.25, 0.25, 0.25, 0, true); + } + } + } + if (this.level() instanceof ServerLevel serverLevel) { + ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 2, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true); + ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 2, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true); + ParticleTool.sendParticle(serverLevel, ParticleTypes.FLAME, this.getX(), this.getY() + 0.85f * getBbHeight(), this.getZ(), 4, 0.35 * this.getBbWidth(), 0.12 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.05, true); + ParticleTool.sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), this.getX(), this.getY() + 0.85f * getBbHeight(), this.getZ(), 4, 0.1 * this.getBbWidth(), 0.05 * this.getBbHeight(), 0.1 * this.getBbWidth(), 0.4, true); + } + if (this.tickCount % 15 == 0) { + this.level().playSound(null, this.getOnPos(), SoundEvents.FIRE_AMBIENT, SoundSource.PLAYERS, 1, 1); + } + } + + if (this.getHealth() < 0.1f * this.getMaxHealth() && tickCount % 13 == 0) { + this.level().playSound(null, this.getOnPos(), ModSounds.NO_HEALTH.get(), SoundSource.PLAYERS, 1, 1); + } else if (this.getHealth() >= 0.1f && this.getHealth() < 0.4f * this.getMaxHealth() && tickCount % 10 == 0) { + this.level().playSound(null, this.getOnPos(), ModSounds.LOW_HEALTH.get(), SoundSource.PLAYERS, 1, 1); + } + } + public void terrainCompactA10() { if (onGround()) { Matrix4f transform = this.getWheelsTransform(1); 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 caa89817c..8b737d72e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -30,6 +30,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Mth; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.damagesource.DamageTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; @@ -169,6 +171,21 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity .reduce(2); } + @Override + public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) { + ItemStack stack = player.getMainHandItem(); + if (stack.getItem() == ModItems.ROCKET_70.get() && this.entityData.get(LOADED_ROCKET) < 14) { + // 装载火箭 + this.entityData.set(LOADED_ROCKET, this.entityData.get(LOADED_ROCKET) + 1); + if (!player.isCreative()) { + stack.shrink(1); + } + this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 2, 1); + return InteractionResult.sidedSuccess(this.level().isClientSide()); + } + return super.interact(player, hand); + } + @Override public void baseTick() { super.baseTick(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java index 0d7c3fd0b..de02d5626 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/VehicleEntity.java @@ -672,7 +672,7 @@ public abstract class VehicleEntity extends Entity { } } - private void playLowHealthParticle(ServerLevel serverLevel) { + public void playLowHealthParticle(ServerLevel serverLevel) { ParticleTool.sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 1, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true); ParticleTool.sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, this.getX(), this.getY() + 0.7f * getBbHeight(), this.getZ(), 1, 0.35 * this.getBbWidth(), 0.15 * this.getBbHeight(), 0.35 * this.getBbWidth(), 0.01, true); }