提取Attachments

This commit is contained in:
Light_Quanta 2025-04-06 21:44:09 +08:00
parent c7a15bb859
commit 8c701b0bbb
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
44 changed files with 357 additions and 326 deletions

View file

@ -1,30 +1,30 @@
package com.atsuishio.superbwarfare.client; package com.atsuishio.superbwarfare.client;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.item.gun.data.Attachment;
import net.minecraft.nbt.CompoundTag; import com.atsuishio.superbwarfare.item.gun.data.AttachmentType;
import com.atsuishio.superbwarfare.item.gun.data.GunData;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import software.bernie.geckolib.cache.object.GeoBone; import software.bernie.geckolib.cache.object.GeoBone;
public class ItemModelHelper { public class ItemModelHelper {
public static void handleGunAttachments(GeoBone bone, ItemStack stack, String name) { public static void handleGunAttachments(GeoBone bone, ItemStack stack, String name) {
var rootTag = NBTTool.getTag(stack); var attachments = GunData.from(stack).attachment;
CompoundTag tag = rootTag.getCompound("Attachments");
splitBoneName(bone, name, "Scope", tag); splitBoneName(bone, name, attachments, AttachmentType.SCOPE);
splitBoneName(bone, name, "Magazine", tag); splitBoneName(bone, name, attachments, AttachmentType.MAGAZINE);
splitBoneName(bone, name, "Barrel", tag); splitBoneName(bone, name, attachments, AttachmentType.BARREL);
splitBoneName(bone, name, "Stock", tag); splitBoneName(bone, name, attachments, AttachmentType.STOCK);
splitBoneName(bone, name, "Grip", tag); 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 { try {
if (boneName.startsWith(tagName)) { if (boneName.startsWith(type.getName())) {
String[] parts = boneName.split("(?<=\\D)(?=\\d)"); String[] parts = boneName.split("(?<=\\D)(?=\\d)");
if (parts.length == 2) { if (parts.length == 2) {
int index = Integer.parseInt(parts[1]); int index = Integer.parseInt(parts[1]);
bone.setHidden(tag.getInt(tagName) != index); bone.setHidden(attachment.get(type) != index);
} }
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {

View file

@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.rifle.AK12Item; import com.atsuishio.superbwarfare.item.gun.rifle.AK12Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -75,7 +75,7 @@ public class AK12ItemModel extends GeoModel<AK12Item> {
var data = GunData.from(stack); var data = GunData.from(stack);
var tag = data.tag(); var tag = data.tag();
int type = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE); int type = data.attachment.get(AttachmentType.SCOPE);
float posY = switch (type) { float posY = switch (type) {
case 0 -> 0.781f; case 0 -> 0.781f;

View file

@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.rifle.AK47Item; import com.atsuishio.superbwarfare.item.gun.rifle.AK47Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -72,7 +72,7 @@ public class AK47ItemModel extends GeoModel<AK47Item> {
double fp = ClientEventHandler.firePos; double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot; 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) { float posYAlt = switch (type) {
case 2 -> 0.45f; case 2 -> 0.45f;

View file

@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.rifle.Hk416Item; import com.atsuishio.superbwarfare.item.gun.rifle.Hk416Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -75,7 +75,7 @@ public class Hk416ItemModel extends GeoModel<Hk416Item> {
double fp = ClientEventHandler.firePos; double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot; 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) { float posY = switch (type) {
case 0 -> 1.04f; case 0 -> 1.04f;

View file

@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.rifle.M4Item; import com.atsuishio.superbwarfare.item.gun.rifle.M4Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -85,7 +85,7 @@ public class M4ItemModel extends GeoModel<M4Item> {
double fp = ClientEventHandler.firePos; double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot; 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); 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); scaleZAlt = Mth.lerp(times, scaleZAlt, NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0.4f : 0.88f);
@ -176,7 +176,7 @@ public class M4ItemModel extends GeoModel<M4Item> {
CrossHairOverlay.gunRot = shen.getRotZ(); CrossHairOverlay.gunRot = shen.getRotZ();
GeoBone flare = getAnimationProcessor().getBone("flare"); 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) { if (BarrelType == 1) {
flare.setPosZ(-2); flare.setPosZ(-2);

View file

@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.rifle.Mk14Item; import com.atsuishio.superbwarfare.item.gun.rifle.Mk14Item;
import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.GunsTool;
@ -70,10 +71,10 @@ public class Mk14ItemModel extends GeoModel<Mk14Item> {
double fp = ClientEventHandler.firePos; double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot; double fr = ClientEventHandler.fireRot;
int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE);
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK); int stockType = GunData.from(stack).attachment.get(AttachmentType.STOCK);
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL); int barrelType = GunData.from(stack).attachment.get(AttachmentType.BARREL);
int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP); int gripType = GunData.from(stack).attachment.get(AttachmentType.GRIP);
float posY = switch (type) { float posY = switch (type) {
case 0 -> 1.68f; case 0 -> 1.68f;

View file

@ -4,9 +4,9 @@ import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.heavy.Ntw20Item; import com.atsuishio.superbwarfare.item.gun.heavy.Ntw20Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -74,7 +74,7 @@ public class Ntw20Model extends GeoModel<Ntw20Item> {
double fp = ClientEventHandler.firePos; double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot; 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) { float posY = switch (type) {
case 0 -> -0.25f; case 0 -> -0.25f;

View file

@ -5,10 +5,10 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.rifle.Qbz95Item; import com.atsuishio.superbwarfare.item.gun.rifle.Qbz95Item;
import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -84,8 +84,9 @@ public class Qbz95ItemModel extends GeoModel<Qbz95Item> {
double fp = ClientEventHandler.firePos; double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot; double fr = ClientEventHandler.fireRot;
var tag = NBTTool.getTag(stack); var data = GunData.from(stack);
int type = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE); var tag = data.tag();
int type = data.attachment.get(AttachmentType.SCOPE);
float posYAlt = switch (type) { float posYAlt = switch (type) {
case 2 -> 0.85f; case 2 -> 0.85f;
@ -175,7 +176,7 @@ public class Qbz95ItemModel extends GeoModel<Qbz95Item> {
} }
GeoBone flare = getAnimationProcessor().getBone("flare"); GeoBone flare = getAnimationProcessor().getBone("flare");
int BarrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL); int BarrelType = data.attachment.get(AttachmentType.BARREL);
if (BarrelType == 1) { if (BarrelType == 1) {
flare.setPosZ(-2); flare.setPosZ(-2);

View file

@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.machinegun.RpkItem; import com.atsuishio.superbwarfare.item.gun.machinegun.RpkItem;
import com.atsuishio.superbwarfare.tools.GunsTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -76,7 +76,7 @@ public class RpkItemModel extends GeoModel<RpkItem> {
var data = GunData.from(stack); var data = GunData.from(stack);
var tag = data.tag(); 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); scopeY = Mth.lerp(times, scopeY, tag.getBoolean("ScopeAlt") ? -0.7f : 0.2f);
scaleZAlt = Mth.lerp(times, scaleZAlt, tag.getBoolean("ScopeAlt") ? 0.45f : 0.74f); scaleZAlt = Mth.lerp(times, scaleZAlt, tag.getBoolean("ScopeAlt") ? 0.45f : 0.74f);
posZAlt = Mth.lerp(times, posZAlt, tag.getBoolean("ScopeAlt") ? 3.3f : 4.25f); posZAlt = Mth.lerp(times, posZAlt, tag.getBoolean("ScopeAlt") ? 3.3f : 4.25f);

View file

@ -5,6 +5,7 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.sniper.SvdItem; import com.atsuishio.superbwarfare.item.gun.sniper.SvdItem;
import com.atsuishio.superbwarfare.tools.GunsTool; import com.atsuishio.superbwarfare.tools.GunsTool;
@ -69,10 +70,10 @@ public class SvdItemModel extends GeoModel<SvdItem> {
double fp = ClientEventHandler.firePos; double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot; double fr = ClientEventHandler.fireRot;
int type = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); int type = GunData.from(stack).attachment.get(AttachmentType.SCOPE);
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK); int stockType = GunData.from(stack).attachment.get(AttachmentType.STOCK);
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL); int barrelType = GunData.from(stack).attachment.get(AttachmentType.BARREL);
int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP); int gripType = GunData.from(stack).attachment.get(AttachmentType.GRIP);
float posX = switch (type) { float posX = switch (type) {
case 0, 1 -> 1.701f; case 0, 1 -> 1.701f;

View file

@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.handgun.Trachelium; import com.atsuishio.superbwarfare.item.gun.handgun.Trachelium;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -80,10 +80,10 @@ public class TracheliumItemModel extends GeoModel<Trachelium> {
double fp = ClientEventHandler.firePos; double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot; double fr = ClientEventHandler.fireRot;
int stockType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.STOCK); int stockType = GunData.from(stack).attachment.get(AttachmentType.STOCK);
int barrelType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.BARREL); int barrelType = GunData.from(stack).attachment.get(AttachmentType.BARREL);
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE);
int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP); int gripType = GunData.from(stack).attachment.get(AttachmentType.GRIP);
posYAlt = Mth.lerp(times, posYAlt, NBTTool.getTag(stack).getBoolean("ScopeAlt") ? -1.98f : -0.83f); 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); scaleZAlt = Mth.lerp(times, scaleZAlt, NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0.4f : 0.8f);

View file

@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay; import com.atsuishio.superbwarfare.client.overlay.CrossHairOverlay;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.smg.VectorItem; import com.atsuishio.superbwarfare.item.gun.smg.VectorItem;
import com.atsuishio.superbwarfare.tools.GunsTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -86,7 +86,7 @@ public class VectorItemModel extends GeoModel<VectorItem> {
double fp = ClientEventHandler.firePos; double fp = ClientEventHandler.firePos;
double fr = ClientEventHandler.fireRot; 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) { float posY = switch (type) {
case 1 -> 0.74f; case 1 -> 0.74f;

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.AK12ItemModel; import com.atsuishio.superbwarfare.client.model.item.AK12ItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.rifle.AK12Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -84,36 +85,36 @@ public class AK12ItemRenderer extends GeoItemRenderer<AK12Item> {
if (name.equals("Cross1")) { if (name.equals("Cross1")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2);
} }
if (name.equals("Cross3")) { if (name.equals("Cross3")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !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"))) { && (name.equals("hidden2"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); 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"))) { && (name.equals("jing") || name.equals("Barrel") || name.equals("humu") || name.equals("qiangguan") || name.equals("houzhunxing"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom);
} }
if (name.equals("flare")) { 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); 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.AK47ItemModel; import com.atsuishio.superbwarfare.client.model.item.AK47ItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.rifle.AK47Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -84,42 +85,42 @@ public class AK47ItemRenderer extends GeoItemRenderer<AK47Item> {
if (name.equals("Cross1")) { if (name.equals("Cross1")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2);
} }
if (name.equals("Cross3")) { if (name.equals("Cross3")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3);
} }
if (name.equals("humu1")) { 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")) { 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")) { && (name.equals("Hidden") || name.equals("gun") || name.equals("Lefthand")) && ClientEventHandler.zoom && !NBTTool.getTag(itemStack).getBoolean("HoloHidden")) {
bone.setHidden(true); bone.setHidden(true);
renderingArms = false; 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"))) { && (name.equals("jing") || name.equals("Barrel") || name.equals("humu") || name.equals("qiangguan") || name.equals("houzhunxing"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom);
} }
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.Aa12ItemModel; import com.atsuishio.superbwarfare.client.model.item.Aa12ItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.shotgun.Aa12Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -81,7 +82,7 @@ public class Aa12ItemRenderer extends GeoItemRenderer<Aa12Item> {
if (!itemStack.is(ModTags.Items.GUN)) return; if (!itemStack.is(ModTags.Items.GUN)) return;
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.Hk416ItemModel; import com.atsuishio.superbwarfare.client.model.item.Hk416ItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.rifle.Hk416Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -84,33 +85,33 @@ public class Hk416ItemRenderer extends GeoItemRenderer<Hk416Item> {
if (name.equals("Cross1")) { if (name.equals("Cross1")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2);
} }
if (name.equals("Cross3")) { if (name.equals("Cross3")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !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"))) { && (name.equals("hidden"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); 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"))) { && (name.equals("jing") || name.equals("Barrel") || name.equals("yugu") || name.equals("qiangguan"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom);
} }
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -4,8 +4,9 @@ import com.atsuishio.superbwarfare.client.AnimationHelper;
import com.atsuishio.superbwarfare.client.model.item.InsidiousItemModel; import com.atsuishio.superbwarfare.client.model.item.InsidiousItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.rifle.InsidiousItem;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -81,7 +82,7 @@ public class InsidiousItemRenderer extends GeoItemRenderer<InsidiousItem> {
if (!itemStack.is(ModTags.Items.GUN)) return; if (!itemStack.is(ModTags.Items.GUN)) return;
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.M4ItemModel; import com.atsuishio.superbwarfare.client.model.item.M4ItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.rifle.M4Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -84,40 +85,40 @@ public class M4ItemRenderer extends GeoItemRenderer<M4Item> {
if (name.equals("Cross1")) { if (name.equals("Cross1")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2
|| NBTTool.getTag(itemStack).getBoolean("ScopeAlt")); || NBTTool.getTag(itemStack).getBoolean("ScopeAlt"));
} }
if (name.equals("CrossAlt")) { if (name.equals("CrossAlt")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2
|| !(NBTTool.getTag(itemStack).getBoolean("ScopeAlt"))); || !(NBTTool.getTag(itemStack).getBoolean("ScopeAlt")));
} }
if (name.equals("Cross3")) { if (name.equals("Cross3")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !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); 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"))) { && (name.equals("hidden2") || name.equals("yugu") || name.equals("qiangguan") || name.equals("Barrel"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom);
} }
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);
@ -128,7 +129,7 @@ public class M4ItemRenderer extends GeoItemRenderer<M4Item> {
} }
if (name.equals("Sight")) { 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); ItemModelHelper.handleGunAttachments(bone, itemStack, name);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.Mk14ItemModel; import com.atsuishio.superbwarfare.client.model.item.Mk14ItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.rifle.Mk14Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -82,39 +83,39 @@ public class Mk14ItemRenderer extends GeoItemRenderer<Mk14Item> {
if (!itemStack.is(ModTags.Items.GUN)) return; if (!itemStack.is(ModTags.Items.GUN)) return;
if (name.equals("qiaojia")) { 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")) { if (name.equals("Cross1")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2);
} }
if (name.equals("Cross3")) { if (name.equals("Cross3")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !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"))) { && (name.equals("hidden"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); 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"))) { && (name.equals("jing") || name.equals("yugu") || name.equals("qiangguan") || name.equals("Barrel"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom);
} }
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.Ntw20Model; import com.atsuishio.superbwarfare.client.model.item.Ntw20Model;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.heavy.Ntw20Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -82,39 +83,39 @@ public class Ntw20Renderer extends GeoItemRenderer<Ntw20Item> {
if (!itemStack.is(ModTags.Items.GUN)) return; if (!itemStack.is(ModTags.Items.GUN)) return;
if (name.equals("ironSight")) { 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")) { if (name.equals("Cross1")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2);
} }
if (name.equals("Cross3")) { if (name.equals("Cross3")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !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"))) { && (name.equals("bone1") || name.equals("zhituiqi") || name.equals("guan") || name.equals("hidden"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); 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"))) { && (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); bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom);
} }
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.Qbz95ItemModel; import com.atsuishio.superbwarfare.client.model.item.Qbz95ItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.rifle.Qbz95Item;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -84,45 +85,45 @@ public class Qbz95ItemRenderer extends GeoItemRenderer<Qbz95Item> {
if (name.equals("Cross1")) { if (name.equals("Cross1")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("tiba")) { 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")) { 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")) { 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")) { if (name.equals("Cross2")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2);
} }
if (name.equals("Cross3")) { if (name.equals("Cross3")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !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"))) { && (name.equals("hidden"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); 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"))) { && (name.equals("hidden2") || name.equals("jimiao2"))) {
bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom); bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom);
} }
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,9 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.RpkItemModel; import com.atsuishio.superbwarfare.client.model.item.RpkItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.item.gun.machinegun.RpkItem; 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.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
@ -88,49 +88,49 @@ public class RpkItemRenderer extends GeoItemRenderer<RpkItem> {
if (name.equals("Cross1")) { if (name.equals("Cross1")) {
bone.setHidden(tag.getBoolean("HoloHidden") bone.setHidden(tag.getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(tag.getBoolean("HoloHidden") bone.setHidden(tag.getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2
|| tag.getBoolean("ScopeAlt")); || tag.getBoolean("ScopeAlt"));
} }
if (name.equals("CrossAlt")) { if (name.equals("CrossAlt")) {
bone.setHidden(tag.getBoolean("HoloHidden") bone.setHidden(tag.getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2
|| !(tag.getBoolean("ScopeAlt"))); || !(tag.getBoolean("ScopeAlt")));
} }
if (name.equals("Cross3")) { if (name.equals("Cross3")) {
bone.setHidden(tag.getBoolean("HoloHidden") bone.setHidden(tag.getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 3); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 3);
} }
if (name.equals("humu1")) { 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")) { 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"))) { && (name.equals("glass") || name.equals("Barrel") || name.equals("humu") || name.equals("qiangguan"))) {
bone.setHidden(!tag.getBoolean("HoloHidden") && ClientEventHandler.zoom); 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"))) { && (name.equals("jing") || name.equals("Barrel") || name.equals("humu") || name.equals("qiangguan") || name.equals("houzhunxing"))) {
bone.setHidden(!tag.getBoolean("HoloHidden") && ClientEventHandler.zoom); bone.setHidden(!tag.getBoolean("HoloHidden") && ClientEventHandler.zoom);
} }
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.SvdItemModel; import com.atsuishio.superbwarfare.client.model.item.SvdItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.sniper.SvdItem;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -82,32 +83,32 @@ public class SvdItemRenderer extends GeoItemRenderer<SvdItem> {
if (!itemStack.is(ModTags.Items.GUN)) return; if (!itemStack.is(ModTags.Items.GUN)) return;
if (name.equals("mount")) { 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")) { if (name.equals("Cross1")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !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")) { && (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); bone.setHidden(true);
renderingArms = false; renderingArms = false;
} }
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } 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.setPosY(-2f);
} }
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.TracheliumItemModel; import com.atsuishio.superbwarfare.client.model.item.TracheliumItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.handgun.Trachelium;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -84,49 +85,49 @@ public class TracheliumItemRenderer extends GeoItemRenderer<Trachelium> {
if (!itemStack.is(ModTags.Items.GUN)) return; if (!itemStack.is(ModTags.Items.GUN)) return;
if (name.equals("humu")) { 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")) { 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")) { 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")) { 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")) { if (name.equals("Cross1")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2
|| NBTTool.getTag(itemStack).getBoolean("ScopeAlt")); || NBTTool.getTag(itemStack).getBoolean("ScopeAlt"));
} }
if (name.equals("CrossAlt")) { if (name.equals("CrossAlt")) {
bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2 || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2
|| !(NBTTool.getTag(itemStack).getBoolean("ScopeAlt"))); || !(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); bone.setHidden(!NBTTool.getTag(itemStack).getBoolean("HoloHidden") && ClientEventHandler.zoom);
} }
ItemModelHelper.handleGunAttachments(bone, itemStack, name); ItemModelHelper.handleGunAttachments(bone, itemStack, name);
if (name.equals("flare")) { 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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);

View file

@ -5,8 +5,9 @@ import com.atsuishio.superbwarfare.client.ItemModelHelper;
import com.atsuishio.superbwarfare.client.model.item.VectorItemModel; import com.atsuishio.superbwarfare.client.model.item.VectorItemModel;
import com.atsuishio.superbwarfare.event.ClientEventHandler; import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModTags; 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.item.gun.smg.VectorItem;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer; import com.mojang.blaze3d.vertex.VertexConsumer;
@ -89,21 +90,21 @@ public class VectorItemRenderer extends GeoItemRenderer<VectorItem> {
if (name.equals("Cross1")) { if (name.equals("Cross1")) {
bone.setHidden(tag.getBoolean("HoloHidden") bone.setHidden(tag.getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
} }
if (name.equals("Cross2")) { if (name.equals("Cross2")) {
bone.setHidden(tag.getBoolean("HoloHidden") bone.setHidden(tag.getBoolean("HoloHidden")
|| !ClientEventHandler.zoom || !ClientEventHandler.zoom
|| GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2);
} }
if (name.equals("tuoxin")) { 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 (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); bone.setHidden(true);
} else { } else {
bone.setHidden(false); bone.setHidden(false);
@ -143,17 +144,17 @@ public class VectorItemRenderer extends GeoItemRenderer<VectorItem> {
// if (name.equals("Cross1")) { // if (name.equals("Cross1")) {
// bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") // bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
// || !ClientEventHandler.zoom // || !ClientEventHandler.zoom
// || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 1); // || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 1);
// } // }
// //
// if (name.equals("Cross2")) { // if (name.equals("Cross2")) {
// bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden") // bone.setHidden(NBTTool.getTag(itemStack).getBoolean("HoloHidden")
// || !ClientEventHandler.zoom // || !ClientEventHandler.zoom
// || GunsTool.getAttachmentType(itemStack, GunsTool.AttachmentType.SCOPE) != 2); // || GunData.from(itemStack).attachment.get(AttachmentType.SCOPE) != 2);
// } // }
// //
// if (name.equals("tuoxin")) { // 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 (name.equals("flare")) {
@ -163,7 +164,7 @@ public class VectorItemRenderer extends GeoItemRenderer<VectorItem> {
//// } //// }
//// } //// }
//// ////
//// 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); // bone.setHidden(true);
// } else { // } else {
// bone.setHidden(false); // bone.setHidden(false);

View file

@ -11,6 +11,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity;
import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.WeaponVehicleEntity;
import com.atsuishio.superbwarfare.init.*; import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.network.message.send.*; import com.atsuishio.superbwarfare.network.message.send.*;
import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.AmmoPerk;
@ -235,7 +236,7 @@ public class ClientEventHandler {
isProne(player); isProne(player);
beamShoot(player, stack); beamShoot(player, stack);
handleLungeAttack(player, stack); handleLungeAttack(player, stack);
handleGunMelee(player, stack, tag); handleGunMelee(player, stack);
var options = Minecraft.getInstance().options; var options = Minecraft.getInstance().options;
short keys = 0; 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(); && !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) { if (stack.getItem() instanceof GunItem gunItem) {
var data = GunData.from(stack); var data = GunData.from(stack);
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
@ -686,7 +687,8 @@ public class ClientEventHandler {
player.playSound(ModSounds.HENG.get(), 1f, 1f); 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"))); 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; if (player == null) return;
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!(stack.getItem() instanceof GunItem gunItem)) return; 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)) if (player.getVehicle() instanceof ArmedVehicleEntity iArmedVehicle && iArmedVehicle.isDriver(player) && iArmedVehicle.hidePassenger(player))
return; return;
@ -833,12 +835,12 @@ public class ClientEventHandler {
if (player.isCrouching() && player.getBbHeight() >= 1 && !isProne(player)) { if (player.isCrouching() && player.getBbHeight() >= 1 && !isProne(player)) {
pose = 0.85f; pose = 0.85f;
} else if (isProne(player)) { } 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 { } else {
pose = 1; pose = 1;
} }
int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK); int stockType = data.attachment.get(AttachmentType.STOCK);
double sway = switch (stockType) { double sway = switch (stockType) {
case 1 -> 1; case 1 -> 1;
@ -846,7 +848,6 @@ public class ClientEventHandler {
default -> 0.8; default -> 0.8;
}; };
var data = GunData.from(stack);
double customWeight = data.customWeight(); double customWeight = data.customWeight();
var cap = player.getCapability(ModCapabilities.PLAYER_VARIABLE, null); 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; LocalPlayer player = Minecraft.getInstance().player;
float yaw = event.getYaw(); float yaw = event.getYaw();
@ -918,15 +918,15 @@ public class ClientEventHandler {
} }
if (level != null && stack.is(ModTags.Items.GUN)) { if (level != null && stack.is(ModTags.Items.GUN)) {
handleWeaponSway(living, tag); handleWeaponSway(living);
handleWeaponMove(living); handleWeaponMove(living);
handleWeaponZoom(living); handleWeaponZoom(living);
handlePlayerBreath(living); handlePlayerBreath(living);
handleWeaponFire(event, living, tag); handleWeaponFire(event, living);
handleWeaponShell(); handleWeaponShell();
handleGunRecoil(tag); handleGunRecoil();
handleBowPullAnimation(living); handleBowPullAnimation(living);
handleWeaponDraw(living, tag); handleWeaponDraw(living);
handlePlayerCamera(event); 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(); ItemStack stack = entity.getMainHandItem();
if (stack.getItem() instanceof GunItem gunItem && entity instanceof Player player) { 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); float times = 2 * (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.8);
double pose; double pose;
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && isProne(player)) { if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && isProne(player)) {
pose = 0.85; pose = 0.85;
} else if (isProne(player)) { } 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 { } else {
pose = 1; pose = 1;
} }
@ -1067,7 +1069,6 @@ public class ClientEventHandler {
if (!(entity instanceof Player player)) return; if (!(entity instanceof Player player)) return;
var stack = player.getMainHandItem(); var stack = player.getMainHandItem();
var data = GunData.from(stack); var data = GunData.from(stack);
final var tag = data.tag();
float times = 5 * Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(); float times = 5 * Minecraft.getInstance().getTimer().getRealtimeDeltaTicks();
double weight = data.weight(); double weight = data.weight();
@ -1093,7 +1094,7 @@ public class ClientEventHandler {
zoomPosZ = AnimationCurves.PARABOLA.apply(zoomTime); 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 times = 2f * Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 0.48f);
float yaw = event.getYaw(); float yaw = event.getYaw();
float pitch = event.getPitch(); 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; Player player = Minecraft.getInstance().player;
if (player == null) return; if (player == null) return;
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!(stack.getItem() instanceof GunItem gunItem)) return; if (!(stack.getItem() instanceof GunItem gunItem)) return;
var data = GunData.from(stack);
float times = (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 1.6); float times = (float) Math.min(Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(), 1.6);
int barrelType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.BARREL); int barrelType = data.attachment.get(AttachmentType.BARREL);
int gripType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP); int gripType = data.attachment.get(AttachmentType.GRIP);
double recoil = switch (barrelType) { double recoil = switch (barrelType) {
case 1 -> 1.5; case 1 -> 1.5;
@ -1220,7 +1222,6 @@ public class ClientEventHandler {
gripRecoilY = 1.25; gripRecoilY = 1.25;
} }
var data = GunData.from(stack);
double customWeight = data.customWeight(); double customWeight = data.customWeight();
double rpm = 1; double rpm = 1;
@ -1239,7 +1240,7 @@ public class ClientEventHandler {
if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && !isProne(player)) { if (player.isShiftKeyDown() && player.getBbHeight() >= 1 && !isProne(player)) {
pose = 0.7f; pose = 0.7f;
} else if (isProne(player)) { } 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; pose = 0.1f;
} else { } else {
pose = 0.5f; pose = 0.5f;
@ -1526,7 +1527,7 @@ public class ClientEventHandler {
burstFireAmount = 0; burstFireAmount = 0;
} }
private static void handleWeaponDraw(LivingEntity entity, final CompoundTag tag) { private static void handleWeaponDraw(LivingEntity entity) {
float times = Minecraft.getInstance().getTimer().getRealtimeDeltaTicks(); float times = Minecraft.getInstance().getTimer().getRealtimeDeltaTicks();
ItemStack stack = entity.getMainHandItem(); ItemStack stack = entity.getMainHandItem();
var data = GunData.from(stack); var data = GunData.from(stack);

View file

@ -10,6 +10,7 @@ import com.atsuishio.superbwarfare.init.ModPerks;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.item.gun.data.ReloadState; import com.atsuishio.superbwarfare.item.gun.data.ReloadState;
import com.atsuishio.superbwarfare.perk.AmmoPerk; import com.atsuishio.superbwarfare.perk.AmmoPerk;
@ -128,7 +129,7 @@ public class GunEventHandler {
} }
float soundRadius = (float) data.soundRadius(); 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"))); SoundEvent sound3p = BuiltInRegistries.SOUND_EVENT.get(Mod.loc(name + (barrelType == 2 ? "_fire_3p_s" : "_fire_3p")));
if (sound3p != null) { if (sound3p != null) {

View file

@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.init.ModItems;
import com.atsuishio.superbwarfare.init.ModPerks; import com.atsuishio.superbwarfare.init.ModPerks;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.CustomRendererItem; 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.item.gun.data.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -398,34 +399,34 @@ public abstract class GunItem extends Item implements CustomRendererItem {
* 获取额外总重量加成 * 获取额外总重量加成
*/ */
public double getCustomWeight(ItemStack stack) { 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 1 -> 0.5;
case 2 -> 1; case 2 -> 1;
case 3 -> 1.5; case 3 -> 1.5;
default -> 0; default -> 0;
}; };
double barrelWeight = switch (tag.getInt("Barrel")) { double barrelWeight = switch (attachment.get(AttachmentType.BARREL)) {
case 1 -> 0.5; case 1 -> 0.5;
case 2 -> 1; case 2 -> 1;
default -> 0; default -> 0;
}; };
double magazineWeight = switch (tag.getInt("Magazine")) { double magazineWeight = switch (attachment.get(AttachmentType.MAGAZINE)) {
case 1 -> 1; case 1 -> 1;
case 2 -> 2; case 2 -> 2;
default -> 0; default -> 0;
}; };
double stockWeight = switch (tag.getInt("Stock")) { double stockWeight = switch (attachment.get(AttachmentType.STOCK)) {
case 1 -> -2; case 1 -> -2;
case 2 -> 1.5; case 2 -> 1.5;
default -> 0; default -> 0;
}; };
double gripWeight = switch (tag.getInt("Grip")) { double gripWeight = switch (attachment.get(AttachmentType.GRIP)) {
case 1, 2 -> 0.25; case 1, 2 -> 0.25;
case 3 -> 1; case 3 -> 1;
default -> 0; default -> 0;
@ -445,7 +446,7 @@ public abstract class GunItem extends Item implements CustomRendererItem {
* 获取额外音效半径加成 * 获取额外音效半径加成
*/ */
public double getCustomSoundRadius(ItemStack stack) { 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) { public int getCustomBoltActionTime(ItemStack stack) {

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -21,6 +21,7 @@ public class GunData {
private final CompoundTag tag; private final CompoundTag tag;
private final CompoundTag data; private final CompoundTag data;
private final CompoundTag perk; private final CompoundTag perk;
private final CompoundTag attachmentTag;
private final String id; private final String id;
private static final WeakHashMap<ItemStack, GunData> dataCache = new WeakHashMap<>(); private static final WeakHashMap<ItemStack, GunData> dataCache = new WeakHashMap<>();
@ -37,23 +38,25 @@ public class GunData {
var customData = stack.get(DataComponents.CUSTOM_DATA); var customData = stack.get(DataComponents.CUSTOM_DATA);
this.tag = customData != null ? customData.copyTag() : new CompoundTag(); this.tag = customData != null ? customData.copyTag() : new CompoundTag();
if (!tag.contains("GunData")) { data = getOrPut("GunData");
data = new CompoundTag(); perk = getOrPut("PerkData");
tag.put("GunData", data); attachmentTag = getOrPut("Attachments");
} else {
data = tag.getCompound("GunData");
}
if (!tag.contains("PerkData")) {
perk = new CompoundTag();
tag.put("PerkData", perk);
} else {
perk = tag.getCompound("PerkData");
}
reload = new Reload(this); reload = new Reload(this);
charge = new Charge(this); charge = new Charge(this);
bolt = new Bolt(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() { public boolean initialized() {
@ -96,6 +99,10 @@ public class GunData {
return perk; return perk;
} }
public CompoundTag attachment() {
return attachmentTag;
}
double getGunData(String key) { double getGunData(String key) {
return getGunData(key, 0); return getGunData(key, 0);
} }
@ -214,12 +221,12 @@ public class GunData {
} }
public double minZoom() { 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; return scopeType == 3 ? getGunData("MinZoom", 1.25) : 1.25;
} }
public double maxZoom() { 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; return scopeType == 3 ? getGunData("MaxZoom", 1) : 114514;
} }
@ -294,6 +301,7 @@ public class GunData {
} }
public final Bolt bolt; public final Bolt bolt;
public final Attachment attachment;
public void save() { public void save() {
stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag)); stack.set(DataComponents.CUSTOM_DATA, CustomData.of(tag));

View file

@ -7,15 +7,14 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.ChatFormatting; import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.Style; import net.minecraft.network.chat.Style;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
@ -65,9 +64,9 @@ public class Trachelium extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
final var tag = NBTTool.getTag(stack); var data = GunData.from(stack);
boolean stock = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK) == 2; boolean stock = data.attachment.get(AttachmentType.STOCK) == 2;
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) > 0 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE) > 0; boolean grip = data.attachment.get(AttachmentType.GRIP) > 0 || data.attachment.get(AttachmentType.SCOPE) > 0;
if (ClientEventHandler.firePosTimer > 0 && ClientEventHandler.firePosTimer < 1.7) { if (ClientEventHandler.firePosTimer > 0 && ClientEventHandler.firePosTimer < 1.7) {
if (stock) { if (stock) {
@ -106,10 +105,9 @@ public class Trachelium extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); var data = GunData.from(stack);
final var tag = data.tag();
boolean stock = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK) == 2; boolean stock = data.attachment.get(AttachmentType.STOCK) == 2;
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) > 0 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.SCOPE) > 0; boolean grip = data.attachment.get(AttachmentType.GRIP) > 0 || data.attachment.get(AttachmentType.SCOPE) > 0;
if (data.bolt.actionTime() > 0) { if (data.bolt.actionTime() > 0) {
if (stock) { if (stock) {
@ -236,18 +234,17 @@ public class Trachelium extends GunItem implements GeoItem {
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, world, entity, slot, 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 scopeType = data.attachment.get(AttachmentType.SCOPE);
int stockType = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.STOCK); int stockType = data.attachment.get(AttachmentType.STOCK);
CompoundTag tags = tag.getCompound("Attachments");
if (stockType == 1) { if (stockType == 1) {
tags.putInt("Stock", 2); data.attachment.set(AttachmentType.STOCK, 2);
} }
if (scopeType == 3) { 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 @Override
public boolean canSwitchScope(ItemStack stack) { 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) { private boolean useSpecialAttributes(ItemStack stack) {
int scopeType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE); int scopeType = GunData.from(stack).attachment.get(AttachmentType.SCOPE);
int gripType = GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP); int gripType = GunData.from(stack).attachment.get(AttachmentType.GRIP);
return scopeType > 0 || gripType > 0; return scopeType > 0 || gripType > 0;
} }
@ -277,7 +274,7 @@ public class Trachelium extends GunItem implements GeoItem {
@Override @Override
public double getCustomZoom(ItemStack stack) { 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; return scopeType == 2 ? (NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75) : 0;
} }

View file

@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.init.ModRarity;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -57,7 +58,6 @@ public class Ntw20Item extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); var data = GunData.from(stack);
final var tag = data.tag();
if (data.bolt.actionTime() > 0) { if (data.bolt.actionTime() > 0) {
return event.setAndContinue(RawAnimation.begin().thenPlay("animation.ntw_20.shift")); 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(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); var data = GunData.from(stack);
final var tag = data.tag();
if (player.isSprinting() && player.onGround() if (player.isSprinting() && player.onGround()
&& player.getPersistentData().getDouble("noRun") == 0 && player.getPersistentData().getDouble("noRun") == 0
@ -127,12 +126,12 @@ public class Ntw20Item extends GunItem implements GeoItem {
@Override @Override
public boolean canAdjustZoom(ItemStack stack) { public boolean canAdjustZoom(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3;
} }
@Override @Override
public double getCustomZoom(ItemStack stack) { 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) { return switch (scopeType) {
case 2 -> 2.25; case 2 -> 2.25;
case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
@ -142,7 +141,7 @@ public class Ntw20Item extends GunItem implements GeoItem {
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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 1 -> 3;
case 2 -> 6; case 2 -> 6;
default -> 0; default -> 0;

View file

@ -8,6 +8,7 @@ import com.atsuishio.superbwarfare.init.ModPerks;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -15,7 +16,6 @@ import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
@ -57,10 +57,9 @@ public class RpkItem extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); var data = GunData.from(stack);
var tag = data.tag();
boolean drum = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.MAGAZINE) == 2; boolean drum = data.attachment.get(AttachmentType.MAGAZINE) == 2;
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.GRIP) == 2; boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || GunData.from(stack).attachment.get(AttachmentType.GRIP) == 2;
if (GunData.from(stack).reload.empty()) { if (GunData.from(stack).reload.empty()) {
if (drum) { if (drum) {
@ -137,7 +136,7 @@ public class RpkItem extends GunItem implements GeoItem {
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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) { return switch (magType) {
case 1 -> 20; case 1 -> 20;
case 2 -> 60; case 2 -> 60;
@ -147,7 +146,7 @@ public class RpkItem extends GunItem implements GeoItem {
@Override @Override
public double getCustomZoom(ItemStack stack) { 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) { return switch (scopeType) {
case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75; case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75;
case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
@ -157,7 +156,7 @@ public class RpkItem extends GunItem implements GeoItem {
@Override @Override
public boolean canAdjustZoom(ItemStack stack) { public boolean canAdjustZoom(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3;
} }
@Override @Override
@ -189,19 +188,19 @@ public class RpkItem extends GunItem implements GeoItem {
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level level, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, level, entity, slot, 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) { if (gripType == 3) {
var data = GunData.from(stack); data.attachment.set(AttachmentType.GRIP, 0);
CompoundTag tag = data.tag().getCompound("Attachments");
tag.putInt("Grip", 0);
data.save(); data.save();
} }
} }
@Override @Override
public boolean canSwitchScope(ItemStack stack) { public boolean canSwitchScope(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 2; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 2;
} }
@Override @Override

View file

@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -57,10 +58,9 @@ public class AK12Item extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); 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;
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2;
if (GunData.from(stack).reload.empty()) { if (GunData.from(stack).reload.empty()) {
if (grip) { if (grip) {
@ -134,12 +134,12 @@ public class AK12Item extends GunItem implements GeoItem {
@Override @Override
public boolean canAdjustZoom(ItemStack stack) { public boolean canAdjustZoom(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3;
} }
@Override @Override
public double getCustomZoom(ItemStack stack) { 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) { return switch (scopeType) {
case 2 -> 2.15; case 2 -> 2.15;
case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
@ -149,7 +149,7 @@ public class AK12Item extends GunItem implements GeoItem {
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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) { return switch (magType) {
case 1 -> 15; case 1 -> 15;
case 2 -> 45; case 2 -> 45;

View file

@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -57,10 +58,9 @@ public class AK47Item extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); 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;
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2;
if (GunData.from(stack).reload.empty()) { if (GunData.from(stack).reload.empty()) {
if (drum) { if (drum) {
@ -142,7 +142,7 @@ public class AK47Item extends GunItem implements GeoItem {
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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) { return switch (magType) {
case 1 -> 15; case 1 -> 15;
case 2 -> 40; case 2 -> 40;
@ -152,7 +152,7 @@ public class AK47Item extends GunItem implements GeoItem {
@Override @Override
public double getCustomZoom(ItemStack stack) { 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) { return switch (scopeType) {
case 2 -> 2.75; case 2 -> 2.75;
case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
@ -162,7 +162,7 @@ public class AK47Item extends GunItem implements GeoItem {
@Override @Override
public boolean canAdjustZoom(ItemStack stack) { public boolean canAdjustZoom(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3;
} }
@Override @Override

View file

@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -52,10 +53,9 @@ public class Hk416Item extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); 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;
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2;
if (GunData.from(stack).reload.empty()) { if (GunData.from(stack).reload.empty()) {
if (drum) { if (drum) {
@ -132,7 +132,7 @@ public class Hk416Item extends GunItem implements GeoItem {
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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) { return switch (magType) {
case 1 -> 15; case 1 -> 15;
case 2 -> 30; case 2 -> 30;
@ -142,7 +142,7 @@ public class Hk416Item extends GunItem implements GeoItem {
@Override @Override
public double getCustomZoom(ItemStack stack) { 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) { return switch (scopeType) {
case 2 -> 2.25; case 2 -> 2.25;
case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
@ -152,7 +152,7 @@ public class Hk416Item extends GunItem implements GeoItem {
@Override @Override
public boolean canAdjustZoom(ItemStack stack) { public boolean canAdjustZoom(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3;
} }
@Override @Override

View file

@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -53,10 +54,9 @@ public class M4Item extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); 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;
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2;
if (data.reload.empty()) { if (data.reload.empty()) {
if (drum) { if (drum) {
@ -143,12 +143,12 @@ public class M4Item extends GunItem implements GeoItem {
@Override @Override
public boolean canSwitchScope(ItemStack stack) { public boolean canSwitchScope(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 2; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 2;
} }
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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) { return switch (magType) {
case 1 -> 15; case 1 -> 15;
case 2 -> 30; case 2 -> 30;
@ -158,7 +158,7 @@ public class M4Item extends GunItem implements GeoItem {
@Override @Override
public double getCustomZoom(ItemStack stack) { 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) { return switch (scopeType) {
case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75; case 2 -> NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75;
case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
@ -168,7 +168,7 @@ public class M4Item extends GunItem implements GeoItem {
@Override @Override
public boolean canAdjustZoom(ItemStack stack) { public boolean canAdjustZoom(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3;
} }
@Override @Override

View file

@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -52,10 +53,9 @@ public class Mk14Item extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); 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;
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2;
if (data.reload.empty()) { if (data.reload.empty()) {
if (drum) { if (drum) {
@ -137,7 +137,7 @@ public class Mk14Item extends GunItem implements GeoItem {
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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) { return switch (magType) {
case 1 -> 10; case 1 -> 10;
case 2 -> 30; case 2 -> 30;
@ -147,7 +147,7 @@ public class Mk14Item extends GunItem implements GeoItem {
@Override @Override
public double getCustomZoom(ItemStack stack) { 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) { return switch (scopeType) {
case 2 -> 2.25; case 2 -> 2.25;
case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
@ -157,7 +157,7 @@ public class Mk14Item extends GunItem implements GeoItem {
@Override @Override
public boolean canAdjustZoom(ItemStack stack) { public boolean canAdjustZoom(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3;
} }
@Override @Override

View file

@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -14,7 +15,6 @@ import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
@ -56,10 +56,9 @@ public class Qbz95Item extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); 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;
boolean grip = GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 1 || GunsTool.getAttachmentType(tag, GunsTool.AttachmentType.GRIP) == 2; boolean grip = data.attachment.get(AttachmentType.GRIP) == 1 || data.attachment.get(AttachmentType.GRIP) == 2;
if (data.reload.empty()) { if (data.reload.empty()) {
if (drum) { 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) { public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, world, entity, slot, 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) { if (magType == 1) {
CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments"); data.attachment.set(AttachmentType.MAGAZINE, 2);
tag.putInt("Magazine", 2); data.save();
} }
} }
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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; return magType == 2 ? 30 : 0;
} }
@Override @Override
public double getCustomZoom(ItemStack stack) { 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) { return switch (scopeType) {
case 2 -> 2.15; case 2 -> 2.15;
case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
@ -169,7 +170,7 @@ public class Qbz95Item extends GunItem implements GeoItem {
@Override @Override
public boolean canAdjustZoom(ItemStack stack) { public boolean canAdjustZoom(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3;
} }
@Override @Override

View file

@ -7,14 +7,13 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
import com.atsuishio.superbwarfare.tools.GunsTool;
import com.atsuishio.superbwarfare.tools.NBTTool; import com.atsuishio.superbwarfare.tools.NBTTool;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer; import net.minecraft.client.player.LocalPlayer;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
@ -52,9 +51,8 @@ public class VectorItem extends GunItem implements GeoItem {
ItemStack stack = player.getMainHandItem(); ItemStack stack = player.getMainHandItem();
if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP; if (!stack.is(ModTags.Items.GUN)) return PlayState.STOP;
var data = GunData.from(stack); 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 (data.reload.empty()) {
if (drum) { if (drum) {
@ -115,28 +113,30 @@ public class VectorItem extends GunItem implements GeoItem {
return new VectorItemRenderer(); return new VectorItemRenderer();
} }
// TODO 移除inventoryTick
@Override @Override
@ParametersAreNonnullByDefault @ParametersAreNonnullByDefault
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) { public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, world, entity, slot, 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) { if (scopeType == 3) {
CompoundTag tag = NBTTool.getTag(stack).getCompound("Attachments"); data.attachment.set(AttachmentType.SCOPE, 0);
tag.putInt("Scope", 0); data.save();
} }
} }
@Override @Override
public double getCustomZoom(ItemStack stack) { 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; return scopeType == 2 ? (NBTTool.getTag(stack).getBoolean("ScopeAlt") ? 0 : 2.75) : 0;
} }
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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) { return switch (magType) {
case 1 -> 20; case 1 -> 20;
case 2 -> 57; case 2 -> 57;

View file

@ -7,6 +7,7 @@ import com.atsuishio.superbwarfare.event.ClientEventHandler;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; import com.atsuishio.superbwarfare.init.ModTags;
import com.atsuishio.superbwarfare.item.gun.GunItem; 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.GunData;
import com.atsuishio.superbwarfare.perk.Perk; import com.atsuishio.superbwarfare.perk.Perk;
import com.atsuishio.superbwarfare.perk.PerkHelper; import com.atsuishio.superbwarfare.perk.PerkHelper;
@ -106,7 +107,7 @@ public class SvdItem extends GunItem implements GeoItem {
@Override @Override
public int getCustomMagazine(ItemStack stack) { 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) { return switch (magType) {
case 1 -> 10; case 1 -> 10;
case 2 -> 20; case 2 -> 20;
@ -116,7 +117,7 @@ public class SvdItem extends GunItem implements GeoItem {
@Override @Override
public double getCustomZoom(ItemStack stack) { 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) { return switch (scopeType) {
case 2 -> 2.75; case 2 -> 2.75;
case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom"); case 3 -> GunsTool.getGunDoubleTag(NBTTool.getTag(stack), "CustomZoom");
@ -126,7 +127,7 @@ public class SvdItem extends GunItem implements GeoItem {
@Override @Override
public boolean canAdjustZoom(ItemStack stack) { public boolean canAdjustZoom(ItemStack stack) {
return GunsTool.getAttachmentType(stack, GunsTool.AttachmentType.SCOPE) == 3; return GunData.from(stack).attachment.get(AttachmentType.SCOPE) == 3;
} }
@Override @Override

View file

@ -3,10 +3,10 @@ package com.atsuishio.superbwarfare.network.message.send;
import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.Mod;
import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.init.ModSounds;
import com.atsuishio.superbwarfare.init.ModTags; 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.data.GunData;
import com.atsuishio.superbwarfare.tools.SoundTool; import com.atsuishio.superbwarfare.tools.SoundTool;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.ByteBufCodecs;
import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.codec.StreamCodec;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload; 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; if (!stack.is(ModTags.Items.GUN)) return;
var data = GunData.from(stack); var data = GunData.from(stack);
var rootTag = data.tag(); var attachment = data.attachment;
CompoundTag tag = rootTag.getCompound("Attachments");
switch (type) { switch (type) {
case 0 -> { case 0 -> {
int att = tag.getInt("Scope"); int att = attachment.get(AttachmentType.SCOPE);
att++; att++;
att %= 4; att %= 4;
tag.putInt("Scope", att); attachment.set(AttachmentType.SCOPE, att);
} }
case 1 -> { case 1 -> {
int att = tag.getInt("Barrel"); int att = attachment.get(AttachmentType.BARREL);
att++; att++;
att %= 3; att %= 3;
tag.putInt("Barrel", att); attachment.set(AttachmentType.BARREL, att);
} }
case 2 -> { case 2 -> {
int att = tag.getInt("Magazine"); int att = attachment.get(AttachmentType.MAGAZINE);
att++; att++;
att %= 3; att %= 3;
tag.putInt("Magazine", att); attachment.set(AttachmentType.MAGAZINE, att);
} }
case 3 -> { case 3 -> {
int att = tag.getInt("Stock"); int att = attachment.get(AttachmentType.STOCK);
att++; att++;
att %= 3; att %= 3;
tag.putInt("Stock", att); attachment.set(AttachmentType.STOCK, att);
} }
case 4 -> { case 4 -> {
int att = tag.getInt("Grip"); int att = attachment.get(AttachmentType.GRIP);
att++; att++;
att %= 4; att %= 4;
tag.putInt("Grip", att); attachment.set(AttachmentType.GRIP, att);
} }
} }
rootTag.put("Attachments", tag);
data.save(); data.save();
SoundTool.playLocalSound(player, ModSounds.EDIT.get(), 1f, 1f); SoundTool.playLocalSound(player, ModSounds.EDIT.get(), 1f, 1f);
} }

View file

@ -85,16 +85,14 @@ public class GunsTool {
reload(player, stack, gunData, type, false); reload(player, stack, gunData, type, false);
} }
public static void reload(Player player, ItemStack stack, GunData gunData, AmmoType type, boolean extraOne) { public static void reload(Player player, ItemStack stack, GunData data, AmmoType type, boolean extraOne) {
var data = gunData.data(); int mag = data.magazine();
int ammo = data.ammo();
int mag = gunData.magazine();
int ammo = gunData.ammo();
int ammoToAdd = mag - ammo + (extraOne ? 1 : 0); int ammoToAdd = mag - ammo + (extraOne ? 1 : 0);
// 空仓换弹的栓动武器应该在换弹后取消待上膛标记 // 空仓换弹的栓动武器应该在换弹后取消待上膛标记
if (ammo == 0 && gunData.bolt.defaultActionTime() > 0 && !stack.is(ModTags.Items.REVOLVER)) { if (ammo == 0 && data.bolt.defaultActionTime() > 0 && !stack.is(ModTags.Items.REVOLVER)) {
gunData.bolt.markNeedless(); data.bolt.markNeedless();
} }
var capability = player.getCapability(ModCapabilities.PLAYER_VARIABLE); var capability = player.getCapability(ModCapabilities.PLAYER_VARIABLE);
@ -109,8 +107,8 @@ public class GunsTool {
int needToAdd = ammo + Math.min(ammoToAdd, playerAmmo); int needToAdd = ammo + Math.min(ammoToAdd, playerAmmo);
gunData.setAmmo(needToAdd); data.setAmmo(needToAdd);
gunData.reload.setState(ReloadState.NOT_RELOADING); data.reload.setState(ReloadState.NOT_RELOADING);
} }
/* PerkData */ /* PerkData */
@ -150,33 +148,6 @@ public class GunsTool {
return tag.getBoolean(name); 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 */ /* GunData */
public static CompoundTag getGunData(final CompoundTag tag) { public static CompoundTag getGunData(final CompoundTag tag) {