summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/util
diff options
context:
space:
mode:
authorOnyxDarkKnight <sor1n.iliutza16@gmail.com>2014-04-15 23:05:32 +0300
committerOnyxDarkKnight <sor1n.iliutza16@gmail.com>2014-04-15 23:05:32 +0300
commit256653501365eb4f95d3dddbcdfdc23a2a9594d5 (patch)
tree682c8ff1f943936d173299acfa42e77462eb297c /src/main/java/darkknight/jewelrycraft/util
parent4b8b13b34d7a8fd0ee7c7b13f11be9c2bf3b5d18 (diff)
Moved source files
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/util')
-rw-r--r--src/main/java/darkknight/jewelrycraft/util/BlockUtils.java122
-rw-r--r--src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java626
-rw-r--r--src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java139
-rw-r--r--src/main/java/darkknight/jewelrycraft/util/PlayerUtils.java57
4 files changed, 944 insertions, 0 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/util/BlockUtils.java b/src/main/java/darkknight/jewelrycraft/util/BlockUtils.java
new file mode 100644
index 0000000..a5f7684
--- /dev/null
+++ b/src/main/java/darkknight/jewelrycraft/util/BlockUtils.java
@@ -0,0 +1,122 @@
+package darkknight.jewelrycraft.util;
+
+
+import net.minecraft.entity.EntityLivingBase;
+import net.minecraft.entity.item.EntityItem;
+import net.minecraft.inventory.IInventory;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.util.MathHelper;
+import net.minecraft.util.MovingObjectPosition;
+import net.minecraft.world.World;
+import net.minecraftforge.common.util.ForgeDirection;
+
+public class BlockUtils
+{
+
+ public static final ForgeDirection DEFAULT_BLOCK_DIRECTION = ForgeDirection.WEST;
+
+ public static ForgeDirection get2dOrientation(EntityLivingBase entity)
+ {
+ int l = MathHelper.floor_double(entity.rotationYaw * 4.0F / 360.0F + 0.5D) & 0x3;
+ switch (l) {
+ case 0:
+ return ForgeDirection.SOUTH;
+ case 1:
+ return ForgeDirection.WEST;
+ case 2:
+ return ForgeDirection.NORTH;
+ case 3:
+ return ForgeDirection.EAST;
+ }
+ return ForgeDirection.SOUTH;
+
+ }
+
+ public static float getRotationFromDirection(ForgeDirection direction) {
+ switch (direction) {
+ case NORTH:
+ return 0F;
+ case SOUTH:
+ return 180F;
+ case WEST:
+ return 90F;
+ case EAST:
+ return -90F;
+ case DOWN:
+ return -90f;
+ case UP:
+ return 90f;
+ default:
+ return 0f;
+ }
+ }
+
+ public static ForgeDirection get3dOrientation(EntityLivingBase entity) {
+ if (entity.rotationPitch > 45.5F) {
+ return ForgeDirection.DOWN;
+ } else if (entity.rotationPitch < -45.5F) { return ForgeDirection.UP; }
+ return get2dOrientation(entity);
+ }
+
+ public static EntityItem dropItemStackInWorld(World worldObj, double x, double y, double z, ItemStack stack) {
+ float f = 0.7F;
+ float d0 = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5F;
+ float d1 = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5F;
+ float d2 = worldObj.rand.nextFloat() * f + (1.0F - f) * 0.5F;
+ EntityItem entityitem = new EntityItem(worldObj, x + d0, y + d1, z + d2, stack);
+ entityitem.delayBeforeCanPickup = 10;
+ if (stack.hasTagCompound()) {
+ entityitem.getEntityItem().setTagCompound((NBTTagCompound)stack.getTagCompound().copy());
+ }
+ worldObj.spawnEntityInWorld(entityitem);
+ return entityitem;
+ }
+
+ public static EntityItem ejectItemInDirection(World world, double x, double y, double z, ForgeDirection direction, ItemStack stack) {
+ EntityItem item = BlockUtils.dropItemStackInWorld(world, x, y, z, stack);
+ item.motionX = direction.offsetX / 5F;
+ item.motionY = direction.offsetY / 5F;
+ item.motionZ = direction.offsetZ / 5F;
+ return item;
+ }
+
+ public static void dropInventory(IInventory inventory, World world, double x, double y, double z) {
+ if (inventory == null) { return; }
+ for (int i = 0; i < inventory.getSizeInventory(); ++i) {
+ ItemStack itemStack = inventory.getStackInSlot(i);
+ if (itemStack != null) {
+ dropItemStackInWorld(world, x, y, z, itemStack);
+ }
+ }
+ }
+
+ public static void dropInventory(IInventory inventory, World world, int x, int y, int z) {
+ dropInventory(inventory, world, x + 0.5, y + 0.5, z + 0.5);
+ }
+
+ public static TileEntity getTileInDirection(TileEntity tile, ForgeDirection direction) {
+ int targetX = tile.xCoord + direction.offsetX;
+ int targetY = tile.yCoord + direction.offsetY;
+ int targetZ = tile.zCoord + direction.offsetZ;
+ return tile.getWorldObj().getTileEntity(targetX, targetY, targetZ);
+ }
+
+ public static int getFirstNonAirBlockFromTop(World world, int x, int z) {
+ int y;
+ for (y = world.getActualHeight(); world.isAirBlock(x, y - 1, z) && y > 0; y--) {}
+ return y;
+ }
+
+ public static boolean isBlockHit(MovingObjectPosition mop, TileEntity tile) {
+ if (tile == null) return false;
+ return isBlockHit(mop, tile.xCoord, tile.yCoord, tile.zCoord);
+ }
+
+ public static boolean isBlockHit(MovingObjectPosition mop, int x, int y, int z) {
+ if (mop == null) return false;
+ return mop.blockX == x && mop.blockY == y && mop.blockZ == z;
+ }
+
+} \ No newline at end of file
diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java
new file mode 100644
index 0000000..d76c84e
--- /dev/null
+++ b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java
@@ -0,0 +1,626 @@
+package darkknight.jewelrycraft.util;
+
+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.init.Blocks;
+import net.minecraft.init.Items;
+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
+{
+ //TODO NBT Tag Adding
+ /**
+ *
+ * @param item The item you want to add the NBT data on
+ * @param metal The metal you want to add on the item
+ */
+ 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);
+ }
+
+ /**
+ *
+ * @param item The item you want to add the NBT data on
+ * @param jewel The jewel you want to add on the item
+ */
+ public static void addJewel(ItemStack item, ItemStack jewel)
+ {
+ if(jewel != null)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound jewelNBT = new NBTTagCompound();
+ jewel.writeToNBT(jewelNBT);
+ itemStackData.setTag("jewel", jewelNBT);
+ }
+ }
+
+ /**
+ *
+ * @param item The item you want to add the NBT data on
+ * @param modifier The modifier you want to add on the item
+ */
+ public static void addModifier(ItemStack item, ItemStack modifier)
+ {
+ if(modifier != null)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound modifierNBT = new NBTTagCompound();
+ modifier.writeToNBT(modifierNBT);
+ itemStackData.setTag("modifier", modifierNBT);
+ }
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+ 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;
+ 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);
+ }
+
+ public static void addMode(ItemStack item, String modeN)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound mode = new NBTTagCompound();
+ mode.setString("mode", modeN);
+ itemStackData.setTag("mode", mode);
+ }
+
+ 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());
+ }
+
+ public static void addIngotColor(ItemStack item, int color)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound colors = new NBTTagCompound();
+ colors.setInteger("ingotColor", color);
+ itemStackData.setTag("ingotColor", colors);
+ }
+
+ public static void addJewelColor(ItemStack item, int color)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound colors = new NBTTagCompound();
+ colors.setInteger("jewelColor", color);
+ itemStackData.setTag("jewelColor", colors);
+ }
+
+ @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
+ 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);
+ }
+
+ public static void removeEntity(ItemStack item)
+ {
+ JewelryNBT.removeNBT(item, "entityID");
+ JewelryNBT.removeNBT(item, "entity");
+ JewelryNBT.removeNBT(item, "ench");
+ }
+
+ 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");
+ }
+
+ //TODO NTB Tag Checking
+ public static boolean hasTag(ItemStack item, String tag)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ if(itemStackData.hasKey(tag)) return true;
+ return false;
+ }
+
+ public static boolean isJewelX(ItemStack stack, ItemStack jewel)
+ {
+ if(jewel(stack) != null && jewel(stack).getItem() == jewel.getItem() && jewel(stack).getItemDamage() == jewel.getItemDamage()) return true;
+ return false;
+ }
+
+ public static boolean isModifierX(ItemStack stack, ItemStack modifier)
+ {
+ if(modifier(stack) != null && modifier(stack).getItem() == modifier.getItem() && modifier(stack).getItemDamage() == modifier.getItemDamage()) return true;
+ return false;
+ }
+
+ public static boolean isModifierEffectType(ItemStack stack)
+ {
+ if(modifier(stack) != null && (isModifierX(stack, new ItemStack(Items.blaze_powder)) || isModifierX(stack, new ItemStack(Items.sugar))
+ || isModifierX(stack, new ItemStack(Items.iron_pickaxe)) || isModifierX(stack, new ItemStack(Items.feather))
+ || isModifierX(stack, new ItemStack(Items.potionitem, 1, 8270)))) return true;
+ return false;
+ }
+
+ public static boolean isIngotX(ItemStack stack, ItemStack ingot)
+ {
+ if(ingot(stack) != null && ingot(stack).getItem() == ingot.getItem() && ingot(stack).getItemDamage() == ingot.getItemDamage()) return true;
+ return false;
+ }
+
+ public static boolean isModeX(ItemStack stack, String modeN)
+ {
+ if(modeName(stack) != null && modeName(stack).equals(modeN)) return true;
+ return false;
+ }
+
+ 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;
+ }
+
+ public static boolean isDimNameX(ItemStack stack, String dimName)
+ {
+ if(ingot(stack) != null && dimName(stack).equals(dimName)) return true;
+ return false;
+ }
+
+ 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 jewel(ItemStack stack)
+ {
+ if(stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("jewel"))
+ {
+ NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("jewel");
+ ItemStack jewel = new ItemStack(Item.getItemById(0), 0, 0);
+ jewel.readFromNBT(jewelNBT);
+ return jewel;
+ }
+ return null;
+ }
+
+ public static ItemStack modifier(ItemStack stack)
+ {
+ if(stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("modifier"))
+ {
+ NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier");
+ ItemStack modifier = new ItemStack(Item.getItemById(0), 0, 0);
+ modifier.readFromNBT(modifierNBT);
+ return modifier;
+ }
+ return null;
+ }
+
+ public static ItemStack ingot(ItemStack stack)
+ {
+ if(stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("ingot"))
+ {
+ NBTTagCompound ingotNBT = (NBTTagCompound) stack.getTagCompound().getTag("ingot");
+ ItemStack ingot = new ItemStack(Item.getItemById(0), 0, 0);
+ ingot.readFromNBT(ingotNBT);
+ return ingot;
+ }
+ return null;
+ }
+
+ 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;
+ }
+
+ 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) TileEntity.createAndLoadEntity(tileNBT);
+ if(tile != null && tile instanceof TileEntity)
+ {
+ tile.readFromNBT(tileNBT);
+ return tile;
+ }
+ else return null;
+ }
+ return null;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+ return 16777215;
+ }
+
+ public static int jewelColor(ItemStack stack)
+ {
+ if(stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("jewelColor"))
+ {
+ NBTTagCompound colors = (NBTTagCompound) stack.getTagCompound().getTag("jewelColor");
+ int color = colors.getInteger("jewelColor");
+ return color;
+ }
+ return 16777215;
+ }
+
+ @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 i = 0; i < entityID.length; i++){
+ entity = (EntityLivingBase) EntityList.createEntityByID(entityID[i], player.worldObj);
+ list.add(entity);
+ }
+ return list;
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java
new file mode 100644
index 0000000..271f6f9
--- /dev/null
+++ b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java
@@ -0,0 +1,139 @@
+package darkknight.jewelrycraft.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Random;
+
+import net.minecraft.init.Blocks;
+import net.minecraft.init.Items;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.oredict.OreDictionary;
+import darkknight.jewelrycraft.item.ItemList;
+
+public class JewelrycraftUtil
+{
+ public static ArrayList<ItemStack> modifiers = new ArrayList<ItemStack>();
+ public static ArrayList<ItemStack> jewel = new ArrayList<ItemStack>();
+ public static ArrayList<ItemStack> jewelry = new ArrayList<ItemStack>();
+ public static ArrayList<ItemStack> metal = new ArrayList<ItemStack>();
+ public static ArrayList<String> jamcraftPlayers = new ArrayList<String>();
+ public static HashMap<String,Item> liquids = new HashMap<String,Item>();
+ public static Random rand = new Random();
+
+ public static void addStuff()
+ {
+ //Modifiers
+ modifiers.add(new ItemStack(Blocks.chest));
+ modifiers.add(new ItemStack(Blocks.torch));
+ modifiers.add(new ItemStack(Items.book));
+ modifiers.add(new ItemStack(Items.dye, 1, 15));
+ modifiers.add(new ItemStack(Items.bone));
+ modifiers.add(new ItemStack(Items.sugar));
+ modifiers.add(new ItemStack(Items.feather));
+ modifiers.add(new ItemStack(Items.bed));
+ modifiers.add(new ItemStack(Items.iron_pickaxe));
+ modifiers.add(new ItemStack(Items.redstone));
+ modifiers.add(new ItemStack(Items.diamond_pickaxe));
+ modifiers.add(new ItemStack(Items.blaze_powder));
+ modifiers.add(new ItemStack(Items.ender_eye));
+ modifiers.add(new ItemStack(Items.potionitem, 1, 8270));
+
+ //Jewels
+ for(int i=0; i < 16; i++)
+ jewel.add(new ItemStack(ItemList.crystal, 1, i));
+ jewel.add(new ItemStack(Blocks.redstone_block));
+ jewel.add(new ItemStack(Blocks.lapis_block));
+ jewel.add(new ItemStack(Blocks.obsidian));
+ jewel.add(new ItemStack(Items.diamond));
+ jewel.add(new ItemStack(Items.emerald));
+ jewel.add(new ItemStack(Items.ender_pearl));
+ jewel.add(new ItemStack(Items.nether_star));
+
+ //Jewelry
+ jewelry.add(new ItemStack(ItemList.ring));
+ jewelry.add(new ItemStack(ItemList.necklace));
+ }
+
+ 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 void addMetals()
+ {
+ int index = 0, index2 = 0;
+ while(index < OreDictionary.getOreNames().length)
+ {
+ while(index2 < OreDictionary.getOres(OreDictionary.getOreNames()[index]).size())
+ {
+ ItemStack stack = OreDictionary.getOres(OreDictionary.getOreNames()[index]).get(index2).copy();
+ if(stack.getItemDamage() == Short.MAX_VALUE) stack.setItemDamage(0);
+ if(stack.getUnlocalizedName().toLowerCase().contains("ingot") && !JewelrycraftUtil.metal.contains(stack))
+ metal.add(OreDictionary.getOres(OreDictionary.getOreNames()[index]).get(index2));
+ index2++;
+ }
+ index2 = 0;
+ index++;
+ }
+ if(!metal.contains(new ItemStack(Items.gold_ingot)))metal.add(new ItemStack(Items.gold_ingot));
+ if(!metal.contains(new ItemStack(Items.iron_ingot)))metal.add(new ItemStack(Items.iron_ingot));
+ }
+
+ public static boolean isModifier(ItemStack item)
+ {
+ Iterator<ItemStack> i = modifiers.iterator();
+
+ while (i.hasNext())
+ {
+ ItemStack temp = i.next();
+ if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage())
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isJewel(ItemStack item)
+ {
+ Iterator<ItemStack> i = jewel.iterator();
+
+ while (i.hasNext())
+ {
+ ItemStack temp = i.next();
+ if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage())
+ return true;
+ }
+ return false;
+ }
+
+ public static boolean isJewelry(ItemStack item)
+ {
+ Iterator<ItemStack> i = jewelry.iterator();
+
+ while (i.hasNext())
+ {
+ ItemStack temp = i.next();
+ if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage())
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/src/main/java/darkknight/jewelrycraft/util/PlayerUtils.java b/src/main/java/darkknight/jewelrycraft/util/PlayerUtils.java
new file mode 100644
index 0000000..aa6a12b
--- /dev/null
+++ b/src/main/java/darkknight/jewelrycraft/util/PlayerUtils.java
@@ -0,0 +1,57 @@
+package darkknight.jewelrycraft.util;
+
+import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.integrated.IntegratedServer;
+import cpw.mods.fml.common.FMLCommonHandler;
+
+/**
+ * Code taken from OpenBlocks
+ */
+public class PlayerUtils
+{
+ public static boolean isPlayerOp(String username)
+ {
+ username = username.toLowerCase();
+
+ MinecraftServer server = FMLCommonHandler.instance().getSidedDelegate().getServer();
+
+ // SP and LAN
+ if (server.isSinglePlayer()) {
+ if (server instanceof IntegratedServer) return server.getServerOwner().equals(username);
+ return server.getConfigurationManager().getOps().contains(username);
+ }
+
+ // SMP
+ return server.getConfigurationManager().getOps().contains(username);
+ }
+
+ public static NBTTagCompound getModPlayerPersistTag(EntityPlayer player, String modName)
+ {
+
+ NBTTagCompound tag = player.getEntityData();
+
+ NBTTagCompound persistTag = null;
+ if (tag.hasKey(EntityPlayer.PERSISTED_NBT_TAG))
+ {
+ persistTag = tag.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
+ } else
+ {
+ persistTag = new NBTTagCompound();
+ tag.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistTag);
+ }
+
+ NBTTagCompound modTag = null;
+ if (persistTag.hasKey(modName))
+ {
+ modTag = persistTag.getCompoundTag(modName);
+ } else
+ {
+ modTag = new NBTTagCompound();
+ persistTag.setTag(modName, modTag);
+ }
+
+ return modTag;
+ }
+} \ No newline at end of file