From 43ef55b2424eb49110e27d603adf95a84bf37560 Mon Sep 17 00:00:00 2001 From: bspkrs Date: Mon, 16 Dec 2013 14:09:52 -0500 Subject: fixed up adding ingots to rings --- common/darkknight/jewelrycraft/item/ItemRing.java | 69 +++++++++++++++-------- 1 file changed, 47 insertions(+), 22 deletions(-) (limited to 'common/darkknight/jewelrycraft/item/ItemRing.java') diff --git a/common/darkknight/jewelrycraft/item/ItemRing.java b/common/darkknight/jewelrycraft/item/ItemRing.java index 17f961d..f05b146 100644 --- a/common/darkknight/jewelrycraft/item/ItemRing.java +++ b/common/darkknight/jewelrycraft/item/ItemRing.java @@ -10,26 +10,12 @@ import net.minecraft.util.EnumChatFormatting; public class ItemRing extends ItemBase { - public static String ingot; - public PotionEffect effect; - public ItemRing(int par1) { super(par1); this.setMaxStackSize(1); } - - public ItemRing(int par1, String ingot) - { - this(par1); - this.ingot = ingot; - } - - public ItemRing(int par1, String ingot, PotionEffect effect) - { - this(par1, ingot); - this.effect = effect; - } + NBTTagCompound tag = new NBTTagCompound(); public String getMetal(ItemStack stack) @@ -37,21 +23,60 @@ public class ItemRing extends ItemBase return tag.getString("ingot"); } - public static void addMetal(ItemStack item, String metal) + public static void addMetal(ItemStack item, ItemStack metal) + { + NBTTagCompound itemStackData; + if (item.hasTagCompound()) + itemStackData = item.getTagCompound(); + else + { + itemStackData = new NBTTagCompound(); + item.setTagCompound(itemStackData); + } + NBTTagCompound ingotNBT = new NBTTagCompound(); + metal.writeToNBT(ingotNBT); + itemStackData.setTag("ingot", ingotNBT); + } + + public static void addEffect(ItemStack item, PotionEffect effect) { - NBTTagCompound tag = new NBTTagCompound(); - item.setTagCompound(tag); - tag.setString("ingot", metal); - ingot = metal; + NBTTagCompound itemStackData; + if (item.hasTagCompound()) + itemStackData = item.getTagCompound(); + else + { + itemStackData = new NBTTagCompound(); + item.setTagCompound(itemStackData); + } + NBTTagCompound effectNBT = new NBTTagCompound(); + effect.writeCustomPotionEffectToNBT(effectNBT); + itemStackData.setTag("effect", effectNBT); } /** * allows items to add custom lines of information to the mouseover description */ + @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { - if(ingot != null) list.add(EnumChatFormatting.GRAY + ingot); - if(effect != null) list.add(EnumChatFormatting.GREEN + effect.getEffectName()); + if (stack.hasTagCompound()) + { + if (stack.getTagCompound().hasKey("ingot")) + { + NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot"); + ItemStack ingotStack = new ItemStack(0, 0, 0); + ingotStack.readFromNBT(ingotNBT); + list.add(EnumChatFormatting.GRAY + ingotStack.getDisplayName()); + } + + if (stack.getTagCompound().hasKey("effect")) + { + NBTTagCompound effectNBT = (NBTTagCompound) stack.getTagCompound().getTag("effect"); + PotionEffect effect = new PotionEffect(0, 0); + effect.readCustomPotionEffectFromNBT(effectNBT); + list.add(EnumChatFormatting.GREEN + effect.getEffectName()); + } + } } } -- cgit v1.2.3