diff --git a/src/main/java/com/atsuishio/superbwarfare/ModUtils.java b/src/main/java/com/atsuishio/superbwarfare/ModUtils.java index f85d93000..e2ca06fc4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/ModUtils.java +++ b/src/main/java/com/atsuishio/superbwarfare/ModUtils.java @@ -169,6 +169,7 @@ public class ModUtils { addNetworkMessage(ShowChargingRangeMessage.class, ShowChargingRangeMessage::encode, ShowChargingRangeMessage::decode, ShowChargingRangeMessage::handler); addNetworkMessage(MeleeAttackMessage.class, MeleeAttackMessage::encode, MeleeAttackMessage::decode, MeleeAttackMessage::handler); addNetworkMessage(ResetCameraTypeMessage.class, ResetCameraTypeMessage::encode, ResetCameraTypeMessage::decode, ResetCameraTypeMessage::handler, Optional.of(NetworkDirection.PLAY_TO_CLIENT)); + addNetworkMessage(SwitchVehicleWeaponMessage.class, SwitchVehicleWeaponMessage::encode, SwitchVehicleWeaponMessage::decode, SwitchVehicleWeaponMessage::handler); event.enqueueWork(() -> BrewingRecipeRegistry.addRecipe(Ingredient.of(PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.WATER)), Ingredient.of(Items.LIGHTNING_ROD), PotionUtils.setPotion(new ItemStack(Items.POTION), ModPotion.SHOCK.get()))); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index 6094cdc04..a554a50e8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -5,10 +5,7 @@ import com.atsuishio.superbwarfare.compat.CompatHolder; import com.atsuishio.superbwarfare.compat.clothconfig.ClothConfigHelper; import com.atsuishio.superbwarfare.config.client.ReloadConfig; import com.atsuishio.superbwarfare.entity.MortarEntity; -import com.atsuishio.superbwarfare.entity.vehicle.IArmedVehicleEntity; -import com.atsuishio.superbwarfare.entity.vehicle.ICannonEntity; -import com.atsuishio.superbwarfare.entity.vehicle.MobileVehicleEntity; -import com.atsuishio.superbwarfare.entity.vehicle.VehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.*; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.gun.GunItem; @@ -155,6 +152,11 @@ public class ClickHandler { double scroll = event.getScrollDelta(); + if (player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle && multiWeaponVehicle.isDriver(player)) { + ModUtils.PACKET_HANDLER.sendToServer(new SwitchVehicleWeaponMessage(-scroll)); + event.setCanceled(true); + } + if (stack.is(ModTags.Items.GUN) && ClientEventHandler.zoom) { var tag = stack.getOrCreateTag(); if (GunsTool.getGunBooleanTag(stack, "CanSwitchScope", false)) { 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 a3cd1f4f8..b708fac52 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/VehicleHudOverlay.java @@ -209,10 +209,19 @@ public class VehicleHudOverlay { int addW = (w / h) * 48; int addH = (w / h) * 27; preciseBlit(guiGraphics, FRAME, (float) -addW / 2, (float) -addH / 2, 10, 0, 0.0F, w + addW, h + addH, w + addW, h + addH); - preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_cross.png"), k, l, 0, 0.0F, i, j, i, j); preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 - 64, h - 56, 0, 0.0F, 128, 1, 128, 1); preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/line.png"), w / 2 + 112, h - 71, 0, 0.0F, 1, 16, 1, 16); + //不同武器种类的准星 + + if (multiWeaponVehicle.getWeaponType() == 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() == 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() == 2) { + preciseBlit(guiGraphics, ModUtils.loc("textures/screens/land/lav_missile_cross.png"), k, l, 0, 0.0F, i, j, i, j); + } + //指南针 preciseBlit(guiGraphics, ModUtils.loc("textures/screens/compass.png"), (float) w / 2 - 128, (float) 10, 128 + ((float) 64 / 45 * player.getYRot()), 0, 256, 16, 512, 16); @@ -277,7 +286,6 @@ public class VehicleHudOverlay { 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); } - } if (player.getVehicle() instanceof Bmp2Entity bmp2) { 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 49b075c55..27ddbbe1d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Ah6Entity.java @@ -761,15 +761,21 @@ public class Ah6Entity extends ContainerMobileEntity implements GeoEntity, IHeli } @Override - public void changeWeapon() { -// entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + 1); + public void changeWeapon(int scroll) { + entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + scroll); if (entityData.get(WEAPON_TYPE) == 0) { this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); - entityData.set(WEAPON_TYPE, 1); - } else if (entityData.get(WEAPON_TYPE) == 1) { - entityData.set(WEAPON_TYPE, 0); + } + if (entityData.get(WEAPON_TYPE) == 1) { this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1); } + + if (entityData.get(WEAPON_TYPE) <= -1) { + entityData.set(WEAPON_TYPE, 1); + } + if (entityData.get(WEAPON_TYPE) >= 2) { + entityData.set(WEAPON_TYPE, 0); + } } @Override 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 a8b3119eb..1961880c5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -812,17 +812,25 @@ public class Bmp2Entity extends ContainerMobileEntity implements GeoEntity, ICha } @Override - public void changeWeapon() { + public void changeWeapon(int scroll) { + entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + scroll); + if (entityData.get(WEAPON_TYPE) == 0) { this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); - entityData.set(WEAPON_TYPE, 1); - } else if (entityData.get(WEAPON_TYPE) == 1) { - entityData.set(WEAPON_TYPE, 2); + } + if (entityData.get(WEAPON_TYPE) == 1) { this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1); - } else if (entityData.get(WEAPON_TYPE) == 2) { - entityData.set(WEAPON_TYPE, 0); + } + if (entityData.get(WEAPON_TYPE) == 2) { this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); } + + if (entityData.get(WEAPON_TYPE) <= -1) { + entityData.set(WEAPON_TYPE, 2); + } + if (entityData.get(WEAPON_TYPE) >= 3) { + entityData.set(WEAPON_TYPE, 0); + } } @Override 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 84dac656b..5dd123e97 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Lav150Entity.java @@ -778,14 +778,21 @@ public class Lav150Entity extends ContainerMobileEntity implements GeoEntity, IC } @Override - public void changeWeapon() { + public void changeWeapon(int scroll) { + entityData.set(WEAPON_TYPE, entityData.get(WEAPON_TYPE) + scroll); if (entityData.get(WEAPON_TYPE) == 0) { this.level().playSound(null, this, ModSounds.INTO_MISSILE.get(), this.getSoundSource(), 1, 1); - entityData.set(WEAPON_TYPE, 1); - } else if (entityData.get(WEAPON_TYPE) == 1) { - entityData.set(WEAPON_TYPE, 0); + } + if (entityData.get(WEAPON_TYPE) == 1) { this.level().playSound(null, this, ModSounds.INTO_CANNON.get(), this.getSoundSource(), 1, 1); } + + if (entityData.get(WEAPON_TYPE) <= -1) { + entityData.set(WEAPON_TYPE, 1); + } + if (entityData.get(WEAPON_TYPE) >= 2) { + entityData.set(WEAPON_TYPE, 0); + } } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MultiWeaponVehicleEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MultiWeaponVehicleEntity.java index 2938516d7..bf76ba495 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MultiWeaponVehicleEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/MultiWeaponVehicleEntity.java @@ -1,6 +1,6 @@ package com.atsuishio.superbwarfare.entity.vehicle; -public interface MultiWeaponVehicleEntity { - void changeWeapon(); +public interface MultiWeaponVehicleEntity extends IArmedVehicleEntity { + void changeWeapon(int scroll); int getWeaponType(); } 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 8e9432807..8c91d3989 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/SpeedboatEntity.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.config.server.ExplosionDestroyConfig; import com.atsuishio.superbwarfare.config.server.VehicleConfig; import com.atsuishio.superbwarfare.entity.projectile.ProjectileEntity; import com.atsuishio.superbwarfare.init.*; +import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.network.ModVariables; import com.atsuishio.superbwarfare.network.message.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.CustomExplosion; @@ -555,7 +556,7 @@ public class SpeedboatEntity extends ContainerMobileEntity implements GeoEntity, @Override public boolean banHand() { - return true; + return !(this.getFirstPassenger() instanceof Player player) || !(player.getMainHandItem().getItem() instanceof GunItem); } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java index 3e9015fbf..3a7424514 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java @@ -339,6 +339,7 @@ public class LivingEventHandler { player.getCapability(ModCapabilities.LASER_CAPABILITY).ifPresent(LaserCapability.ILaserCapability::stop); if (player instanceof ServerPlayer serverPlayer) { + ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new DrawClientMessage(true)); if (newStack.getItem() != oldStack.getItem() || newStack.getTag() == null || oldStack.getTag() == null || (newStack.is(ModTags.Items.GUN) && !GunsTool.getGunData(newStack).hasUUID("UUID")) @@ -420,10 +421,6 @@ public class LivingEventHandler { GunsTool.setPerkIntTag(newStack, "KillingTally", 0); } - if (player.level() instanceof ServerLevel) { - ModUtils.PACKET_HANDLER.send(PacketDistributor.PLAYER.with(() -> serverPlayer), new DrawClientMessage(true)); - } - player.getCapability(ModVariables.PLAYER_VARIABLES_CAPABILITY, null).ifPresent(capability -> { capability.tacticalSprint = false; capability.syncPlayerVariables(player); diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/FireModeMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/FireModeMessage.java index c06d6b8f6..9b713ecf3 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/FireModeMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/FireModeMessage.java @@ -1,7 +1,5 @@ package com.atsuishio.superbwarfare.network.message; -import com.atsuishio.superbwarfare.entity.vehicle.IArmedVehicleEntity; -import com.atsuishio.superbwarfare.entity.vehicle.MultiWeaponVehicleEntity; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; @@ -127,10 +125,6 @@ public class FireModeMessage { GunsTool.setGunBooleanTag(stack, "NeedBoltAction", true); } } - return; - } - if (player.getVehicle() instanceof IArmedVehicleEntity iArmedVehicle && iArmedVehicle.isDriver(player) && iArmedVehicle instanceof MultiWeaponVehicleEntity multiWeaponVehicle) { - multiWeaponVehicle.changeWeapon(); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/SwitchVehicleWeaponMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/SwitchVehicleWeaponMessage.java new file mode 100644 index 000000000..91a9ae150 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/SwitchVehicleWeaponMessage.java @@ -0,0 +1,42 @@ +package com.atsuishio.superbwarfare.network.message; + +import com.atsuishio.superbwarfare.entity.vehicle.MultiWeaponVehicleEntity; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Mth; +import net.minecraftforge.network.NetworkEvent; + +import java.util.function.Supplier; + +public class SwitchVehicleWeaponMessage { + + private final double scroll; + + public SwitchVehicleWeaponMessage(double scroll) { + this.scroll = scroll; + } + + public static void encode(SwitchVehicleWeaponMessage message, FriendlyByteBuf byteBuf) { + byteBuf.writeDouble(message.scroll); + } + + public static SwitchVehicleWeaponMessage decode(FriendlyByteBuf byteBuf) { + return new SwitchVehicleWeaponMessage(byteBuf.readDouble()); + } + + public static void handler(SwitchVehicleWeaponMessage message, Supplier context) { + context.get().enqueueWork(() -> { + ServerPlayer player = context.get().getSender(); + if (player == null) { + return; + } + + if (player.getVehicle() instanceof MultiWeaponVehicleEntity multiWeaponVehicle && multiWeaponVehicle.isDriver(player)) { + multiWeaponVehicle.changeWeapon(Mth.clamp(message.scroll > 0 ? Mth.ceil(message.scroll) : Mth.floor(message.scroll), -1, 1)); + } + + }); + context.get().setPacketHandled(true); + } + +} diff --git a/src/main/resources/assets/superbwarfare/textures/screens/land/lav_cannon_cross.png b/src/main/resources/assets/superbwarfare/textures/screens/land/lav_cannon_cross.png new file mode 100644 index 000000000..d63db5293 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/land/lav_cannon_cross.png differ diff --git a/src/main/resources/assets/superbwarfare/textures/screens/land/lav_cross.png b/src/main/resources/assets/superbwarfare/textures/screens/land/lav_gun_cross.png similarity index 100% rename from src/main/resources/assets/superbwarfare/textures/screens/land/lav_cross.png rename to src/main/resources/assets/superbwarfare/textures/screens/land/lav_gun_cross.png diff --git a/src/main/resources/assets/superbwarfare/textures/screens/land/lav_missile_cross.png b/src/main/resources/assets/superbwarfare/textures/screens/land/lav_missile_cross.png new file mode 100644 index 000000000..3bc93a245 Binary files /dev/null and b/src/main/resources/assets/superbwarfare/textures/screens/land/lav_missile_cross.png differ