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 --- .../darkknight/jewelrycraft/block/BlockMolder.java | 12 ++-- common/darkknight/jewelrycraft/item/ItemRing.java | 69 +++++++++++++++------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/common/darkknight/jewelrycraft/block/BlockMolder.java b/common/darkknight/jewelrycraft/block/BlockMolder.java index 0003015..9d39afb 100644 --- a/common/darkknight/jewelrycraft/block/BlockMolder.java +++ b/common/darkknight/jewelrycraft/block/BlockMolder.java @@ -5,8 +5,6 @@ import java.util.Random; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; -import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.EnchantmentData; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; @@ -43,7 +41,7 @@ public class BlockMolder extends BlockContainer @Override public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) - { + { TileEntityMolder te = (TileEntityMolder) world.getBlockTileEntity(i, j, k); ItemStack item = entityPlayer.inventory.getCurrentItem(); if (te != null && item != null && !te.hasMold && item.itemID == ItemList.molds.itemID) @@ -63,7 +61,7 @@ public class BlockMolder extends BlockContainer @Override public void onBlockDestroyedByPlayer(World world, int i, int j, int k, int par5) - { + { TileEntityMolder te = (TileEntityMolder) world.getBlockTileEntity(i, j, k); if (te != null) { @@ -105,11 +103,11 @@ public class BlockMolder extends BlockContainer @Override public void onBlockDestroyedByExplosion(World world, int i, int j, int k, Explosion par5Explosion) - { + { onBlockDestroyedByPlayer(world, i, j, k, 0); } - public void giveJewelToPlayer(TileEntityMolder md, EntityPlayer player, ItemStack item, String metal) + public void giveJewelToPlayer(TileEntityMolder md, EntityPlayer player, ItemStack item, ItemStack metal) { if (item != null) { @@ -123,7 +121,7 @@ public class BlockMolder extends BlockContainer @Override public void onBlockClicked(World world, int i, int j, int k, EntityPlayer player) - { + { TileEntityMolder me = (TileEntityMolder) world.getBlockTileEntity(i, j, k); if (me != null && me.hasJewelBase) { 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