From f242b3b9e2d62cc2263e9e9288c9feb9613e8132 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Thu, 22 Aug 2019 20:51:35 -0400 Subject: Update --- .../darkknight/jewelrycraft/util/JewelryNBT.java | 216 ++++++++++++++------- 1 file changed, 151 insertions(+), 65 deletions(-) (limited to 'src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java') diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java index 3d42750..17090ab 100755 --- a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java @@ -11,12 +11,14 @@ public class JewelryNBT { public static void addItem(ItemStack item, ItemStack target) { if (target != null) { NBTTagCompound itemStackData; - if (item.hasTagCompound()) + + if (item.hasTagCompound()) { itemStackData = item.getTagCompound(); - else { + } else { itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } + NBTTagCompound targetNBT = new NBTTagCompound(); target.writeToNBT(targetNBT); itemStackData.setTag("target", targetNBT); @@ -31,12 +33,14 @@ public class JewelryNBT { */ public static void addMetal(ItemStack item, ItemStack metal) { NBTTagCompound itemStackData; - if (item.hasTagCompound()) + + if (item.hasTagCompound()) { itemStackData = item.getTagCompound(); - else { + } else { itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } + if (metal != null) { NBTTagCompound ingotNBT = new NBTTagCompound(); metal.writeToNBT(ingotNBT); @@ -53,12 +57,14 @@ public class JewelryNBT { public static void addGem(ItemStack item, ItemStack gem) { if (gem != null) { NBTTagCompound itemStackData; - if (item.hasTagCompound()) + + if (item.hasTagCompound()) { itemStackData = item.getTagCompound(); - else { + } else { itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } + NBTTagCompound gemNBT = new NBTTagCompound(); gem.writeToNBT(gemNBT); itemStackData.setTag("gem", gemNBT); @@ -74,17 +80,20 @@ public class JewelryNBT { public static void addModifiers(ItemStack item, ArrayList modifier) { if (modifier != null) { NBTTagCompound itemStackData; - if (item.hasTagCompound()) + + if (item.hasTagCompound()) { itemStackData = item.getTagCompound(); - else { + } else { itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } + for (int i = 0; i < modifier.size(); i++) { NBTTagCompound modifierNBT = new NBTTagCompound(); modifier.get(i).writeToNBT(modifierNBT); itemStackData.setTag("modifier" + i, modifierNBT); } + itemStackData.setInteger("modifierSize", modifier.size()); } } @@ -95,12 +104,14 @@ public class JewelryNBT { */ public static void addIngotColor(ItemStack item, int color) { NBTTagCompound itemStackData; - if (item.hasTagCompound()) + + if (item.hasTagCompound()) { itemStackData = item.getTagCompound(); - else { + } else { itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } + itemStackData.setInteger("ingotColor", color); } @@ -111,12 +122,14 @@ public class JewelryNBT { */ public static void addGemColor(ItemStack item, int color) { NBTTagCompound itemStackData; - if (item.hasTagCompound()) + + if (item.hasTagCompound()) { itemStackData = item.getTagCompound(); - else { + } else { itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } + itemStackData.setInteger("gemColor", color); } @@ -128,14 +141,18 @@ public class JewelryNBT { */ public static boolean hasTag(ItemStack item, String tag) { NBTTagCompound itemStackData; - if (item.hasTagCompound()) + + if (item.hasTagCompound()) { itemStackData = item.getTagCompound(); - else { + } else { itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } - if (itemStackData.hasKey(tag)) + + if (itemStackData.hasKey(tag)) { return true; + } + return false; } @@ -145,9 +162,14 @@ public class JewelryNBT { * @return */ public static boolean isGemX(ItemStack stack, ItemStack gem) { - if (gem(stack) != null && gem(stack).getItem() == gem.getItem() - && gem(stack).getItemDamage() == gem.getItemDamage()) - return true; + if (gem(stack) != null) { + if (gem(stack).getItem() == gem.getItem()) { + if (gem(stack).getItemDamage() == gem.getItemDamage()) { + return true; + } + } + } + return false; } @@ -159,28 +181,40 @@ public class JewelryNBT { public static boolean doesModifierExist(ItemStack stack, ItemStack modifier) { if (modifier(stack) != null) { ArrayList list = modifier(stack); - for (int i = 0; i < list.size(); i++) - if (list.get(i).getItem() == modifier.getItem() - && list.get(i).getItemDamage() == modifier.getItemDamage()) - return true; + + for (int i = 0; i < list.size(); i++) { + if (list.get(i).getItem() == modifier.getItem()) { + if (list.get(i).getItemDamage() == modifier.getItemDamage()) { + return true; + } + } + } } + return false; } public static int modifierSize(ItemStack stack, ItemStack modifier) { if (modifier(stack) != null) { ArrayList list = modifier(stack); - for (int i = 0; i < list.size(); i++) - if (list.get(i).getItem() == modifier.getItem() - && list.get(i).getItemDamage() == modifier.getItemDamage()) - return list.get(i).stackSize; + + for (int i = 0; i < list.size(); i++) { + if (list.get(i).getItem() == modifier.getItem()) { + if (list.get(i).getItemDamage() == modifier.getItemDamage()) { + return list.get(i).stackSize; + } + } + } } + return -1; } public static int numberOfModifiers(ItemStack stack) { - if (modifier(stack) != null) + if (modifier(stack) != null) { return modifier(stack).size(); + } + return -1; } @@ -190,21 +224,34 @@ public class JewelryNBT { * @return */ public static boolean isIngotX(ItemStack stack, ItemStack ingot) { - if (ingot(stack) != null && ingot(stack).getItem() == ingot.getItem() - && ingot(stack).getItemDamage() == ingot.getItemDamage()) - return true; + if (ingot(stack) != null) { + if (ingot(stack).getItem() == ingot.getItem()) { + if (ingot(stack).getItemDamage() == ingot.getItemDamage()) + return true; + } + } + return false; } // TODO Return components based on NBT public static ItemStack item(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() - && stack.getTagCompound().hasKey("target")) { - NBTTagCompound itemNBT = (NBTTagCompound) stack.getTagCompound().getTag("target"); - ItemStack target = new ItemStack(Item.getItemById(0), 0, 0); - target.readFromNBT(itemNBT); - return target; + if (stack != null) { + if (stack != new ItemStack(Item.getItemById(0), 0, 0)) { + if (stack.hasTagCompound()) { + if (stack.getTagCompound().hasKey("target")) { + NBTTagCompound itemNBT = (NBTTagCompound) stack.getTagCompound().getTag("target"); + + ItemStack target = new ItemStack(Item.getItemById(0), 0, 0); + + target.readFromNBT(itemNBT); + + return target; + } + } + } } + return null; } @@ -213,13 +260,20 @@ public class JewelryNBT { * @return */ public static ItemStack gem(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() - && stack.getTagCompound().hasKey("gem")) { - NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("gem"); - ItemStack gem = new ItemStack(Item.getItemById(0), 0, 0); - gem.readFromNBT(jewelNBT); - return gem; + if (stack != null) { + if (stack != new ItemStack(Item.getItemById(0), 0, 0)) { + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("gem")) { + NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("gem"); + + ItemStack gem = new ItemStack(Item.getItemById(0), 0, 0); + + gem.readFromNBT(jewelNBT); + + return gem; + } + } } + return null; } @@ -228,17 +282,28 @@ public class JewelryNBT { * @return */ public static ArrayList modifier(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound()) { - int size = stack.getTagCompound().getInteger("modifierSize"); - ArrayList list = new ArrayList<>(); - for (int i = 0; i < size; i++) { - ItemStack modifier = new ItemStack(Item.getItemById(0), 0, 0); - NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier" + i); - modifier.readFromNBT(modifierNBT); - list.add(modifier); + if (stack != null) { + if (stack != new ItemStack(Item.getItemById(0), 0, 0)) { + if (stack.hasTagCompound()) { + int size = stack.getTagCompound().getInteger("modifierSize"); + + ArrayList list = new ArrayList<>(); + + for (int i = 0; i < size; i++) { + ItemStack modifier = new ItemStack(Item.getItemById(0), 0, 0); + + NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier" + i); + + modifier.readFromNBT(modifierNBT); + + list.add(modifier); + } + + return list; + } } - return list; } + return null; } @@ -247,13 +312,22 @@ public class JewelryNBT { * @return */ public static ItemStack ingot(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() - && stack.getTagCompound().hasKey("ingot")) { - NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot"); - ItemStack ingot = new ItemStack(Item.getItemById(0), 0, 0); - ingot.readFromNBT(ingotNBT); - return ingot; + if (stack != null) { + if (stack != new ItemStack(Item.getItemById(0), 0, 0)) { + if (stack.hasTagCompound()) { + if (stack.getTagCompound().hasKey("ingot")) { + NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot"); + + ItemStack ingot = new ItemStack(Item.getItemById(0), 0, 0); + + ingot.readFromNBT(ingotNBT); + + return ingot; + } + } + } } + return null; } @@ -262,9 +336,16 @@ public class JewelryNBT { * @return */ public static int ingotColor(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() - && stack.getTagCompound().hasKey("ingotColor")) - return stack.getTagCompound().getInteger("ingotColor"); + if (stack != null) { + if (stack != new ItemStack(Item.getItemById(0), 0, 0)) { + if (stack.hasTagCompound()) { + if (stack.getTagCompound().hasKey("ingotColor")) { + return stack.getTagCompound().getInteger("ingotColor"); + } + } + } + } + return 16777215; } @@ -274,10 +355,15 @@ public class JewelryNBT { * @return */ public static int gemColor(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() - && stack.getTagCompound().hasKey("gemColor")) - return stack.getTagCompound().getInteger("gemColor"); + if (stack != null) { + if (stack != new ItemStack(Item.getItemById(0), 0, 0)) { + if (stack.hasTagCompound()) { + if (stack.getTagCompound().hasKey("gemColor")) + return stack.getTagCompound().getInteger("gemColor"); + } + } + } + return 16777215; } - -} +} \ No newline at end of file -- cgit v1.2.3