From 01c8701b68986ccfa83e902515716838d6829311 Mon Sep 17 00:00:00 2001 From: Onyx Date: Tue, 1 Dec 2015 20:55:30 +0000 Subject: - Fixed all of the bugs mentioned on github - Added new config options - Rabbits paw now increases the chance of spawning hearts, rather than itself spawning some - Hearts now have a much lower chance to spawn by default - You can no longer increase your health past 20 hearts (aka double the default health) - The guide now also shows the total number of pages on each tab - A new luck stat has been added to the Curse API - Cleaned up the code a bit (removed unused methods, imports etc) - The displayer's info now has a purple solid color background; the text also has a much closer shadow and now shrinks in height as well as in width when too big - I have modified the potion list to use Mithion's code, credits have been given --- .../darkknight/jewelrycraft/util/JewelryNBT.java | 516 +-------------------- 1 file changed, 9 insertions(+), 507 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 1944510..52d965c 100644 --- a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java @@ -1,17 +1,10 @@ package darkknight.jewelrycraft.util; import java.util.ArrayList; -import java.util.List; -import net.minecraft.block.Block; -import net.minecraft.entity.EntityList; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.entity.player.EntityPlayer; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; public class JewelryNBT { @@ -90,182 +83,7 @@ public class JewelryNBT itemStackData.setInteger("modifierSize", modifier.size()); } } - - /** - * @param item The item you want to add the NBT data on - * @param entity The entity to add on the item - */ - public static void addEntity(ItemStack item, EntityLivingBase entity) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound entityNBT = new NBTTagCompound(); - entity.writeToNBT(entityNBT); - itemStackData.setTag("entity", entityNBT); - } - - /** - * @param item - * @param entity - */ - public static void addEntityID(ItemStack item, EntityLivingBase entity) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound entityNBT = new NBTTagCompound(); - int id = EntityList.getEntityID(entity); - entityNBT.setInteger("entityID", id); - itemStackData.setTag("entityID", entityNBT); - } - - /** - * @param item - * @param x - * @param y - * @param z - */ - public static void addCoordonates(ItemStack item, double x, double y, double z) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound coords = new NBTTagCompound(); - coords.setDouble("x", x); - coords.setDouble("y", y); - coords.setDouble("z", z); - itemStackData.setTag("x", coords); - itemStackData.setTag("y", coords); - itemStackData.setTag("z", coords); - } - - /** - * @param item - * @param world - * @param x - * @param y - * @param z - */ - public static void addTileEntityBlock(ItemStack item, World world, int x, int y, int z) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound tileNBT = new NBTTagCompound(); - NBTTagCompound block = new NBTTagCompound(); - world.getTileEntity(x, y, z).writeToNBT(tileNBT); - itemStackData.setTag("tile", tileNBT); - block.setInteger("blockID", Block.getIdFromBlock(world.getBlock(x, y, z))); - block.setInteger("metadata", world.getBlockMetadata(x, y, z)); - block.setInteger("blockX", x); - block.setInteger("blockY", y); - block.setInteger("blockZ", z); - itemStackData.setTag("metadata", block); - itemStackData.setTag("blockID", block); - itemStackData.setTag("blockX", block); - itemStackData.setTag("blockY", block); - itemStackData.setTag("blockZ", block); - } - - /** - * @param item - * @param block - * @param metadata - */ - public static void addBlock(ItemStack item, int block, int metadata) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound blockNBT = new NBTTagCompound(); - blockNBT.setInteger("blockID", block); - itemStackData.setTag("blockID", blockNBT); - blockNBT.setInteger("metadata", metadata); - itemStackData.setTag("metadata", blockNBT); - } - - /** - * @param item - * @param x - * @param y - * @param z - */ - 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); - } - - /** - * @param item - * @param x - * @param y - * @param z - * @param dim - * @param name - */ - public static void addCoordonatesAndDimension(ItemStack item, double x, double y, double z, int dim, String name) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound coords = new NBTTagCompound(); - coords.setDouble("x", x); - coords.setDouble("y", y); - coords.setDouble("z", z); - coords.setInteger("dimension", dim); - coords.setString("dimName", name); - itemStackData.setTag("x", coords); - itemStackData.setTag("y", coords); - itemStackData.setTag("z", coords); - itemStackData.setTag("dimension", coords); - itemStackData.setTag("dimName", coords); - } - - /** - * @param item - */ - public static void addFakeEnchantment(ItemStack item) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - itemStackData.setTag("ench", new NBTTagList()); - } - + /** * @param item * @param color @@ -278,9 +96,7 @@ public class JewelryNBT itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } - NBTTagCompound colors = new NBTTagCompound(); - colors.setInteger("ingotColor", color); - itemStackData.setTag("ingotColor", colors); + itemStackData.setInteger("ingotColor", color); } // TODO @@ -296,67 +112,7 @@ public class JewelryNBT itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } - NBTTagCompound colors = new NBTTagCompound(); - colors.setInteger("gemColor", color); - itemStackData.setTag("gemColor", colors); - } - - /** - * @param item - * @param list - */ - @SuppressWarnings ("rawtypes") - public static void addEntities(ItemStack item, List list) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound entityNBT = new NBTTagCompound(); - for(int i = 0; i < list.size(); i++) - ((EntityLivingBase)list.get(i)).writeToNBT(entityNBT); - itemStackData.setTag("entities", entityNBT); - } - - // TODO NBT Tag Removing - /** - * @param item - * @param tag - */ - public static void removeNBT(ItemStack item, String tag) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - itemStackData.removeTag(tag); - } - - /** - * @param item - */ - public static void removeEntity(ItemStack item) - { - JewelryNBT.removeNBT(item, "entityID"); - JewelryNBT.removeNBT(item, "entity"); - JewelryNBT.removeNBT(item, "ench"); - } - - /** - * @param item - */ - public static void removeBlock(ItemStack item) - { - JewelryNBT.removeNBT(item, "blockID"); - JewelryNBT.removeNBT(item, "metadata"); - JewelryNBT.removeNBT(item, "tile"); - JewelryNBT.removeNBT(item, "blockX"); - JewelryNBT.removeNBT(item, "blockY"); - JewelryNBT.removeNBT(item, "blockZ"); + itemStackData.setInteger("gemColor", color); } // TODO NTB Tag Checking @@ -417,7 +173,7 @@ public class JewelryNBT { if (modifier(stack) != null) return modifier(stack).size(); return -1; - } + } /** * @param stack @@ -430,40 +186,6 @@ public class JewelryNBT return false; } - /** - * @param stack - * @param player - * @param entity - * @return - */ - public static boolean isEntityX(ItemStack stack, EntityPlayer player, EntityLivingBase entity) - { - if (entity != null && entity instanceof EntityLivingBase && entity(stack, player) != null && entity(stack, player).equals(entity)) return true; - return false; - } - - /** - * @param stack - * @param dimName - * @return - */ - public static boolean isDimNameX(ItemStack stack, String dimName) - { - if (ingot(stack) != null && dimName(stack).equals(dimName)) return true; - return false; - } - - /** - * @param stack - * @param dimension - * @return - */ - public static boolean isDimensionX(ItemStack stack, int dimension) - { - if (dimension(stack) != -2 && dimension(stack) == dimension) return true; - return false; - } - // TODO Return components based on NBT public static ItemStack item(ItemStack stack) { @@ -526,209 +248,14 @@ public class JewelryNBT return null; } - /** - * @param stack - * @param player - * @return - */ - public static EntityLivingBase entity(ItemStack stack, EntityPlayer player) - { - if (stack != null && stack != new ItemStack(Item.getItemById(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); - if (entity != null && entity instanceof EntityLivingBase){ - entity.readFromNBT(en); - return entity; - }else return null; - } - return null; - } - - /** - * @param stack - * @return - */ - public static TileEntity tileEntity(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("tile")){ - NBTTagCompound tileNBT = (NBTTagCompound)stack.getTagCompound().getTag("tile"); - TileEntity tile = TileEntity.createAndLoadEntity(tileNBT); - if (tile != null && tile instanceof TileEntity){ - tile.readFromNBT(tileNBT); - return tile; - }else return null; - } - return null; - } - - /** - * @param stack - * @return - */ - public static String dimName(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(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; - } - - /** - * @param stack - * @return - */ - public static String modeName(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("mode")){ - NBTTagCompound dim = (NBTTagCompound)stack.getTagCompound().getTag("mode"); - String name = dim.getString("mode"); - return name; - } - return null; - } - - /** - * @param stack - * @return - */ - public static int dimension(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(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; - } - - /** - * @param stack - * @return - */ - public static int blockCoordX(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockX")){ - NBTTagCompound x = (NBTTagCompound)stack.getTagCompound().getTag("blockX"); - int posX = x.getInteger("blockX"); - return posX; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static int blockCoordY(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockY")){ - NBTTagCompound y = (NBTTagCompound)stack.getTagCompound().getTag("blockY"); - int posY = y.getInteger("blockY"); - return posY; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static int blockCoordZ(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockZ")){ - NBTTagCompound z = (NBTTagCompound)stack.getTagCompound().getTag("blockZ"); - int posZ = z.getInteger("blockZ"); - return posZ; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static int blockID(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockID")){ - NBTTagCompound blockID = (NBTTagCompound)stack.getTagCompound().getTag("blockID"); - int blockId = blockID.getInteger("blockID"); - return blockId; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static int blockMetadata(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("metadata")){ - NBTTagCompound metadataNBT = (NBTTagCompound)stack.getTagCompound().getTag("metadata"); - int metadata = metadataNBT.getInteger("metadata"); - return metadata; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static double playerPosX(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("x")){ - NBTTagCompound x = (NBTTagCompound)stack.getTagCompound().getTag("x"); - double posX = x.getDouble("x"); - return posX; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static double playerPosY(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("y")){ - NBTTagCompound y = (NBTTagCompound)stack.getTagCompound().getTag("y"); - double posY = y.getDouble("y"); - return posY; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static double playerPosZ(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("z")){ - NBTTagCompound z = (NBTTagCompound)stack.getTagCompound().getTag("z"); - double posZ = z.getDouble("z"); - return posZ; - } - return -1; - } - /** * @param stack * @return */ public static int ingotColor(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("ingotColor")){ - NBTTagCompound colors = (NBTTagCompound)stack.getTagCompound().getTag("ingotColor"); - int color = colors.getInteger("ingotColor"); - return color; - } + if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("ingotColor")) + return stack.getTagCompound().getInteger("ingotColor"); return 16777215; } @@ -739,34 +266,9 @@ public class JewelryNBT */ public static int gemColor(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("gemColor")){ - NBTTagCompound colors = (NBTTagCompound)stack.getTagCompound().getTag("gemColor"); - int color = colors.getInteger("gemColor"); - return color; - } + if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("gemColor")) + return stack.getTagCompound().getInteger("gemColor"); return 16777215; } - /** - * @param stack - * @param player - * @return - */ - @SuppressWarnings ({"rawtypes", "unchecked", "null"}) - public static List entities(ItemStack stack, EntityPlayer player) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("entities")){ - NBTTagCompound enID = (NBTTagCompound)stack.getTagCompound().getTag("entitiesID"); - List list = null; - int[] entityID; - EntityLivingBase entity; - entityID = enID.getIntArray("entitiesID"); - for(int element: entityID){ - entity = (EntityLivingBase)EntityList.createEntityByID(element, player.worldObj); - list.add(entity); - } - return list; - } - return null; - } } -- cgit v1.2.3