From 00f40884a6f38dad4436d689a98234c0d3c0bd31 Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Tue, 11 Mar 2025 01:26:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BD=BD=E5=85=B7=E6=AD=A6?= =?UTF-8?q?=E5=99=A8=E6=96=B9=E6=B3=95=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/overlay/HelicopterHudOverlay.java | 4 +- .../client/overlay/VehicleHudOverlay.java | 66 +++++++++++++------ .../entity/vehicle/Ah6Entity.java | 10 +-- .../entity/vehicle/Bmp2Entity.java | 24 +++---- .../entity/vehicle/Lav150Entity.java | 20 +++--- .../entity/vehicle/Mk42Entity.java | 4 +- .../entity/vehicle/Mle1934Entity.java | 6 +- .../entity/vehicle/Yx100Entity.java | 8 +-- .../vehicle/base/WeaponVehicleEntity.java | 14 ++-- .../entity/vehicle/weapon/VehicleWeapon.java | 3 +- .../event/ClientEventHandler.java | 14 ++-- .../superbwarfare/mixins/MinecraftMixin.java | 2 +- 12 files changed, 102 insertions(+), 73 deletions(-) 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 347f33ba2..bbfe1a454 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java @@ -118,7 +118,7 @@ public class HelicopterHudOverlay { w / 2 - 140, h / 2, 0x66FF00, false); if (mobileVehicle instanceof Ah6Entity ah6Entity) { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { double heat = 1 - ah6Entity.heat / 100.0F; 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 { @@ -186,7 +186,7 @@ public class HelicopterHudOverlay { poseStack.scale(0.75f, 0.75f, 1); if (mobileVehicle instanceof Ah6Entity ah6Entity) { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { double heat = ah6Entity.heat / 100.0F; 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 { 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 a814f7bf2..2c388ee1f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java @@ -117,7 +117,7 @@ public class VehicleHudOverlay { // // if (InventoryTool.hasCreativeAmmoBox(player) // && !(iVehicle instanceof CannonEntity -// || (iVehicle instanceof Ah6Entity ah6Entity && ah6Entity.getWeaponType(0) == 1)) +// || (iVehicle instanceof Ah6Entity ah6Entity && ah6Entity.getWeaponIndex(0) == 1)) // ) { // event.getGuiGraphics().drawString( // Minecraft.getInstance().font, @@ -169,7 +169,7 @@ public class VehicleHudOverlay { return Component.translatable("des.superbwarfare.tips.ammo_type.cal50").getString(); } if (iVehicle instanceof Ah6Entity ah6Entity) { - if (ah6Entity.getWeaponType(0) == 0) { + if (ah6Entity.getWeaponIndex(0) == 0) { return Component.translatable("des.superbwarfare.tips.ammo_type.20mm_cannon").getString(); } else { return Component.translatable("des.superbwarfare.tips.ammo_type.rocket").getString(); @@ -229,18 +229,18 @@ public class VehicleHudOverlay { // 不同武器种类的准星 if (weaponVehicle instanceof Yx100Entity) { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/tank_cannon_cross_ap.png"), k, l, 0, 0.0F, i, j, i, j); - } else if (weaponVehicle.getWeaponType(0) == 1) { + } else if (weaponVehicle.getWeaponIndex(0) == 1) { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/tank_cannon_cross_he.png"), k, l, 0, 0.0F, i, j, i, j); } } else { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_cannon_cross.png"), k, l, 0, 0.0F, i, j, i, j); - } else if (weaponVehicle.getWeaponType(0) == 1) { + } else if (weaponVehicle.getWeaponIndex(0) == 1) { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_gun_cross.png"), k, l, 0, 0.0F, i, j, i, j); - } else if (weaponVehicle.getWeaponType(0) == 2) { + } else if (weaponVehicle.getWeaponIndex(0) == 2) { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_missile_cross.png"), k, l, 0, 0.0F, i, j, i, j); } } @@ -260,7 +260,6 @@ public class VehicleHudOverlay { w / 2 + 160, h / 2 - 48, 0x66FF00, false); // 低电量警告 - if (mobileVehicle.getEnergy() < 0.02 * mobileVehicle.getMaxEnergy()) { guiGraphics.drawString(mc.font, Component.literal("NO POWER!"), w / 2 - 144, h / 2 + 14, -65536, false); @@ -299,9 +298,9 @@ public class VehicleHudOverlay { } // 武器名称 - //LAV-150 + // LAV-150 if (player.getVehicle() instanceof Lav150Entity lav) { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { double heat = 1 - lav.getEntityData().get(HEAT) / 100.0F; 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 { @@ -310,12 +309,12 @@ public class VehicleHudOverlay { } } - //BMP-2 + // BMP-2 if (player.getVehicle() instanceof Bmp2Entity bmp2) { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { double heat = 1 - bmp2.getEntityData().get(HEAT) / 100.0F; 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) { + } else if (weaponVehicle.getWeaponIndex(0) == 1) { double heat = 1 - bmp2.getEntityData().get(COAX_HEAT) / 100.0F; 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 { @@ -324,9 +323,9 @@ public class VehicleHudOverlay { } - //YX-100 + // YX-100 if (player.getVehicle() instanceof Yx100Entity yx100) { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { 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) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(AMMO))), w / 2 - 33, h - 65, 0x66FF00, false); @@ -357,7 +356,7 @@ public class VehicleHudOverlay { // LAV-150 if (weaponVehicle instanceof Lav150Entity lav1501) { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { double heat = lav1501.getEntityData().get(HEAT) / 100.0F; 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 { @@ -367,10 +366,10 @@ public class VehicleHudOverlay { } // BMP-2 if (weaponVehicle instanceof Bmp2Entity bmp201) { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { double heat = bmp201.getEntityData().get(HEAT) / 100.0F; 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) { + } else if (weaponVehicle.getWeaponIndex(0) == 1) { double heat2 = bmp201.getEntityData().get(COAX_HEAT) / 100.0F; 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 { @@ -379,7 +378,7 @@ public class VehicleHudOverlay { } // YX-100 if (weaponVehicle instanceof Yx100Entity yx100) { - if (weaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponIndex(0) == 0) { 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) + " " + (InventoryTool.hasCreativeAmmoBox(player) ? "∞" : yx100.getEntityData().get(AMMO))), 30, -9, -1, false); @@ -510,6 +509,35 @@ public class VehicleHudOverlay { var weapons = weaponVehicle.getAvailableWeapons(index); if (weapons.isEmpty()) return; + int weaponType = weaponVehicle.getWeaponIndex(index); + if (weaponType == -1) return; + + var pose = guiGraphics.pose(); + + pose.pushPose(); + + RenderSystem.disableDepthTest(); + RenderSystem.depthMask(false); + RenderSystem.enableBlend(); + RenderSystem.setShader(GameRenderer::getPositionTexShader); + RenderSystem.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + RenderSystem.setShaderColor(1, 1, 1, 1); + // TODO 实现载具武器HUD + int frameIndex = 0; + + for (int i = weapons.size() - 1; i >= 0 && i < 9; i--) { + ResourceLocation frame = ModUtils.loc("textures/screens/vehicle_weapon/frame_" + (i + 1) + ".png"); + + pose.pushPose(); + + preciseBlit(guiGraphics, frame, w - 85, h - frameIndex * 18 - 20, 100, 0, 0, 75, 16, 75, 16); + + pose.popPose(); + + frameIndex++; + } + + pose.popPose(); } } 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 dfe7df187..e779b26ce 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -245,7 +245,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity this.level().playSound(null, this, ModSounds.MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1); } - if (this.getWeaponType(0) == 0) { + if (this.getWeaponIndex(0) == 0) { this.entityData.set(AMMO, ammoCount); } else { this.entityData.set(AMMO, this.getEntityData().get(LOADED_ROCKET)); @@ -570,7 +570,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity Vector4f worldPositionRight; Vector4f worldPositionLeft; - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { if (this.cannotFire) return; x = 1.15f; @@ -635,7 +635,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new ShakeClientMessage(6, 5, 7, this.getX(), this.getEyeY(), this.getZ())); } } - } else if (getWeaponType(0) == 1 && this.getEntityData().get(LOADED_ROCKET) > 0) { + } else if (getWeaponIndex(0) == 1 && this.getEntityData().get(LOADED_ROCKET) > 0) { x = 1.7f; y = 0.62f - 1.45f; z = 0.8f; @@ -718,9 +718,9 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity @Override public boolean canShoot(Player player) { - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire; - } else if (getWeaponType(0) == 1) { + } else if (getWeaponIndex(0) == 1) { return this.entityData.get(AMMO) > 0; } return false; 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 ba4ecaca1..07fd9d3b1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -312,9 +312,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit this.level().playSound(null, this, ModSounds.BMP_MISSILE_RELOAD.get(), this.getSoundSource(), 1, 1); } - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { this.entityData.set(AMMO, countItem(ModItems.SMALL_SHELL.get())); - } else if (getWeaponType(0) == 1) { + } else if (getWeaponIndex(0) == 1) { this.entityData.set(AMMO, ammoCount); } else { this.entityData.set(AMMO, countItem(ModItems.WIRE_GUIDE_MISSILE.get())); @@ -332,7 +332,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit @Override public void vehicleShoot(Player player, int type) { Matrix4f transform = getBarrelTransform(); - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { if (this.cannotFire) return; float x = -0.1125f; float y = 0.174025f; @@ -370,7 +370,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit this.entityData.set(HEAT, this.entityData.get(HEAT) + 7); this.entityData.set(FIRE_ANIM, 3); this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1)); - } else if (getWeaponType(0) == 1) { + } else if (getWeaponIndex(0) == 1) { if (this.cannotFireCoax) return; float x = 0.1125f; float y = 0.174025f; @@ -414,7 +414,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit serverPlayer.playSound(ModSounds.M_60_VERYFAR.get(), 12, 1); } } - } else if (getWeaponType(0) == 2 && this.getEntityData().get(LOADED_MISSILE) > 0) { + } else if (getWeaponIndex(0) == 2 && this.getEntityData().get(LOADED_MISSILE) > 0) { Matrix4f transformT = getBarrelTransform(); Vector4f worldPosition = transformPosition(transformT, 0, 1, 0); @@ -683,11 +683,11 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit } private PlayState firePredicate(AnimationState event) { - if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponType(0) == 0) { + if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponIndex(0) == 0) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire")); } - if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponType(0) == 1) { + if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponIndex(0) == 1) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire2")); } @@ -716,9 +716,9 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit @Override public int mainGunRpm(Player player) { - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { return 250; - } else if (getWeaponType(0) == 1) { + } else if (getWeaponIndex(0) == 1) { return 750; } return 250; @@ -726,11 +726,11 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit @Override public boolean canShoot(Player player) { - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire; - } else if (getWeaponType(0) == 1) { + } else if (getWeaponIndex(0) == 1) { return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFireCoax; - } else if (getWeaponType(0) == 2) { + } else if (getWeaponIndex(0) == 2) { return (this.entityData.get(LOADED_MISSILE) > 0); } return false; 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 d128b710b..71ccb6a9a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -275,9 +275,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt return false; }).mapToInt(AmmoType.RIFLE::get).sum() + countItem(ModItems.RIFLE_AMMO.get()); - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { this.entityData.set(AMMO, countItem(ModItems.SMALL_SHELL.get())); - } else if (getWeaponType(0) == 1) { + } else if (getWeaponIndex(0) == 1) { this.entityData.set(AMMO, ammoCount); } } @@ -295,7 +295,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt boolean hasCreativeAmmo = InventoryTool.hasCreativeAmmoBox(player); Matrix4f transform = getBarrelTransform(); - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { if (this.cannotFire) return; float x = -0.0234375f; float y = 0f; @@ -334,7 +334,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt this.entityData.set(FIRE_ANIM, 3); this.getItemStacks().stream().filter(stack -> stack.is(ModItems.SMALL_SHELL.get())).findFirst().ifPresent(stack -> stack.shrink(1)); - } else if (getWeaponType(0) == 1) { + } else if (getWeaponIndex(0) == 1) { if (this.cannotFireCoax) return; float x = 0.3f; float y = 0.08f; @@ -624,11 +624,11 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt } private PlayState firePredicate(AnimationState event) { - if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponType(0) == 0) { + if (this.entityData.get(FIRE_ANIM) > 1 && getWeaponIndex(0) == 0) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire")); } - if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponType(0) == 1) { + if (this.entityData.get(FIRE_ANIM) > 0 && getWeaponIndex(0) == 1) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.lav.fire2")); } @@ -657,9 +657,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt @Override public int mainGunRpm(Player player) { - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { return 300; - } else if (getWeaponType(0) == 1) { + } else if (getWeaponIndex(0) == 1) { return 600; } return 300; @@ -667,9 +667,9 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt @Override public boolean canShoot(Player player) { - if (getWeaponType(0) == 0) { + if (getWeaponIndex(0) == 0) { return (this.entityData.get(AMMO) > 0 || InventoryTool.hasCreativeAmmoBox(player)) && !cannotFire; - } else if (getWeaponType(0) == 1) { + } else if (getWeaponIndex(0) == 1) { 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 bf2aa5fef..61f1f922d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mk42Entity.java @@ -132,7 +132,7 @@ 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; - setWeaponType(0, weaponType); + setWeaponIndex(0, weaponType); vehicleShoot(player, 0); } return InteractionResult.SUCCESS; @@ -266,7 +266,7 @@ public class Mk42Entity extends VehicleEntity implements GeoEntity, CannonEntity var isCreative = player.isCreative() || InventoryTool.hasCreativeAmmoBox(player); if (!isCreative) { - var ammo = getWeaponType(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get(); + var ammo = getWeaponIndex(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get(); var ammoCount = InventoryTool.countItem(player.getInventory().items, ammo); if (ammoCount <= 0) return; 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 95629e72e..df8b6dab5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Mle1934Entity.java @@ -136,7 +136,7 @@ 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; - setWeaponType(0, weaponType); + setWeaponIndex(0, weaponType); vehicleShoot(player, 0); } return InteractionResult.SUCCESS; @@ -282,7 +282,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt if (isCreative) { consumed = 2; } else { - var ammo = getWeaponType(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get(); + var ammo = getWeaponIndex(0) == 0 ? ModItems.AP_5_INCHES.get() : ModItems.HE_5_INCHES.get(); var ammoCount = InventoryTool.countItem(player.getInventory().items, ammo); // 尝试消耗两发弹药 @@ -298,7 +298,7 @@ public class Mle1934Entity extends VehicleEntity implements GeoEntity, CannonEnt int durability; boolean salvoShoot = consumed == 2; - if (getWeaponType(0) == 1) { + if (getWeaponIndex(0) == 1) { // HE hitDamage = VehicleConfig.MLE1934_HE_DAMAGE.get(); explosionRadius = VehicleConfig.MLE1934_HE_EXPLOSION_RADIUS.get(); 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 dd56d8e0f..e9a1a4d08 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -166,16 +166,16 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti public void addAdditionalSaveData(CompoundTag compound) { super.addAdditionalSaveData(compound); compound.putInt("LoadedAmmo", this.entityData.get(LOADED_AMMO)); - compound.putInt("WeaponType", getWeaponType(0)); - compound.putInt("PassengerWeaponType", getWeaponType(1)); + compound.putInt("WeaponType", getWeaponIndex(0)); + compound.putInt("PassengerWeaponType", getWeaponIndex(1)); } @Override public void readAdditionalSaveData(CompoundTag compound) { super.readAdditionalSaveData(compound); this.entityData.set(LOADED_AMMO, compound.getInt("LoadedAmmo")); - setWeaponType(0, compound.getInt("WeaponType")); - setWeaponType(1, compound.getInt("PassengerWeaponType")); + setWeaponIndex(0, compound.getInt("WeaponType")); + setWeaponIndex(1, compound.getInt("PassengerWeaponType")); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java index 40a7dc21f..e0d3bcdd8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java @@ -38,11 +38,11 @@ public interface WeaponVehicleEntity extends ArmedVehicleEntity { if (weapons.isEmpty()) return; var count = weapons.size(); - var typeIndex = isScroll ? (value + getWeaponType(index) + count) % count : value; + var typeIndex = isScroll ? (value + getWeaponIndex(index) + count) % count : value; var weapon = weapons.get(typeIndex); // 修改该槽位选择的武器 - setWeaponType(index, typeIndex); + setWeaponIndex(index, typeIndex); // 播放武器切换音效 var sound = weapon.sound; @@ -92,19 +92,19 @@ public interface WeaponVehicleEntity extends ArmedVehicleEntity { var weapons = getAvailableWeapons(index); if (weapons.isEmpty()) return null; - var type = getWeaponType(index); + var type = getWeaponIndex(index); if (type < 0 || type >= weapons.size()) return null; return weapons.get(type); } /** - * 获取该槽位当前的武器类型,返回-1则表示该位置没有可用武器 + * 获取该槽位当前的武器编号,返回-1则表示该位置没有可用武器 * * @param index 武器槽位 * @return 武器类型 */ - default int getWeaponType(int index) { + default int getWeaponIndex(int index) { if (!(this instanceof VehicleEntity vehicle)) return -1; var selectedWeapons = vehicle.getEntityData().get(VehicleEntity.SELECTED_WEAPON); @@ -114,12 +114,12 @@ public interface WeaponVehicleEntity extends ArmedVehicleEntity { } /** - * 设置该槽位当前的武器类型 + * 设置该槽位当前的武器编号 * * @param index 武器槽位 * @param type 武器类型 */ - default void setWeaponType(int index, int type) { + default void setWeaponIndex(int index, int type) { if (!(this instanceof VehicleEntity vehicle)) return; var selectedWeapons = vehicle.getEntityData().get(VehicleEntity.SELECTED_WEAPON).toIntArray(); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java index 4d3612bab..1186eab7c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/weapon/VehicleWeapon.java @@ -1,5 +1,6 @@ package com.atsuishio.superbwarfare.entity.vehicle.weapon; +import com.atsuishio.superbwarfare.ModUtils; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; @@ -8,7 +9,7 @@ import net.minecraft.world.item.Item; public abstract class VehicleWeapon { // 武器的图标 - public ResourceLocation icon; + public ResourceLocation icon = ModUtils.loc("textures/screens/vehicle_weapon/empty.png"); // 武器的名称 public Component name; // 武器使用的弹药类型 diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index 1f44f30d5..7582c2265 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -740,33 +740,33 @@ public class ClientEventHandler { if (iVehicle instanceof Ah6Entity ah6Entity) { float pitch = ah6Entity.heat <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - ah6Entity.heat)); - if (ah6Entity.getWeaponType(0) == 0) { + if (ah6Entity.getWeaponIndex(0) == 0) { ah6Entity.heat += 5; player.playSound(ModSounds.HELICOPTER_CANNON_FIRE_1P.get(), 1f, pitch); - } else if (ah6Entity.getWeaponType(0) == 1) { + } else if (ah6Entity.getWeaponIndex(0) == 1) { player.playSound(ModSounds.HELICOPTER_ROCKET_FIRE_1P.get(), 1f, 1); } } if (iVehicle instanceof Lav150Entity lav150) { - if (lav150.getWeaponType(0) == 0) { + if (lav150.getWeaponIndex(0) == 0) { float pitch = lav150.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(HEAT))); player.playSound(ModSounds.LAV_CANNON_FIRE_1P.get(), 1f, pitch); player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } else if (lav150.getWeaponType(0) == 1) { + } else if (lav150.getWeaponIndex(0) == 1) { float pitch = lav150.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - lav150.getEntityData().get(COAX_HEAT))); player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch); } } if (iVehicle instanceof Bmp2Entity bmp2) { - if (bmp2.getWeaponType(0) == 0) { + if (bmp2.getWeaponIndex(0) == 0) { float pitch = bmp2.getEntityData().get(HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(HEAT))); player.playSound(ModSounds.BMP_CANNON_FIRE_1P.get(), 1f, pitch); player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); - } else if (bmp2.getWeaponType(0) == 1) { + } else if (bmp2.getWeaponIndex(0) == 1) { float pitch = bmp2.getEntityData().get(COAX_HEAT) <= 60 ? 1 : (float) (1 - 0.011 * Math.abs(60 - bmp2.getEntityData().get(COAX_HEAT))); player.playSound(ModSounds.COAX_FIRE_1P.get(), 1f, pitch); - } else if (bmp2.getWeaponType(0) == 2) { + } else if (bmp2.getWeaponIndex(0) == 2) { player.playSound(ModSounds.BMP_MISSILE_FIRE_1P.get(), 1f, 1); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/MinecraftMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/MinecraftMixin.java index 699778968..7ae5e4161 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/MinecraftMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/MinecraftMixin.java @@ -70,7 +70,7 @@ public class MinecraftMixin { // 数字键 武器切换 if (!Screen.hasShiftDown() && weaponVehicle.hasWeapon(seatIndex) - && weaponVehicle.getWeaponType(seatIndex) != index) { + && weaponVehicle.getWeaponIndex(seatIndex) != index) { ModUtils.PACKET_HANDLER.sendToServer(new SwitchVehicleWeaponMessage(seatIndex, index, false)); } }