diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index a907b5e11..15b268862 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -344,11 +344,9 @@ public class ClickHandler { } } else { PacketDistributor.sendToServer(new FireMessage(0)); - if ((!(data.normalReloading() || data.emptyReloading()) - && !data.reloading() - && !GunsTool.getGunBooleanTag(tag, "Charging") - && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction")) - && drawTime < 0.01) { + if ((!data.reloading() && !data.charging() + && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction") + ) && drawTime < 0.01) { if (data.fireMode() == 1) { if (ClientEventHandler.burstFireAmount == 0) { ClientEventHandler.burstFireAmount = data.burstAmount(); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/PoseTool.java b/src/main/java/com/atsuishio/superbwarfare/client/PoseTool.java index c9230f050..eaffa1f72 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/PoseTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/PoseTool.java @@ -1,8 +1,7 @@ package com.atsuishio.superbwarfare.client; import com.atsuishio.superbwarfare.item.gun.GunData; -import com.atsuishio.superbwarfare.tools.GunsTool; -import com.atsuishio.superbwarfare.tools.NBTTool; +import com.atsuishio.superbwarfare.item.gun.GunItem; import net.minecraft.client.model.HumanoidModel; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.LivingEntity; @@ -14,15 +13,14 @@ import net.neoforged.api.distmarker.OnlyIn; public class PoseTool { public static HumanoidModel.ArmPose pose(LivingEntity entityLiving, InteractionHand hand, ItemStack stack) { - var tag = NBTTool.getTag(stack); - var data = GunData.from(stack); - if (data.emptyReloading() - || data.getReloadState() == GunData.ReloadState.NORMAL_RELOADING - || data.reloading() - || GunsTool.getGunBooleanTag(tag, "Charging") - ) { - return HumanoidModel.ArmPose.CROSSBOW_CHARGE; - } else if (entityLiving.isSprinting() && entityLiving.onGround() && entityLiving.getPersistentData().getDouble("noRun") == 0) { + if (stack.getItem() instanceof GunItem) { + var data = GunData.from(stack); + if (data.reloading() || data.charging()) { + return HumanoidModel.ArmPose.CROSSBOW_CHARGE; + } + } + + if (entityLiving.isSprinting() && entityLiving.onGround() && entityLiving.getPersistentData().getDouble("noRun") == 0) { return HumanoidModel.ArmPose.CROSSBOW_CHARGE; } else { return HumanoidModel.ArmPose.BOW_AND_ARROW; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/K98ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/K98ItemModel.java index 1dbb0fe0a..6dc587277 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/K98ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/K98ItemModel.java @@ -46,7 +46,7 @@ public class K98ItemModel extends GeoModel { var data = GunData.from(stack); final var tag = data.tag(); - if (tag.getDouble("prepare") > 11 && data.ammo() == 1) { + if (tag.getDouble("PrepareTime") > 11 && data.ammo() == 1) { clip.setScaleX(0); clip.setScaleY(0); clip.setScaleZ(0); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/MarlinItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/MarlinItemModel.java index 43ae2615f..92abfd48b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/MarlinItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/MarlinItemModel.java @@ -84,7 +84,7 @@ public class MarlinItemModel extends GeoModel { CrossHairOverlay.gunRot = shen.getRotZ(); - if (NBTTool.getTag(stack).getBoolean("empty")) { + if (NBTTool.getTag(stack).getBoolean("IsEmpty")) { jichui.setRotX(-0.52f); } diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/SentinelItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/SentinelItemModel.java index 7cc4edf69..9ebbf2be0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/SentinelItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/SentinelItemModel.java @@ -118,7 +118,7 @@ public class SentinelItemModel extends GeoModel { float numR = (float) (1 - 0.9 * zt); float numP = (float) (1 - 0.98 * zt); - if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0 || GunsTool.getGunBooleanTag(tag, "Charging")) { + if (GunsTool.getGunIntTag(tag, "ReloadTime") > 0 || data.charging()) { main.setRotX(numR * main.getRotX()); main.setRotY(numR * main.getRotY()); main.setRotZ(numR * main.getRotZ()); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/RpgItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/RpgItemRenderer.java index ce68c849c..a0fda4074 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/RpgItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/RpgItemRenderer.java @@ -78,7 +78,7 @@ public class RpgItemRenderer extends GeoItemRenderer { if (!itemStack.is(ModTags.Items.GUN)) return; if (name.equals("Rockets")) { - bone.setHidden(NBTTool.getTag(itemStack).getBoolean("empty")); + bone.setHidden(NBTTool.getTag(itemStack).getBoolean("IsEmpty")); } if (name.equals("flare")) { diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java index 5d01e9ad2..d3646bf61 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/DroneEntity.java @@ -265,6 +265,7 @@ public class DroneEntity extends MobileVehicleEntity implements GeoEntity { this.entityData.set(CONTROLLER, player.getStringUUID()); Monitor.link(tag, this.getStringUUID()); + NBTTool.saveTag(stack, tag); player.displayClientMessage(Component.translatable("tips.superbwarfare.monitor.linked").withStyle(ChatFormatting.GREEN), true); if (player instanceof ServerPlayer serverPlayer) { diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index dc1c9efbb..4ac95f8a8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -313,8 +313,9 @@ public class ClientEventHandler { && cap != null && !cap.edit && !(data.normalReloading() || data.emptyReloading()) && !data.reloading() + && !data.charging() && !player.getCooldowns().isOnCooldown(stack.getItem()) - && !GunsTool.getGunBooleanTag(tag, "Charging")) { + ) { gunMelee = 36; cantFireTime = 40; player.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, 1f, 1); @@ -474,7 +475,7 @@ public class ClientEventHandler { && !notInGame() && (!(data.normalReloading() || data.emptyReloading()) && !data.reloading() - && !GunsTool.getGunBooleanTag(tag, "Charging") + && !data.charging() && data.ammo() > 0 && !player.getCooldowns().isOnCooldown(stack.getItem()) && !GunsTool.getGunBooleanTag(tag, "NeedBoltAction") diff --git a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java index 4cc256d0d..29f1fd056 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java @@ -73,7 +73,7 @@ public class GunEventHandler { } if (stack.getItem() == ModItems.MARLIN.get() && GunsTool.getGunIntTag(tag, "BoltActionTick") == 9) { - tag.putBoolean("empty", false); + tag.remove("IsEmpty"); } if (GunsTool.getGunIntTag(tag, "BoltActionTick") == 1) { @@ -334,7 +334,7 @@ public class GunEventHandler { gunData.setReloadState(GunData.ReloadState.EMPTY_RELOADING); playGunEmptyReloadSounds(player); } - data.putBoolean("StartReload", false); + data.remove("StartReload"); } if (data.getInt("ReloadTime") > 0) { @@ -343,27 +343,27 @@ public class GunEventHandler { if (stack.getItem() == ModItems.RPG.get()) { if (data.getInt("ReloadTime") == 84) { - tag.putBoolean("empty", false); + tag.remove("IsEmpty"); } if (data.getInt("ReloadTime") == 9) { - data.putBoolean("CloseHammer", false); + data.remove("CloseHammer"); } } if (stack.getItem() == ModItems.MK_14.get() && data.getInt("ReloadTime") == 18) { - data.putBoolean("HoldOpen", false); + data.remove("HoldOpen"); } if (stack.getItem() == ModItems.SVD.get() && data.getInt("ReloadTime") == 17) { - data.putBoolean("HoldOpen", false); + data.remove("HoldOpen"); } if (stack.getItem() == ModItems.SKS.get() && data.getInt("ReloadTime") == 14) { - data.putBoolean("HoldOpen", false); + data.remove("HoldOpen"); } if (stack.getItem() == ModItems.M_60.get() && data.getInt("ReloadTime") == 55) { - data.putBoolean("HideBulletChain", false); + data.remove("HideBulletChain"); } if (stack.getItem() == ModItems.GLOCK_17.get() @@ -372,12 +372,12 @@ public class GunEventHandler { || stack.getItem() == ModItems.MP_443.get() ) { if (data.getInt("ReloadTime") == 9) { - data.putBoolean("HoldOpen", false); + data.remove("HoldOpen"); } } if (stack.getItem() == ModItems.QBZ_95.get() && data.getInt("ReloadTime") == 14) { - data.putBoolean("HoldOpen", false); + data.remove("HoldOpen"); } if (data.getInt("ReloadTime") == 1) { @@ -390,7 +390,7 @@ public class GunEventHandler { } else { playGunEmptyReload(player, gunData); } - data.putBoolean("StartReload", false); + data.remove("StartReload"); } } @@ -496,90 +496,90 @@ public class GunEventHandler { var tag = gunData.tag(); // 换弹流程计时器 - if (tag.getDouble("prepare") > 0) { - tag.putDouble("prepare", tag.getDouble("prepare") - 1); + if (tag.getDouble("PrepareTime") > 0) { + tag.putDouble("PrepareTime", tag.getDouble("PrepareTime") - 1); } - if (tag.getDouble("prepare_load") > 0) { - tag.putDouble("prepare_load", tag.getDouble("prepare_load") - 1); + if (tag.getDouble("PrepareLoadTime") > 0) { + tag.putDouble("PrepareLoadTime", tag.getDouble("PrepareLoadTime") - 1); } - if (tag.getDouble("iterative") > 0) { - tag.putDouble("iterative", tag.getDouble("iterative") - 1); + if (tag.getDouble("IterativeLoadTime") > 0) { + tag.putDouble("IterativeLoadTime", tag.getDouble("IterativeLoadTime") - 1); } - if (tag.getDouble("finish") > 0) { - tag.putDouble("finish", tag.getDouble("finish") - 1); + if (tag.getDouble("FinishTime") > 0) { + tag.putDouble("FinishTime", tag.getDouble("FinishTime") - 1); } -// player.displayClientMessage(Component.literal("prepare: " + new DecimalFormat("##.#").format(tag.getDouble("prepare")) -// + " prepare_load: " + new DecimalFormat("##.#").format(tag.getDouble("prepare_load")) -// + " iterative: " + new DecimalFormat("##.#").format(tag.getDouble("iterative")) -// + " finish: " + new DecimalFormat("##.#").format(tag.getDouble("finish")) +// player.displayClientMessage(Component.literal("prepare: " + new DecimalFormat("##.#").format(tag.getDouble("PrepareTime")) +// + " prepare_load: " + new DecimalFormat("##.#").format(tag.getDouble("PrepareLoadTime")) +// + " iterative: " + new DecimalFormat("##.#").format(tag.getDouble("IterativeLoadTime")) +// + " finish: " + new DecimalFormat("##.#").format(tag.getDouble("FinishTime")) // + " reload_stage: " + new DecimalFormat("##.#").format(tag.getDouble("reload_stage")) // ), true); // 一阶段 - if (tag.getBoolean("start_single_reload")) { + if (tag.getBoolean("StartSingleReload")) { NeoForge.EVENT_BUS.post(new ReloadEvent.Pre(player, stack)); if ((gunData.prepareLoadTime() != 0 && gunData.ammo() == 0) || stack.is(ModItems.SECONDARY_CATACLYSM.get())) { // 此处判断空仓换弹的时候,是否在准备阶段就需要装填一发,如M870 playGunPrepareLoadReloadSounds(player); int prepareLoadTime = gunData.prepareLoadTime(); - tag.putInt("prepare_load", prepareLoadTime + 1); + tag.putInt("PrepareLoadTime", prepareLoadTime + 1); player.getCooldowns().addCooldown(stack.getItem(), prepareLoadTime); } else if (gunData.prepareEmptyTime() != 0 && gunData.ammo() == 0) { // 此处判断空仓换弹,如莫辛纳甘 playGunEmptyPrepareSounds(player); int prepareEmptyTime = gunData.prepareEmptyTime(); - tag.putInt("prepare", prepareEmptyTime + 1); + tag.putInt("PrepareTime", prepareEmptyTime + 1); player.getCooldowns().addCooldown(stack.getItem(), prepareEmptyTime); } else { playGunPrepareReloadSounds(player); int prepareTime = gunData.prepareTime(); - tag.putInt("prepare", prepareTime + 1); + tag.putInt("PrepareTime", prepareTime + 1); player.getCooldowns().addCooldown(stack.getItem(), prepareTime); } - tag.putBoolean("force_stop", false); - tag.putBoolean("stop", false); + tag.remove("ForceStop"); + tag.remove("Stopped"); gunData.setReloadStage(1); gunData.setReloadState(GunData.ReloadState.NORMAL_RELOADING); - tag.putBoolean("start_single_reload", false); + tag.remove("StartSingleReload"); } - if (stack.getItem() == ModItems.M_870.get() && tag.getInt("prepare_load") == 10) { + if (stack.getItem() == ModItems.M_870.get() && tag.getInt("PrepareLoadTime") == 10) { singleLoad(player, gunData); } - if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("prepare_load") == 3) { + if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("PrepareLoadTime") == 3) { singleLoad(player, gunData); } // 一阶段结束,检查备弹,如果有则二阶段启动,无则直接跳到三阶段 - if ((tag.getDouble("prepare") == 1 || tag.getDouble("prepare_load") == 1)) { + if ((tag.getDouble("PrepareTime") == 1 || tag.getDouble("PrepareLoadTime") == 1)) { if (!InventoryTool.hasCreativeAmmoBox(player)) { var capability = player.getCapability(ModCapabilities.PLAYER_VARIABLE); if (capability == null) capability = new PlayerVariable(); if (stack.is(ModTags.Items.USE_SHOTGUN_AMMO) && capability.shotgunAmmo == 0) { - tag.putBoolean("force_stage3_start", true); + tag.putBoolean("ForceStartStage3", true); } else if (stack.is(ModTags.Items.USE_SNIPER_AMMO) && capability.sniperAmmo == 0) { - tag.putBoolean("force_stage3_start", true); + tag.putBoolean("ForceStartStage3", true); } else if ((stack.is(ModTags.Items.USE_HANDGUN_AMMO) || stack.is(ModTags.Items.SMG)) && capability.handgunAmmo == 0) { - tag.putBoolean("force_stage3_start", true); + tag.putBoolean("ForceStartStage3", true); } else if (stack.is(ModTags.Items.USE_RIFLE_AMMO) && capability.rifleAmmo == 0) { - tag.putBoolean("force_stage3_start", true); + tag.putBoolean("ForceStartStage3", true); } else if (stack.is(ModTags.Items.USE_HEAVY_AMMO) && capability.heavyAmmo == 0) { - tag.putBoolean("force_stage3_start", true); + tag.putBoolean("ForceStartStage3", true); } else if (stack.is(ModTags.Items.LAUNCHER) && GunsTool.getGunIntTag(tag, "MaxAmmo") == 0) { - tag.putBoolean("force_stage3_start", true); + tag.putBoolean("ForceStartStage3", true); } else if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && gunData.ammo() >= gunData.magazine()) { - tag.putBoolean("force_stage3_start", true); + tag.putBoolean("ForceStartStage3", true); } else { gunData.setReloadStage(2); } } else { if (stack.is(ModItems.SECONDARY_CATACLYSM.get()) && gunData.ammo() >= gunData.magazine()) { - tag.putBoolean("force_stage3_start", true); + tag.putBoolean("ForceStartStage3", true); } else { gunData.setReloadStage(2); } @@ -588,51 +588,51 @@ public class GunEventHandler { } // 强制停止换弹,进入三阶段 - if (tag.getBoolean("force_stop") && gunData.getReloadStage() == 2 && tag.getInt("iterative") > 0) { - tag.putBoolean("stop", true); + if (tag.getBoolean("ForceStop") && gunData.getReloadStage() == 2 && tag.getInt("IterativeLoadTime") > 0) { + tag.putBoolean("Stopped", true); } // 二阶段 - if ((tag.getDouble("prepare") == 0 || tag.getDouble("prepare_load") == 0) + if ((tag.getDouble("PrepareTime") == 0 || tag.getDouble("PrepareLoadTime") == 0) && gunData.getReloadStage() == 2 - && tag.getInt("iterative") == 0 - && !tag.getBoolean("stop") + && tag.getInt("IterativeLoadTime") == 0 + && !tag.getBoolean("Stopped") && gunData.ammo() < gunData.magazine() ) { playGunLoopReloadSounds(player); int iterativeTime = gunData.iterativeTime(); - tag.putDouble("iterative", iterativeTime); + tag.putDouble("IterativeLoadTime", iterativeTime); player.getCooldowns().addCooldown(stack.getItem(), iterativeTime); // 动画播放nbt - if (tag.getDouble("load_index") == 1) { - tag.putDouble("load_index", 0); + if (tag.getDouble("LoadIndex") == 1) { + tag.putDouble("LoadIndex", 0); } else { - tag.putDouble("load_index", 1); + tag.putDouble("LoadIndex", 1); } } // 装填 if ((stack.getItem() == ModItems.M_870.get() || stack.getItem() == ModItems.MARLIN.get()) - && tag.getInt("iterative") == 3 + && tag.getInt("IterativeLoadTime") == 3 ) { singleLoad(player, gunData); } - if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("iterative") == 16) { + if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && tag.getInt("IterativeLoadTime") == 16) { singleLoad(player, gunData); } if ((stack.getItem() == ModItems.K_98.get() || stack.getItem() == ModItems.MOSIN_NAGANT.get()) - && tag.getInt("iterative") == 1 + && tag.getInt("IterativeLoadTime") == 1 ) { singleLoad(player, gunData); } // 二阶段结束 - if (tag.getInt("iterative") == 1) { + if (tag.getInt("IterativeLoadTime") == 1) { // 装满结束 if (gunData.ammo() >= gunData.magazine()) { gunData.setReloadStage(3); @@ -657,35 +657,35 @@ public class GunEventHandler { } // 强制结束 - if (tag.getBoolean("stop")) { + if (tag.getBoolean("Stopped")) { gunData.setReloadStage(3); - tag.putBoolean("force_stop", false); - tag.putBoolean("stop", false); + tag.remove("ForceStop"); + tag.remove("Stopped"); } } // 三阶段 - if ((tag.getInt("iterative") == 1 && gunData.getReloadStage() == 3) || tag.getBoolean("force_stage3_start")) { + if ((tag.getInt("IterativeLoadTime") == 1 && gunData.getReloadStage() == 3) || tag.getBoolean("ForceStartStage3")) { gunData.setReloadStage(3); - tag.putBoolean("force_stage3_start", false); + tag.remove("ForceStartStage3"); int finishTime = gunData.finishTime(); - tag.putInt("finish", finishTime + 2); + tag.putInt("FinishTime", finishTime + 2); player.getCooldowns().addCooldown(stack.getItem(), finishTime + 2); playGunEndReloadSounds(player); } - if (stack.getItem() == ModItems.MARLIN.get() && tag.getInt("finish") == 10) { - tag.putBoolean("empty", false); + if (stack.getItem() == ModItems.MARLIN.get() && tag.getInt("FinishTime") == 10) { + tag.remove("IsEmpty"); } // 三阶段结束 - if (tag.getInt("finish") == 1) { + if (tag.getInt("FinishTime") == 1) { gunData.setReloadStage(0); if (gunData.boltActionTime() > 0) { GunsTool.setGunBooleanTag(tag, "NeedBoltAction", false); } gunData.setReloadState(GunData.ReloadState.NOT_RELOADING); - tag.putBoolean("start_single_reload", false); + tag.remove("StartSingleReload"); NeoForge.EVENT_BUS.post(new ReloadEvent.Post(player, stack)); } @@ -831,32 +831,29 @@ public class GunEventHandler { /** * 哨兵充能 */ - private static void handleSentinelCharge(Player player, GunData gunData) { + private static void handleSentinelCharge(Player player, GunData data) { if (!(player.getMainHandItem().getItem() instanceof GunItem)) return; - var tag = gunData.tag(); - final var data = gunData.data(); - // 启动换弹 - if (GunsTool.getGunBooleanTag(tag, "StartCharge")) { - data.putInt("ChargeTime", 127); - data.putBoolean("Charging", true); + // 启动充能 + if (data.charge.shouldStartCharge()) { + data.charge.setTime(127); SoundEvent sound1p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc("sentinel_charge")); if (sound1p != null && player instanceof ServerPlayer serverPlayer) { SoundTool.playLocalSound(serverPlayer, sound1p, 2f, 1f); } - data.putBoolean("StartCharge", true); + data.charge.markStarted(); } - if (GunsTool.getGunIntTag(tag, "ChargeTime") > 0) { - data.putInt("ChargeTime", data.getInt("ChargeTime") - 1); + if (data.charge.time() > 0) { + data.charge.reduce(); } - if (GunsTool.getGunIntTag(tag, "ChargeTime") == 17) { + if (data.charge.time() == 17) { for (var cell : player.getInventory().items) { if (cell.is(ModItems.CELL.get())) { - var stackStorage = cell.getCapability(Capabilities.EnergyStorage.ITEM); + var stackStorage = data.stack().getCapability(Capabilities.EnergyStorage.ITEM); if (stackStorage == null) continue; int stackMaxEnergy = stackStorage.getMaxEnergyStored(); @@ -875,9 +872,5 @@ public class GunEventHandler { } } } - - if (GunsTool.getGunIntTag(tag, "ChargeTime") == 1) { - data.putBoolean("Charging", false); - } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java index a02e949a9..9892da0ca 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java @@ -370,18 +370,17 @@ public class LivingEventHandler { oldData.setReloadState(GunData.ReloadState.NOT_RELOADING); if (oldData.iterativeTime() != 0) { - oldTag.putBoolean("force_stop", false); - oldTag.putBoolean("stop", false); + oldTag.remove("ForceStop"); + oldTag.remove("Stopped"); oldData.setReloadStage(0); - oldTag.putDouble("prepare", 0); - oldTag.putDouble("prepare_load", 0); - oldTag.putDouble("iterative", 0); - oldTag.putDouble("finish", 0); + oldTag.remove("PrepareTime"); + oldTag.remove("PrepareLoadTime"); + oldTag.remove("IterativeLoadTime"); + oldTag.remove("FinishTime"); } if (oldStack.is(ModItems.SENTINEL.get())) { - data.putBoolean("Charging", false); - data.putInt("ChargeTime", 0); + oldData.charge.reset(); } var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); @@ -406,22 +405,21 @@ public class LivingEventHandler { newData.setReloadState(GunData.ReloadState.NOT_RELOADING); var data = newTag.getCompound("GunData"); - data.putInt("ReloadTime", 0); + data.remove("ReloadTime"); newTag.put("GunData", data); if (newData.iterativeTime() != 0) { - newTag.putBoolean("force_stop", false); - newTag.putBoolean("stop", false); + newTag.remove("ForceStop"); + newTag.remove("Stopped"); newData.setReloadStage(0); - newTag.putDouble("prepare", 0); - newTag.putDouble("prepare_load", 0); - newTag.putDouble("iterative", 0); - newTag.putDouble("finish", 0); + newTag.remove("PrepareTime"); + newTag.remove("PrepareLoadTime"); + newTag.remove("IterativeLoadTime"); + newTag.remove("FinishTime"); } if (newStack.is(ModItems.SENTINEL.get())) { - GunsTool.setGunBooleanTag(newTag, "Charging", false); - GunsTool.setGunIntTag(newTag, "ChargeTime", 0); + newData.charge.reset(); } int level = PerkHelper.getItemPerkLevel(ModPerks.KILLING_TALLY.get(), newTag); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java index 7c5051660..c599fffd0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/PlayerEventHandler.java @@ -207,7 +207,7 @@ public class PlayerEventHandler { var tag = data.tag(); if ((stack.is(ModItems.RPG.get()) || stack.is(ModItems.BOCEK.get())) && data.ammo() == 1) { - tag.putDouble("empty", 0); + tag.remove("IsEmpty"); data.save(); } } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/GunData.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/GunData.java index 8b2dd1cb9..891cc24be 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/GunData.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/GunData.java @@ -315,7 +315,11 @@ public class GunData { } public void setReloadState(ReloadState state) { - data.putInt("ReloadState", state.ordinal()); + if (state == ReloadState.NOT_RELOADING) { + data.remove("ReloadState"); + } else { + data.putInt("ReloadState", state.ordinal()); + } } public int getReloadStage() { @@ -323,7 +327,51 @@ public class GunData { } public void setReloadStage(int stage) { - data.putInt("ReloadStage", stage); + if (stage == 0) { + data.remove("ReloadStage"); + } else { + data.putInt("ReloadStage", stage); + } + } + + public final Charge charge = new Charge(); + + public class Charge { + public void markStart() { + data.putBoolean("StartCharge", true); + } + + public boolean shouldStartCharge() { + return data.getBoolean("StartCharge"); + } + + public void markStarted() { + data.remove("StartCharge"); + } + + public int time() { + return data.getInt("ChargeTime"); + } + + public void reduce() { + setTime(time() - 1); + } + + public void setTime(int chargeTime) { + if (chargeTime <= 0) { + data.remove("ChargeTime"); + } else { + data.putInt("ChargeTime", chargeTime); + } + } + + public void reset() { + setTime(0); + } + } + + public boolean charging() { + return charge.time() > 0; } public void save() { diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java index 9da1c131f..15e497460 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/launcher/RpgItem.java @@ -138,7 +138,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon { tag.putBoolean("draw", false); if (data.ammo() == 0) { - tag.putDouble("empty", 1); + tag.putBoolean("IsEmpty", true); } } @@ -241,7 +241,7 @@ public class RpgItem extends GunItem implements GeoItem, SpecialFireWeapon { } if (data.ammo() == 1) { - tag.putBoolean("empty", true); + tag.putBoolean("IsEmpty", true); GunsTool.setGunBooleanTag(tag, "CloseHammer", true); } 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 60d8ea69c..a2796c04d 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 @@ -90,15 +90,15 @@ public class SecondaryCataclysm extends GunItem implements GeoItem, SpecialFireW var data = GunData.from(stack); final var tag = data.tag(); - if (data.getReloadStage() == 1 && tag.getDouble("prepare_load") > 0) { + if (data.getReloadStage() == 1 && tag.getDouble("PrepareLoadTime") > 0) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.prepare")); } - if (tag.getDouble("load_index") == 0 && data.getReloadStage() == 2) { + if (tag.getDouble("LoadIndex") == 0 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.iterativeload")); } - if (tag.getDouble("load_index") == 1 && data.getReloadStage() == 2) { + if (tag.getDouble("LoadIndex") == 1 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sc.iterativeload2")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/MarlinItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/MarlinItem.java index 4ae05fed1..e5da4c6b2 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/MarlinItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/rifle/MarlinItem.java @@ -56,15 +56,15 @@ public class MarlinItem extends GunItem implements GeoItem { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.shift")); } - if (data.getReloadStage() == 1 && tag.getDouble("prepare") > 0) { + if (data.getReloadStage() == 1 && tag.getDouble("PrepareTime") > 0) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.prepare")); } - if (tag.getDouble("load_index") == 0 && data.getReloadStage() == 2) { + if (tag.getDouble("LoadIndex") == 0 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload")); } - if (tag.getDouble("load_index") == 1 && data.getReloadStage() == 2) { + if (tag.getDouble("LoadIndex") == 1 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.marlin.iterativeload2")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/shotgun/M870Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/shotgun/M870Item.java index 1dcea6dd5..8fa192e03 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/shotgun/M870Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/shotgun/M870Item.java @@ -61,19 +61,19 @@ public class M870Item extends GunItem implements GeoItem { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.shift")); } - if (data.getReloadStage() == 1 && tag.getDouble("prepare_load") > 0) { + if (data.getReloadStage() == 1 && tag.getDouble("PrepareLoadTime") > 0) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.preparealt")); } - if (data.getReloadStage() == 1 && tag.getDouble("prepare") > 0) { + if (data.getReloadStage() == 1 && tag.getDouble("PrepareTime") > 0) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.prepare")); } - if (tag.getDouble("load_index") == 0 && data.getReloadStage() == 2) { + if (tag.getDouble("LoadIndex") == 0 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload")); } - if (tag.getDouble("load_index") == 1 && data.getReloadStage() == 2) { + if (tag.getDouble("LoadIndex") == 1 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.m870.iterativeload2")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/K98Item.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/K98Item.java index 75f422a16..282c07d61 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/K98Item.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/K98Item.java @@ -61,15 +61,15 @@ public class K98Item extends GunItem implements GeoItem { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.reload_empty")); } - if (data.getReloadStage() == 1 && tag.getDouble("prepare") > 0) { + if (data.getReloadStage() == 1 && tag.getDouble("PrepareTime") > 0) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.prepare")); } - if (tag.getDouble("load_index") == 0 && data.getReloadStage() == 2) { + if (tag.getDouble("LoadIndex") == 0 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload")); } - if (tag.getDouble("load_index") == 1 && data.getReloadStage() == 2) { + if (tag.getDouble("LoadIndex") == 1 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.k98.iterativeload2")); } diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/MosinNagantItem.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/MosinNagantItem.java index f0c9bd347..1115fcbe4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/MosinNagantItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/sniper/MosinNagantItem.java @@ -65,11 +65,11 @@ public class MosinNagantItem extends GunItem implements GeoItem { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.prepare")); } - if (NBTTool.getTag(stack).getDouble("load_index") == 0 && data.getReloadStage() == 2) { + if (NBTTool.getTag(stack).getDouble("LoadIndex") == 0 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.iterativeload")); } - if (NBTTool.getTag(stack).getDouble("load_index") == 1 && data.getReloadStage() == 2) { + if (NBTTool.getTag(stack).getDouble("LoadIndex") == 1 && data.getReloadStage() == 2) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.mosin.iterativeload2")); } 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 c300c0b97..bf41dff88 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 @@ -88,7 +88,7 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.reload_normal")); } - if (GunsTool.getGunBooleanTag(tag, "Charging")) { + if (data.charging()) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.sentinel.charge")); } @@ -105,8 +105,10 @@ public class SentinelItem extends GunItem implements GeoItem, EnergyStorageItem if (player.isSprinting() && player.onGround() && player.getPersistentData().getDouble("noRun") == 0 - && !(data.normalReloading() || data.emptyReloading()) - && !GunsTool.getGunBooleanTag(tag, "Charging") && ClientEventHandler.drawTime < 0.01) { + && !data.reloading() + && !data.charging() + && ClientEventHandler.drawTime < 0.01 + ) { if (player.hasEffect(MobEffects.MOVEMENT_SPEED) && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0) { return event.setAndContinue(RawAnimation.begin().thenLoop("animation.sentinel.run_fast")); } else { diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireMessage.java index 023b1dcdd..5caa9575d 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireMessage.java @@ -52,8 +52,8 @@ public record FireMessage(int msgType) implements CustomPacketPayload { var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); if (type == 0) { - if (tag.getDouble("prepare") == 0 && data.reloading() && data.ammo() > 0) { - tag.putDouble("force_stop", 1); + if (tag.getDouble("PrepareTime") == 0 && data.reloading() && data.ammo() > 0) { + tag.putBoolean("ForceStop", true); } if (cap != null) { @@ -97,7 +97,8 @@ public record FireMessage(int msgType) implements CustomPacketPayload { && !(data.normalReloading() || data.emptyReloading()) && !data.reloading() - && !GunsTool.getGunBooleanTag(tag, "Charging")) { + && !data.charging() + ) { if (!player.getCooldowns().isOnCooldown(stack.getItem()) && GunsTool.getGunBooleanTag(tag, "NeedBoltAction")) { GunsTool.setGunIntTag(tag, "BoltActionTick", data.boltActionTime() + 1); GunEventHandler.playGunBoltSounds(player); diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireModeMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireModeMessage.java index 5edecb5a4..6fa649b22 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireModeMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/FireModeMessage.java @@ -90,13 +90,13 @@ public record FireModeMessage(int msgType) implements CustomPacketPayload { && !player.isSpectator() && !(player.getCooldowns().isOnCooldown(stack.getItem())) && GunsTool.getGunIntTag(tag, "ReloadTime") == 0 - && !GunsTool.getGunBooleanTag(tag, "Charging")) { - + && !data.charging() + ) { for (var cell : player.getInventory().items) { if (cell.is(ModItems.CELL.get())) { var cap = cell.getCapability(Capabilities.EnergyStorage.ITEM); if (cap != null && cap.getEnergyStored() > 0) { - GunsTool.setGunBooleanTag(tag, "StartCharge", true); + data.charge.markStart(); } } } 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 3767d5e85..81f52c63e 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 @@ -44,10 +44,10 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload { var tag = data.tag(); if (!player.isSpectator() - && !GunsTool.getGunBooleanTag(tag, "Charging") + && !data.charging() + && !data.reloading() && GunsTool.getGunIntTag(tag, "ReloadTime") == 0 && GunsTool.getGunIntTag(tag, "BoltActionTick") == 0 - && !data.reloading() ) { boolean canSingleReload = gunItem.isIterativeReload(stack); boolean canReload = gunItem.isMagazineReload(stack) && !gunItem.isClipReload(stack); @@ -94,7 +94,7 @@ public record ReloadMessage(int msgType) implements CustomPacketPayload { } if (canSingleReload && data.ammo() < data.magazine()) { - tag.putBoolean("start_single_reload", true); + tag.putBoolean("StartSingleReload", true); } data.save(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ShootMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ShootMessage.java index ed3fb39cf..79af6cbb4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/ShootMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/ShootMessage.java @@ -66,7 +66,7 @@ public record ShootMessage(double spread) implements CustomPacketPayload { } data.setAmmo(data.ammo() - 1); - tag.putDouble("empty", 1); + tag.putBoolean("IsEmpty", true); if (stack.getItem() == ModItems.M_60.get() && data.ammo() <= 5) { GunsTool.setGunBooleanTag(tag, "HideBulletChain", true);