From 73fbb55a68228b539d14547cf5db0002989a8912 Mon Sep 17 00:00:00 2001 From: Atsuishio <842960157@qq.com> Date: Sat, 12 Jul 2025 00:13:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E7=81=AB=E7=82=AE=E5=BC=80?= =?UTF-8?q?=E7=81=AB=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entity/vehicle/Mk42Entity.java | 21 ++++++++++++++---- .../entity/vehicle/Mle1934Entity.java | 22 ++++++++++++++++--- .../entity/vehicle/MortarEntity.java | 10 +++++++-- 3 files changed, 44 insertions(+), 9 deletions(-) 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 a9ac0ca78..13c55c872 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -14,6 +14,7 @@ import com.atsuishio.superbwarfare.event.ClientMouseHandler; 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.item.ArtilleryIndicator; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; @@ -136,7 +137,6 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity public @NotNull InteractionResult interact(Player player, @NotNull InteractionHand hand) { ItemStack stack = player.getMainHandItem(); - if (stack.getItem() instanceof ArtilleryIndicator indicator) { if (indicator.addCannon(stack, getStringUUID())) { if (player instanceof ServerPlayer serverPlayer) { @@ -155,15 +155,28 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity } } - if (stack.getItem() instanceof CannonShellItem) { - if (this.entityData.get(COOL_DOWN) == 0) { - var weaponType = stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1; + if (stack.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) { + if (this.stack.getItem() instanceof CannonShellItem) { + var weaponType = this.stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1; setWeaponIndex(0, weaponType); vehicleShoot(player, 0); } return InteractionResult.SUCCESS; } + if (stack.getItem() instanceof CannonShellItem) { + if (this.entityData.get(COOL_DOWN) == 0 && this.stack.isEmpty()) { + this.stack = stack.copyWithCount(1); + if (!player.isCreative()) { + stack.shrink(1); + } + if (player instanceof ServerPlayer serverPlayer) { + SoundTool.playLocalSound(serverPlayer, ModSounds.CANNON_RELOAD.get(), 2, 1); + } + } + return InteractionResult.SUCCESS; + } + if (player.getMainHandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) { if (setTarget(player.getMainHandItem())) { player.swing(InteractionHand.MAIN_HAND); 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 d32b71d63..3b977b18e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -14,6 +14,7 @@ import com.atsuishio.superbwarfare.event.ClientMouseHandler; 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.item.ArtilleryIndicator; import com.atsuishio.superbwarfare.item.common.ammo.CannonShellItem; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; @@ -48,6 +49,7 @@ import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; +import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.event.EventHooks; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -158,15 +160,29 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt } } - if (stack.getItem() instanceof CannonShellItem) { - if (this.entityData.get(COOL_DOWN) == 0) { - var weaponType = stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1; + if (stack.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) { + if (this.stack.getItem() instanceof CannonShellItem) { + var weaponType = this.stack.is(ModItems.AP_5_INCHES.get()) ? 0 : 1; setWeaponIndex(0, weaponType); vehicleShoot(player, 0); } return InteractionResult.SUCCESS; } + if (stack.getItem() instanceof CannonShellItem) { + var itemHandler = this.getCapability(Capabilities.ItemHandler.ENTITY); + if (itemHandler != null && this.entityData.get(COOL_DOWN) == 0 && (stack.getItem() == this.stack.getItem() || this.stack.isEmpty())) { + itemHandler.insertItem(0, stack.copyWithCount(1), false); + if (!player.isCreative()) { + stack.shrink(1); + } + if (player instanceof ServerPlayer serverPlayer) { + SoundTool.playLocalSound(serverPlayer, ModSounds.CANNON_RELOAD.get(), 2, 1); + } + } + return InteractionResult.SUCCESS; + } + if (player.getMainHandItem().getItem() == ModItems.FIRING_PARAMETERS.get()) { if (setTarget(player.getMainHandItem())) { player.swing(InteractionHand.MAIN_HAND); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java index ca2258dcc..605128e4e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MortarEntity.java @@ -153,12 +153,18 @@ public class MortarEntity extends VehicleEntity implements GeoEntity, Container } } - if (mainHandItem.getItem() instanceof MortarShell && !player.isShiftKeyDown() && this.entityData.get(FIRE_TIME) == 0) { + if (mainHandItem.is(ModTags.Items.CROWBAR) && !player.isShiftKeyDown()) { + if (this.stack.getItem() instanceof MortarShell) { + fire(player); + } + return InteractionResult.SUCCESS; + } + + if (mainHandItem.getItem() instanceof MortarShell && !player.isShiftKeyDown() && this.entityData.get(FIRE_TIME) == 0 && stack.isEmpty()) { this.stack = mainHandItem.copyWithCount(1); if (!player.isCreative()) { mainHandItem.shrink(1); } - fire(player); }