diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ItemModelHelper.java b/src/main/java/com/atsuishio/superbwarfare/client/ItemModelHelper.java index 0281cca5a..b917ed8cd 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ItemModelHelper.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ItemModelHelper.java @@ -1,30 +1,30 @@ package com.atsuishio.superbwarfare.client; -import com.atsuishio.superbwarfare.tools.NBTTool; -import net.minecraft.nbt.CompoundTag; +import com.atsuishio.superbwarfare.item.gun.data.Attachment; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import net.minecraft.world.item.ItemStack; import software.bernie.geckolib.cache.object.GeoBone; public class ItemModelHelper { public static void handleGunAttachments(GeoBone bone, ItemStack stack, String name) { - var rootTag = NBTTool.getTag(stack); - CompoundTag tag = rootTag.getCompound("Attachments"); + var attachments = GunData.from(stack).attachment; - splitBoneName(bone, name, "Scope", tag); - splitBoneName(bone, name, "Magazine", tag); - splitBoneName(bone, name, "Barrel", tag); - splitBoneName(bone, name, "Stock", tag); - splitBoneName(bone, name, "Grip", tag); + splitBoneName(bone, name, attachments, AttachmentType.SCOPE); + splitBoneName(bone, name, attachments, AttachmentType.MAGAZINE); + splitBoneName(bone, name, attachments, AttachmentType.BARREL); + splitBoneName(bone, name, attachments, AttachmentType.STOCK); + splitBoneName(bone, name, attachments, AttachmentType.GRIP); } - private static void splitBoneName(GeoBone bone, String boneName, String tagName, CompoundTag tag) { + private static void splitBoneName(GeoBone bone, String boneName, Attachment attachment, AttachmentType type) { try { - if (boneName.startsWith(tagName)) { + if (boneName.startsWith(type.getName())) { String[] parts = boneName.split("(?<=\\D)(?=\\d)"); if (parts.length == 2) { int index = Integer.parseInt(parts[1]); - bone.setHidden(tag.getInt(tagName) != index); + bone.setHidden(attachment.get(type) != index); } } } catch (NumberFormatException ignored) { diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/AK12ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/AK12ItemModel.java index 6093f761e..5e00d7b37 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/AK12ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/AK12ItemModel.java @@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.AK12Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -75,7 +75,7 @@ public class AK12ItemModel extends GeoModel { var data = GunData.from(stack); var tag = data.tag(); - int type = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE); + int type = data.attachment.get(AttachmentType.SCOPE); float posY = switch (type) { case 0 -> 0.781f; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/AK47ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/AK47ItemModel.java index d613490e7..c81e14bf1 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/AK47ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/AK47ItemModel.java @@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.AK47Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -72,7 +72,7 @@ public class AK47ItemModel extends GeoModel { double fp = ClientEventHandler.firePos; double fr = ClientEventHandler.fireRot; - int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE); float posYAlt = switch (type) { case 2 -> 0.45f; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Hk416ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Hk416ItemModel.java index 63a60f172..3a1aad2c3 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Hk416ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Hk416ItemModel.java @@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.Hk416Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -75,7 +75,7 @@ public class Hk416ItemModel extends GeoModel { double fp = ClientEventHandler.firePos; double fr = ClientEventHandler.fireRot; - int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE); float posY = switch (type) { case 0 -> 1.04f; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/M4ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/M4ItemModel.java index 845735cad..c88c0bed4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/M4ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/M4ItemModel.java @@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.M4Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; @@ -85,7 +85,7 @@ public class M4ItemModel extends GeoModel { double fp = ClientEventHandler.firePos; double fr = ClientEventHandler.fireRot; - int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE); posYAlt = Mth.lerp(times, posYAlt, NBTTool.getTag(stack).getBoolean("ScopeAlt") ? -0.6875f : 0.5625f); scaleZAlt = Mth.lerp(times, scaleZAlt, NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0.4f : 0.88f); @@ -176,7 +176,7 @@ public class M4ItemModel extends GeoModel { CrossHairOverlay.gunRot = shen.getRotZ(); GeoBone flare = getAnimationProcessor().getBone("flare"); - int BarrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL); + int BarrelType = GunData.from(stack).attachment.get(AttachmentType.BARREL); if (BarrelType == 1) { flare.setPosZ(-2); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Mk14ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Mk14ItemModel.java index de7e216e5..5e751014e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Mk14ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Mk14ItemModel.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.Mk14Item; import com.atsuishio.superbwarfare.tools.GunsTool; @@ -70,10 +71,10 @@ public class Mk14ItemModel extends GeoModel { double fp = ClientEventHandler.firePos; double fr = ClientEventHandler.fireRot; - int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); - int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK); - int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL); - int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP); + int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE); + int stockType = GunData.from(stack).attachment.get(AttachmentType.STOCK); + int barrelType = GunData.from(stack).attachment.get(AttachmentType.BARREL); + int gripType = GunData.from(stack).attachment.get(AttachmentType.GRIP); float posY = switch (type) { case 0 -> 1.68f; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Ntw20Model.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Ntw20Model.java index 03b42b830..9515232c7 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Ntw20Model.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Ntw20Model.java @@ -4,9 +4,9 @@ import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.heavy.Ntw20Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -74,7 +74,7 @@ public class Ntw20Model extends GeoModel { double fp = ClientEventHandler.firePos; double fr = ClientEventHandler.fireRot; - int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE); float posY = switch (type) { case 0 -> -0.25f; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Qbz95ItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Qbz95ItemModel.java index 5b81326cd..a735dd035 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/Qbz95ItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/Qbz95ItemModel.java @@ -5,10 +5,10 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.Qbz95Item; import com.atsuishio.superbwarfare.tools.GunsTool; -import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -84,8 +84,9 @@ public class Qbz95ItemModel extends GeoModel { double fp = ClientEventHandler.firePos; double fr = ClientEventHandler.fireRot; - var tag = NBTTool.getTag(stack); - int type = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE); + var data = GunData.from(stack); + var tag = data.tag(); + int type = data.attachment.get(AttachmentType.SCOPE); float posYAlt = switch (type) { case 2 -> 0.85f; @@ -175,7 +176,7 @@ public class Qbz95ItemModel extends GeoModel { } GeoBone flare = getAnimationProcessor().getBone("flare"); - int BarrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL); + int BarrelType = data.attachment.get(AttachmentType.BARREL); if (BarrelType == 1) { flare.setPosZ(-2); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/RpkItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/RpkItemModel.java index 43d1d6bfa..1cca3d890 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/RpkItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/RpkItemModel.java @@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.machinegun.RpkItem; -import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -76,7 +76,7 @@ public class RpkItemModel extends GeoModel { var data = GunData.from(stack); var tag = data.tag(); - int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE); scopeY = Mth.lerp(times, scopeY, tag.getBoolean("ScopeAlt") ? -0.7f : 0.2f); scaleZAlt = Mth.lerp(times, scaleZAlt, tag.getBoolean("ScopeAlt") ? 0.45f : 0.74f); posZAlt = Mth.lerp(times, posZAlt, tag.getBoolean("ScopeAlt") ? 3.3f : 4.25f); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/SvdItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/SvdItemModel.java index 82fa2f9b0..f80135e8a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/SvdItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/SvdItemModel.java @@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.sniper.SvdItem; import com.atsuishio.superbwarfare.tools.GunsTool; @@ -69,10 +70,10 @@ public class SvdItemModel extends GeoModel { double fp = ClientEventHandler.firePos; double fr = ClientEventHandler.fireRot; - int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); - int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK); - int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL); - int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP); + int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE); + int stockType = GunData.from(stack).attachment.get(AttachmentType.STOCK); + int barrelType = GunData.from(stack).attachment.get(AttachmentType.BARREL); + int gripType = GunData.from(stack).attachment.get(AttachmentType.GRIP); float posX = switch (type) { case 0, 1 -> 1.701f; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/TracheliumItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/TracheliumItemModel.java index c60f7276d..9b03eab69 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/TracheliumItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/TracheliumItemModel.java @@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.handgun.Trachelium; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; @@ -80,10 +80,10 @@ public class TracheliumItemModel extends GeoModel { double fp = ClientEventHandler.firePos; double fr = ClientEventHandler.fireRot; - int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK); - int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL); - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); - int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP); + int stockType = GunData.from(stack).attachment.get(AttachmentType.STOCK); + int barrelType = GunData.from(stack).attachment.get(AttachmentType.BARREL); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); + int gripType = GunData.from(stack).attachment.get(AttachmentType.GRIP); posYAlt = Mth.lerp(times, posYAlt, NBTTool.getTag(stack).getBoolean("ScopeAlt") ? -1.98f : -0.83f); scaleZAlt = Mth.lerp(times, scaleZAlt, NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0.4f : 0.8f); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/model/item/VectorItemModel.java b/src/main/java/com/atsuishio/superbwarfare/client/model/item/VectorItemModel.java index c3617951e..8546443f5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/model/item/VectorItemModel.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/model/item/VectorItemModel.java @@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.smg.VectorItem; -import com.atsuishio.superbwarfare.tools.GunsTool; import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.Mth; @@ -86,7 +86,7 @@ public class VectorItemModel extends GeoModel { double fp = ClientEventHandler.firePos; double fr = ClientEventHandler.fireRot; - int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE); float posY = switch (type) { case 1 -> 0.74f; diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/AK12ItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/AK12ItemRenderer.java index dd30f1c58..1724a2c7a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/AK12ItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/AK12ItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.AK12ItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.AK12Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -84,36 +85,36 @@ public class AK12ItemRenderer extends GeoItemRenderer { if (name.equals("Cross1")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2); } if (name.equals("Cross3")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && (name.equals("hidden2"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3 && (name.equals("jing") || name.equals("Barrel") || name.equals("humu") || name.equals("qiangguan") || name.equals("houzhunxing"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } if (name.equals("flare")) { - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 1) { + if (GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 1) { bone.setPosZ(2.25f); } - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/AK47ItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/AK47ItemRenderer.java index 2e25ff25c..4396e9e31 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/AK47ItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/AK47ItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.AK47ItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.AK47Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -84,42 +85,42 @@ public class AK47ItemRenderer extends GeoItemRenderer { if (name.equals("Cross1")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2); } if (name.equals("Cross3")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3); } if (name.equals("humu1")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.GRIP) != 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.GRIP) != 0); } if (name.equals("humu2")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.GRIP) == 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.GRIP) == 0); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && (name.equals("Hidden") || name.equals("gun") || name.equals("Lefthand")) && ClientEventHandler.zoom && !NBTTool.getTag(itemStack).getBoolean("HoloHidden")) { bone.setHidden(true); renderingArms = false; } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3 && (name.equals("jing") || name.equals("Barrel") || name.equals("humu") || name.equals("qiangguan") || name.equals("houzhunxing"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Aa12ItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Aa12ItemRenderer.java index 26bbf5ab5..c2b6dbaa9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Aa12ItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Aa12ItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.Aa12ItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.shotgun.Aa12Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.Minecraft; @@ -81,7 +82,7 @@ public class Aa12ItemRenderer extends GeoItemRenderer { if (!itemStack.is(ModTags.Items.GUN)) return; if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Hk416ItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Hk416ItemRenderer.java index 3c7be69f9..9f2555b77 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Hk416ItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Hk416ItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.Hk416ItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.Hk416Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -84,33 +85,33 @@ public class Hk416ItemRenderer extends GeoItemRenderer { if (name.equals("Cross1")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2); } if (name.equals("Cross3")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && (name.equals("hidden"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3 && (name.equals("jing") || name.equals("Barrel") || name.equals("yugu") || name.equals("qiangguan"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/InsidiousItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/InsidiousItemRenderer.java index 3c3f263c2..d9d7f4bc0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/InsidiousItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/InsidiousItemRenderer.java @@ -4,8 +4,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper; import com.atsuishio.superbwarfare.client.model.item.InsidiousItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.InsidiousItem; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -81,7 +82,7 @@ public class InsidiousItemRenderer extends GeoItemRenderer { if (!itemStack.is(ModTags.Items.GUN)) return; if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/M4ItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/M4ItemRenderer.java index 002e7304c..d59c54ff0 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/M4ItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/M4ItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.M4ItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.M4Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -84,40 +85,40 @@ public class M4ItemRenderer extends GeoItemRenderer { if (name.equals("Cross1")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2 || NBTTool.getTag(itemStack).getBoolean("ScopeAlt")); } if (name.equals("CrossAlt")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2 || !(NBTTool.getTag(itemStack).getBoolean("ScopeAlt"))); } if (name.equals("Cross3")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 && !NBTTool.getTag(itemStack).getBoolean("ScopeAlt") && (name.equals("hidden"))) { + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && !NBTTool.getTag(itemStack).getBoolean("ScopeAlt") && (name.equals("hidden"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3 && (name.equals("hidden2") || name.equals("yugu") || name.equals("qiangguan") || name.equals("Barrel"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); @@ -128,7 +129,7 @@ public class M4ItemRenderer extends GeoItemRenderer { } if (name.equals("Sight")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3); } ItemModelHelper.handleGunAttachments(bone, itemStack, name); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Mk14ItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Mk14ItemRenderer.java index b0751d71a..23d6a4cc5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Mk14ItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Mk14ItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.Mk14ItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.Mk14Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -82,39 +83,39 @@ public class Mk14ItemRenderer extends GeoItemRenderer { if (!itemStack.is(ModTags.Items.GUN)) return; if (name.equals("qiaojia")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 0); } if (name.equals("Cross1")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2); } if (name.equals("Cross3")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && (name.equals("hidden"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3 && (name.equals("jing") || name.equals("yugu") || name.equals("qiangguan") || name.equals("Barrel"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Ntw20Renderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Ntw20Renderer.java index 25905630b..c4ec14a3b 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Ntw20Renderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Ntw20Renderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.Ntw20Model; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.heavy.Ntw20Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -82,39 +83,39 @@ public class Ntw20Renderer extends GeoItemRenderer { if (!itemStack.is(ModTags.Items.GUN)) return; if (name.equals("ironSight")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 0); } if (name.equals("Cross1")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2); } if (name.equals("Cross3")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && (name.equals("bone1") || name.equals("zhituiqi") || name.equals("guan") || name.equals("hidden"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3 && (name.equals("bone1") || name.equals("zhituiqi") || name.equals("guan") || name.equals("jing") || name.equals("rail") || name.equals("base2") || name.equals("guan7"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Qbz95ItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Qbz95ItemRenderer.java index 7b09de31b..736fd6c83 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Qbz95ItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/Qbz95ItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.Qbz95ItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.rifle.Qbz95Item; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -84,45 +85,45 @@ public class Qbz95ItemRenderer extends GeoItemRenderer { if (name.equals("Cross1")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("tiba")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 0); } if (name.equals("longbow")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 0); } if (name.equals("under_rail")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.GRIP) == 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.GRIP) == 0); } if (name.equals("Cross2")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2); } if (name.equals("Cross3")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && (name.equals("hidden"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3 && (name.equals("hidden2") || name.equals("jimiao2"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/RpkItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/RpkItemRenderer.java index db58a2c2f..c96c98efd 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/RpkItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/RpkItemRenderer.java @@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.RpkItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.machinegun.RpkItem; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import net.minecraft.client.Minecraft; @@ -88,49 +88,49 @@ public class RpkItemRenderer extends GeoItemRenderer { if (name.equals("Cross1")) { bone.setHidden(tag.getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(tag.getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2 || tag.getBoolean("ScopeAlt")); } if (name.equals("CrossAlt")) { bone.setHidden(tag.getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2 || !(tag.getBoolean("ScopeAlt"))); } if (name.equals("Cross3")) { bone.setHidden(tag.getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3); } if (name.equals("humu1")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.GRIP) != 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.GRIP) != 0); } if (name.equals("humu2")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.GRIP) == 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.GRIP) == 0); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 && !tag.getBoolean("ScopeAlt") + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && !tag.getBoolean("ScopeAlt") && (name.equals("glass") || name.equals("Barrel") || name.equals("humu") || name.equals("qiangguan"))) { bone.setHidden(!tag.getBoolean("HoloHidden") && ClientEventHandler.zoom); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3 + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3 && (name.equals("jing") || name.equals("Barrel") || name.equals("humu") || name.equals("qiangguan") || name.equals("houzhunxing"))) { bone.setHidden(!tag.getBoolean("HoloHidden") && ClientEventHandler.zoom); } if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/SvdItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/SvdItemRenderer.java index f39a9f083..94cd798a4 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/SvdItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/SvdItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.SvdItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.sniper.SvdItem; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -82,32 +83,32 @@ public class SvdItemRenderer extends GeoItemRenderer { if (!itemStack.is(ModTags.Items.GUN)) return; if (name.equals("mount")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 0 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 0 || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2); } if (name.equals("Cross1")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2); } - if ((GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 3) + if ((GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 3) && (name.equals("Hidden2") || name.equals("Hidden") || name.equals("gun") || name.equals("bolt") || name.equals("Lefthand") || name.equals("Barrel") || name.equals("bipod") || name.equals("mount")) && ClientEventHandler.zoom && !NBTTool.getTag(itemStack).getBoolean("HoloHidden")) { bone.setHidden(true); renderingArms = false; } if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 3) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 3) { bone.setHidden(true); } else { - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 && ClientEventHandler.zoom && !NBTTool.getTag(itemStack).getBoolean("HoloHidden")) { + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && ClientEventHandler.zoom && !NBTTool.getTag(itemStack).getBoolean("HoloHidden")) { bone.setPosY(-2f); } bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/TracheliumItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/TracheliumItemRenderer.java index 2a5140183..6c8fbb708 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/TracheliumItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/TracheliumItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.TracheliumItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.handgun.Trachelium; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -84,49 +85,49 @@ public class TracheliumItemRenderer extends GeoItemRenderer { if (!itemStack.is(ModTags.Items.GUN)) return; if (name.equals("humu")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 0 && GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.GRIP) == 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 0 && GunData.from(itemStack).attachment.get(AttachmentType.GRIP) == 0); } if (name.equals("qianzhunxing1")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) > 0 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.GRIP) > 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) > 0 || GunData.from(itemStack).attachment.get(AttachmentType.GRIP) > 0); } if (name.equals("railup")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 0); } if (name.equals("raildown")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.GRIP) == 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.GRIP) == 0); } if (name.equals("Cross1")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2 || NBTTool.getTag(itemStack).getBoolean("ScopeAlt")); } if (name.equals("CrossAlt")) { bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2 || !(NBTTool.getTag(itemStack).getBoolean("ScopeAlt"))); } - if (GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) == 2 && !NBTTool.getTag(itemStack).getBoolean("ScopeAlt") && (name.equals("hidden"))) { + if (GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) == 2 && !NBTTool.getTag(itemStack).getBoolean("ScopeAlt") && (name.equals("hidden"))) { bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); } ItemModelHelper.handleGunAttachments(bone, itemStack, name); if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/VectorItemRenderer.java b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/VectorItemRenderer.java index b847f7569..fdde209ed 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/VectorItemRenderer.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/renderer/item/VectorItemRenderer.java @@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper; import com.atsuishio.superbwarfare.client.model.item.VectorItemModel; import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; +import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.smg.VectorItem; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; @@ -89,21 +90,21 @@ public class VectorItemRenderer extends GeoItemRenderer { if (name.equals("Cross1")) { bone.setHidden(tag.getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); } if (name.equals("Cross2")) { bone.setHidden(tag.getBoolean("HoloHidden") || !ClientEventHandler.zoom - || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); + || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2); } if (name.equals("tuoxin")) { - bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.STOCK) == 0); + bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.STOCK) == 0); } if (name.equals("flare")) { - if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { + if (ClientEventHandler.firePosTimer == 0 || ClientEventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { bone.setHidden(true); } else { bone.setHidden(false); @@ -143,17 +144,17 @@ public class VectorItemRenderer extends GeoItemRenderer { // if (name.equals("Cross1")) { // bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") // || !ClientEventHandler.zoom -// || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); +// || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1); // } // // if (name.equals("Cross2")) { // bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") // || !ClientEventHandler.zoom -// || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); +// || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2); // } // // if (name.equals("tuoxin")) { -// bone.setHidden(GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.STOCK) == 0); +// bone.setHidden(GunData.from(itemStack).attachment.get(AttachmentType.STOCK) == 0); // } // // if (name.equals("flare")) { @@ -163,7 +164,7 @@ public class VectorItemRenderer extends GeoItemRenderer { //// } //// } //// -//// ItemModelHelper.handleGunAttachments(bone, itemStack, name);EventHandler.firePosTimer > 0.5 || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.BARREL) == 2) { +//// ItemModelHelper.handleGunAttachments(bone, itemStack, name);EventHandler.firePosTimer > 0.5 || GunData.from(itemStack).attachment.get(AttachmentType.BARREL) == 2) { // bone.setHidden(true); // } else { // bone.setHidden(false); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java index 5020c6da0..fbfb380d5 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/ClientEventHandler.java @@ -11,6 +11,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.network.message.send.*; import com.atsuishio.superbwarfare.perk.AmmoPerk; @@ -235,7 +236,7 @@ public class ClientEventHandler { isProne(player); beamShoot(player, stack); handleLungeAttack(player, stack); - handleGunMelee(player, stack, tag); + handleGunMelee(player, stack); var options = Minecraft.getInstance().options; short keys = 0; @@ -301,7 +302,7 @@ public class ClientEventHandler { && !level.getBlockState(BlockPos.containing(player.getX() + 0.7 * player.getLookAngle().x, player.getY() + 1.5, player.getZ() + 0.7 * player.getLookAngle().z)).canOcclude(); } - public static void handleGunMelee(Player player, ItemStack stack, final CompoundTag tag) { + public static void handleGunMelee(Player player, ItemStack stack) { if (stack.getItem() instanceof GunItem gunItem) { var data = GunData.from(stack); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); @@ -686,7 +687,8 @@ public class ClientEventHandler { player.playSound(ModSounds.HENG.get(), 1f, 1f); } - int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL); + var data = GunData.from(stack); + int barrelType = data.attachment.get(AttachmentType.BARREL); SoundEvent sound1p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_1p_s" : "_fire_1p"))); @@ -822,7 +824,7 @@ public class ClientEventHandler { if (player == null) return; ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem gunItem)) return; - final var tag = NBTTool.getTag(stack); + var data = GunData.from(stack); if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.isDriver(player) && iArmedVehicle.hidePassenger(player)) return; @@ -833,12 +835,12 @@ public class ClientEventHandler { if (player.isCrouching() && player.getBbHeight() >= 1 && !isProne(player)) { pose = 0.85f; } else if (isProne(player)) { - pose = (GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) ? 0 : 0.25f; + pose = (data.attachment.get(AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) ? 0 : 0.25f; } else { pose = 1; } - int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK); + int stockType = data.attachment.get(AttachmentType.STOCK); double sway = switch (stockType) { case 1 -> 1; @@ -846,7 +848,6 @@ public class ClientEventHandler { default -> 0.8; }; - var data = GunData.from(stack); double customWeight = data.customWeight(); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null); @@ -884,7 +885,6 @@ public class ClientEventHandler { } } - float times = Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(); LocalPlayer player = Minecraft.getInstance().player; float yaw = event.getYaw(); @@ -918,15 +918,15 @@ public class ClientEventHandler { } if (level != null && stack.is(ModTags.Items.GUN)) { - handleWeaponSway(living, tag); + handleWeaponSway(living); handleWeaponMove(living); handleWeaponZoom(living); handlePlayerBreath(living); - handleWeaponFire(event, living, tag); + handleWeaponFire(event, living); handleWeaponShell(); - handleGunRecoil(tag); + handleGunRecoil(); handleBowPullAnimation(living); - handleWeaponDraw(living, tag); + handleWeaponDraw(living); handlePlayerCamera(event); } @@ -979,16 +979,18 @@ public class ClientEventHandler { } } - private static void handleWeaponSway(LivingEntity entity, final CompoundTag tag) { + private static void handleWeaponSway(LivingEntity entity) { ItemStack stack = entity.getMainHandItem(); + if (stack.getItem() instanceof GunItem gunItem && entity instanceof Player player) { + var data = GunData.from(stack); float times = 2 * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8); double pose; if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && isProne(player)) { pose = 0.85; } else if (isProne(player)) { - pose = (GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) ? 0 : 0.25f; + pose = (data.attachment.get(AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) ? 0 : 0.25f; } else { pose = 1; } @@ -1067,7 +1069,6 @@ public class ClientEventHandler { if (!(entity instanceof Player player)) return; var stack = player.getMainHandItem(); var data = GunData.from(stack); - final var tag = data.tag(); float times = 5 * Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(); double weight = data.weight(); @@ -1093,7 +1094,7 @@ public class ClientEventHandler { zoomPosZ = AnimationCurves.PARABOLA.apply(zoomTime); } - private static void handleWeaponFire(ViewportEvent.ComputeCameraAngles event, LivingEntity entity, final CompoundTag tag) { + private static void handleWeaponFire(ViewportEvent.ComputeCameraAngles event, LivingEntity entity) { float times = 2f * Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.48f); float yaw = event.getYaw(); float pitch = event.getPitch(); @@ -1186,15 +1187,16 @@ public class ClientEventHandler { } } - private static void handleGunRecoil(final CompoundTag tag) { + private static void handleGunRecoil() { Player player = Minecraft.getInstance().player; if (player == null) return; ItemStack stack = player.getMainHandItem(); if (!(stack.getItem() instanceof GunItem gunItem)) return; + var data = GunData.from(stack); float times = (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 1.6); - int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL); - int gripType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP); + int barrelType = data.attachment.get(AttachmentType.BARREL); + int gripType = data.attachment.get(AttachmentType.GRIP); double recoil = switch (barrelType) { case 1 -> 1.5; @@ -1220,7 +1222,6 @@ public class ClientEventHandler { gripRecoilY = 1.25; } - var data = GunData.from(stack); double customWeight = data.customWeight(); double rpm = 1; @@ -1239,7 +1240,7 @@ public class ClientEventHandler { if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && !isProne(player)) { pose = 0.7f; } else if (isProne(player)) { - if (GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) { + if (data.attachment.get(AttachmentType.GRIP) == 3 || gunItem.hasBipod(stack)) { pose = 0.1f; } else { pose = 0.5f; @@ -1526,7 +1527,7 @@ public class ClientEventHandler { burstFireAmount = 0; } - private static void handleWeaponDraw(LivingEntity entity, final CompoundTag tag) { + private static void handleWeaponDraw(LivingEntity entity) { float times = Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(); ItemStack stack = entity.getMainHandItem(); var data = GunData.from(stack); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java index 3316608e8..1db8a4098 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/GunEventHandler.java @@ -10,6 +10,7 @@ import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.item.gun.data.ReloadState; import com.atsuishio.superbwarfare.perk.AmmoPerk; @@ -128,7 +129,7 @@ public class GunEventHandler { } float soundRadius = (float) data.soundRadius(); - int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL); + int barrelType = data.attachment.get(AttachmentType.BARREL); SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p"))); if (sound3p != null) { 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 2698ee49b..eca707ae8 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/GunItem.java @@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.init.ModItems; import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.CustomRendererItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -398,34 +399,34 @@ public abstract class GunItem extends Item implements CustomRendererItem { * 获取额外总重量加成 */ public double getCustomWeight(ItemStack stack) { - CompoundTag tag = GunData.from(stack).tag().getCompound("Attachments"); + var attachment = GunData.from(stack).attachment; - double scopeWeight = switch (tag.getInt("Scope")) { + double scopeWeight = switch (attachment.get(AttachmentType.SCOPE)) { case 1 -> 0.5; case 2 -> 1; case 3 -> 1.5; default -> 0; }; - double barrelWeight = switch (tag.getInt("Barrel")) { + double barrelWeight = switch (attachment.get(AttachmentType.BARREL)) { case 1 -> 0.5; case 2 -> 1; default -> 0; }; - double magazineWeight = switch (tag.getInt("Magazine")) { + double magazineWeight = switch (attachment.get(AttachmentType.MAGAZINE)) { case 1 -> 1; case 2 -> 2; default -> 0; }; - double stockWeight = switch (tag.getInt("Stock")) { + double stockWeight = switch (attachment.get(AttachmentType.STOCK)) { case 1 -> -2; case 2 -> 1.5; default -> 0; }; - double gripWeight = switch (tag.getInt("Grip")) { + double gripWeight = switch (attachment.get(AttachmentType.GRIP)) { case 1, 2 -> 0.25; case 3 -> 1; default -> 0; @@ -445,7 +446,7 @@ public abstract class GunItem extends Item implements CustomRendererItem { * 获取额外音效半径加成 */ public double getCustomSoundRadius(ItemStack stack) { - return GunData.from(stack).tag().getCompound("Attachments").getInt("Barrel") == 2 ? 0.6 : 1; + return GunData.from(stack).attachment.get(AttachmentType.BARREL) == 2 ? 0.6 : 1; } public int getCustomBoltActionTime(ItemStack stack) { diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/data/Attachment.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/Attachment.java new file mode 100644 index 000000000..01b957f6d --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/Attachment.java @@ -0,0 +1,19 @@ +package com.atsuishio.superbwarfare.item.gun.data; + +import net.minecraft.nbt.CompoundTag; + +public final class Attachment { + private final CompoundTag attachment; + + Attachment(GunData gun) { + this.attachment = gun.attachment(); + } + + public int get(AttachmentType type) { + return attachment.getInt(type.getName()); + } + + public void set(AttachmentType type, int value) { + attachment.putInt(type.getName(), value); + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/data/AttachmentType.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/AttachmentType.java new file mode 100644 index 000000000..4cc5c6e9e --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/AttachmentType.java @@ -0,0 +1,19 @@ +package com.atsuishio.superbwarfare.item.gun.data; + +public enum AttachmentType { + SCOPE("Scope"), + MAGAZINE("Magazine"), + BARREL("Barrel"), + STOCK("Stock"), + GRIP("Grip"); + + private final String name; + + AttachmentType(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/com/atsuishio/superbwarfare/item/gun/data/GunData.java b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/GunData.java index f751b260a..edcb21d98 100644 --- a/src/main/java/com/atsuishio/superbwarfare/item/gun/data/GunData.java +++ b/src/main/java/com/atsuishio/superbwarfare/item/gun/data/GunData.java @@ -21,6 +21,7 @@ public class GunData { private final CompoundTag tag; private final CompoundTag data; private final CompoundTag perk; + private final CompoundTag attachmentTag; private final String id; private static final WeakHashMap dataCache = new WeakHashMap<>(); @@ -37,23 +38,25 @@ public class GunData { var customData = stack.get(DataComponents.CUSTOM_DATA); this.tag = customData != null ? customData.copyTag() : new CompoundTag(); - if (!tag.contains("GunData")) { - data = new CompoundTag(); - tag.put("GunData", data); - } else { - data = tag.getCompound("GunData"); - } - - if (!tag.contains("PerkData")) { - perk = new CompoundTag(); - tag.put("PerkData", perk); - } else { - perk = tag.getCompound("PerkData"); - } + data = getOrPut("GunData"); + perk = getOrPut("PerkData"); + attachmentTag = getOrPut("Attachments"); reload = new Reload(this); charge = new Charge(this); bolt = new Bolt(this); + attachment = new Attachment(this); + } + + private CompoundTag getOrPut(String name) { + CompoundTag tag; + if (!this.tag.contains(name)) { + tag = new CompoundTag(); + this.tag.put(name, tag); + } else { + tag = this.tag.getCompound(name); + } + return tag; } public boolean initialized() { @@ -96,6 +99,10 @@ public class GunData { return perk; } + public CompoundTag attachment() { + return attachmentTag; + } + double getGunData(String key) { return getGunData(key, 0); } @@ -214,12 +221,12 @@ public class GunData { } public double minZoom() { - int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE); + int scopeType = this.attachment.get(AttachmentType.SCOPE); return scopeType == 3 ? getGunData("MinZoom", 1.25) : 1.25; } public double maxZoom() { - int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE); + int scopeType = this.attachment.get(AttachmentType.SCOPE); return scopeType == 3 ? getGunData("MaxZoom", 1) : 114514; } @@ -294,6 +301,7 @@ public class GunData { } public final Bolt bolt; + public final Attachment attachment; public void save() { stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag)); 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 149c19b75..15111a35c 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 @@ -7,15 +7,14 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Style; import net.minecraft.sounds.SoundEvent; @@ -65,9 +64,9 @@ public class Trachelium extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; - final var tag = NBTTool.getTag(stack); - boolean stock = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK) == 2; - boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) > 0 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE) > 0; + var data = GunData.from(stack); + boolean stock = data.attachment.get(AttachmentType.STOCK) == 2; + boolean grip = data.attachment.get(AttachmentType.GRIP) > 0 || data.attachment.get(AttachmentType.SCOPE) > 0; if (ClientEventHandler.firePosTimer > 0 && ClientEventHandler.firePosTimer < 1.7) { if (stock) { @@ -106,10 +105,9 @@ public class Trachelium extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); - boolean stock = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK) == 2; - boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) > 0 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE) > 0; + boolean stock = data.attachment.get(AttachmentType.STOCK) == 2; + boolean grip = data.attachment.get(AttachmentType.GRIP) > 0 || data.attachment.get(AttachmentType.SCOPE) > 0; if (data.bolt.actionTime() > 0) { if (stock) { @@ -236,18 +234,17 @@ public class Trachelium extends GunItem implements GeoItem { @ParametersAreNonnullByDefault public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { super.inventoryTick(stack, world, entity, slot, selected); - final var tag = NBTTool.getTag(stack); + var data = GunData.from(stack); - int scopeType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE); - int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK); - CompoundTag tags = tag.getCompound("Attachments"); + int scopeType = data.attachment.get(AttachmentType.SCOPE); + int stockType = data.attachment.get(AttachmentType.STOCK); if (stockType == 1) { - tags.putInt("Stock", 2); + data.attachment.set(AttachmentType.STOCK, 2); } if (scopeType == 3) { - tags.putInt("Scope", 0); + data.attachment.set(AttachmentType.SCOPE, 0); } } @@ -258,12 +255,12 @@ public class Trachelium extends GunItem implements GeoItem { @Override public boolean canSwitchScope(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 2; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 2; } private boolean useSpecialAttributes(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); - int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); + int gripType = GunData.from(stack).attachment.get(AttachmentType.GRIP); return scopeType > 0 || gripType > 0; } @@ -277,7 +274,7 @@ public class Trachelium extends GunItem implements GeoItem { @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return scopeType == 2 ? (NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75) : 0; } 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 263d2717e..6d4f606f0 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 @@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.init.ModRarity; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -57,7 +58,6 @@ public class Ntw20Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); if (data.bolt.actionTime() > 0) { return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.shift")); @@ -80,7 +80,6 @@ public class Ntw20Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); if (player.isSprinting() && player.onGround() && player.getPersistentData().getDouble("noRun") == 0 @@ -127,12 +126,12 @@ public class Ntw20Item extends GunItem implements GeoItem { @Override public boolean canAdjustZoom(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3; } @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return switch (scopeType) { case 2 -> 2.25; case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); @@ -142,7 +141,7 @@ public class Ntw20Item extends GunItem implements GeoItem { @Override public int getCustomMagazine(ItemStack stack) { - return switch (GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE)) { + return switch (GunData.from(stack).attachment.get(AttachmentType.MAGAZINE)) { case 1 -> 3; case 2 -> 6; default -> 0; 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 df2d65a51..2a5c8cbef 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 @@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -15,7 +16,6 @@ import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.effect.MobEffects; @@ -57,10 +57,9 @@ public class RpkItem extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - var tag = data.tag(); - boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2; - boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2; + boolean drum = data.attachment.get(AttachmentType.MAGAZINE) == 2; + boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || GunData.from(stack).attachment.get(AttachmentType.GRIP) == 2; if (GunData.from(stack).reload.empty()) { if (drum) { @@ -137,7 +136,7 @@ public class RpkItem extends GunItem implements GeoItem { @Override public int getCustomMagazine(ItemStack stack) { - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + int magType = GunData.from(stack).attachment.get(AttachmentType.MAGAZINE); return switch (magType) { case 1 -> 20; case 2 -> 60; @@ -147,7 +146,7 @@ public class RpkItem extends GunItem implements GeoItem { @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return switch (scopeType) { case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75; case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); @@ -157,7 +156,7 @@ public class RpkItem extends GunItem implements GeoItem { @Override public boolean canAdjustZoom(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3; } @Override @@ -189,19 +188,19 @@ public class RpkItem extends GunItem implements GeoItem { @ParametersAreNonnullByDefault public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) { super.inventoryTick(stack, level, entity, slot, selected); - int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP); + + var data = GunData.from(stack); + int gripType = data.attachment.get(AttachmentType.GRIP); if (gripType == 3) { - var data = GunData.from(stack); - CompoundTag tag = data.tag().getCompound("Attachments"); - tag.putInt("Grip", 0); + data.attachment.set(AttachmentType.GRIP, 0); data.save(); } } @Override public boolean canSwitchScope(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 2; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 2; } @Override 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 73f0f50b1..a43537559 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 @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -57,10 +58,9 @@ public class AK12Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); - boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2; - boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; + boolean drum = data.attachment.get(AttachmentType.MAGAZINE) == 2; + boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2; if (GunData.from(stack).reload.empty()) { if (grip) { @@ -134,12 +134,12 @@ public class AK12Item extends GunItem implements GeoItem { @Override public boolean canAdjustZoom(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3; } @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return switch (scopeType) { case 2 -> 2.15; case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); @@ -149,7 +149,7 @@ public class AK12Item extends GunItem implements GeoItem { @Override public int getCustomMagazine(ItemStack stack) { - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + int magType = GunData.from(stack).attachment.get(AttachmentType.MAGAZINE); return switch (magType) { case 1 -> 15; case 2 -> 45; 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 79d156906..dbb93c7d9 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 @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -57,10 +58,9 @@ public class AK47Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); - boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2; - boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; + boolean drum = data.attachment.get(AttachmentType.MAGAZINE) == 2; + boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2; if (GunData.from(stack).reload.empty()) { if (drum) { @@ -142,7 +142,7 @@ public class AK47Item extends GunItem implements GeoItem { @Override public int getCustomMagazine(ItemStack stack) { - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + int magType = GunData.from(stack).attachment.get(AttachmentType.MAGAZINE); return switch (magType) { case 1 -> 15; case 2 -> 40; @@ -152,7 +152,7 @@ public class AK47Item extends GunItem implements GeoItem { @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return switch (scopeType) { case 2 -> 2.75; case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); @@ -162,7 +162,7 @@ public class AK47Item extends GunItem implements GeoItem { @Override public boolean canAdjustZoom(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3; } @Override 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 daafe0070..b3a7cdedd 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 @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -52,10 +53,9 @@ public class Hk416Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); - boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2; - boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; + boolean drum = data.attachment.get(AttachmentType.MAGAZINE) == 2; + boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2; if (GunData.from(stack).reload.empty()) { if (drum) { @@ -132,7 +132,7 @@ public class Hk416Item extends GunItem implements GeoItem { @Override public int getCustomMagazine(ItemStack stack) { - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + int magType = GunData.from(stack).attachment.get(AttachmentType.MAGAZINE); return switch (magType) { case 1 -> 15; case 2 -> 30; @@ -142,7 +142,7 @@ public class Hk416Item extends GunItem implements GeoItem { @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return switch (scopeType) { case 2 -> 2.25; case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); @@ -152,7 +152,7 @@ public class Hk416Item extends GunItem implements GeoItem { @Override public boolean canAdjustZoom(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3; } @Override 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 510658b5e..bd022713d 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 @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -53,10 +54,9 @@ public class M4Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); - boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2; - boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; + boolean drum = data.attachment.get(AttachmentType.MAGAZINE) == 2; + boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2; if (data.reload.empty()) { if (drum) { @@ -143,12 +143,12 @@ public class M4Item extends GunItem implements GeoItem { @Override public boolean canSwitchScope(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 2; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 2; } @Override public int getCustomMagazine(ItemStack stack) { - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + int magType = GunData.from(stack).attachment.get(AttachmentType.MAGAZINE); return switch (magType) { case 1 -> 15; case 2 -> 30; @@ -158,7 +158,7 @@ public class M4Item extends GunItem implements GeoItem { @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return switch (scopeType) { case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75; case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); @@ -168,7 +168,7 @@ public class M4Item extends GunItem implements GeoItem { @Override public boolean canAdjustZoom(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3; } @Override 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 2494ef528..7a26d949f 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 @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -52,10 +53,9 @@ public class Mk14Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); - boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2; - boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; + boolean drum = data.attachment.get(AttachmentType.MAGAZINE) == 2; + boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2; if (data.reload.empty()) { if (drum) { @@ -137,7 +137,7 @@ public class Mk14Item extends GunItem implements GeoItem { @Override public int getCustomMagazine(ItemStack stack) { - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + int magType = GunData.from(stack).attachment.get(AttachmentType.MAGAZINE); return switch (magType) { case 1 -> 10; case 2 -> 30; @@ -147,7 +147,7 @@ public class Mk14Item extends GunItem implements GeoItem { @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return switch (scopeType) { case 2 -> 2.25; case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); @@ -157,7 +157,7 @@ public class Mk14Item extends GunItem implements GeoItem { @Override public boolean canAdjustZoom(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3; } @Override 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 a50792ba0..a9342718b 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 @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -14,7 +15,6 @@ import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.effect.MobEffects; @@ -56,10 +56,9 @@ public class Qbz95Item extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); - boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2; - boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; + boolean drum = data.attachment.get(AttachmentType.MAGAZINE) == 2; + boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2; if (data.reload.empty()) { if (drum) { @@ -144,22 +143,24 @@ public class Qbz95Item extends GunItem implements GeoItem { public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { super.inventoryTick(stack, world, entity, slot, selected); - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + var data = GunData.from(stack); + int magType = data.attachment.get(AttachmentType.GRIP); + if (magType == 1) { - CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments"); - tag.putInt("Magazine", 2); + data.attachment.set(AttachmentType.MAGAZINE, 2); + data.save(); } } @Override public int getCustomMagazine(ItemStack stack) { - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + int magType = GunData.from(stack).attachment.get(AttachmentType.MAGAZINE); return magType == 2 ? 30 : 0; } @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return switch (scopeType) { case 2 -> 2.15; case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); @@ -169,7 +170,7 @@ public class Qbz95Item extends GunItem implements GeoItem { @Override public boolean canAdjustZoom(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3; } @Override 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 58795b07d..c002d970e 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 @@ -7,14 +7,13 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; -import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.NBTTool; import net.minecraft.client.Minecraft; import net.minecraft.client.player.LocalPlayer; -import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.effect.MobEffects; @@ -52,9 +51,8 @@ public class VectorItem extends GunItem implements GeoItem { ItemStack stack = player.getMainHandItem(); if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; var data = GunData.from(stack); - final var tag = data.tag(); - boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2; + boolean drum = data.attachment.get(AttachmentType.MAGAZINE) == 2; if (data.reload.empty()) { if (drum) { @@ -115,28 +113,30 @@ public class VectorItem extends GunItem implements GeoItem { return new VectorItemRenderer(); } + // TODO 移除inventoryTick @Override @ParametersAreNonnullByDefault public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { super.inventoryTick(stack, world, entity, slot, selected); - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + var data = GunData.from(stack); + int scopeType = data.attachment.get(AttachmentType.SCOPE); if (scopeType == 3) { - CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments"); - tag.putInt("Scope", 0); + data.attachment.set(AttachmentType.SCOPE, 0); + data.save(); } } @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return scopeType == 2 ? (NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75) : 0; } @Override public int getCustomMagazine(ItemStack stack) { - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + int magType = GunData.from(stack).attachment.get(AttachmentType.MAGAZINE); return switch (magType) { case 1 -> 20; case 2 -> 57; 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 0bfd32380..955b70704 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 @@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.item.gun.GunItem; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.PerkHelper; @@ -106,7 +107,7 @@ public class SvdItem extends GunItem implements GeoItem { @Override public int getCustomMagazine(ItemStack stack) { - int magType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.MAGAZINE); + int magType = GunData.from(stack).attachment.get(AttachmentType.MAGAZINE); return switch (magType) { case 1 -> 10; case 2 -> 20; @@ -116,7 +117,7 @@ public class SvdItem extends GunItem implements GeoItem { @Override public double getCustomZoom(ItemStack stack) { - int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); + int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE); return switch (scopeType) { case 2 -> 2.75; case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); @@ -126,7 +127,7 @@ public class SvdItem extends GunItem implements GeoItem { @Override public boolean canAdjustZoom(ItemStack stack) { - return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; + return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3; } @Override diff --git a/src/main/java/com/atsuishio/superbwarfare/network/message/send/EditMessage.java b/src/main/java/com/atsuishio/superbwarfare/network/message/send/EditMessage.java index 813b0ed0e..7b29088c6 100644 --- a/src/main/java/com/atsuishio/superbwarfare/network/message/send/EditMessage.java +++ b/src/main/java/com/atsuishio/superbwarfare/network/message/send/EditMessage.java @@ -3,10 +3,10 @@ package com.atsuishio.superbwarfare.network.message.send; import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModTags; +import com.atsuishio.superbwarfare.item.gun.data.AttachmentType; import com.atsuishio.superbwarfare.item.gun.data.GunData; import com.atsuishio.superbwarfare.tools.SoundTool; import io.netty.buffer.ByteBuf; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; @@ -35,41 +35,40 @@ public record EditMessage(int msgType) implements CustomPacketPayload { if (!stack.is(ModTags.Items.GUN)) return; var data = GunData.from(stack); - var rootTag = data.tag(); - CompoundTag tag = rootTag.getCompound("Attachments"); + var attachment = data.attachment; + switch (type) { case 0 -> { - int att = tag.getInt("Scope"); + int att = attachment.get(AttachmentType.SCOPE); att++; att %= 4; - tag.putInt("Scope", att); + attachment.set(AttachmentType.SCOPE, att); } case 1 -> { - int att = tag.getInt("Barrel"); + int att = attachment.get(AttachmentType.BARREL); att++; att %= 3; - tag.putInt("Barrel", att); + attachment.set(AttachmentType.BARREL, att); } case 2 -> { - int att = tag.getInt("Magazine"); + int att = attachment.get(AttachmentType.MAGAZINE); att++; att %= 3; - tag.putInt("Magazine", att); + attachment.set(AttachmentType.MAGAZINE, att); } case 3 -> { - int att = tag.getInt("Stock"); + int att = attachment.get(AttachmentType.STOCK); att++; att %= 3; - tag.putInt("Stock", att); + attachment.set(AttachmentType.STOCK, att); } case 4 -> { - int att = tag.getInt("Grip"); + int att = attachment.get(AttachmentType.GRIP); att++; att %= 4; - tag.putInt("Grip", att); + attachment.set(AttachmentType.GRIP, att); } } - rootTag.put("Attachments", tag); data.save(); SoundTool.playLocalSound(player, ModSounds.EDIT.get(), 1f, 1f); } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/GunsTool.java b/src/main/java/com/atsuishio/superbwarfare/tools/GunsTool.java index e980a501b..7e58f4c3e 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/GunsTool.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/GunsTool.java @@ -85,16 +85,14 @@ public class GunsTool { reload(player, stack, gunData, type, false); } - public static void reload(Player player, ItemStack stack, GunData gunData, AmmoType type, boolean extraOne) { - var data = gunData.data(); - - int mag = gunData.magazine(); - int ammo = gunData.ammo(); + public static void reload(Player player, ItemStack stack, GunData data, AmmoType type, boolean extraOne) { + int mag = data.magazine(); + int ammo = data.ammo(); int ammoToAdd = mag - ammo + (extraOne ? 1 : 0); // 空仓换弹的栓动武器应该在换弹后取消待上膛标记 - if (ammo == 0 && gunData.bolt.defaultActionTime() > 0 && !stack.is(ModTags.Items.REVOLVER)) { - gunData.bolt.markNeedless(); + if (ammo == 0 && data.bolt.defaultActionTime() > 0 && !stack.is(ModTags.Items.REVOLVER)) { + data.bolt.markNeedless(); } var capability = player.getCapability(ModCapabilities.PLAYER_VARIABLE); @@ -109,8 +107,8 @@ public class GunsTool { int needToAdd = ammo + Math.min(ammoToAdd, playerAmmo); - gunData.setAmmo(needToAdd); - gunData.reload.setState(ReloadState.NOT_RELOADING); + data.setAmmo(needToAdd); + data.reload.setState(ReloadState.NOT_RELOADING); } /* PerkData */ @@ -150,33 +148,6 @@ public class GunsTool { return tag.getBoolean(name); } - /* Attachments */ - public static int getAttachmentType(final CompoundTag rootTag, AttachmentType type) { - CompoundTag tag = rootTag.getCompound("Attachments"); - return tag.getInt(type.getName()); - } - - public static int getAttachmentType(ItemStack stack, AttachmentType type) { - return getAttachmentType(NBTTool.getTag(stack), type); - } - - public enum AttachmentType { - SCOPE("Scope"), - MAGAZINE("Magazine"), - BARREL("Barrel"), - STOCK("Stock"), - GRIP("Grip"); - - private final String name; - - AttachmentType(String name) { - this.name = name; - } - - public String getName() { - return name; - } - } /* GunData */ public static CompoundTag getGunData(final CompoundTag tag) {