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 :) --- .../darkknight/jewelrycraft/util/JewelryNBT.java | 201 +++++++++++++++++++++ .../jewelrycraft/util/JewelrycraftUtil.java | 111 ++++++++++++ 2 files changed, 312 insertions(+) create mode 100644 common/darkknight/jewelrycraft/util/JewelrycraftUtil.java (limited to 'common/darkknight/jewelrycraft/util') diff --git a/common/darkknight/jewelrycraft/util/JewelryNBT.java b/common/darkknight/jewelrycraft/util/JewelryNBT.java index c097a49..be2f959 100644 --- a/common/darkknight/jewelrycraft/util/JewelryNBT.java +++ b/common/darkknight/jewelrycraft/util/JewelryNBT.java @@ -2,6 +2,7 @@ package darkknight.jewelrycraft.util; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLivingBase; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -104,6 +105,25 @@ public class JewelryNBT itemStackData.setTag("z", coords); } + public static void addBlockCoordonates(ItemStack item, int x, int y, int z) + { + NBTTagCompound itemStackData; + if (item.hasTagCompound()) + itemStackData = item.getTagCompound(); + else + { + itemStackData = new NBTTagCompound(); + item.setTagCompound(itemStackData); + } + NBTTagCompound coords = new NBTTagCompound(); + coords.setInteger("blockX", x); + coords.setInteger("blockY", y); + coords.setInteger("blockZ", z); + itemStackData.setTag("blockX", coords); + itemStackData.setTag("blockY", coords); + itemStackData.setTag("blockZ", coords); + } + public static void addCoordonatesAndDimension(ItemStack item, double x, double y, double z, int dim, String name) { NBTTagCompound itemStackData; @@ -139,6 +159,13 @@ public class JewelryNBT } itemStackData.removeTag(tag); } + + public static void removeEntity(ItemStack item) + { + JewelryNBT.removeNBT(item, "entityID"); + JewelryNBT.removeNBT(item, "entity"); + JewelryNBT.removeNBT(item, "ench"); + } public static void addEnchantment(ItemStack item) { @@ -153,4 +180,178 @@ public class JewelryNBT itemStackData.setTag("ench", new NBTTagList("ench")); } + public static ItemStack jewel(ItemStack stack) + { + if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("jewel")) + { + NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel"); + ItemStack jewel = new ItemStack(0, 0, 0); + jewel.readFromNBT(jewelNBT); + return jewel; + } + return null; + } + + public static boolean isJewelX(ItemStack stack, ItemStack jewel) + { + if(jewel(stack) != null && jewel(stack).itemID == jewel.itemID && jewel(stack).getItemDamage() == jewel.getItemDamage()) return true; + return false; + } + + public static ItemStack modifier(ItemStack stack) + { + if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("modifier")) + { + NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier"); + ItemStack modifier = new ItemStack(0, 0, 0); + modifier.readFromNBT(modifierNBT); + return modifier; + } + return null; + } + + public static boolean isModifierX(ItemStack stack, ItemStack modifier) + { + if(modifier(stack) != null && modifier(stack).itemID == modifier.itemID && modifier(stack).getItemDamage() == modifier.getItemDamage()) return true; + return false; + } + + public static ItemStack ingot(ItemStack stack) + { + if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("ingot")) + { + NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot"); + ItemStack ingot = new ItemStack(0, 0, 0); + ingot.readFromNBT(ingotNBT); + return ingot; + } + return null; + } + + public static boolean isIngotX(ItemStack stack, ItemStack ingot) + { + if(ingot(stack) != null && ingot(stack).itemID == ingot.itemID && ingot(stack).getItemDamage() == ingot.getItemDamage()) return true; + return false; + } + + public static EntityLivingBase entity(ItemStack stack, EntityPlayer player) + { + 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); + return entity; + } + return null; + } + + public static boolean isEntityX(ItemStack stack, EntityPlayer player, EntityLivingBase entity) + { + if(entity(stack, player) != null && entity(stack, player).equals(entity)) return true; + return false; + } + + public static String dimName(ItemStack stack) + { + if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("dimName")) + { + NBTTagCompound dim = (NBTTagCompound) stack.getTagCompound().getTag("dimName"); + String name = dim.getString("dimName"); + return name; + } + return null; + } + + public static boolean isDimNameX(ItemStack stack, String dimName) + { + if(ingot(stack) != null && dimName(stack).equals(dimName)) return true; + return false; + } + + public static int dimension(ItemStack stack) + { + if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("dimension")) + { + NBTTagCompound dim = (NBTTagCompound) stack.getTagCompound().getTag("dimension"); + int dimension = dim.getInteger("dimension"); + return dimension; + } + return -2; + } + + public static boolean isDimensionX(ItemStack stack, int dimension) + { + if(dimension(stack) != -2 && dimension(stack) == dimension) return true; + return false; + } + + public static int blockCoordX(ItemStack stack) + { + if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("blockX")) + { + NBTTagCompound x = (NBTTagCompound) stack.getTagCompound().getTag("blockX"); + int posX = x.getInteger("blockX"); + return posX; + } + return -1; + } + + public static int blockCoordY(ItemStack stack) + { + if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("blockY")) + { + NBTTagCompound y = (NBTTagCompound) stack.getTagCompound().getTag("blockY"); + int posY = y.getInteger("blockY"); + return posY; + } + return -1; + } + + public static int blockCoordZ(ItemStack stack) + { + if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("blockZ")) + { + NBTTagCompound z = (NBTTagCompound) stack.getTagCompound().getTag("blockZ"); + int posZ = z.getInteger("blockZ"); + return posZ; + } + return -1; + } + + public static double playerPosX(ItemStack stack) + { + if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("x")) + { + NBTTagCompound x = (NBTTagCompound) stack.getTagCompound().getTag("x"); + double posX = x.getDouble("x"); + return posX; + } + return -1; + } + + public static double playerPosY(ItemStack stack) + { + if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("y")) + { + NBTTagCompound y = (NBTTagCompound) stack.getTagCompound().getTag("y"); + double posY = y.getDouble("y"); + return posY; + } + return -1; + } + + public static double playerPosZ(ItemStack stack) + { + if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("z")) + { + NBTTagCompound z = (NBTTagCompound) stack.getTagCompound().getTag("z"); + double posZ = z.getDouble("z"); + return posZ; + } + return -1; + } } diff --git a/common/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/common/darkknight/jewelrycraft/util/JewelrycraftUtil.java new file mode 100644 index 0000000..255d4f5 --- /dev/null +++ b/common/darkknight/jewelrycraft/util/JewelrycraftUtil.java @@ -0,0 +1,111 @@ +package darkknight.jewelrycraft.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import darkknight.jewelrycraft.item.ItemList; + +public class JewelrycraftUtil +{ + public static ArrayList modifiers = new ArrayList(); + public static ArrayList jewel = new ArrayList(); + public static ArrayList jewelry = new ArrayList(); + public static ArrayList jamcraftPlayers = new ArrayList(); + public static HashMap combinations = new HashMap(); + + public static void addStuff() + { + //Modifiers + modifiers.add(new ItemStack(Item.blazePowder)); + modifiers.add(new ItemStack(Item.sugar)); + modifiers.add(new ItemStack(Block.chest)); + modifiers.add(new ItemStack(Item.pickaxeIron)); + modifiers.add(new ItemStack(Item.bed)); + modifiers.add(new ItemStack(Item.eyeOfEnder)); + + //Jewels + jewel.add(new ItemStack(Item.enderPearl)); + jewel.add(new ItemStack(Item.diamond)); + jewel.add(new ItemStack(Item.emerald)); + jewel.add(new ItemStack(Block.obsidian)); + jewel.add(new ItemStack(Item.netherStar)); + + //Jewelry + jewelry.add(new ItemStack(ItemList.ring)); + } + + public static void addSpecialCombinations() + { + combinations.put(new ItemStack(Item.enderPearl), new ItemStack(Block.chest)); + combinations.put(new ItemStack(Item.enderPearl), new ItemStack(Item.bed)); + combinations.put(new ItemStack(Block.obsidian), new ItemStack(Item.eyeOfEnder)); + combinations.put(new ItemStack(Item.netherStar), new ItemStack(Block.chest)); + //An ender pearl with any modifier that is not a chest or bed + combinations.put(new ItemStack(Item.enderPearl), new ItemStack(Item.itemsList.length, 0, 0)); + } + + public static void jamcrafters() + { + jamcraftPlayers.add("allout58"); + jamcraftPlayers.add("ChewBaker"); + jamcraftPlayers.add("domi1819"); + jamcraftPlayers.add("founderio"); + jamcraftPlayers.add("Ironhammer354"); + jamcraftPlayers.add("isomgirls6"); + jamcraftPlayers.add("jmjmjm439"); + jamcraftPlayers.add("Joban"); + jamcraftPlayers.add("KJ4IPS"); + jamcraftPlayers.add("Mitchellbrine"); + jamcraftPlayers.add("MrComputerGhost"); + jamcraftPlayers.add("MrKol999"); + jamcraftPlayers.add("Resinresin"); + jamcraftPlayers.add("sci4me"); + jamcraftPlayers.add("sor1n"); + jamcraftPlayers.add("theminecoder"); + jamcraftPlayers.add("YSPilot"); + jamcraftPlayers.add("direwolf20"); + } + + public static boolean isModifier(ItemStack item) + { + Iterator i = modifiers.iterator(); + + while (i.hasNext()) + { + ItemStack temp = i.next(); + if (temp.itemID == item.itemID && temp.getItemDamage() == item.getItemDamage()) + return true; + } + return false; + } + + public static boolean isJewel(ItemStack item) + { + Iterator i = jewel.iterator(); + + while (i.hasNext()) + { + ItemStack temp = i.next(); + if (temp.itemID == item.itemID && temp.getItemDamage() == item.getItemDamage()) + return true; + } + return false; + } + + public static boolean isJewelry(ItemStack item) + { + Iterator i = jewelry.iterator(); + + while (i.hasNext()) + { + ItemStack temp = i.next(); + if (temp.itemID == item.itemID && temp.getItemDamage() == item.getItemDamage()) + return true; + } + return false; + } +} -- cgit v1.2.3