From 27d59709a5c5bd9bb439ff7a8cace42e2805b519 Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Wed, 5 Mar 2025 04:04:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E8=AE=BE=E8=AE=A1MultiWeapon?= =?UTF-8?q?VehicleEntity=EF=BC=8C=E6=AD=A3=E7=A1=AE=E5=A4=84=E7=90=86?= =?UTF-8?q?=E7=9E=84=E5=87=86=E9=9F=B3=E6=95=88=E6=92=AD=E6=94=BE=E5=88=A4?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../superbwarfare/client/ClickHandler.java | 6 ++-- .../client/overlay/HelicopterHudOverlay.java | 8 ++--- .../client/overlay/VehicleHudOverlay.java | 36 +++++++++---------- .../entity/vehicle/Ah6Entity.java | 4 +-- .../entity/vehicle/Bmp2Entity.java | 4 +-- .../entity/vehicle/Lav150Entity.java | 4 +-- .../entity/vehicle/SpeedboatEntity.java | 8 ++++- .../entity/vehicle/Yx100Entity.java | 4 +-- .../entity/vehicle/base/CannonEntity.java | 3 +- ...leEntity.java => WeaponVehicleEntity.java} | 14 +++++--- .../event/ClientEventHandler.java | 4 +-- .../message/SwitchVehicleWeaponMessage.java | 6 ++-- .../network/message/ZoomMessage.java | 26 +++++++++----- 13 files changed, 74 insertions(+), 53 deletions(-) rename src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/{MultiWeaponVehicleEntity.java => WeaponVehicleEntity.java} (70%) diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index d3ca29696..587a2af22 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -154,11 +154,11 @@ public class ClickHandler { double scroll = event.getScrollDelta(); - // 未按下shift时,为有多武器的载具切换武器 + // 未按下shift时,为有武器的载具切换武器 if (!Screen.hasShiftDown() && player.getVehicle() instanceof VehicleEntity vehicle - && vehicle instanceof MultiWeaponVehicleEntity multiWeaponVehicle - && multiWeaponVehicle.hasWeapon(vehicle.getSeatIndex(player)) + && vehicle instanceof WeaponVehicleEntity weaponVehicle + && weaponVehicle.hasWeapon(vehicle.getSeatIndex(player)) ) { int index = vehicle.getSeatIndex(player); ModUtils.PACKET_HANDLER.sendToServer(new SwitchVehicleWeaponMessage(index, -scroll)); 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 246a7cebb..5e6aaf194 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java @@ -5,8 +5,8 @@ import com.atsuishio.superbwarfare.client.RenderHelper; import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity; import com.atsuishio.superbwarfare.entity.vehicle.base.HelicopterEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity; 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; @@ -62,7 +62,7 @@ public class HelicopterHudOverlay { if (player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).orElse(new ModVariables.PlayerVariables()).edit) return; - if (player.getVehicle() instanceof HelicopterEntity iHelicopterEntity && player.getVehicle() instanceof MobileVehicleEntity mobileVehicle && iHelicopterEntity.isDriver(player) && player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle) { + if (player.getVehicle() instanceof HelicopterEntity iHelicopterEntity && player.getVehicle() instanceof MobileVehicleEntity mobileVehicle && iHelicopterEntity.isDriver(player) && player.getVehicle() instanceof WeaponVehicleEntity weaponVehicle) { poseStack.pushPose(); poseStack.translate(-6 * ClientEventHandler.turnRot[1], -6 * ClientEventHandler.turnRot[0], 0); @@ -119,7 +119,7 @@ public class HelicopterHudOverlay { w / 2 - 140, h / 2, 0x66FF00, false); if (mobileVehicle instanceof Ah6Entity ah6Entity) { - if (multiWeaponVehicle.getWeaponType(0) == 0) { + 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); } else { @@ -187,7 +187,7 @@ public class HelicopterHudOverlay { poseStack.scale(0.75f, 0.75f, 1); if (mobileVehicle instanceof Ah6Entity ah6Entity) { - if (multiWeaponVehicle.getWeaponType(0) == 0) { + 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); } 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 f411b5e6e..4c18f8e58 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java @@ -187,7 +187,7 @@ public class VehicleHudOverlay { if (player == null) return; if (player.getVehicle() instanceof LandArmorEntity iLand && iLand.isDriver(player) - && iLand instanceof MultiWeaponVehicleEntity multiWeaponVehicle + && iLand instanceof WeaponVehicleEntity weaponVehicle && iLand instanceof MobileVehicleEntity mobileVehicle) { poseStack.pushPose(); @@ -218,19 +218,19 @@ public class VehicleHudOverlay { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2f + 112, h - 71, 0, 0.0F, 1, 16, 1, 16); // 不同武器种类的准星 - if (multiWeaponVehicle instanceof Yx100Entity) { - if (multiWeaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle instanceof Yx100Entity) { + if (weaponVehicle.getWeaponType(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 (multiWeaponVehicle.getWeaponType(0) == 1) { + } else if (weaponVehicle.getWeaponType(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 (multiWeaponVehicle.getWeaponType(0) == 0) { + if (weaponVehicle.getWeaponType(0) == 0) { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_cannon_cross.png"), k, l, 0, 0.0F, i, j, i, j); - } else if (multiWeaponVehicle.getWeaponType(0) == 1) { + } else if (weaponVehicle.getWeaponType(0) == 1) { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_gun_cross.png"), k, l, 0, 0.0F, i, j, i, j); - } else if (multiWeaponVehicle.getWeaponType(0) == 2) { + } else if (weaponVehicle.getWeaponType(0) == 2) { preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_missile_cross.png"), k, l, 0, 0.0F, i, j, i, j); } } @@ -288,7 +288,7 @@ public class VehicleHudOverlay { // 武器名称 //LAV-150 if (player.getVehicle() instanceof Lav150Entity lav) { - if (multiWeaponVehicle.getWeaponType(0) == 0) { + 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); } else { @@ -299,10 +299,10 @@ public class VehicleHudOverlay { //BMP-2 if (player.getVehicle() instanceof Bmp2Entity bmp2) { - if (multiWeaponVehicle.getWeaponType(0) == 0) { + 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); - } else if (multiWeaponVehicle.getWeaponType(0) == 1) { + } 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); } else { @@ -313,7 +313,7 @@ public class VehicleHudOverlay { //YX-100 if (player.getVehicle() instanceof Yx100Entity yx100) { - if (multiWeaponVehicle.getWeaponType(0) == 0) { + 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); } 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); @@ -344,8 +344,8 @@ public class VehicleHudOverlay { poseStack.scale(0.75f, 0.75f, 1); //LAV-150 - if (multiWeaponVehicle instanceof Lav150Entity lav1501) { - if (multiWeaponVehicle.getWeaponType(0) == 0) { + 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); } else { @@ -354,11 +354,11 @@ public class VehicleHudOverlay { } } //BMP-2 - if (multiWeaponVehicle instanceof Bmp2Entity bmp201) { - if (multiWeaponVehicle.getWeaponType(0) == 0) { + 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); - } else if (multiWeaponVehicle.getWeaponType(0) == 1) { + } 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); } else { @@ -366,8 +366,8 @@ public class VehicleHudOverlay { } } //YX-100 - if (multiWeaponVehicle instanceof Yx100Entity yx100) { - if (multiWeaponVehicle.getWeaponType(0) == 0) { + 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); } 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); 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 6745eff7f..f4368d46c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -8,7 +8,7 @@ import com.atsuishio.superbwarfare.entity.projectile.HeliRocketEntity; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.HelicopterEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; @@ -60,7 +60,7 @@ import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; -public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity, HelicopterEntity, MultiWeaponVehicleEntity { +public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity, HelicopterEntity, WeaponVehicleEntity { private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); public static final float MAX_HEALTH = VehicleConfig.AH_6_HP.get(); 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 f1fb64484..8c840490a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -8,7 +8,7 @@ import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity; import com.atsuishio.superbwarfare.entity.projectile.WgMissileEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; @@ -59,7 +59,7 @@ import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; -public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, MultiWeaponVehicleEntity { +public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity { public static final EntityDataAccessor FIRE_ANIM = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.FLOAT); 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 a4b0d3a08..26574fc29 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -7,7 +7,7 @@ import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.projectile.SmallCannonShellEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; @@ -61,7 +61,7 @@ import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; -public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, MultiWeaponVehicleEntity { +public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity { public static final EntityDataAccessor FIRE_ANIM = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(Lav150Entity.class, EntityDataSerializers.FLOAT); 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 0e1e85650..c393c3120 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -6,6 +6,7 @@ import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.ModVariables; @@ -51,7 +52,7 @@ import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; -public class SpeedboatEntity extends ContainerMobileVehicleEntity implements GeoEntity, ArmedVehicleEntity { +public class SpeedboatEntity extends ContainerMobileVehicleEntity implements GeoEntity, ArmedVehicleEntity, WeaponVehicleEntity { public static final EntityDataAccessor FIRE_ANIM = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.INT); public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(SpeedboatEntity.class, EntityDataSerializers.FLOAT); @@ -535,4 +536,9 @@ public class SpeedboatEntity extends ContainerMobileVehicleEntity implements Geo public ResourceLocation getVehicleIcon() { return ModUtils.loc("textures/vehicle_icon/speedboat_icon.png"); } + + @Override + public int getWeaponType(int index) { + return index == 0 ? 0 : -1; + } } 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 0f68c69cb..321df78d4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Yx100Entity.java @@ -6,7 +6,7 @@ import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.projectile.CannonShellEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.ContainerMobileVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.LandArmorEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.damage.DamageModifier; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; @@ -65,7 +65,7 @@ import java.util.List; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; -public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, MultiWeaponVehicleEntity { +public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEntity, LandArmorEntity, WeaponVehicleEntity { public static final EntityDataAccessor FIRE_ANIM = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor DELTA_ROT = SynchedEntityData.defineId(Yx100Entity.class, EntityDataSerializers.FLOAT); diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/CannonEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/CannonEntity.java index 58c23f576..50c4fe3b2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/CannonEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/CannonEntity.java @@ -1,5 +1,4 @@ package com.atsuishio.superbwarfare.entity.vehicle.base; -public interface CannonEntity extends ArmedVehicleEntity { - +public interface CannonEntity extends ArmedVehicleEntity, WeaponVehicleEntity { } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MultiWeaponVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java similarity index 70% rename from src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MultiWeaponVehicleEntity.java rename to src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java index b7e8c3723..b55cb8c85 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/MultiWeaponVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/base/WeaponVehicleEntity.java @@ -1,6 +1,9 @@ package com.atsuishio.superbwarfare.entity.vehicle.base; -public interface MultiWeaponVehicleEntity extends ArmedVehicleEntity { +/** + * 拥有任意武器的载具 + */ +public interface WeaponVehicleEntity extends ArmedVehicleEntity { /** * 检测该槽位是否有可用武器 * @@ -17,7 +20,8 @@ public interface MultiWeaponVehicleEntity extends ArmedVehicleEntity { * @param index 武器槽位 * @param scroll 滚动值,-1~1之间的整数 */ - void changeWeapon(int index, int scroll); + default void changeWeapon(int index, int scroll) { + } /** * 获取该槽位当前的武器类型,返回-1则表示该位置没有可用武器 @@ -26,7 +30,8 @@ public interface MultiWeaponVehicleEntity extends ArmedVehicleEntity { * @return 武器类型 */ default int getWeaponType(int index) { - return -1; + // 默认认为只有第一个位置拥有一个武器 + return index == 0 ? 0 : -1; } /** @@ -36,5 +41,6 @@ public interface MultiWeaponVehicleEntity extends ArmedVehicleEntity { * @param type 武器类型 */ - void setWeaponType(int index, int type); + default void setWeaponType(int index, int type) { + } } diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index f3ba57e66..926ab6d1e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -6,8 +6,8 @@ import com.atsuishio.superbwarfare.config.client.DisplayConfig; import com.atsuishio.superbwarfare.entity.vehicle.*; import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.network.ModVariables; @@ -737,7 +737,7 @@ public class ClientEventHandler { player.playSound(ModSounds.SHELL_CASING_50CAL.get(), 0.3f, 1); } - if (iVehicle instanceof MultiWeaponVehicleEntity) { + if (iVehicle instanceof WeaponVehicleEntity) { 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) { diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/SwitchVehicleWeaponMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/SwitchVehicleWeaponMessage.java index 198b24b8d..f4479244b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/SwitchVehicleWeaponMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/SwitchVehicleWeaponMessage.java @@ -1,6 +1,6 @@ package com.atsuishio.superbwarfare.network.message; -import com.atsuishio.superbwarfare.entity.vehicle.base.MultiWeaponVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; @@ -34,8 +34,8 @@ public class SwitchVehicleWeaponMessage { return; } - if (player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle && multiWeaponVehicle.isDriver(player)) { - multiWeaponVehicle.changeWeapon(message.index, Mth.clamp(message.scroll > 0 ? Mth.ceil(message.scroll) : Mth.floor(message.scroll), -1, 1)); + if (player.getVehicle() instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.isDriver(player)) { + weaponVehicle.changeWeapon(message.index, Mth.clamp(message.scroll > 0 ? Mth.ceil(message.scroll) : Mth.floor(message.scroll), -1, 1)); } }); context.get().setPacketHandled(true); diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/ZoomMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/ZoomMessage.java index 15336ebf3..181c571dc 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/ZoomMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/ZoomMessage.java @@ -1,8 +1,8 @@ package com.atsuishio.superbwarfare.network.message; import com.atsuishio.superbwarfare.ModUtils; -import com.atsuishio.superbwarfare.entity.vehicle.WheelChairEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.network.ModVariables; @@ -38,6 +38,9 @@ public class ZoomMessage { ServerPlayer player = context.getSender(); if (player == null) return; + var vehicle = player.getVehicle(); + // 缩放音效播放条件: 载具是武器载具,且该位置有可用武器 + if (message.type == 0) { player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { capability.zoom = true; @@ -45,9 +48,12 @@ public class ZoomMessage { capability.syncPlayerVariables(player); }); - if (player.isPassenger() && player.getVehicle() instanceof ArmedVehicleEntity && !(player.getVehicle() instanceof WheelChairEntity)) { - SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1); - } + if (player.isPassenger() + && vehicle instanceof WeaponVehicleEntity weaponEntity + && vehicle instanceof VehicleEntity vehicleEntity + && weaponEntity.hasWeapon(vehicleEntity.getSeatIndex(player)) + ) SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_IN.get(), 2, 1); + } if (message.type == 1) { @@ -57,9 +63,12 @@ public class ZoomMessage { capability.syncPlayerVariables(player); }); - if (player.isPassenger() && player.getVehicle() instanceof ArmedVehicleEntity && !(player.getVehicle() instanceof WheelChairEntity)) { - SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1); - } + if (player.isPassenger() + && vehicle instanceof WeaponVehicleEntity weaponEntity + && vehicle instanceof VehicleEntity vehicleEntity + && weaponEntity.hasWeapon(vehicleEntity.getSeatIndex(player)) + ) SoundTool.playLocalSound(player, ModSounds.CANNON_ZOOM_OUT.get(), 2, 1); + if (player.getMainHandItem().getItem() == ModItems.JAVELIN.get()) { var handItem = player.getMainHandItem(); @@ -74,4 +83,5 @@ public class ZoomMessage { }); context.setPacketHandled(true); } + }