From a710b6b807ac37c483867fce80e5e227760c39d3 Mon Sep 17 00:00:00 2001 From: Atsuishio <842960157@qq.com> Date: Mon, 21 Apr 2025 23:10:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86isEditing=E6=94=B9=E4=B8=BA=E7=BA=AF?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../capability/player/PlayerVariable.java | 29 +---- .../superbwarfare/client/ClickHandler.java | 12 +- .../client/overlay/CrossHairOverlay.java | 6 +- .../overlay/GrenadeLauncherOverlay.java | 7 +- .../client/overlay/HandsomeFrameOverlay.java | 103 +++++++++--------- .../client/overlay/HelicopterHudOverlay.java | 5 +- .../client/overlay/JavelinHudOverlay.java | 6 +- .../client/overlay/StaminaOverlay.java | 4 +- .../event/ClientEventHandler.java | 16 ++- .../event/LivingEventHandler.java | 6 - .../superbwarfare/item/gun/GunItem.java | 2 - .../item/gun/handgun/Trachelium.java | 4 +- .../item/gun/heavy/Ntw20Item.java | 4 +- .../item/gun/launcher/SecondaryCataclysm.java | 4 +- .../item/gun/machinegun/RpkItem.java | 4 +- .../item/gun/rifle/AK12Item.java | 4 +- .../item/gun/rifle/AK47Item.java | 4 +- .../item/gun/rifle/Hk416Item.java | 4 +- .../superbwarfare/item/gun/rifle/M4Item.java | 4 +- .../item/gun/rifle/Mk14Item.java | 4 +- .../item/gun/rifle/Qbz95Item.java | 4 +- .../item/gun/smg/VectorItem.java | 4 +- .../item/gun/sniper/SentinelItem.java | 4 +- .../item/gun/sniper/SvdItem.java | 4 +- .../item/gun/special/TaserItem.java | 4 +- .../network/NetworkRegistry.java | 3 +- .../receive/PlayerVariablesSyncMessage.java | 19 ++-- .../network/message/send/EditModeMessage.java | 52 --------- .../network/message/send/ReloadMessage.java | 8 +- .../network/message/send/ZoomMessage.java | 5 - 30 files changed, 122 insertions(+), 217 deletions(-) delete mode 100644 src/main/java/com/atsuishio/superbwarfare/network/message/send/EditModeMessage.java diff --git a/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java b/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java index 22fbe2e67..590d0d125 100644 --- a/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java +++ b/src/main/java/com/atsuishio/superbwarfare/capability/player/PlayerVariable.java @@ -8,7 +8,6 @@ import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.player.Player; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.common.util.INBTSerializable; @@ -19,7 +18,6 @@ import org.jetbrains.annotations.NotNull; import javax.annotation.ParametersAreNonnullByDefault; import java.util.HashMap; import java.util.Map; -import java.util.function.Consumer; @EventBusSubscriber(modid = Mod.MODID) @@ -28,7 +26,6 @@ public class PlayerVariable implements INBTSerializable { public Map ammo = new HashMap<>(); public boolean tacticalSprint = false; - public boolean edit = false; public void sync(Entity entity) { if (!entity.hasData(ModAttachments.PLAYER_VARIABLE)) return; @@ -41,10 +38,6 @@ public class PlayerVariable implements INBTSerializable { } } - public static boolean isEditing(Entity entity) { - return entity.getData(ModAttachments.PLAYER_VARIABLE).edit; - } - @SubscribeEvent public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { if (!(event.getEntity() instanceof ServerPlayer player)) return; @@ -79,7 +72,6 @@ public class PlayerVariable implements INBTSerializable { } map.put((byte) -1, this.tacticalSprint ? 1 : 0); - map.put((byte) -2, this.edit ? 1 : 0); return map; } @@ -100,22 +92,10 @@ public class PlayerVariable implements INBTSerializable { if (old.tacticalSprint != this.tacticalSprint) { map.put((byte) -1, this.tacticalSprint ? 1 : 0); } - if (old.edit != this.edit) { - map.put((byte) -2, this.edit ? 1 : 0); - } return map; } - /** - * 编辑并同步玩家变量 - */ - public void modify(Player player, Consumer consumer) { - watch(); - consumer.accept(this); - sync(player); - } - public CompoundTag writeToNBT() { CompoundTag nbt = new CompoundTag(); @@ -125,20 +105,17 @@ public class PlayerVariable implements INBTSerializable { } nbt.putBoolean("TacticalSprint", tacticalSprint); - nbt.putBoolean("EditMode", edit); return nbt; } - public PlayerVariable readFromNBT(CompoundTag tag) { + public void readFromNBT(CompoundTag tag) { for (var type : Ammo.values()) { type.set(this, type.get(tag)); } tacticalSprint = tag.getBoolean("TacticalSprint"); - edit = tag.getBoolean("EditMode"); - return this; } public PlayerVariable copy() { @@ -148,7 +125,6 @@ public class PlayerVariable implements INBTSerializable { type.set(clone, type.get(this)); } - clone.edit = this.edit; clone.tacticalSprint = this.tacticalSprint; return clone; @@ -162,8 +138,7 @@ public class PlayerVariable implements INBTSerializable { if (type.get(this) != type.get(other)) return false; } - return tacticalSprint == other.tacticalSprint - && edit == other.edit; + return tacticalSprint == other.tacticalSprint; } @SubscribeEvent diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index e0affdd05..722c75800 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -44,7 +44,7 @@ import static com.atsuishio.superbwarfare.event.ClientEventHandler.*; @EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT) public class ClickHandler { - + public static boolean isEditing = false; public static boolean switchZoom = false; private static boolean notInGame() { @@ -211,6 +211,7 @@ public class ClickHandler { if (key == ModKeyMappings.RELOAD.getKey().getValue()) { ClientEventHandler.burstFireAmount = 0; + ClickHandler.isEditing = false; PacketDistributor.sendToServer(new ReloadMessage(0)); } if (key == ModKeyMappings.FIRE_MODE.getKey().getValue()) { @@ -224,14 +225,15 @@ public class ClickHandler { } if (key == ModKeyMappings.EDIT_MODE.getKey().getValue() && ClientEventHandler.burstFireAmount == 0) { ClientEventHandler.holdFire = false; - PacketDistributor.sendToServer(new EditModeMessage(0)); + isEditing = true; + player.playSound(ModSounds.EDIT_MODE.get(), 1, 1); } if (key == ModKeyMappings.BREATH.getKey().getValue() && !exhaustion && zoom) { breath = true; } - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (isEditing) { if (!(stack.getItem() instanceof GunItem gunItem)) return; if (ModKeyMappings.EDIT_GRIP.getKeyModifier().isActive(KeyConflictContext.IN_GAME)) { if (key == ModKeyMappings.EDIT_GRIP.getKey().getValue() && gunItem.hasCustomGrip(stack)) { @@ -305,6 +307,7 @@ public class ClickHandler { } public static void handleWeaponFirePress(Player player, ItemStack stack) { + isEditing = false; if (player.hasEffect(ModMobEffects.SHOCK)) return; if (stack.is(Items.SPYGLASS) && player.isScoping() && player.getOffhandItem().is(ModItems.FIRING_PARAMETERS.get())) { @@ -373,12 +376,15 @@ public class ClickHandler { bowPull = false; holdFire = false; holdFireVehicle = false; + isEditing = false; customRpm = 0; } public static void handleWeaponZoomPress(Player player, ItemStack stack) { PacketDistributor.sendToServer(new ZoomMessage(0)); + ClickHandler.isEditing = false; + if (player.getVehicle() instanceof VehicleEntity pVehicle && player.getVehicle() instanceof WeaponVehicleEntity iVehicle && iVehicle.hasWeapon(pVehicle.getSeatIndex(player)) && iVehicle.banHand(player)) { ClientEventHandler.zoomVehicle = true; return; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/CrossHairOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/CrossHairOverlay.java index 9ca7651e2..ac954c518 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/CrossHairOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/CrossHairOverlay.java @@ -1,11 +1,11 @@ package com.atsuishio.superbwarfare.client.overlay; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.config.client.DisplayConfig; import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity; import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -62,8 +62,8 @@ public class CrossHairOverlay implements LayeredDraw.Layer { return; } - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return; - + if (ClickHandler.isEditing) + return; if (!player.getMainHandItem().is(ModTags.Items.GUN) || (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player))) return; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/GrenadeLauncherOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/GrenadeLauncherOverlay.java index 57dbafbc9..49fc09863 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/GrenadeLauncherOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/GrenadeLauncherOverlay.java @@ -1,10 +1,10 @@ package com.atsuishio.superbwarfare.client.overlay; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.CannonEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModItems; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; @@ -34,9 +34,8 @@ public class GrenadeLauncherOverlay implements LayeredDraw.Layer { Player player = Minecraft.getInstance().player; if (player == null) return; - var cap = player.getData(ModAttachments.PLAYER_VARIABLE); - if (cap.edit) return; - + if (ClickHandler.isEditing) + return; if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) return; if (!shouldRenderCrossHair(player)) return; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HandsomeFrameOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HandsomeFrameOverlay.java index 553f9b633..4ccaa1a6c 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HandsomeFrameOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HandsomeFrameOverlay.java @@ -1,10 +1,10 @@ package com.atsuishio.superbwarfare.client.overlay; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.RenderHelper; import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -45,73 +45,74 @@ public class HandsomeFrameOverlay implements LayeredDraw.Layer { Player player = Minecraft.getInstance().player; PoseStack poseStack = guiGraphics.pose(); - if (player != null) { - ItemStack stack = player.getMainHandItem(); - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return; - if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) - return; + if (player == null) return; + ItemStack stack = player.getMainHandItem(); - if (stack.getItem() instanceof GunItem && Minecraft.getInstance().options.getCameraType().isFirstPerson()) { - var data = GunData.from(stack); - int level = data.perk.getLevel(ModPerks.INTELLIGENT_CHIP); - if (level == 0) return; + if (ClickHandler.isEditing) + return; + if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) + return; - 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); + if (stack.getItem() instanceof GunItem && Minecraft.getInstance().options.getCameraType().isFirstPerson()) { + var data = GunData.from(stack); + int level = data.perk.getLevel(ModPerks.INTELLIGENT_CHIP); + if (level == 0) return; - List allEntities = SeekTool.seekLivingEntitiesThroughWall(player, player.level(), 32 + 8 * (level - 1), 30); - List visibleEntities = SeekTool.seekLivingEntities(player, player.level(), 32 + 8 * (level - 1), 30); + 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); - Entity naerestEntity = SeekTool.seekLivingEntity(player, player.level(), 32 + 8 * (level - 1), 30); - Entity targetEntity = ClientEventHandler.entity; + List allEntities = SeekTool.seekLivingEntitiesThroughWall(player, player.level(), 32 + 8 * (level - 1), 30); + List visibleEntities = SeekTool.seekLivingEntities(player, player.level(), 32 + 8 * (level - 1), 30); + + Entity naerestEntity = SeekTool.seekLivingEntity(player, player.level(), 32 + 8 * (level - 1), 30); + Entity targetEntity = ClientEventHandler.entity; - float fovAdjust2 = (float) (Minecraft.getInstance().options.fov().get() / 30) - 1; + float fovAdjust2 = (float) (Minecraft.getInstance().options.fov().get() / 30) - 1; - double zoom = 1; + double zoom = 1; - if (ClientEventHandler.zoom) { - zoom = Minecraft.getInstance().options.fov().get() / ClientEventHandler.fov + 0.05 * fovAdjust2; - } + if (ClientEventHandler.zoom) { + zoom = Minecraft.getInstance().options.fov().get() / ClientEventHandler.fov + 0.05 * fovAdjust2; + } - for (var e : allEntities) { - Vec3 playerVec = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.xo, player.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.zo, player.getZ())); - Vec3 pos = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.xo, e.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.zo, e.getZ())); - Vec3 lookAngle = player.getLookAngle().normalize().scale(pos.distanceTo(playerVec) * (1 - 1.0 / zoom)); + for (var e : allEntities) { + Vec3 playerVec = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.xo, player.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.yo + player.getEyeHeight(), player.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), player.zo, player.getZ())); + Vec3 pos = new Vec3(Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.xo, e.getX()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.yo + e.getEyeHeight(), e.getEyeY()), Mth.lerp(deltaTracker.getGameTimeDeltaPartialTick(true), e.zo, e.getZ())); + Vec3 lookAngle = player.getLookAngle().normalize().scale(pos.distanceTo(playerVec) * (1 - 1.0 / zoom)); - var cPos = playerVec.add(lookAngle); - Vec3 point = RenderHelper.worldToScreen(pos, cPos); - if (point == null) return; + var cPos = playerVec.add(lookAngle); + Vec3 point = RenderHelper.worldToScreen(pos, cPos); + if (point == null) return; - boolean lockOn = e == targetEntity; - boolean isNearestEntity = e == naerestEntity; + boolean lockOn = e == targetEntity; + boolean isNearestEntity = e == naerestEntity; - poseStack.pushPose(); - float x = (float) point.x; - float y = (float) point.y; + poseStack.pushPose(); + float x = (float) point.x; + float y = (float) point.y; - var canBeSeen = visibleEntities.contains(e); + var canBeSeen = visibleEntities.contains(e); - ResourceLocation icon; - if (lockOn) { - icon = FRAME_LOCK; - } else if (canBeSeen) { - if (isNearestEntity) { - icon = FRAME_TARGET; - } else { - icon = FRAME; - } + ResourceLocation icon; + if (lockOn) { + icon = FRAME_LOCK; + } else if (canBeSeen) { + if (isNearestEntity) { + icon = FRAME_TARGET; } else { - icon = FRAME_WEAK; + icon = FRAME; } - - RenderHelper.preciseBlit(guiGraphics, icon, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); - poseStack.popPose(); + } else { + icon = FRAME_WEAK; } + + RenderHelper.preciseBlit(guiGraphics, icon, x - 12, y - 12, 24, 24, 0, 0, 24, 24, 24, 24); + poseStack.popPose(); } } } 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 11d58ca76..caadfa919 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/HelicopterHudOverlay.java @@ -1,6 +1,7 @@ package com.atsuishio.superbwarfare.client.overlay; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.RenderHelper; import com.atsuishio.superbwarfare.entity.vehicle.Ah6Entity; import com.atsuishio.superbwarfare.entity.vehicle.base.HelicopterEntity; @@ -8,7 +9,6 @@ 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.ModAttachments; import com.atsuishio.superbwarfare.tools.FormatTool; import com.atsuishio.superbwarfare.tools.InventoryTool; import com.mojang.blaze3d.platform.GlStateManager; @@ -63,7 +63,8 @@ public class HelicopterHudOverlay implements LayeredDraw.Layer { if (player == null) return; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return; + if (ClickHandler.isEditing) + return; if (player.getVehicle() instanceof HelicopterEntity iHelicopterEntity && player.getVehicle() instanceof MobileVehicleEntity mobileVehicle && iHelicopterEntity.isDriver(player) && player.getVehicle() instanceof WeaponVehicleEntity weaponVehicle) { poseStack.pushPose(); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/JavelinHudOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/JavelinHudOverlay.java index 68c430442..a15e3e647 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/JavelinHudOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/JavelinHudOverlay.java @@ -1,10 +1,10 @@ package com.atsuishio.superbwarfare.client.overlay; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.RenderHelper; import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.tools.EntityFindUtil; @@ -53,8 +53,8 @@ public class JavelinHudOverlay implements LayeredDraw.Layer { if (player != null) { ItemStack stack = player.getMainHandItem(); - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) return; - + if (ClickHandler.isEditing) + return; if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) return; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/overlay/StaminaOverlay.java b/src/main/java/com/atsuishio/superbwarfare/client/overlay/StaminaOverlay.java index 792dab822..69bd7133b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/overlay/StaminaOverlay.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/overlay/StaminaOverlay.java @@ -1,11 +1,11 @@ package com.atsuishio.superbwarfare.client.overlay; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.RenderHelper; import com.atsuishio.superbwarfare.config.client.DisplayConfig; import com.atsuishio.superbwarfare.entity.vehicle.base.ArmedVehicleEntity; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.DeltaTracker; @@ -34,7 +34,7 @@ public class StaminaOverlay implements LayeredDraw.Layer { var w = guiGraphics.guiWidth(); var h = guiGraphics.guiHeight(); - if (player != null && player.getData(ModAttachments.PLAYER_VARIABLE).edit) + if (player != null && ClickHandler.isEditing) return; if (player != null && player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) return; diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index 412e634fe..ce4dc8074 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -415,7 +415,6 @@ public class ClientEventHandler { public static void handleGunMelee(Player player, ItemStack stack) { if (stack.getItem() instanceof GunItem gunItem) { var data = GunData.from(stack); - var cap = player.getData(ModAttachments.PLAYER_VARIABLE); if (gunItem.hasMeleeAttack(stack) && gunMelee == 0 && drawTime < 0.01 @@ -423,7 +422,7 @@ public class ClientEventHandler { && !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) && !holdFireVehicle && !notInGame() - && !cap.edit + && !ClickHandler.isEditing && !(data.reload.normal() || data.reload.empty()) && !data.reloading() && !data.charging() && !player.getCooldowns().isOnCooldown(stack.getItem()) @@ -575,8 +574,6 @@ public class ClientEventHandler { revolverPreTime = Mth.clamp(revolverPreTime - 1.2 * times, 0, 1); } - var cap = player.getData(ModAttachments.PLAYER_VARIABLE); - if (((holdFire || burstFireAmount > 0) && shootDelay >= data.shootDelay()) && !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) && !holdFireVehicle @@ -585,8 +582,9 @@ public class ClientEventHandler { && (stack.is(ModTags.Items.NORMAL_GUN) && cantFireTime == 0 && drawTime < 0.01 - && !cap.edit + && !ClickHandler.isEditing && !notInGame() + && !ClickHandler.isEditing && (!(data.reload.normal() || data.reload.empty()) && !data.reloading() && !data.charging() @@ -1119,7 +1117,7 @@ public class ClientEventHandler { onGround = 0.001; } - if (!entity.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (!ClickHandler.isEditing) { if (Minecraft.getInstance().options.keyUp.isDown() && firePosTimer == 0) { moveRotZ = Mth.lerp(0.2f * times, moveRotZ, 0.14) * (1 - zoomTime); } else { @@ -1182,12 +1180,11 @@ public class ClientEventHandler { double weight = data.weight(); double speed = 1.5 - (0.07 * weight); - var cap = player.getData(ModAttachments.PLAYER_VARIABLE); if (zoom && !(player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.banHand(player)) && !notInGame() && drawTime < 0.01 - && !cap.edit) { + && !ClickHandler.isEditing) { if (Minecraft.getInstance().player != null) { cantSprint = 5; } @@ -1515,7 +1512,7 @@ public class ClientEventHandler { if (zoom && !notInGame() && drawTime < 0.01 - && !player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + && !ClickHandler.isEditing) { if (!player.isShiftKeyDown()) { int intelligentChipLevel = data.perk.getLevel(ModPerks.INTELLIGENT_CHIP); @@ -1625,6 +1622,7 @@ public class ClientEventHandler { bowPullTimer = 0; bowPower = 0; cantSprint = 20; + ClickHandler.isEditing = false; } private static void handleWeaponDraw(LivingEntity entity) { diff --git a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java index 994f260f6..623a65bb1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java @@ -388,12 +388,6 @@ public class LivingEventHandler { oldData.charge.timer.reset(); } - var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); - cap.edit = false; - - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - cap.sync(player); - oldData.save(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java index 01fc8acf7..9c044ded0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java @@ -632,8 +632,6 @@ public abstract class GunItem extends Item implements CustomRendererItem { if (data.reload.prepareTimer.get() == 0 && data.reloading() && data.hasEnoughAmmoToShoot(player)) { data.forceStop.set(true); } - - player.getData(ModAttachments.PLAYER_VARIABLE).modify(player, cap -> cap.edit = false); } /** diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Trachelium.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Trachelium.java index 69c9bea3c..347686fd6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Trachelium.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/handgun/Trachelium.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.handgun; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.TooltipTool; import com.atsuishio.superbwarfare.client.renderer.item.TracheliumItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -190,7 +190,7 @@ public class Trachelium extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.trachelium.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/heavy/Ntw20Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/heavy/Ntw20Item.java index e0f4fa83a..561f3a59b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/heavy/Ntw20Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/heavy/Ntw20Item.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.heavy; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.Ntw20Renderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModEnumExtensions; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; @@ -101,7 +101,7 @@ public class Ntw20Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java index 4672c586d..874471434 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/SecondaryCataclysm.java @@ -53,13 +53,13 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, EnergyStorag } @Override - public boolean isBarVisible(ItemStack stack) { + public boolean isBarVisible(@NotNull ItemStack stack) { var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM); return cap != null && cap.getEnergyStored() > 0; } @Override - public int getBarWidth(ItemStack stack) { + public int getBarWidth(@NotNull ItemStack stack) { var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM); return Math.round((float) (cap != null ? cap.getEnergyStored() : 0) * 13.0F / 24000F); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/machinegun/RpkItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/machinegun/RpkItem.java index 671653aed..f49895891 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/machinegun/RpkItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/machinegun/RpkItem.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.machinegun; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.RpkItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; @@ -118,7 +118,7 @@ public class RpkItem extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/AK12Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/AK12Item.java index f24a5365a..e047a6e2b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/AK12Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/AK12Item.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.rifle; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.AK12ItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -111,7 +111,7 @@ public class AK12Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak12.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/AK47Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/AK47Item.java index 7926fd4d1..89a899db6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/AK47Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/AK47Item.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.rifle; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.AK47ItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -119,7 +119,7 @@ public class AK47Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ak47.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Hk416Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Hk416Item.java index 701f72de2..5032ea858 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Hk416Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Hk416Item.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.rifle; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.Hk416ItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -114,7 +114,7 @@ public class Hk416Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m4.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/M4Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/M4Item.java index 12816e2a4..764005810 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/M4Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/M4Item.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.rifle; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.M4ItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -115,7 +115,7 @@ public class M4Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m4.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Mk14Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Mk14Item.java index 51fba9bbf..5cb95b25b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Mk14Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Mk14Item.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.rifle; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.Mk14ItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -116,7 +116,7 @@ public class Mk14Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m14.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Qbz95Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Qbz95Item.java index 314a4814e..83e1a478d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Qbz95Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/Qbz95Item.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.rifle; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.Qbz95ItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -119,7 +119,7 @@ public class Qbz95Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.qbz95.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/smg/VectorItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/smg/VectorItem.java index ef4f39af3..077fbb94e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/smg/VectorItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/smg/VectorItem.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.smg; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.VectorItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -86,7 +86,7 @@ public class VectorItem extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.vector.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SentinelItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SentinelItem.java index 0513b08ef..be0709181 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SentinelItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SentinelItem.java @@ -42,13 +42,13 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem } @Override - public boolean isBarVisible(ItemStack stack) { + public boolean isBarVisible(@NotNull ItemStack stack) { var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM); return cap != null && cap.getEnergyStored() > 0; } @Override - public int getBarWidth(ItemStack stack) { + public int getBarWidth(@NotNull ItemStack stack) { var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM); return Math.round((float) (cap != null ? cap.getEnergyStored() : 0) * 13.0F / 24000F); diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SvdItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SvdItem.java index 0b51be2f1..29c34e797 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SvdItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/SvdItem.java @@ -1,9 +1,9 @@ package com.atsuishio.superbwarfare.item.gun.sniper; import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.ClickHandler; import com.atsuishio.superbwarfare.client.renderer.item.SvdItemRenderer; import com.atsuishio.superbwarfare.event.ClientEventHandler; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -80,7 +80,7 @@ public class SvdItem extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem)) return PlayState.STOP; - if (player.getData(ModAttachments.PLAYER_VARIABLE).edit) { + if (ClickHandler.isEditing) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.svd.edit")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java index af7267824..ab6a1b45e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/special/TaserItem.java @@ -50,13 +50,13 @@ public class TaserItem extends GunItem implements GeoItem, EnergyStorageItem { } @Override - public boolean isBarVisible(ItemStack stack) { + public boolean isBarVisible(@NotNull ItemStack stack) { var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM); return cap != null && cap.getEnergyStored() != 0; } @Override - public int getBarWidth(ItemStack stack) { + public int getBarWidth(@NotNull ItemStack stack) { var cap = stack.getCapability(Capabilities.EnergyStorage.ITEM); return Math.round((float) (cap != null ? cap.getEnergyStored() : 0) * 13.0F / MAX_ENERGY); } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/NetworkRegistry.java b/src/main/java/com/atsuishio/superbwarfare/network/NetworkRegistry.java index aefd1b39d..5c91e5402 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/NetworkRegistry.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/NetworkRegistry.java @@ -9,7 +9,7 @@ public class NetworkRegistry { public static void register(final RegisterPayloadHandlersEvent event) { final PayloadRegistrar registrar = event.registrar("1"); - registrar.playToClient(PlayerVariablesSyncMessage.TYPE, PlayerVariablesSyncMessage.STREAM_CODEC, PlayerVariablesSyncMessage::handler); + registrar.playToClient(PlayerVariablesSyncMessage.TYPE, PlayerVariablesSyncMessage.STREAM_CODEC, (message, context1) -> PlayerVariablesSyncMessage.handler(message)); registrar.playToClient(ShakeClientMessage.TYPE, ShakeClientMessage.STREAM_CODEC, ShakeClientMessage::handler); registrar.playToClient(ClientMotionSyncMessage.TYPE, ClientMotionSyncMessage.STREAM_CODEC, ClientMotionSyncMessage::handler); registrar.playToClient(ClientIndicatorMessage.TYPE, ClientIndicatorMessage.STREAM_CODEC, ClientIndicatorMessage::handler); @@ -49,7 +49,6 @@ public class NetworkRegistry { registrar.playToServer(SetFiringParametersMessage.TYPE, SetFiringParametersMessage.STREAM_CODEC, SetFiringParametersMessage::handler); registrar.playToServer(SensitivityMessage.TYPE, SensitivityMessage.STREAM_CODEC, SensitivityMessage::handler); registrar.playToServer(EditMessage.TYPE, EditMessage.STREAM_CODEC, EditMessage::handler); - registrar.playToServer(EditModeMessage.TYPE, EditModeMessage.STREAM_CODEC, EditModeMessage::handler); registrar.playToServer(InteractMessage.TYPE, InteractMessage.STREAM_CODEC, InteractMessage::handler); registrar.playToServer(AdjustMortarAngleMessage.TYPE, AdjustMortarAngleMessage.STREAM_CODEC, AdjustMortarAngleMessage::handler); registrar.playToServer(ChangeVehicleSeatMessage.TYPE, ChangeVehicleSeatMessage.STREAM_CODEC, ChangeVehicleSeatMessage::handler); diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/receive/PlayerVariablesSyncMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/receive/PlayerVariablesSyncMessage.java index 0c219537a..96209023a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/receive/PlayerVariablesSyncMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/receive/PlayerVariablesSyncMessage.java @@ -8,7 +8,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.neoforged.neoforge.network.handling.IPayloadContext; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -31,7 +30,7 @@ public record PlayerVariablesSyncMessage(int target, Map data) im ); - public static void handler(final PlayerVariablesSyncMessage message, final IPayloadContext context) { + public static void handler(final PlayerVariablesSyncMessage message) { if (Minecraft.getInstance().player == null) return; var entity = Minecraft.getInstance().player.level().getEntity(message.target()); @@ -42,15 +41,13 @@ public record PlayerVariablesSyncMessage(int target, Map data) im for (var entry : map.entrySet()) { var type = entry.getKey(); - switch (type) { - case -1 -> variable.tacticalSprint = entry.getValue() == 1; - case -2 -> variable.edit = entry.getValue() == 1; - default -> { - var ammoTypes = Ammo.values(); - if (type < ammoTypes.length) { - var ammo = ammoTypes[type]; - variable.ammo.put(ammo, entry.getValue()); - } + if (type == -1) { + variable.tacticalSprint = entry.getValue() == 1; + } else { + var ammoTypes = Ammo.values(); + if (type < ammoTypes.length) { + var ammo = ammoTypes[type]; + variable.ammo.put(ammo, entry.getValue()); } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/EditModeMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/EditModeMessage.java deleted file mode 100644 index cd14a4793..000000000 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/EditModeMessage.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.atsuishio.superbwarfare.network.message.send; - -import com.atsuishio.superbwarfare.Mod; -import com.atsuishio.superbwarfare.init.ModAttachments; -import com.atsuishio.superbwarfare.init.ModSounds; -import com.atsuishio.superbwarfare.item.gun.GunItem; -import com.atsuishio.superbwarfare.tools.SoundTool; -import io.netty.buffer.ByteBuf; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.neoforged.neoforge.network.handling.IPayloadContext; -import org.jetbrains.annotations.NotNull; - -public record EditModeMessage(int msgType) implements CustomPacketPayload { - public static final Type TYPE = new Type<>(Mod.loc("edit_mode")); - - public static final StreamCodec STREAM_CODEC = StreamCodec.composite( - ByteBufCodecs.INT, - EditModeMessage::msgType, - EditModeMessage::new - ); - - public static void handler(EditModeMessage message, final IPayloadContext context) { - pressAction(context.player(), message.msgType); - } - - public static void pressAction(Player player, int type) { - if (player == null) return; - if (type != 0) return; - - ItemStack mainHandItem = player.getMainHandItem(); - if (!(mainHandItem.getItem() instanceof GunItem gunItem)) return; - var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); - - if (gunItem.isCustomizable(mainHandItem)) { - if (!cap.edit) { - SoundTool.playLocalSound(player, ModSounds.EDIT_MODE.get(), 1f, 1f); - } - cap.edit = !cap.edit; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - cap.sync(player); - } - } - - @Override - public @NotNull Type type() { - return TYPE; - } -} diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ReloadMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ReloadMessage.java index 278242052..296a24a9e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ReloadMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ReloadMessage.java @@ -1,7 +1,6 @@ package com.atsuishio.superbwarfare.network.message.send; import com.atsuishio.superbwarfare.Mod; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.item.gun.GunItem; import com.atsuishio.superbwarfare.item.gun.data.GunData; import io.netty.buffer.ByteBuf; @@ -28,18 +27,13 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload { public static void pressAction(Player player, int type) { if (type != 0) return; + ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem gunItem)) return; var data = GunData.from(stack); if (data.useBackpackAmmo()) return; - var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); - cap.edit = false; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - cap.sync(player); - - if (!player.isSpectator() && !data.charging() && !data.reloading() diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java index 8b7062779..4bcddf382 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ZoomMessage.java @@ -3,7 +3,6 @@ package com.atsuishio.superbwarfare.network.message.send; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; -import com.atsuishio.superbwarfare.init.ModAttachments; import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.item.gun.data.GunData; @@ -32,12 +31,8 @@ public record ZoomMessage(int msgType) implements CustomPacketPayload { var vehicle = player.getVehicle(); // 缩放音效播放条件: 载具是武器载具,且该位置有可用武器 - var cap = player.getData(ModAttachments.PLAYER_VARIABLE).watch(); if (message.msgType == 0) { - cap.edit = false; - player.setData(ModAttachments.PLAYER_VARIABLE, cap); - cap.sync(player); if (player.isPassenger() && vehicle instanceof WeaponVehicleEntity weaponEntity