summaryrefslogtreecommitdiff
path: root/src/main/java/darkknight/jewelrycraft/util
diff options
context:
space:
mode:
authorOnyx <sor1n.iliutza16@gmail.com>2015-12-01 20:55:30 +0000
committerOnyx <sor1n.iliutza16@gmail.com>2015-12-01 20:55:30 +0000
commit01c8701b68986ccfa83e902515716838d6829311 (patch)
treeb21aa78f4df6ca9bac90e2726221114a41f2294a /src/main/java/darkknight/jewelrycraft/util
parent35da479288f75d6686c64a00e1dc77e7e7fd50e1 (diff)
- 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
Diffstat (limited to 'src/main/java/darkknight/jewelrycraft/util')
-rw-r--r--src/main/java/darkknight/jewelrycraft/util/BlockUtils.java306
-rw-r--r--src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java516
-rw-r--r--src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java703
3 files changed, 533 insertions, 992 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/util/BlockUtils.java b/src/main/java/darkknight/jewelrycraft/util/BlockUtils.java
index 18cb9eb..a33fd5e 100644
--- a/src/main/java/darkknight/jewelrycraft/util/BlockUtils.java
+++ b/src/main/java/darkknight/jewelrycraft/util/BlockUtils.java
@@ -1,155 +1,153 @@
-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;
-
- /**
- * This method is used to get the direction an entity is facing (NORTH, SOUTH, EAST or WEST) based on the entity's rotationYaw.
- *
- * @param entity the living entity
- * @return a direction
- */
- 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;
- }
-
- /**
- * This gets a float value depending on a direction
- *
- * @param direction the forge direction
- * @return value depending on direction
- */
- 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;
- }
- }
-
- /**
- * This method is used to get the direction an entity is looking at (UP or DOWN) based on the entitiy's rotationPitch
- *
- * @param entity the living entity
- * @return a forge direction
- */
- 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);
- }
-
- /**
- * This spawns the item specified and returns the EntityItem it created
- *
- * @param worldObj the world
- * @param x position of the item to drop on the X axis
- * @param y position of the item to drop on the Y axis
- * @param z position of the item to drop on the Z axis
- * @param stack the item to spawn
- * @return the EntityItem of the stack
- */
- 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;
- }
-
- /**
- * It spawns the item with momentum in a certain direction
- *
- * @param world the world to spawn the item
- * @param x the X coordinate to spawn it in
- * @param y the Y coordinate to spawn it in
- * @param z the Z coordinate to spawn it in
- * @param direction the direction towards which it should eject
- * @param stack the item to spawn
- * @return the spawned 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;
- }
-
- /**
- * Drops the content of an inventory with doubles as coordinates
- *
- * @param inventory the inventory the items are contained in
- * @param world the world in which to spawn
- * @param x the X coordinate to spawn it in
- * @param y the Y coordinate to spawn it in
- * @param z the Z coordinate to spawn it in
- */
- 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);
- }
- }
-
- /**
- * Drops the content of an inventory with integer as coordinates
- *
- * @param inventory the inventory the items are contained in
- * @param world the world in which to spawn
- * @param x the X coordinate to spawn it in
- * @param y the Y coordinate to spawn it in
- * @param z the Z coordinate to spawn it in
- */
- 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);
- }
+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.util.MathHelper;
+import net.minecraft.world.World;
+import net.minecraftforge.common.util.ForgeDirection;
+
+public class BlockUtils
+{
+ public static final ForgeDirection DEFAULT_BLOCK_DIRECTION = ForgeDirection.WEST;
+
+ /**
+ * This method is used to get the direction an entity is facing (NORTH, SOUTH, EAST or WEST) based on the entity's rotationYaw.
+ *
+ * @param entity the living entity
+ * @return a direction
+ */
+ 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;
+ }
+
+ /**
+ * This gets a float value depending on a direction
+ *
+ * @param direction the forge direction
+ * @return value depending on direction
+ */
+ 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;
+ }
+ }
+
+ /**
+ * This method is used to get the direction an entity is looking at (UP or DOWN) based on the entitiy's rotationPitch
+ *
+ * @param entity the living entity
+ * @return a forge direction
+ */
+ 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);
+ }
+
+ /**
+ * This spawns the item specified and returns the EntityItem it created
+ *
+ * @param worldObj the world
+ * @param x position of the item to drop on the X axis
+ * @param y position of the item to drop on the Y axis
+ * @param z position of the item to drop on the Z axis
+ * @param stack the item to spawn
+ * @return the EntityItem of the stack
+ */
+ 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;
+ }
+
+ /**
+ * It spawns the item with momentum in a certain direction
+ *
+ * @param world the world to spawn the item
+ * @param x the X coordinate to spawn it in
+ * @param y the Y coordinate to spawn it in
+ * @param z the Z coordinate to spawn it in
+ * @param direction the direction towards which it should eject
+ * @param stack the item to spawn
+ * @return the spawned 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;
+ }
+
+ /**
+ * Drops the content of an inventory with doubles as coordinates
+ *
+ * @param inventory the inventory the items are contained in
+ * @param world the world in which to spawn
+ * @param x the X coordinate to spawn it in
+ * @param y the Y coordinate to spawn it in
+ * @param z the Z coordinate to spawn it in
+ */
+ 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);
+ }
+ }
+
+ /**
+ * Drops the content of an inventory with integer as coordinates
+ *
+ * @param inventory the inventory the items are contained in
+ * @param world the world in which to spawn
+ * @param x the X coordinate to spawn it in
+ * @param y the Y coordinate to spawn it in
+ * @param z the Z coordinate to spawn it in
+ */
+ 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);
+ }
} \ 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
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)
{
@@ -528,207 +250,12 @@ public class JewelryNBT
/**
* @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;
- }
}
diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java
index 818a526..4c9669e 100644
--- a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java
+++ b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java
@@ -36,7 +36,6 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
-import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
@@ -46,334 +45,376 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;
-public class JewelrycraftUtil {
- public static ArrayList<ItemStack> objects = new ArrayList<ItemStack>();
- public static ArrayList<ItemStack> gem = new ArrayList<ItemStack>();
- public static ArrayList<ItemStack> jewelry = new ArrayList<ItemStack>();
- public static ArrayList<ItemStack> metal = new ArrayList<ItemStack>();
- public static ArrayList<ItemStack> ores = new ArrayList<ItemStack>();
- public static HashMap<ItemStack, ItemStack> oreToIngot = new HashMap<ItemStack, ItemStack>();
- public static HashMap<ItemStack, Integer> colors = new HashMap<ItemStack, Integer>();
- public static ArrayList<String> jamcraftPlayers = new ArrayList<String>();
- private static ArrayList<ItemStack> items = new ArrayList<ItemStack>();
- public static ArrayList<WorldGenStructure> structures = new ArrayList<WorldGenStructure>();
- public static Random rand = new Random();
- public static EnumCreatureAttribute HEART;
-
- /**
- * Adds gems and jewelry to their appropriate list
- */
- public static void addStuff() {
- // Jewels
- for (int i = 0; i < 16; i++)
- gem.add(new ItemStack(BlockList.crystal, 1, i));
- gem.add(new ItemStack(Blocks.redstone_block));
- gem.add(new ItemStack(Blocks.lapis_block));
- gem.add(new ItemStack(Blocks.obsidian));
- gem.add(new ItemStack(Items.diamond));
- gem.add(new ItemStack(Items.emerald));
- gem.add(new ItemStack(Items.ender_pearl));
- gem.add(new ItemStack(Items.nether_star));
- // Jewelry
- jewelry.add(new ItemStack(ItemList.ring));
- jewelry.add(new ItemStack(ItemList.necklace));
- jewelry.add(new ItemStack(ItemList.bracelet));
- jewelry.add(new ItemStack(ItemList.earrings));
- for (Object item : GameData.getItemRegistry()) {
- if (Loader.isModLoaded("Mantle") && ((Item) item).getUnlocalizedName().equals("Mantle:item.mantle.manual")) continue;
- try {
- if (item != null && (Item) item != null && ((Item) item).getHasSubtypes() && FMLCommonHandler.instance().getSide() == Side.CLIENT) {
- ((Item) item).getSubItems((Item) item, null, items);
- }
- else objects.add(new ItemStack((Item) item));
- if (!items.isEmpty()) objects.addAll(items);
- items.removeAll(items);
- }
- catch (Exception e) {
- JewelrycraftMod.logger.info("Error, tried to add subtypes of item " + ((Item) item).getUnlocalizedName() + "\nItem is not added in the list.");
- }
- }
- // Structures
- try {
- for (Field f : Generation.class.getDeclaredFields()) {
- Object obj = f.get(null);
- if (obj instanceof WorldGenStructure) structures.add((WorldGenStructure) obj);
- }
- }
- catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- }
-
- @SideOnly(Side.CLIENT)
- public static void generateColors() {
- for (Object item : GameData.getItemRegistry()) {
- if (Loader.isModLoaded("Mantle") && ((Item) item).getUnlocalizedName().equals("Mantle:item.mantle.manual")) continue;
- try {
- if (item != null && (Item) item != null && ((Item) item).getHasSubtypes() && FMLCommonHandler.instance().getSide() == Side.CLIENT) {
- ((Item) item).getSubItems((Item) item, null, items);
- }
- else {
- ItemStack it = new ItemStack((Item) item);
- colors.put(it, color(it, 0));
- }
- if (!items.isEmpty()) for (ItemStack it : items)
- colors.put(it, color(it, 0));
- items.removeAll(items);
- }
- catch (Exception e) {
- JewelrycraftMod.logger.info("Error, tried to add the color of the item " + ((Item) item).getUnlocalizedName() + " but something went wrong.");
- }
- }
- }
-
- @SideOnly(Side.CLIENT)
- public static int getColor(ItemStack item) {
- for (ItemStack stack : colors.keySet())
- if (item != null && item.getItem() != null && stack.getItem() != null && item.getItem().equals(stack.getItem()) && item.getItemDamage() == stack.getItemDamage()) return colors.get(stack);
- return 0xFFFFFF;
- }
-
- @SideOnly(Side.CLIENT)
- public static int color(ItemStack stack, int pass) throws IOException {
- IResourceManager rm = Minecraft.getMinecraft().getResourceManager();
- ResourceLocation ingot;
- BufferedImage icon;
- if (stack != null && Item.getIdFromItem(stack.getItem()) > 0 && stack.getItem().getColorFromItemStack(stack, pass) == 16777215) {
- try {
- ingot = getLocation(stack);
- }
- catch (Exception e) {
- ingot = new ResourceLocation("textures/items/apple.png");
- }
- icon = ImageIO.read(rm.getResource(ingot).getInputStream());
- int height = icon.getHeight();
- int width = icon.getWidth();
- Map m = new HashMap();
- for (int i = 0; i < width; i++)
- for (int j = 0; j < height; j++) {
- int rgb = icon.getRGB(i, j);
- int red = rgb >> 16 & 0xff;
- int green = rgb >> 8 & 0xff;
- int blue = rgb & 0xff;
- int[] rgbArr = { red, green, blue };
- int Cmax = Math.max(red, Math.max(green, blue));
- int Cmin = Math.min(red, Math.min(green, blue));
- if (!isGray(rgbArr)) m.put(rgb, (Cmax + Cmin) / 2);
- }
- return getMostCommonColour(m);
- }
- else return stack.getItem().getColorFromItemStack(stack, pass);
- }
-
- public static ResourceLocation getLocation(ItemStack item) {
- String domain = "";
- String texture;
- IIcon itemIcon = item.getItem().getIcon(item, 0);
- if (!(Block.getBlockFromItem(item.getItem()) instanceof BlockAir) && !Block.getBlockFromItem(item.getItem()).getIcon(0, item.getItemDamage()).getIconName().equals("soul_sand")) itemIcon = Block.getBlockFromItem(item.getItem()).getIcon(0, item.getItemDamage());
- String iconName = itemIcon.getIconName();
- if (iconName.substring(0, iconName.indexOf(":") + 1) != "") domain = iconName.substring(0, iconName.indexOf(":") + 1).replace(":", " ").trim();
- else domain = "minecraft";
- texture = iconName.substring(iconName.lastIndexOf(":") + 1) + ".png";
- ResourceLocation textureLocation = null;
- TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
- if (texturemanager.getResourceLocation(item.getItemSpriteNumber()).toString().contains("items")) textureLocation = new ResourceLocation(domain.toLowerCase(), "textures/items/" + texture);
- else textureLocation = new ResourceLocation(domain.toLowerCase(), "textures/blocks/" + texture);
- return textureLocation;
- }
-
- @SideOnly(Side.CLIENT)
- public static int getMostCommonColour(Map map) {
- List list = new LinkedList(map.entrySet());
- Collections.sort(list, new Comparator() {
- public int compare(Object o1, Object o2) {
- return ((Comparable) ((Map.Entry) o1).getValue()).compareTo(((Map.Entry) o2).getValue());
- }
- });
- Map.Entry me = (Map.Entry) list.get(list.size() - 1);
- for (int i = 0; i < list.size(); i++) {
- float alpha = Float.valueOf(list.get(i).toString().split("=")[1]);
- if (alpha < 180) me = (Map.Entry) list.get(i);
- }
- int rgb = (Integer) me.getKey();
- return rgb;
- }
-
- @SideOnly(Side.CLIENT)
- public static boolean isGray(int[] rgbArr) {
- int rgbSum = rgbArr[0] + rgbArr[1] + rgbArr[2];
- if (rgbSum > 0 && rgbSum < 256 * 3) return false;
- return true;
- }
-
- public static WeightedRandomCurse[] getCurses(World world, EntityPlayer player, Random random) {
- WeightedRandomCurse[] curses = new WeightedRandomCurse[Curse.availableCurses.size()];
- for (int c = 0; c < Curse.availableCurses.size(); c++)
- curses[c] = new WeightedRandomCurse(Curse.availableCurses.get(c), Curse.availableCurses.get(c).weight(world, player, random));
- return curses;
- }
-
- /**
- * Adds curse points to a player
- *
- * @param player the player to add the points to
- * @param points amount of curse points
- */
- public static void addCursePoints(EntityPlayer player, int points) {
- NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID);
- playerInfo.setInteger("cursePoints", playerInfo.hasKey("cursePoints") ? (playerInfo.getInteger("cursePoints") + points) : points);
- playerInfo.setBoolean("playerCursePointsChanged", true);
- }
-
- public static int getCursePoints(EntityPlayer player) {
- NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID);
- return playerInfo.getInteger("cursePoints");
- }
-
- /**
- * Adds the UUID's of the jamcrafters in a list (+ special people)
- */
- public static void jamcrafters() {
- jamcraftPlayers.add("d3214311-7550-4c9c-a372-d9292c10b8a6"); //allout58
- jamcraftPlayers.add("a690119f-c4a2-4bd6-a99d-d63679abb328"); //ChewBaker
- jamcraftPlayers.add("de7c9903-51fa-4a24-88cd-48faf122ca36"); //domi1819
- jamcraftPlayers.add("70aeb298-3a7b-46da-a393-ab10df9359f2"); //founderio
- jamcraftPlayers.add("6fbe603c-14bf-4085-afdd-abe592c26e7c"); //GerbShert
- jamcraftPlayers.add("b0d21306-36bf-4d85-84df-a956d183c45a"); //isomgirls6
- jamcraftPlayers.add("1733a31f-01f9-4f4d-82aa-7de30ca810d3"); //TH3N00B
- jamcraftPlayers.add("4833eacf-1d94-49a7-9f89-4cf88d69dcf9"); //Joban
- jamcraftPlayers.add("718cf671-9084-4e78-b91f-033e80aa11bf"); //KJ4IPS
- jamcraftPlayers.add("bea5e0c4-85c4-454d-a081-e1eaae6895ee"); //Mitchellbrine
- jamcraftPlayers.add("7ecf3e2f-fedf-4f7e-8d24-6731d078db4f"); //MrComputerGhost
- jamcraftPlayers.add("1b11ad3a-f0ca-4695-a019-2d7e5d83a5fd"); //Resinresin
- jamcraftPlayers.add("3ec9ac58-2f1b-4d3f-b4eb-3b875da877ae"); //sci4me
- jamcraftPlayers.add("cf9fa23f-205e-4eed-aba3-9f2848cd6a4d"); //OnyxDarkKnight
- jamcraftPlayers.add("91880caa-b032-48e3-bfe8-c2c7ed31824e"); //theminecoder
- jamcraftPlayers.add("8d0b3804-f71c-4219-897b-8c315448ea7c"); //YSPilot
- jamcraftPlayers.add("bbb87dbe-690f-4205-bdc5-72ffb8ebc29d"); //direwolf20
- }
-
- /**
- * Adds a random amount of modifiers to a list
- *
- * @param randValue maximum number of modifiers
- * @return a list containing the random modifiers
- */
- public static ArrayList<ItemStack> addRandomModifiers(int randValue) {
- ArrayList<ItemStack> list = new ArrayList<ItemStack>();
- for (int i = 0; i < 2 + randValue; i++) {
- ItemStack item = objects.get(new Random().nextInt(objects.size()));
- item.stackSize = 1 + new Random().nextInt(2);
- list.add(item);
- }
- return list;
- }
-
- /**
- * Links ores with their appropriate ingot
- */
- public static void addMetals() {
- int index = 0;
- while (index < OreDictionary.getOreNames().length) {
- Iterator<ItemStack> i = OreDictionary.getOres(OreDictionary.getOreNames()[index]).iterator();
- while (i.hasNext()) {
- ItemStack nextStack = i.next();
- String stackName = nextStack.getItem().getUnlocalizedName().toLowerCase();
- if ((stackName.contains("ingot") || stackName.contains("alloy")) && !metal.contains(nextStack)) metal.add(nextStack);
- if (nextStack.getItem().getUnlocalizedName().toLowerCase().contains("ore") && !ores.contains(nextStack)) {
- ItemStack ingot = FurnaceRecipes.smelting().getSmeltingResult(nextStack);
- if (ingot != null && (ingot.getItem().getUnlocalizedName().toLowerCase().contains("ingot") || ingot.getItem().getUnlocalizedName().toLowerCase().contains("alloy"))) {
- ores.add(nextStack);
- oreToIngot.put(nextStack, ingot);
- JewelrycraftMod.logger.info(nextStack + " Adding " + nextStack.getDisplayName() + " with damage value " + nextStack.getItemDamage() + " and with " + nextStack.stackSize + " in stack");
- JewelrycraftMod.logger.info(ingot + " Adding ingot " + ingot.getDisplayName() + " with damage value " + ingot.getItemDamage() + " and with " + ingot.stackSize + " in stack");
- }
- }
- }
- index++;
- }
- }
-
- /**
- * Checks to see if the specified item is a gem
- *
- * @param item ItemStack containing the item
- * @return is the item a gem
- */
- public static boolean isGem(ItemStack item) {
- Iterator<ItemStack> i = gem.iterator();
- while (i.hasNext()) {
- ItemStack temp = i.next();
- if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) return true;
- }
- return false;
- }
-
- /**
- * Checks to see if the specified item is a metal
- *
- * @param item ItemStack containing the item
- * @return is the item a metal
- */
- public static boolean isMetal(ItemStack item) {
- Iterator<ItemStack> i = metal.iterator();
- while (i.hasNext()) {
- ItemStack temp = i.next();
- if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage()) return true;
- }
- return false;
- }
-
- /**
- * Checks to see if the specified item is a piece of jewelry
- *
- * @param item ItemStack containing the item
- * @return is the item a piece of jewelry
- */
- 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;
- }
-
- /**
- * Checks to see if the specified item is an ore
- *
- * @param item ItemStack containing the item
- * @return is the item an ore
- */
- public static boolean isOre(ItemStack item) {
- Iterator<ItemStack> i = ores.iterator();
- while (i.hasNext()) {
- ItemStack temp = i.next();
- if (temp.getItem().equals(item.getItem()) && temp.getItemDamage() == item.getItemDamage()) return true;
- }
- return false;
- }
-
- /**
- * Gets the ingot from the ore
- *
- * @param ore the ore
- * @return the ingot
- */
- public static ItemStack getIngotFromOre(ItemStack ore) {
- for (ItemStack ores : JewelrycraftUtil.oreToIngot.keySet())
- if (ores.getItem().equals(ore.getItem()) && ores.getItemDamage() == ore.getItemDamage()) return oreToIngot.get(ores);
- return null;
- }
-
- /**
- * This determines whether the player unlocked an achievement or not.
- *
- * @param player The player to unlock the achievement
- * @param achievement The achievement to be unlocked
- * @return True or False depending if the player did unlock the achievement or not
- */
- public static boolean AchievemtUnlocked(EntityPlayer player, Achievement achievement) {
- return ((EntityPlayerMP) player).func_147099_x().hasAchievementUnlocked(achievement);
- }
+public class JewelrycraftUtil
+{
+ public static ArrayList<ItemStack> objects = new ArrayList<ItemStack>();
+ public static ArrayList<ItemStack> gem = new ArrayList<ItemStack>();
+ public static ArrayList<ItemStack> jewelry = new ArrayList<ItemStack>();
+ public static ArrayList<ItemStack> metal = new ArrayList<ItemStack>();
+ public static ArrayList<ItemStack> ores = new ArrayList<ItemStack>();
+ public static HashMap<ItemStack, ItemStack> oreToIngot = new HashMap<ItemStack, ItemStack>();
+ public static HashMap<ItemStack, Integer> colors = new HashMap<ItemStack, Integer>();
+ public static ArrayList<String> jamcraftPlayers = new ArrayList<String>();
+ private static ArrayList<ItemStack> items = new ArrayList<ItemStack>();
+ public static ArrayList<WorldGenStructure> structures = new ArrayList<WorldGenStructure>();
+ public static Random rand = new Random();
+ public static EnumCreatureAttribute HEART;
+
+ /**
+ * Adds gems and jewelry to their appropriate list
+ */
+ public static void addStuff()
+ {
+ // Jewels
+ for(int i = 0; i < 16; i++)
+ gem.add(new ItemStack(BlockList.crystal, 1, i));
+ gem.add(new ItemStack(Blocks.redstone_block));
+ gem.add(new ItemStack(Blocks.lapis_block));
+ gem.add(new ItemStack(Blocks.obsidian));
+ gem.add(new ItemStack(Items.diamond));
+ gem.add(new ItemStack(Items.emerald));
+ gem.add(new ItemStack(Items.ender_pearl));
+ gem.add(new ItemStack(Items.nether_star));
+ // Jewelry
+ jewelry.add(new ItemStack(ItemList.ring));
+ jewelry.add(new ItemStack(ItemList.necklace));
+ jewelry.add(new ItemStack(ItemList.bracelet));
+ jewelry.add(new ItemStack(ItemList.earrings));
+ for(Object item: GameData.getItemRegistry()){
+ if (item != null) {
+ if (Loader.isModLoaded("Mantle") && ((Item)item).getUnlocalizedName().equals("Mantle:item.mantle.manual"))
+ continue;
+ try{
+ if (((Item)item).getHasSubtypes() && FMLCommonHandler.instance().getSide() == Side.CLIENT) {
+ ((Item)item).getSubItems((Item)item, null, items);
+ }else
+ objects.add(new ItemStack((Item)item));
+ if (!items.isEmpty())
+ objects.addAll(items);
+ items.removeAll(items);
+ }
+ catch(Exception e){
+ JewelrycraftMod.logger.info("Error, tried to add subtypes of item " + ((Item)item).getUnlocalizedName() + "\nItem is not added in the list.");
+ }
+ }
+ }
+ // Structures
+ try{
+ for(Field f: Generation.class.getDeclaredFields()){
+ Object obj = f.get(null);
+ if (obj instanceof WorldGenStructure)
+ structures.add((WorldGenStructure)obj);
+ }
+ }
+ catch(IllegalAccessException e){
+ throw new RuntimeException(e);
+ }
+ }
+
+ @SideOnly (Side.CLIENT)
+ public static void generateColors()
+ {
+ for(Object item: GameData.getItemRegistry()){
+ if (item != null) {
+ if (Loader.isModLoaded("Mantle") && ((Item)item).getUnlocalizedName().equals("Mantle:item.mantle.manual"))
+ continue;
+ try{
+ if (((Item)item).getHasSubtypes() && FMLCommonHandler.instance().getSide() == Side.CLIENT) {
+ ((Item)item).getSubItems((Item)item, null, items);
+ }else{
+ ItemStack it = new ItemStack((Item)item);
+ colors.put(it, color(it, 0));
+ }
+ if (!items.isEmpty())
+ for(ItemStack it: items)
+ colors.put(it, color(it, 0));
+ items.removeAll(items);
+ }
+ catch(Exception e){
+ JewelrycraftMod.logger.info("Error, tried to add the color of the item " + ((Item)item).getUnlocalizedName() + " but something went wrong.");
+ }
+ }
+ }
+ }
+
+ @SideOnly (Side.CLIENT)
+ public static int getColor(ItemStack item)
+ {
+ for(ItemStack stack: colors.keySet())
+ if (item != null && item.getItem() != null && stack.getItem() != null && item.getItem().equals(stack.getItem()) && item.getItemDamage() == stack.getItemDamage())
+ return colors.get(stack);
+ return 0xFFFFFF;
+ }
+
+ @SideOnly (Side.CLIENT)
+ public static int color(ItemStack stack, int pass) throws IOException
+ {
+ IResourceManager rm = Minecraft.getMinecraft().getResourceManager();
+ ResourceLocation ingot;
+ BufferedImage icon;
+ if (stack != null && Item.getIdFromItem(stack.getItem()) > 0 && stack.getItem().getColorFromItemStack(stack, pass) == 16777215) {
+ try{
+ ingot = getLocation(stack);
+ }
+ catch(Exception e){
+ ingot = new ResourceLocation("textures/items/apple.png");
+ }
+ icon = ImageIO.read(rm.getResource(ingot).getInputStream());
+ int height = icon.getHeight();
+ int width = icon.getWidth();
+ Map m = new HashMap();
+ for(int i = 0; i < width; i++)
+ for(int j = 0; j < height; j++){
+ int rgb = icon.getRGB(i, j);
+ int red = rgb >> 16 & 0xff;
+ int green = rgb >> 8 & 0xff;
+ int blue = rgb & 0xff;
+ int[] rgbArr = {red, green, blue};
+ int Cmax = Math.max(red, Math.max(green, blue));
+ int Cmin = Math.min(red, Math.min(green, blue));
+ if (!isGray(rgbArr))
+ m.put(rgb, (Cmax + Cmin) / 2);
+ }
+ return getMostCommonColour(m);
+ }else
+ return stack.getItem().getColorFromItemStack(stack, pass);
+ }
+
+ public static ResourceLocation getLocation(ItemStack item)
+ {
+ String domain = "";
+ String texture;
+ IIcon itemIcon = item.getItem().getIcon(item, 0);
+ if (!(Block.getBlockFromItem(item.getItem()) instanceof BlockAir) && !Block.getBlockFromItem(item.getItem()).getIcon(0, item.getItemDamage()).getIconName().equals("soul_sand"))
+ itemIcon = Block.getBlockFromItem(item.getItem()).getIcon(0, item.getItemDamage());
+ String iconName = itemIcon.getIconName();
+ if (iconName.substring(0, iconName.indexOf(":") + 1) != "")
+ domain = iconName.substring(0, iconName.indexOf(":") + 1).replace(":", " ").trim();
+ else domain = "minecraft";
+ texture = iconName.substring(iconName.lastIndexOf(":") + 1) + ".png";
+ ResourceLocation textureLocation = null;
+ TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
+ if (texturemanager.getResourceLocation(item.getItemSpriteNumber()).toString().contains("items"))
+ textureLocation = new ResourceLocation(domain.toLowerCase(), "textures/items/" + texture);
+ else textureLocation = new ResourceLocation(domain.toLowerCase(), "textures/blocks/" + texture);
+ return textureLocation;
+ }
+
+ @SideOnly (Side.CLIENT)
+ public static int getMostCommonColour(Map map)
+ {
+ List list = new LinkedList(map.entrySet());
+ Collections.sort(list, new Comparator(){
+ public int compare(Object o1, Object o2)
+ {
+ return ((Comparable)((Map.Entry)o1).getValue()).compareTo(((Map.Entry)o2).getValue());
+ }
+ });
+ Map.Entry me = (Map.Entry)list.get(list.size() - 1);
+ for(int i = 0; i < list.size(); i++){
+ float alpha = Float.valueOf(list.get(i).toString().split("=")[1]);
+ if (alpha < 180)
+ me = (Map.Entry)list.get(i);
+ }
+ int rgb = (Integer)me.getKey();
+ return rgb;
+ }
+
+ @SideOnly (Side.CLIENT)
+ public static boolean isGray(int[] rgbArr)
+ {
+ int rgbSum = rgbArr[0] + rgbArr[1] + rgbArr[2];
+ if (rgbSum > 0 && rgbSum < 256 * 3)
+ return false;
+ return true;
+ }
+
+ public static WeightedRandomCurse[] getCurses(World world, EntityPlayer player, Random random)
+ {
+ WeightedRandomCurse[] curses = new WeightedRandomCurse[Curse.availableCurses.size()];
+ for(int c = 0; c < Curse.availableCurses.size(); c++)
+ curses[c] = new WeightedRandomCurse(Curse.availableCurses.get(c), Curse.availableCurses.get(c).weight(world, player, random));
+ return curses;
+ }
+
+ /**
+ * Adds curse points to a player
+ *
+ * @param player the player to add the points to
+ * @param points amount of curse points
+ */
+ public static void addCursePoints(EntityPlayer player, int points)
+ {
+ NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID);
+ playerInfo.setInteger("cursePoints", playerInfo.hasKey("cursePoints") ? (playerInfo.getInteger("cursePoints") + points) : points);
+ playerInfo.setBoolean("playerCursePointsChanged", true);
+ }
+
+ public static int getCursePoints(EntityPlayer player)
+ {
+ NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, Variables.MODID);
+ return playerInfo.getInteger("cursePoints");
+ }
+
+ /**
+ * Adds the UUID's of the jamcrafters in a list (+ special people)
+ */
+ public static void jamcrafters()
+ {
+ jamcraftPlayers.add("d3214311-7550-4c9c-a372-d9292c10b8a6"); // allout58
+ jamcraftPlayers.add("a690119f-c4a2-4bd6-a99d-d63679abb328"); // ChewBaker
+ jamcraftPlayers.add("de7c9903-51fa-4a24-88cd-48faf122ca36"); // domi1819
+ jamcraftPlayers.add("70aeb298-3a7b-46da-a393-ab10df9359f2"); // founderio
+ jamcraftPlayers.add("6fbe603c-14bf-4085-afdd-abe592c26e7c"); // GerbShert
+ jamcraftPlayers.add("b0d21306-36bf-4d85-84df-a956d183c45a"); // isomgirls6
+ jamcraftPlayers.add("1733a31f-01f9-4f4d-82aa-7de30ca810d3"); // TH3N00B
+ jamcraftPlayers.add("4833eacf-1d94-49a7-9f89-4cf88d69dcf9"); // Joban
+ jamcraftPlayers.add("718cf671-9084-4e78-b91f-033e80aa11bf"); // KJ4IPS
+ jamcraftPlayers.add("bea5e0c4-85c4-454d-a081-e1eaae6895ee"); // Mitchellbrine
+ jamcraftPlayers.add("7ecf3e2f-fedf-4f7e-8d24-6731d078db4f"); // MrComputerGhost
+ jamcraftPlayers.add("1b11ad3a-f0ca-4695-a019-2d7e5d83a5fd"); // Resinresin
+ jamcraftPlayers.add("3ec9ac58-2f1b-4d3f-b4eb-3b875da877ae"); // sci4me
+ jamcraftPlayers.add("cf9fa23f-205e-4eed-aba3-9f2848cd6a4d"); // OnyxDarkKnight
+ jamcraftPlayers.add("91880caa-b032-48e3-bfe8-c2c7ed31824e"); // theminecoder
+ jamcraftPlayers.add("8d0b3804-f71c-4219-897b-8c315448ea7c"); // YSPilot
+ jamcraftPlayers.add("bbb87dbe-690f-4205-bdc5-72ffb8ebc29d"); // direwolf20
+ }
+
+ /**
+ * Adds a random amount of modifiers to a list
+ *
+ * @param randValue maximum number of modifiers
+ * @return a list containing the random modifiers
+ */
+ public static ArrayList<ItemStack> addRandomModifiers(int randValue)
+ {
+ ArrayList<ItemStack> list = new ArrayList<ItemStack>();
+ for(int i = 0; i < 2 + randValue; i++){
+ ItemStack item = objects.get(new Random().nextInt(objects.size()));
+ item.stackSize = 1 + new Random().nextInt(2);
+ list.add(item);
+ }
+ return list;
+ }
+
+ /**
+ * Links ores with their appropriate ingot
+ */
+ public static void addMetals()
+ {
+ int index = 0;
+ while (index < OreDictionary.getOreNames().length){
+ Iterator<ItemStack> i = OreDictionary.getOres(OreDictionary.getOreNames()[index]).iterator();
+ while (i.hasNext()){
+ ItemStack nextStack = i.next();
+ String stackName = nextStack.getItem().getUnlocalizedName().toLowerCase();
+ if ((stackName.contains("ingot") || stackName.contains("alloy")) && !metal.contains(nextStack))
+ metal.add(nextStack);
+ if (nextStack.getItem().getUnlocalizedName().toLowerCase().contains("ore") && !ores.contains(nextStack)) {
+ ItemStack ingot = FurnaceRecipes.smelting().getSmeltingResult(nextStack);
+ if (ingot != null && (ingot.getItem().getUnlocalizedName().toLowerCase().contains("ingot") || ingot.getItem().getUnlocalizedName().toLowerCase().contains("alloy"))) {
+ ores.add(nextStack);
+ oreToIngot.put(nextStack, ingot);
+ JewelrycraftMod.logger.info(nextStack + " Adding " + nextStack.getDisplayName() + " with damage value " + nextStack.getItemDamage() + " and with " + nextStack.stackSize + " in stack");
+ JewelrycraftMod.logger.info(ingot + " Adding ingot " + ingot.getDisplayName() + " with damage value " + ingot.getItemDamage() + " and with " + ingot.stackSize + " in stack");
+ }
+ }
+ }
+ index++;
+ }
+ }
+
+ /**
+ * Checks to see if the specified item is a gem
+ *
+ * @param item ItemStack containing the item
+ * @return is the item a gem
+ */
+ public static boolean isGem(ItemStack item)
+ {
+ Iterator<ItemStack> i = gem.iterator();
+ while (i.hasNext()){
+ ItemStack temp = i.next();
+ if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage())
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks to see if the specified item is a metal
+ *
+ * @param item ItemStack containing the item
+ * @return is the item a metal
+ */
+ public static boolean isMetal(ItemStack item)
+ {
+ Iterator<ItemStack> i = metal.iterator();
+ while (i.hasNext()){
+ ItemStack temp = i.next();
+ if (temp.getItem() == item.getItem() && temp.getItemDamage() == item.getItemDamage())
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Checks to see if the specified item is a piece of jewelry
+ *
+ * @param item ItemStack containing the item
+ * @return is the item a piece of jewelry
+ */
+ 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;
+ }
+
+ /**
+ * Checks to see if the specified item is an ore
+ *
+ * @param item ItemStack containing the item
+ * @return is the item an ore
+ */
+ public static boolean isOre(ItemStack item)
+ {
+ Iterator<ItemStack> i = ores.iterator();
+ while (i.hasNext()){
+ ItemStack temp = i.next();
+ if (temp.getItem().equals(item.getItem()) && temp.getItemDamage() == item.getItemDamage())
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Gets the ingot from the ore
+ *
+ * @param ore the ore
+ * @return the ingot
+ */
+ public static ItemStack getIngotFromOre(ItemStack ore)
+ {
+ for(ItemStack ores: JewelrycraftUtil.oreToIngot.keySet())
+ if (ores.getItem().equals(ore.getItem()) && ores.getItemDamage() == ore.getItemDamage())
+ return oreToIngot.get(ores);
+ return null;
+ }
+
+ /**
+ * This determines whether the player unlocked an achievement or not.
+ *
+ * @param player The player to unlock the achievement
+ * @param achievement The achievement to be unlocked
+ * @return True or False depending if the player did unlock the achievement or not
+ */
+ public static boolean AchievemtUnlocked(EntityPlayer player, Achievement achievement)
+ {
+ return ((EntityPlayerMP)player).func_147099_x().hasAchievementUnlocked(achievement);
+ }
}