From cd6837fd460c6bc5e191db4cc13c2ce7ee81890e Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Mon, 10 Mar 2025 19:10:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/overlay/AmmoBarOverlay.java | 3 +- .../client/overlay/HelicopterHudOverlay.java | 33 +------ .../client/overlay/VehicleHudOverlay.java | 31 +++--- .../client/overlay/VehicleMgHudOverlay.java | 6 +- .../entity/vehicle/Ah6Entity.java | 15 ++- .../entity/vehicle/Bmp2Entity.java | 17 ++-- .../entity/vehicle/Lav150Entity.java | 11 +-- .../entity/vehicle/Mk42Entity.java | 2 +- .../entity/vehicle/Mle1934Entity.java | 2 +- .../entity/vehicle/SpeedboatEntity.java | 9 +- .../entity/vehicle/Yx100Entity.java | 98 ++++++------------- .../base/ContainerMobileVehicleEntity.java | 9 ++ .../event/ClientEventHandler.java | 4 +- .../superbwarfare/event/GunEventHandler.java | 7 +- .../event/LivingEventHandler.java | 2 +- .../event/PlayerEventHandler.java | 3 +- .../network/message/ShootMessage.java | 5 +- .../superbwarfare/tools/InventoryTool.java | 54 +++++++++- 18 files changed, 152 insertions(+), 159 deletions(-) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/AmmoBarOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/AmmoBarOverlay.java index 1abff9f66..723a95b01 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/AmmoBarOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/AmmoBarOverlay.java @@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.tools.GunsTool; +import com.atsuishio.superbwarfare.tools.InventoryTool; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; @@ -36,7 +37,7 @@ public class AmmoBarOverlay { private static boolean hasCreativeAmmo() { Player player = Minecraft.getInstance().player; if (player == null) return false; - return player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + return InventoryTool.hasCreativeAmmoBox(player); } @SubscribeEvent(priority = EventPriority.NORMAL) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java index 73e5e1cb7..347f33ba2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java @@ -8,9 +8,9 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.tools.FormatTool; +import com.atsuishio.superbwarfare.tools.InventoryTool; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; @@ -36,7 +36,6 @@ import org.joml.Matrix4f; import org.joml.Vector4f; import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; -import static com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay.*; @Mod.EventBusSubscriber(value = Dist.CLIENT) public class HelicopterHudOverlay { @@ -121,7 +120,7 @@ public class HelicopterHudOverlay { if (mobileVehicle instanceof Ah6Entity ah6Entity) { if (weaponVehicle.getWeaponType(0) == 0) { double heat = 1 - ah6Entity.heat / 100.0F; - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : iHelicopterEntity.getAmmoCount(player))), w / 2 - 160, h / 2 - 60, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : iHelicopterEntity.getAmmoCount(player))), w / 2 - 160, h / 2 - 60, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); } else { guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("70MM ROCKET " + iHelicopterEntity.getAmmoCount(player)), w / 2 - 160, h / 2 - 60, 0x66FF00, false); } @@ -189,7 +188,7 @@ public class HelicopterHudOverlay { if (mobileVehicle instanceof Ah6Entity ah6Entity) { if (weaponVehicle.getWeaponType(0) == 0) { double heat = ah6Entity.heat / 100.0F; - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : iHelicopterEntity.getAmmoCount(player))), 25, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : iHelicopterEntity.getAmmoCount(player))), 25, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); } else { guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("70MM ROCKET " + iHelicopterEntity.getAmmoCount(player)), 25, -9, -1, false); } @@ -210,31 +209,7 @@ public class HelicopterHudOverlay { } private static void renderKillIndicator(GuiGraphics guiGraphics, float posX, float posY) { - float rate = (40 - KILL_INDICATOR * 5) / 5.5f; - - if (HIT_INDICATOR > 0) { - preciseBlit(guiGraphics, ModUtils.loc("textures/screens/hit_marker.png"), posX, posY, 0, 0, 16, 16, 16, 16); - } - - if (VEHICLE_INDICATOR > 0) { - preciseBlit(guiGraphics, ModUtils.loc("textures/screens/hit_marker_vehicle.png"), posX, posY, 0, 0, 16, 16, 16, 16); - } - - if (HEAD_INDICATOR > 0) { - preciseBlit(guiGraphics, ModUtils.loc("textures/screens/headshot_mark.png"), posX, posY, 0, 0, 16, 16, 16, 16); - } - - if (KILL_INDICATOR > 0) { - float posX1 = posX - 2 + rate; - float posY1 = posY - 2 + rate; - float posX2 = posX + 2 - rate; - float posY2 = posY + 2 - rate; - - preciseBlit(guiGraphics, ModUtils.loc("textures/screens/kill_mark1.png"), posX1, posY1, 0, 0, 16, 16, 16, 16); - preciseBlit(guiGraphics, ModUtils.loc("textures/screens/kill_mark2.png"), posX2, posY1, 0, 0, 16, 16, 16, 16); - preciseBlit(guiGraphics, ModUtils.loc("textures/screens/kill_mark3.png"), posX1, posY2, 0, 0, 16, 16, 16, 16); - preciseBlit(guiGraphics, ModUtils.loc("textures/screens/kill_mark4.png"), posX2, posY2, 0, 0, 16, 16, 16, 16); - } + VehicleHudOverlay.renderKillIndicator3P(guiGraphics, posX, posY); } private static void renderDriverAngle(GuiGraphics guiGraphics, Player player, Entity heli, float k, float l, float i, float j) { diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java index 0b5e8d0b0..3f3bc6b80 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java @@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.*; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.tools.FormatTool; +import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.SeekTool; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; @@ -114,7 +115,7 @@ public class VehicleHudOverlay { // poseStack.scale(1.5f, 1.5f, 1f); // float v = h / 1.5f - (iCharge ? 42 : 29) / 1.5f; // -// if (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) +// if (InventoryTool.hasCreativeAmmoBox(player) // && !(iVehicle instanceof CannonEntity // || (iVehicle instanceof Ah6Entity ah6Entity && ah6Entity.getWeaponType(0) == 1)) // ) { @@ -302,10 +303,10 @@ public class VehicleHudOverlay { if (player.getVehicle() instanceof Lav150Entity lav) { if (weaponVehicle.getWeaponType(0) == 0) { double heat = 1 - lav.getEntityData().get(HEAT) / 100.0F; - guiGraphics.drawString(mc.font, Component.literal("20MM CANNON " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : lav.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); + guiGraphics.drawString(mc.font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : lav.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); } else { double heat = 1 - lav.getEntityData().get(COAX_HEAT) / 100.0F; - guiGraphics.drawString(mc.font, Component.literal("7.62MM COAX " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : lav.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); + guiGraphics.drawString(mc.font, Component.literal("7.62MM COAX " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : lav.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); } } @@ -313,12 +314,12 @@ public class VehicleHudOverlay { if (player.getVehicle() instanceof Bmp2Entity bmp2) { if (weaponVehicle.getWeaponType(0) == 0) { double heat = 1 - bmp2.getEntityData().get(HEAT) / 100.0F; - guiGraphics.drawString(mc.font, Component.literal(" 30MM 2A42 " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : bmp2.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); + guiGraphics.drawString(mc.font, Component.literal(" 30MM 2A42 " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : bmp2.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); } else if (weaponVehicle.getWeaponType(0) == 1) { double heat = 1 - bmp2.getEntityData().get(COAX_HEAT) / 100.0F; - guiGraphics.drawString(mc.font, Component.literal(" 7.62MM ПКТ " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : bmp2.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); + guiGraphics.drawString(mc.font, Component.literal(" 7.62MM ПКТ " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : bmp2.getAmmoCount(player))), w / 2 - 33, h - 65, Mth.hsvToRgb((float) heat / 3.745318352059925F, 1.0F, 1.0F), false); } else { - guiGraphics.drawString(mc.font, Component.literal(" 9M113 " + bmp2.getEntityData().get(LOADED_MISSILE) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : bmp2.getAmmoCount(player))), w / 2 - 33, h - 65, 0x66FF00, false); + guiGraphics.drawString(mc.font, Component.literal(" 9M113 " + bmp2.getEntityData().get(LOADED_MISSILE) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : bmp2.getAmmoCount(player))), w / 2 - 33, h - 65, 0x66FF00, false); } } @@ -326,9 +327,9 @@ public class VehicleHudOverlay { //YX-100 if (player.getVehicle() instanceof Yx100Entity yx100) { if (weaponVehicle.getWeaponType(0) == 0) { - guiGraphics.drawString(mc.font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false); + guiGraphics.drawString(mc.font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false); } else { - guiGraphics.drawString(mc.font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false); + guiGraphics.drawString(mc.font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false); } } @@ -358,30 +359,30 @@ public class VehicleHudOverlay { if (weaponVehicle instanceof Lav150Entity lav1501) { if (weaponVehicle.getWeaponType(0) == 0) { double heat = lav1501.getEntityData().get(HEAT) / 100.0F; - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : lav1501.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("20MM CANNON " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : lav1501.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); } else { double heat2 = lav1501.getEntityData().get(COAX_HEAT) / 100.0F; - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("7.62MM COAX " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : lav1501.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat2, 1.0F), false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("7.62MM COAX " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : lav1501.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat2, 1.0F), false); } } // BMP-2 if (weaponVehicle instanceof Bmp2Entity bmp201) { if (weaponVehicle.getWeaponType(0) == 0) { double heat = bmp201.getEntityData().get(HEAT) / 100.0F; - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("30MM 2A42 " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : bmp201.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("30MM 2A42 " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : bmp201.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); } else if (weaponVehicle.getWeaponType(0) == 1) { double heat2 = bmp201.getEntityData().get(COAX_HEAT) / 100.0F; - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("7.62MM ПКТ " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : bmp201.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat2, 1.0F), false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("7.62MM ПКТ " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : bmp201.getAmmoCount(player))), 30, -9, Mth.hsvToRgb(0F, (float) heat2, 1.0F), false); } else { - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("9M113 " + bmp201.getEntityData().get(LOADED_MISSILE) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : bmp201.getAmmoCount(player))), 30, -9, -1, false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("9M113 " + bmp201.getEntityData().get(LOADED_MISSILE) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : bmp201.getAmmoCount(player))), 30, -9, -1, false); } } // YX-100 if (weaponVehicle instanceof Yx100Entity yx100) { if (weaponVehicle.getWeaponType(0) == 0) { - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("AP SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false); } else { - guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false); + guiGraphics.drawString(Minecraft.getInstance().font, Component.literal("HE SHELL " + yx100.getAmmoCount(player) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java index 421321b40..e9edf7147 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleMgHudOverlay.java @@ -8,8 +8,8 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.tools.FormatTool; +import com.atsuishio.superbwarfare.tools.InventoryTool; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; @@ -97,13 +97,13 @@ public class VehicleMgHudOverlay { // YX-100 if (player.getVehicle() instanceof Yx100Entity yx100) { double heat = yx100.getEntityData().get(MACHINE_GUN_HEAT) / 100.0F; - guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : yx100.getEntityData().get(MG_AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); + guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(MG_AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); } // 快艇 if (player.getVehicle() instanceof SpeedboatEntity speedboat) { double heat = speedboat.getEntityData().get(HEAT) / 100.0F; - guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())) ? "∞" : speedboat.getEntityData().get(AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); + guiGraphics.drawString(mc.font, Component.literal(".50 HMG " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : speedboat.getEntityData().get(AMMO))), 30, -9, Mth.hsvToRgb(0F, (float) heat, 1.0F), false); } double heal = 1 - mobileVehicle.getHealth() / mobileVehicle.getMaxHealth(); 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 1d8044acc..a2c846d66 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -14,10 +14,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.ProjectileWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.AmmoType; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.ParticleTool; -import com.atsuishio.superbwarfare.tools.SoundTool; +import com.atsuishio.superbwarfare.tools.*; import com.google.common.collect.Lists; import com.mojang.math.Axis; import net.minecraft.core.BlockPos; @@ -237,10 +234,10 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity return false; }).mapToInt(AmmoType.HEAVY::get).sum() + countItem(ModItems.HEAVY_AMMO.get()); - if ((countItem(ModItems.ROCKET_70.get()) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && reloadCoolDown == 0 && this.getEntityData().get(LOADED_ROCKET) < 14) { + if ((hasItem(ModItems.ROCKET_70.get()) || InventoryTool.hasCreativeAmmoBox(player)) && reloadCoolDown == 0 && this.getEntityData().get(LOADED_ROCKET) < 14) { this.entityData.set(LOADED_ROCKET, this.getEntityData().get(LOADED_ROCKET) + 1); reloadCoolDown = 25; - if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + if (!InventoryTool.hasCreativeAmmoBox(player)) { this.getItemStacks().stream().filter(stack -> stack.is(ModItems.ROCKET_70.get())).findFirst().ifPresent(stack -> stack.shrink(1)); } this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1); @@ -517,7 +514,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity @Override public void vehicleShoot(Player player, int type) { - boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + boolean hasCreativeAmmo = InventoryTool.hasCreativeAmmoBox(player); Matrix4f transform = getVehicleTransform(); float x; @@ -545,7 +542,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity (float) 0.2); this.level().addFreshEntity(projectileRight); sendParticle((ServerLevel) this.level(), ParticleTypes.LARGE_SMOKE, worldPositionRight.x, worldPositionRight.y, worldPositionRight.z, 1, 0, 0, 0, 0, false); - if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + if (!InventoryTool.hasCreativeAmmoBox(player)) { this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1)); } } @@ -676,7 +673,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity @Override public boolean canShoot(Player player) { if (getWeaponType(0) == 0) { - return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; + return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire; } else if (getWeaponType(0) == 1) { return this.entityData.get(AMMO) > 0; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java index 3ee4be100..ba4ecaca1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -13,10 +13,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.WgMissileWeapon; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.AmmoType; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.ParticleTool; -import com.atsuishio.superbwarfare.tools.SoundTool; +import com.atsuishio.superbwarfare.tools.*; import com.mojang.math.Axis; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; @@ -304,12 +301,12 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit return false; }).mapToInt(AmmoType.RIFLE::get).sum() + countItem(ModItems.RIFLE_AMMO.get()); - if ((countItem(ModItems.WIRE_GUIDE_MISSILE.get()) > 0 - || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) + if ((hasItem(ModItems.WIRE_GUIDE_MISSILE.get()) + || InventoryTool.hasCreativeAmmoBox(player)) && this.reloadCoolDown <= 0 && this.getEntityData().get(LOADED_MISSILE) < 1) { this.entityData.set(LOADED_MISSILE, this.getEntityData().get(LOADED_MISSILE) + 1); this.reloadCoolDown = 160; - if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + if (!InventoryTool.hasCreativeAmmoBox(player)) { this.getItemStacks().stream().filter(stack -> stack.is(ModItems.WIRE_GUIDE_MISSILE.get())).findFirst().ifPresent(stack -> stack.shrink(1)); } this.level().playSound(null, this, ModSounds.BMP_MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1); @@ -380,7 +377,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit float z = 2f; Vector4f worldPosition = transformPosition(transform, x, y, z); - boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + boolean hasCreativeAmmo = InventoryTool.hasCreativeAmmoBox(player); if (this.entityData.get(AMMO) > 0 || hasCreativeAmmo) { var projectileRight = ((ProjectileWeapon) getWeapon(0)).create(player); @@ -730,9 +727,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit @Override public boolean canShoot(Player player) { if (getWeaponType(0) == 0) { - return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; + return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire; } else if (getWeaponType(0) == 1) { - return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax; + return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFireCoax; } else if (getWeaponType(0) == 2) { return (this.entityData.get(LOADED_MISSILE) > 0); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java index aff2aa605..d128b710b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -12,10 +12,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.SmallCannonShellWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.AmmoType; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.ParticleTool; -import com.atsuishio.superbwarfare.tools.SoundTool; +import com.atsuishio.superbwarfare.tools.*; import com.mojang.math.Axis; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; @@ -295,7 +292,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt @Override public void vehicleShoot(Player player, int type) { - boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + boolean hasCreativeAmmo = InventoryTool.hasCreativeAmmoBox(player); Matrix4f transform = getBarrelTransform(); if (getWeaponType(0) == 0) { @@ -671,9 +668,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt @Override public boolean canShoot(Player player) { if (getWeaponType(0) == 0) { - return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; + return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire; } else if (getWeaponType(0) == 1) { - return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFireCoax; + return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFireCoax; } return false; } 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 2ec3de7d8..bf2aa5fef 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -263,7 +263,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity Level level = player.level(); if (level instanceof ServerLevel server) { - var isCreative = player.isCreative() || InventoryTool.countItem(player.getInventory().items, ModItems.CREATIVE_AMMO_BOX.get()) > 0; + var isCreative = player.isCreative() || InventoryTool.hasCreativeAmmoBox(player); if (!isCreative) { var ammo = getWeaponType(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get(); 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 04725c11a..95629e72e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -276,7 +276,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt Level level = player.level(); if (level instanceof ServerLevel server) { - var isCreative = player.isCreative() || InventoryTool.countItem(player.getInventory().items, ModItems.CREATIVE_AMMO_BOX.get()) > 0; + var isCreative = player.isCreative() || InventoryTool.hasCreativeAmmoBox(player); int consumed; if (isCreative) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java index 4588ab284..bed12123a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -13,10 +13,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.AmmoType; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.ParticleTool; -import com.atsuishio.superbwarfare.tools.SoundTool; +import com.atsuishio.superbwarfare.tools.*; import com.mojang.math.Axis; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; @@ -284,7 +281,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo this.entityData.set(HEAT, this.entityData.get(HEAT) + 4); this.entityData.set(FIRE_ANIM, 3); - boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + boolean hasCreativeAmmo = InventoryTool.hasCreativeAmmoBox(player); if (!hasCreativeAmmo) { ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { @@ -545,7 +542,7 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo @Override public boolean canShoot(Player player) { - return (this.entityData.get(AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) + return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java index 7137fe6de..f673c82c1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -12,10 +12,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.ProjectileWeapon; import com.atsuishio.superbwarfare.entity.vehicle.weapon.VehicleWeapon; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; -import com.atsuishio.superbwarfare.tools.AmmoType; -import com.atsuishio.superbwarfare.tools.CustomExplosion; -import com.atsuishio.superbwarfare.tools.ParticleTool; -import com.atsuishio.superbwarfare.tools.SoundTool; +import com.atsuishio.superbwarfare.tools.*; import com.mojang.math.Axis; import net.minecraft.client.CameraType; import net.minecraft.client.Minecraft; @@ -39,7 +36,6 @@ 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.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Explosion; import net.minecraft.world.level.Level; @@ -114,7 +110,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public VehicleWeapon[][] getAllWeapons() { - // TODO 正确实现武器创建 return new VehicleWeapon[][]{ new VehicleWeapon[]{ // AP @@ -214,11 +209,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.playSound(ModSounds.BMP_STEP.get(), Mth.abs(this.entityData.get(POWER)) * 8, random.nextFloat() * 0.15f + 1f); } - @Override - public double getSubmergedHeight(Entity entity) { - return super.getSubmergedHeight(entity); - } - @Override public void baseTick() { turretYRotO = this.getTurretYRot(); @@ -324,36 +314,29 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti this.refreshDimensions(); } - private Item getCurrentAmmoItem() { - return switch (getWeaponType(0)) { - case 0 -> ModItems.AP_5_INCHES.get(); - case 1 -> ModItems.HE_5_INCHES.get(); - default -> throw new IllegalStateException("Unexpected value: " + getWeaponType(0)); - }; - } private void handleAmmo() { boolean hasCreativeAmmo = false; if (this.getFirstPassenger() instanceof Player player) { - hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + hasCreativeAmmo = InventoryTool.hasCreativeAmmoBox(player); } if (hasCreativeAmmo) { this.entityData.set(AMMO, 9999); this.entityData.set(MG_AMMO, 9999); } else { - this.entityData.set(AMMO, countItem(getCurrentAmmoItem())); - this.entityData.set(MG_AMMO, countItem(ModItems.HEAVY_AMMO.get())); + this.entityData.set(AMMO, countItem(getWeapon(0).ammo)); + this.entityData.set(MG_AMMO, countItem(getWeapon(1).ammo)); } if (this.getEntityData().get(LOADED_AMMO) == 0 && reloadCoolDown <= 0 - && (hasCreativeAmmo || countItem(getCurrentAmmoItem()) > 0) + && (hasCreativeAmmo || hasItem(getWeapon(0).ammo)) ) { this.entityData.set(LOADED_AMMO, 1); if (!hasCreativeAmmo) { - consumeItem(getCurrentAmmoItem(), 1); + consumeItem(getWeapon(0).ammo, 1); } } } @@ -484,21 +467,19 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } } - boolean hasCreativeAmmo = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + if (hasItem(ModItems.CREATIVE_AMMO_BOX.get())) return; - if (!hasCreativeAmmo) { - ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { - if (stack.is(ModItems.AMMO_BOX.get())) { - return AmmoType.HEAVY.get(stack) > 0; - } - return false; - }).findFirst().orElse(ItemStack.EMPTY); - - if (!ammoBox.isEmpty()) { - AmmoType.HEAVY.add(ammoBox, -1); - } else { - this.getItemStacks().stream().filter(stack -> stack.is(ModItems.HEAVY_AMMO.get())).findFirst().ifPresent(stack -> stack.shrink(1)); + ItemStack ammoBox = this.getItemStacks().stream().filter(stack -> { + if (stack.is(ModItems.AMMO_BOX.get())) { + return AmmoType.HEAVY.get(stack) > 0; } + return false; + }).findFirst().orElse(ItemStack.EMPTY); + + if (!ammoBox.isEmpty()) { + AmmoType.HEAVY.add(ammoBox, -1); + } else { + consumeItem(getWeapon(1).ammo, 1); } } } @@ -749,19 +730,15 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti int i = this.getOrderedPassengers().indexOf(passenger); - if (i == 0) { - Vector4f worldPosition = transformPosition(transform, 0.8669625f, -1.3f, 0.6076875f); - passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); - callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); - } else if (i == 1) { - Vector4f worldPosition = transformPosition(transform, -0.87890625f, -1f, -0.6640625f); - passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); - callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); - } else if (i == 2) { - Vector4f worldPosition = transformPosition(transform, 1f, 0.15f, -0.6640625f); - passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); - callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); - } + var worldPosition = switch (i) { + case 0 -> transformPosition(transform, 0.8669625f, -1.3f, 0.6076875f); + case 1 -> transformPosition(transform, -0.87890625f, -1f, -0.6640625f); + case 2 -> transformPosition(transform, 1f, 0.15f, -0.6640625f); + default -> throw new IllegalStateException("Unexpected value: " + i); + }; + + passenger.setPos(worldPosition.x, worldPosition.y, worldPosition.z); + callback.accept(passenger, worldPosition.x, worldPosition.y, worldPosition.z); } public int getMaxPassengers() { @@ -868,7 +845,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti } @Override - public void onPassengerTurned(Entity entity) { + public void onPassengerTurned(@NotNull Entity entity) { this.clampRotation(entity); } @@ -923,8 +900,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public boolean canShoot(Player player) { return switch (getSeatIndex(player)) { case 0 -> this.entityData.get(LOADED_AMMO) > 0; - case 1 -> - (this.entityData.get(MG_AMMO) > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) && !cannotFire; + case 1 -> (this.entityData.get(MG_AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire; default -> false; }; } @@ -936,22 +912,12 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti @Override public boolean banHand(Player player) { - if (player == getNthEntity(0) || player == getNthEntity(1)) { - return true; - } else if (player == getNthEntity(2)) { - return false; - } - return false; + return hidePassenger(player); } @Override public boolean hidePassenger(Entity entity) { - if (entity == getNthEntity(0) || entity == getNthEntity(1)) { - return true; - } else if (entity == getNthEntity(2)) { - return false; - } - return false; + return entity == getNthEntity(0) || entity == getNthEntity(1); } @Override @@ -965,8 +931,8 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti if (index != 0) return; if (entityData.get(LOADED_AMMO) > 0) { - if (this.getFirstPassenger() instanceof Player player && !player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { - this.insertItem(getCurrentAmmoItem(), 1); + if (this.getFirstPassenger() instanceof Player player && !InventoryTool.hasCreativeAmmoBox(player)) { + this.insertItem(getWeapon(0).ammo, 1); } entityData.set(LOADED_AMMO, 0); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ContainerMobileVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ContainerMobileVehicleEntity.java index cb973541f..a1c625e15 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ContainerMobileVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/ContainerMobileVehicleEntity.java @@ -143,6 +143,15 @@ public abstract class ContainerMobileVehicleEntity extends MobileVehicleEntity i return InventoryTool.countItem(this.getItemStacks(), item); } + /** + * 判断载具内是否包含指定物品 + * + * @param item 物品类型 + */ + public boolean hasItem(Item item) { + return countItem(item) > 0; + } + /** * 消耗载具内指定物品 * diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index fa28480c4..1f44f30d5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -454,7 +454,7 @@ public class ClientEventHandler { && !player.isSprinting() && stack.getOrCreateTag().getDouble("overheat") == 0 && !player.getCooldowns().isOnCooldown(stack.getItem()) && miniGunRot >= 20 - && ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0 || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) + && ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0 || InventoryTool.hasCreativeAmmoBox(player)) ))) { if (mode == 0) { if (clientTimer.getProgress() == 0) { @@ -570,7 +570,7 @@ public class ClientEventHandler { var tag = stack.getOrCreateTag(); if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0 - || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + || InventoryTool.hasCreativeAmmoBox(player)) { var perk = PerkHelper.getPerkByType(stack, Perk.Type.AMMO); float pitch = tag.getDouble("heat") <= 40 ? 1 : (float) (1 - 0.025 * Math.abs(40 - tag.getDouble("heat"))); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java index 58e28e7ed..d185a0b63 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java @@ -15,6 +15,7 @@ import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.GunsTool; +import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; @@ -584,7 +585,7 @@ public class GunEventHandler { // 一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段 if ((tag.getDouble("prepare") == 1 || tag.getDouble("prepare_load") == 1)) { - if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + if (!InventoryTool.hasCreativeAmmoBox(player)) { var capability = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()); if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && capability.shotgunAmmo == 0) { tag.putBoolean("force_stage3_start", true); @@ -666,7 +667,7 @@ public class GunEventHandler { } // 备弹耗尽结束 - if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + if (!InventoryTool.hasCreativeAmmoBox(player)) { var capability = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()); if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && capability.shotgunAmmo == 0) { tag.putInt("reload_stage", 3); @@ -721,7 +722,7 @@ public class GunEventHandler { GunsTool.setGunIntTag(stack, "Ammo", GunsTool.getGunIntTag(stack, "Ammo", 0) + 1); - if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + if (!InventoryTool.hasCreativeAmmoBox(player)) { if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO)) { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { capability.shotgunAmmo -= 1; diff --git a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java index 935362bef..3c8211566 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java @@ -644,7 +644,7 @@ public class LivingEventHandler { int ammoReload = (int) Math.min(mag, mag * rate); int ammoNeed = Math.min(mag - ammo, ammoReload); - boolean flag = player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get())); + boolean flag = InventoryTool.hasCreativeAmmoBox(player); if (stack.is(ModTags.Items.USE_RIFLE_AMMO)) { int ammoFinal = Math.min(capability.rifleAmmo, ammoNeed); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java index f01f95d85..0ec98fb2a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java @@ -9,6 +9,7 @@ import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.network.message.SimulationDistanceMessage; import com.atsuishio.superbwarfare.tools.AmmoType; import com.atsuishio.superbwarfare.tools.GunsTool; +import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; @@ -287,7 +288,7 @@ public class PlayerEventHandler { for (ItemStack stack : player.getInventory().items) { if (stack.is(ModTags.Items.GUN)) { - if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + if (!InventoryTool.hasCreativeAmmoBox(player)) { var cap = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()); if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && cap.shotgunAmmo > 0) { diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/ShootMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/ShootMessage.java index 2caa1e676..d734b95db 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/ShootMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/ShootMessage.java @@ -10,6 +10,7 @@ import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.tools.GunsTool; +import com.atsuishio.superbwarfare.tools.InventoryTool; import com.atsuishio.superbwarfare.tools.ParticleTool; import com.atsuishio.superbwarfare.tools.SoundTool; import net.minecraft.core.particles.ParticleTypes; @@ -104,7 +105,7 @@ public class ShootMessage { var tag = stack.getOrCreateTag(); if ((player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables())).rifleAmmo > 0 - || player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + || InventoryTool.hasCreativeAmmoBox(player)) { tag.putDouble("heat", (tag.getDouble("heat") + 0.1)); if (tag.getDouble("heat") >= 50.5) { tag.putDouble("overheat", 40); @@ -129,7 +130,7 @@ public class ShootMessage { } GunEventHandler.gunShoot(player, spared); - if (!player.getInventory().hasAnyMatching(s -> s.is(ModItems.CREATIVE_AMMO_BOX.get()))) { + if (!InventoryTool.hasCreativeAmmoBox(player)) { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { capability.rifleAmmo = player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).rifleAmmo - 1; capability.syncPlayerVariables(player); diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/InventoryTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/InventoryTool.java index a41a1a230..058d79bed 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/InventoryTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/InventoryTool.java @@ -1,6 +1,8 @@ package com.atsuishio.superbwarfare.tools; +import com.atsuishio.superbwarfare.init.ModItems; import net.minecraft.core.NonNullList; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.NotNull; @@ -11,8 +13,8 @@ public class InventoryTool { /** * 计算物品列表内指定物品的数量 * - * @param item 物品类型 - * @return 物品数量 + * @param itemList 物品列表 + * @param item 物品类型 */ public static int countItem(NonNullList itemList, @NotNull Item item) { return itemList.stream() @@ -21,6 +23,54 @@ public class InventoryTool { .sum(); } + /** + * 计算玩家背包内指定物品的数量 + * + * @param player 玩家 + * @param item 物品类型 + */ + public static int countItem(Player player, @NotNull Item item) { + return countItem(player.getInventory().items, item); + } + + /** + * 判断玩家背包内是否有指定物品 + * + * @param player 玩家 + * @param item 物品类型 + */ + public static boolean hasItem(Player player, @NotNull Item item) { + return countItem(player, item) > 0; + } + + /** + * 判断物品列表内是否有指定物品 + * + * @param itemList 物品列表 + * @param item 物品类型 + */ + public static boolean hasItem(NonNullList itemList, @NotNull Item item) { + return countItem(itemList, item) > 0; + } + + /** + * 判断物品列表内是否有创造模式弹药盒 + * + * @param itemList 物品列表 + */ + public static boolean hasCreativeAmmoBox(NonNullList itemList) { + return countItem(itemList, ModItems.CREATIVE_AMMO_BOX.get()) > 0; + } + + /** + * 判断玩家背包内是否有创造模式弹药盒 + * + * @param player 玩家 + */ + public static boolean hasCreativeAmmoBox(Player player) { + return hasItem(player, ModItems.CREATIVE_AMMO_BOX.get()); + } + /** * 消耗物品列表内指定物品 *