From 1a3455b24d90b0def912c28467cbc51662d660e0 Mon Sep 17 00:00:00 2001 From: OnyxDarkKnight Date: Thu, 26 Dec 2013 00:50:16 +0200 Subject: Major changes. Thanks domi for helping me with the chest linking ring :) --- common/darkknight/jewelrycraft/item/ItemRing.java | 368 +++++++--------------- 1 file changed, 113 insertions(+), 255 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 6f31c4d..92e16cf 100644 --- a/common/darkknight/jewelrycraft/item/ItemRing.java +++ b/common/darkknight/jewelrycraft/item/ItemRing.java @@ -6,8 +6,10 @@ import java.util.List; import javax.imageio.ImageIO; +import cpw.mods.fml.common.network.FMLNetworkHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import darkknight.jewelrycraft.JewelrycraftMod; import darkknight.jewelrycraft.util.JewelryNBT; import net.minecraft.block.Block; @@ -15,15 +17,15 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.resources.ResourceManager; import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.InventoryEnderChest; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.Icon; import net.minecraft.util.MathHelper; @@ -31,7 +33,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.StatCollector; import net.minecraft.world.World; -public class ItemRing extends ItemBase +public class ItemRing extends Item { public Icon jewel; private int amplifier; @@ -42,14 +44,14 @@ public class ItemRing extends ItemBase this.setMaxStackSize(1); } - public void registerIcons(IconRegister iconRegister) + public void registerIcons(IconRegister iconRegister) { itemIcon = iconRegister.registerIcon("jewelrycraft:ring"); jewel = iconRegister.registerIcon("jewelrycraft:jewel"); } @Override - public boolean requiresMultipleRenderPasses() + public boolean requiresMultipleRenderPasses() { return true; } @@ -70,170 +72,98 @@ public class ItemRing extends ItemBase public Icon getIcon(ItemStack stack, int pass) { - if (stack.hasTagCompound()) - { - if (stack.getTagCompound().hasKey("jewel")) - { - NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel"); - ItemStack ingotStack = new ItemStack(0, 0, 0); - ingotStack.readFromNBT(ingotNBT); - if(pass == 0) return itemIcon; - if(pass == 1) return jewel; - } - } + if (JewelryNBT.jewel(stack) != null) return pass == 0 ? itemIcon : jewel; return itemIcon; } public static int color(ItemStack stack, int pass) throws IOException { - if (stack.hasTagCompound() && stack.getTagCompound().hasKey("ingot") && !stack.getTagCompound().hasKey("jewel") && pass == 1) + String domain = "", texture; + ResourceManager rm = Minecraft.getMinecraft().getResourceManager(); + if (pass == 1 && JewelryNBT.ingot(stack) != null && JewelryNBT.jewel(stack) == null) { - NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot"); - ItemStack ingotStack = new ItemStack(0, 0, 0); - ingotStack.readFromNBT(ingotNBT); - if(ingotStack.getIconIndex().getIconName() != "") - { - String domain = ""; - if(ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1) != "") - domain = ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1).replace(":", " ").trim(); - else - domain = "minecraft"; - String texture = ingotStack.getIconIndex().getIconName().substring(ingotStack.getIconIndex().getIconName().lastIndexOf(":") + 1) + ".png"; - ResourceLocation ingot = null; - if(ingotStack.getUnlocalizedName().contains("item")) ingot = new ResourceLocation(domain, "textures/items/" + texture); - else ingot = new ResourceLocation(domain, "textures/blocks/" + texture); - ResourceManager rm = Minecraft.getMinecraft().getResourceManager(); - BufferedImage bufferedimage = ImageIO.read(rm.getResource(ingot).getInputStream()); - return bufferedimage.getRGB(9, 9); - } + if (JewelryNBT.ingot(stack).getIconIndex().getIconName().substring(0, JewelryNBT.ingot(stack).getIconIndex().getIconName().indexOf(":") + 1) != "") domain = JewelryNBT.ingot(stack).getIconIndex().getIconName().substring(0, JewelryNBT.ingot(stack).getIconIndex().getIconName().indexOf(":") + 1).replace(":", " ").trim(); + else domain = "minecraft"; + texture = JewelryNBT.ingot(stack).getIconIndex().getIconName().substring(JewelryNBT.ingot(stack).getIconIndex().getIconName().lastIndexOf(":") + 1) + ".png"; + ResourceLocation ingot = null; + if (JewelryNBT.ingot(stack).getUnlocalizedName().contains("item")) ingot = new ResourceLocation(domain, "textures/items/" + texture); + else ingot = new ResourceLocation(domain, "textures/blocks/" + texture); + BufferedImage bufferedimage = ImageIO.read(rm.getResource(ingot).getInputStream()); + return bufferedimage.getRGB(9, 9); } - if (stack.hasTagCompound() && stack.getTagCompound().hasKey("jewel")) + else if (JewelryNBT.ingot(stack) != null && JewelryNBT.jewel(stack) != null) { - if(pass == 1) - { - NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel"); - ItemStack jewel = new ItemStack(0, 0, 0); - jewel.readFromNBT(jewelNBT); - if(jewel != null && jewel != new ItemStack(0, 0, 0) && jewel.getIconIndex().getIconName() != "") - { - String domain = ""; - if(jewel.getIconIndex().getIconName().substring(0, jewel.getIconIndex().getIconName().indexOf(":") + 1) != "") - domain = jewel.getIconIndex().getIconName().substring(0, jewel.getIconIndex().getIconName().indexOf(":") + 1).replace(":", " ").trim(); - else - domain = "minecraft"; - String texture = jewel.getIconIndex().getIconName().substring(jewel.getIconIndex().getIconName().lastIndexOf(":") + 1) + ".png"; - ResourceLocation jewelLoc = null; - if(jewel.getUnlocalizedName().contains("item")) jewelLoc = new ResourceLocation(domain, "textures/items/" + texture); - else jewelLoc = new ResourceLocation(domain, "textures/blocks/" + texture); - ResourceManager rm = Minecraft.getMinecraft().getResourceManager(); - BufferedImage bufferedimage = ImageIO.read(rm.getResource(jewelLoc).getInputStream()); - return bufferedimage.getRGB(9, 4); - } - } - NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot"); - ItemStack ingotStack = new ItemStack(0, 0, 0); - ingotStack.readFromNBT(ingotNBT); - if(ingotStack.getIconIndex().getIconName() != "") - { - String domain = ""; - if(ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1) != "") - domain = ingotStack.getIconIndex().getIconName().substring(0, ingotStack.getIconIndex().getIconName().indexOf(":") + 1).replace(":", " ").trim(); - else - domain = "minecraft"; - String texture = ingotStack.getIconIndex().getIconName().substring(ingotStack.getIconIndex().getIconName().lastIndexOf(":") + 1) + ".png"; - ResourceLocation ingot = null; - if(ingotStack.getUnlocalizedName().contains("item")) ingot = new ResourceLocation(domain, "textures/items/" + texture); - else ingot = new ResourceLocation(domain, "textures/blocks/" + texture); - ResourceManager rm = Minecraft.getMinecraft().getResourceManager(); - BufferedImage bufferedimage = ImageIO.read(rm.getResource(ingot).getInputStream()); - return bufferedimage.getRGB(9, 9); - } + if (pass == 1) + { + if (JewelryNBT.jewel(stack).getIconIndex().getIconName().substring(0, JewelryNBT.jewel(stack).getIconIndex().getIconName().indexOf(":") + 1) != "") domain = JewelryNBT.jewel(stack).getIconIndex().getIconName().substring(0, JewelryNBT.jewel(stack).getIconIndex().getIconName().indexOf(":") + 1).replace(":", " ").trim(); + else domain = "minecraft"; + texture = JewelryNBT.jewel(stack).getIconIndex().getIconName().substring(JewelryNBT.jewel(stack).getIconIndex().getIconName().lastIndexOf(":") + 1) + ".png"; + ResourceLocation jewelLoc = null; + if (JewelryNBT.jewel(stack).getUnlocalizedName().contains("item")) jewelLoc = new ResourceLocation(domain, "textures/items/" + texture); + else jewelLoc = new ResourceLocation(domain, "textures/blocks/" + texture); + BufferedImage bufferedimage = ImageIO.read(rm.getResource(jewelLoc).getInputStream()); + return bufferedimage.getRGB(9, 4); + } + if (JewelryNBT.ingot(stack).getIconIndex().getIconName().substring(0, JewelryNBT.ingot(stack).getIconIndex().getIconName().indexOf(":") + 1) != "") domain = JewelryNBT.ingot(stack).getIconIndex().getIconName().substring(0, JewelryNBT.ingot(stack).getIconIndex().getIconName().indexOf(":") + 1).replace(":", " ").trim(); + else domain = "minecraft"; + texture = JewelryNBT.ingot(stack).getIconIndex().getIconName().substring(JewelryNBT.ingot(stack).getIconIndex().getIconName().lastIndexOf(":") + 1) + ".png"; + ResourceLocation ingot = null; + if (JewelryNBT.ingot(stack).getUnlocalizedName().contains("item")) ingot = new ResourceLocation(domain, "textures/items/" + texture); + else ingot = new ResourceLocation(domain, "textures/blocks/" + texture); + BufferedImage bufferedimage = ImageIO.read(rm.getResource(ingot).getInputStream()); + return bufferedimage.getRGB(9, 9); } return 16777215; } public String getItemDisplayName(ItemStack stack) { - 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); - if (stack.getTagCompound().hasKey("jewel")) - { - NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel"); - ItemStack jewel = new ItemStack(0, 0, 0); - jewel.readFromNBT(jewelNBT); - if(jewel.itemID == Item.diamond.itemID && ingotStack.itemID == Item.ingotGold.itemID) return "Wedding Ring"; - } - return ingotStack.getDisplayName().replace("Ingot", " ").trim() + " " + ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim(); - } - } + if (JewelryNBT.ingot(stack) != null && JewelryNBT.jewel(stack) != null && JewelryNBT.isJewelX(stack, new ItemStack(Item.diamond)) && JewelryNBT.isIngotX(stack, new ItemStack(Item.ingotGold))) return "Wedding Ring"; + else if(JewelryNBT.ingot(stack) != null) return JewelryNBT.ingot(stack).getDisplayName().replace("Ingot", " ").trim() + " " + ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim(); return ("" + StatCollector.translateToLocal(this.getUnlocalizedNameInefficiently(stack) + ".name")).trim(); } public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { - if (!world.isRemote && stack.hasTagCompound()) - { - if(stack.getTagCompound().hasKey("x") && stack.getTagCompound().hasKey("y") && stack.getTagCompound().hasKey("z")) - { - NBTTagCompound x = (NBTTagCompound) stack.getTagCompound().getTag("x"); - NBTTagCompound y = (NBTTagCompound) stack.getTagCompound().getTag("y"); - NBTTagCompound z = (NBTTagCompound) stack.getTagCompound().getTag("z"); - double posX = 0, posY = 0, posZ = 0; - posX = x.getDouble("x"); - posY = y.getDouble("y"); - posZ = z.getDouble("z"); - if(stack.getTagCompound().hasKey("dimension") && stack.getTagCompound().hasKey("dimName")) - { - NBTTagCompound dim = (NBTTagCompound) stack.getTagCompound().getTag("dimension"); - int dimension = 0; - dimension = dim.getInteger("dimension"); - for(int i = 1; i <= 20; i++) - world.spawnParticle("largesmoke", player.posX - 0.5D + Math.random(), player.posY - 1.5D + Math.random(), player.posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D); - if(player.dimension != dimension) player.travelToDimension(dimension); + if (!world.isRemote){ + if (JewelryNBT.playerPosX(stack) != -1 && JewelryNBT.playerPosY(stack) != -1 && JewelryNBT.playerPosZ(stack) != -1){ + double posX = JewelryNBT.playerPosX(stack), posY = JewelryNBT.playerPosY(stack), posZ = JewelryNBT.playerPosZ(stack); + if (JewelryNBT.dimension(stack) != -2 && JewelryNBT.dimName(stack) != null){ + int dimension = JewelryNBT.dimension(stack); + for (int i = 1; i <= 20; i++) world.spawnParticle("largesmoke", player.posX - 0.5D + Math.random(), player.posY - 1.5D + Math.random(), player.posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D); + if (!JewelryNBT.isDimensionX(stack, player.dimension)) player.travelToDimension(dimension); player.setPositionAndUpdate(posX, posY, posZ); - for(int i = 1; i <= 300; i++) - world.spawnParticle("portal", posX - 0.5D + Math.random(), posY + Math.random(), posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D); + for (int i = 1; i <= 300; i++) world.spawnParticle("portal", posX - 0.5D + Math.random(), posY + Math.random(), posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D); } - else - { - for(int i = 1; i <= 20; i++) - world.spawnParticle("largesmoke", player.posX - 0.5D + Math.random(), player.posY - 1.5D + Math.random(), player.posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D); + else{ + for (int i = 1; i <= 20; i++) world.spawnParticle("largesmoke", player.posX - 0.5D + Math.random(), player.posY - 1.5D + Math.random(), player.posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D); player.setPositionAndUpdate(posX, posY, posZ); - for(int i = 1; i <= 300; i++) - world.spawnParticle("portal", posX - 0.5D + Math.random(), posY + Math.random(), posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D); + for (int i = 1; i <= 300; i++) world.spawnParticle("portal", posX - 0.5D + Math.random(), posY + Math.random(), posZ - 0.5D + Math.random(), 0.0D, 0.0D, 0.0D); } } - if(stack.getTagCompound().hasKey("jewel")) - { - NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel"); - ItemStack jewel = new ItemStack(0, 0, 0); - jewel.readFromNBT(jewelNBT); - if(stack.getTagCompound().hasKey("modifier")) - { - NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier"); - ItemStack modifier = new ItemStack(0, 0, 0); - modifier.readFromNBT(modifierNBT); - if(jewel.itemID == Item.enderPearl.itemID && modifier.itemID == Item.bed.itemID && !stack.getTagCompound().hasKey("x") && !stack.getTagCompound().hasKey("y") && !stack.getTagCompound().hasKey("z") && !stack.getTagCompound().hasKey("dimension")) - { - JewelryNBT.addCoordonatesAndDimension(stack, player.posX, player.posY, player.posZ, world.provider.dimensionId, world.provider.getDimensionName()); - JewelryNBT.addEnchantment(stack); - } - if(jewel.itemID == Block.obsidian.blockID && modifier.itemID == Item.eyeOfEnder.itemID) - { - InventoryEnderChest inventoryenderchest = player.getInventoryEnderChest(); - player.displayGUIChest(inventoryenderchest); + else if(JewelryNBT.isJewelX(stack, new ItemStack(Item.enderPearl)) && JewelryNBT.isModifierX(stack, new ItemStack(Item.bed)) && JewelryNBT.dimension(stack) == -2 && JewelryNBT.playerPosX(stack) == -1 && JewelryNBT.playerPosY(stack) == -1 && JewelryNBT.playerPosZ(stack) == -1){ + JewelryNBT.addCoordonatesAndDimension(stack, player.posX, player.posY, player.posZ, world.provider.dimensionId, world.provider.getDimensionName()); + JewelryNBT.addEnchantment(stack); + } + else if (JewelryNBT.isJewelX(stack, new ItemStack(Block.obsidian)) && JewelryNBT.isModifierX(stack, new ItemStack(Item.eyeOfEnder))){ + InventoryEnderChest inventoryenderchest = player.getInventoryEnderChest(); + player.displayGUIChest(inventoryenderchest); + } + else if (JewelryNBT.isJewelX(stack, new ItemStack(Item.enderPearl)) && JewelryNBT.isModifierX(stack, new ItemStack(Block.chest))){ + int i = JewelryNBT.blockCoordX(stack), j = JewelryNBT.blockCoordY(stack), k = JewelryNBT.blockCoordZ(stack); + if (player.getDistance(i + 0.5F, j + 0.5F, k + 0.5F) <= 128 && i != -1 && j != -1 && k != -1){ + int id = world.getBlockId(i, j, k); + if (id != 0 && Block.blocksList[id] != null && Block.blocksList[id].blockID == Block.chest.blockID){ + TileEntity tile = world.getBlockTileEntity(i, j, k); + if (tile != null && tile instanceof TileEntityChest) FMLNetworkHandler.openGui(player, JewelrycraftMod.instance, 0, world, i, j, k); } } - else if(jewel.itemID == Item.enderPearl.itemID && !stack.getTagCompound().hasKey("x") && !stack.getTagCompound().hasKey("y") && !stack.getTagCompound().hasKey("z")) - { - JewelryNBT.addCoordonates(stack, player.posX, player.posY, player.posZ); - JewelryNBT.addEnchantment(stack); - } + else if(i != -1 && j != -1 && k != -1) player.addChatMessage("Chest out of range! You need to be " + ((int)player.getDistance(i + 0.5F, j + 0.5F, k + 0.5F) - 127) + " blocks closer."); + else player.addChatMessage("You need to link the ring with a chest first, before using it!"); + } + else if (JewelryNBT.isJewelX(stack, new ItemStack(Item.enderPearl)) && JewelryNBT.playerPosX(stack) == -1 && JewelryNBT.playerPosY(stack) == -1 && JewelryNBT.playerPosZ(stack) == -1){ + JewelryNBT.addCoordonates(stack, player.posX, player.posY, player.posZ); + JewelryNBT.addEnchantment(stack); } } return stack; @@ -242,115 +172,60 @@ public class ItemRing extends ItemBase @Override public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer player, EntityLivingBase entity) { - if (!player.worldObj.isRemote && stack.hasTagCompound()) - { - if(stack.getTagCompound().hasKey("jewel") && stack.getTagCompound().hasKey("modifier") && !stack.getTagCompound().hasKey("entityID") && !stack.getTagCompound().hasKey("entity")) - { - NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel"); - NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier"); - ItemStack jewel = new ItemStack(0, 0, 0); - ItemStack modifier = new ItemStack(0, 0, 0); - jewel.readFromNBT(jewelNBT); - modifier.readFromNBT(modifierNBT); - if(jewel.itemID == Item.netherStar.itemID && modifier.itemID == Block.chest.blockID) - { - JewelryNBT.addEntity(stack, entity); - JewelryNBT.addEntityID(stack, entity); - entity.setDead(); - JewelryNBT.addEnchantment(stack); - } - } + if (!player.worldObj.isRemote && JewelryNBT.isJewelX(stack, new ItemStack(Item.netherStar)) && JewelryNBT.isModifierX(stack, new ItemStack(Block.chest)) && JewelryNBT.entity(stack, player) == null){ + JewelryNBT.addEntity(stack, entity); + JewelryNBT.addEntityID(stack, entity); + entity.setDead(); + JewelryNBT.addEnchantment(stack); } return true; } /** - * allows items to add custom lines of information to the mouseover description + * allows items to add custom lines of information to the mouseover + * description */ @Override - @SuppressWarnings({ "rawtypes", "unchecked"}) + @SuppressWarnings( + { "rawtypes", "unchecked" }) public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) { if (stack.hasTagCompound() && stack.getDisplayName() != "Wedding Ring") { - if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("ingot")) - { - NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot"); - ItemStack ingotStack = new ItemStack(0, 0, 0); - ingotStack.readFromNBT(ingotNBT); - if(ingotStack != null && ingotStack != new ItemStack(0, 0, 0) && ingotStack.getDisplayName() != null) - list.add("Ingot: " + EnumChatFormatting.YELLOW + ingotStack.getDisplayName()); - } + ItemStack ingot = JewelryNBT.ingot(stack); + if (ingot != null) list.add("Ingot: " + EnumChatFormatting.YELLOW + ingot.getDisplayName()); - if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("jewel")) - { - NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel"); - ItemStack jewel = new ItemStack(0, 0, 0); - jewel.readFromNBT(jewelNBT); - if(jewel != null && jewel != new ItemStack(0, 0, 0) && jewel.getDisplayName() != null) - list.add("Jewel: " + EnumChatFormatting.BLUE + jewel.getDisplayName()); - } + ItemStack jewel = JewelryNBT.jewel(stack); + if (jewel != null) list.add("Jewel: " + EnumChatFormatting.BLUE + jewel.getDisplayName()); - if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("modifier")) - { - NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier"); - ItemStack modifier = new ItemStack(0, 0, 0); - modifier.readFromNBT(modifierNBT); - if(modifier != null && modifier != new ItemStack(0, 0, 0) && modifier.getDisplayName() != null) - list.add("Modifier: " + EnumChatFormatting.DARK_PURPLE + modifier.getDisplayName()); - } + ItemStack modifier = JewelryNBT.modifier(stack); + if(modifier != null) list.add("Modifier: " + EnumChatFormatting.DARK_PURPLE + modifier.getDisplayName()); - if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("x") && stack.getTagCompound().hasKey("y") && stack.getTagCompound().hasKey("z")) - { - NBTTagCompound x = (NBTTagCompound) stack.getTagCompound().getTag("x"); - NBTTagCompound y = (NBTTagCompound) stack.getTagCompound().getTag("y"); - NBTTagCompound z = (NBTTagCompound) stack.getTagCompound().getTag("z"); - double posX = 0, posY = 0, posZ = 0; - posX = x.getDouble("x"); - posY = y.getDouble("y"); - posZ = z.getDouble("z"); - list.add(EnumChatFormatting.YELLOW + "X: " + EnumChatFormatting.GRAY + (int)posX + EnumChatFormatting.YELLOW + " Y: " + EnumChatFormatting.GRAY + (int)posY + EnumChatFormatting.YELLOW + " Z: " + EnumChatFormatting.GRAY + (int)posZ); - } + double playerPosX = JewelryNBT.playerPosX(stack), playerPosY = JewelryNBT.playerPosY(stack), playerPosZ = JewelryNBT.playerPosZ(stack); + if(playerPosX != -1 && playerPosY != -1 && playerPosZ != -1) list.add(EnumChatFormatting.YELLOW + "X: " + EnumChatFormatting.GRAY + (int) playerPosX + EnumChatFormatting.YELLOW + " Y: " + EnumChatFormatting.GRAY + (int) playerPosY + EnumChatFormatting.YELLOW + " Z: " + EnumChatFormatting.GRAY + (int) playerPosZ); - if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("dimName")) - { - NBTTagCompound dim = (NBTTagCompound) stack.getTagCompound().getTag("dimName"); - String name = ""; - name = dim.getString("dimName"); - list.add("Dimension: " + EnumChatFormatting.DARK_GREEN + name); - } + int posX = JewelryNBT.blockCoordX(stack), posY = JewelryNBT.blockCoordY(stack), posZ = JewelryNBT.blockCoordZ(stack); + if(posX != -1 && posY != -1 && posZ != -1) list.add(EnumChatFormatting.YELLOW + "X: " + EnumChatFormatting.GRAY + (int) posX + EnumChatFormatting.YELLOW + " Y: " + EnumChatFormatting.GRAY + (int) posY + EnumChatFormatting.YELLOW + " Z: " + EnumChatFormatting.GRAY + (int) posZ); - if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("entityID") && stack.getTagCompound().hasKey("entity")) - { - NBTTagCompound enID = (NBTTagCompound) stack.getTagCompound().getTag("entityID"); - NBTTagCompound en = (NBTTagCompound) stack.getTagCompound().getTag("entity"); - int entityID = 0; - entityID = enID.getInteger("entityID"); - EntityLivingBase entity = (EntityLivingBase) EntityList.createEntityByID(entityID, player.worldObj); - entity.readFromNBT(en); - list.add("Entity: " + EnumChatFormatting.GOLD + entity.getEntityName()); - } + String name = JewelryNBT.dimName(stack); + if(name != null) list.add("Dimension: " + EnumChatFormatting.DARK_GREEN + name); + + EntityLivingBase entity = JewelryNBT.entity(stack, player); + if (entity != null) list.add("Entity: " + EnumChatFormatting.GOLD + entity.getEntityName()); } } public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int i, int j, int k, int side, float par8, float par9, float par10) { - if (!world.isRemote && stack.hasTagCompound()) + if (!world.isRemote) { - if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("entityID") && stack.getTagCompound().hasKey("entity")) - { - NBTTagCompound enID = (NBTTagCompound) stack.getTagCompound().getTag("entityID"); - NBTTagCompound en = (NBTTagCompound) stack.getTagCompound().getTag("entity"); - int entityID = 0; - entityID = enID.getInteger("entityID"); - EntityLivingBase entity = (EntityLivingBase) EntityList.createEntityByID(entityID, player.worldObj); - entity.readFromNBT(en); - entity.setLocationAndAngles(i + 0.5D, j + 1D, k + 0.5D, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F); + EntityLivingBase entity = JewelryNBT.entity(stack, player); + if(entity != null){ + entity.setLocationAndAngles(i + 0.5D, j + 1D, k + 0.5D, MathHelper.wrapAngleTo180_float(world.rand.nextFloat() * 360.0F), 0.0F); world.spawnEntityInWorld(entity); - JewelryNBT.removeNBT(stack, "entityID"); - JewelryNBT.removeNBT(stack, "entity"); - JewelryNBT.removeNBT(stack, "ench"); - } + JewelryNBT.removeEntity(stack); + } + if (JewelryNBT.isJewelX(stack, new ItemStack(Item.enderPearl)) && JewelryNBT.isModifierX(stack, new ItemStack(Block.chest)) && world.getBlockId(i, j, k) == Block.chest.blockID) JewelryNBT.addBlockCoordonates(stack, i, j, k); } return true; } @@ -359,32 +234,15 @@ public class ItemRing extends ItemBase public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) { amplifier = 0; - if (!world.isRemote && stack.hasTagCompound()) - { - if(stack.getTagCompound().hasKey("jewel")) - { - NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel"); - ItemStack jewel = new ItemStack(0, 0, 0); - jewel.readFromNBT(jewelNBT); - if(jewel.itemID == Item.diamond.itemID) amplifier = 1; - if(jewel.itemID == Item.emerald.itemID) amplifier = 2; - } - if(stack.getTagCompound().hasKey("modifier")) - { - if (entity instanceof EntityPlayer) - { - EntityPlayer entityplayer = (EntityPlayer)entity; - NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier"); - ItemStack modifier = new ItemStack(0, 0, 0); - modifier.readFromNBT(modifierNBT); - if(modifier.itemID == Item.blazePowder.itemID && entityplayer != null) - entityplayer.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 4, amplifier)); - if(modifier.itemID == Item.sugar.itemID && entityplayer != null) - entityplayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 4, amplifier)); - if(modifier.itemID == Item.pickaxeIron.itemID && entityplayer != null) - entityplayer.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 4, amplifier)); - } - } + if (!world.isRemote){ + EntityPlayer entityplayer = (EntityPlayer) entity; + if (JewelryNBT.isJewelX(stack, new ItemStack(Item.diamond))) amplifier = 1; + else if (JewelryNBT.isJewelX(stack, new ItemStack(Item.emerald))) amplifier = 2; + else if (JewelryNBT.isJewelX(stack, new ItemStack(Item.netherStar))) amplifier = 7; + + if (JewelryNBT.isModifierX(stack, new ItemStack(Item.blazePowder)) && entityplayer != null) entityplayer.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 4, amplifier)); + else if (JewelryNBT.isModifierX(stack, new ItemStack(Item.sugar)) && entityplayer != null) entityplayer.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 4, amplifier)); + else if (JewelryNBT.isModifierX(stack, new ItemStack(Item.pickaxeIron)) && entityplayer != null) entityplayer.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 4, amplifier)); } } } -- cgit v1.2.3