diff options
| author | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-02-21 21:31:16 +0000 |
|---|---|---|
| committer | OnyxDarkKnight <sor1n.iliutza16@gmail.com> | 2015-02-21 21:31:16 +0000 |
| commit | 420faddca46e70e3a70def168fb4e452ef193b0d (patch) | |
| tree | 247e334012e4bf9e4fa6d42718bf601ce6bd42d9 /java/darkknight/jewelrycraft/util | |
| parent | 3f4c717de5ebc9b942d65ae45ac87c43bdf8a31b (diff) | |
Added just a butt ton of stuff, also thanks to pau101 for helping me with the Hand Pedestal animation :)
Diffstat (limited to 'java/darkknight/jewelrycraft/util')
| -rw-r--r-- | java/darkknight/jewelrycraft/util/BlockUtils.java | 115 | ||||
| -rw-r--r-- | java/darkknight/jewelrycraft/util/JewelryNBT.java | 379 | ||||
| -rw-r--r-- | java/darkknight/jewelrycraft/util/JewelrycraftUtil.java | 191 | ||||
| -rw-r--r-- | java/darkknight/jewelrycraft/util/PlayerUtils.java | 32 |
4 files changed, 433 insertions, 284 deletions
diff --git a/java/darkknight/jewelrycraft/util/BlockUtils.java b/java/darkknight/jewelrycraft/util/BlockUtils.java index 385c175..18cb9eb 100644 --- a/java/darkknight/jewelrycraft/util/BlockUtils.java +++ b/java/darkknight/jewelrycraft/util/BlockUtils.java @@ -13,13 +13,18 @@ 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) + switch(l) { case 0: return ForgeDirection.SOUTH; @@ -31,12 +36,17 @@ public class BlockUtils 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) + switch(direction) { case NORTH: return 0F; @@ -55,16 +65,29 @@ public class BlockUtils } } + /** + * 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; } + 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; @@ -73,14 +96,22 @@ public class BlockUtils 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()); - } + 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); @@ -90,51 +121,35 @@ public class BlockUtils 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) - { + 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); - } + 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); } - - 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/java/darkknight/jewelrycraft/util/JewelryNBT.java b/java/darkknight/jewelrycraft/util/JewelryNBT.java index 3f38f94..9526a4d 100644 --- a/java/darkknight/jewelrycraft/util/JewelryNBT.java +++ b/java/darkknight/jewelrycraft/util/JewelryNBT.java @@ -2,14 +2,10 @@ package darkknight.jewelrycraft.util; import java.util.ArrayList; import java.util.List; -import java.util.Random; - -import darkknight.jewelrycraft.item.ItemRing; 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.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -28,8 +24,7 @@ public class JewelryNBT { NBTTagCompound itemStackData; if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -44,12 +39,10 @@ public class JewelryNBT */ public static void addGem(ItemStack item, ItemStack gem) { - if (gem != null) - { + if (gem != null){ NBTTagCompound itemStackData; if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -65,17 +58,14 @@ public class JewelryNBT */ public static void addModifiers(ItemStack item, ArrayList<ItemStack> modifier) { - if (modifier != null) - { + if (modifier != null){ NBTTagCompound itemStackData; if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } - for (int i = 0; i < modifier.size(); i++) - { + for(int i = 0; i < modifier.size(); i++){ NBTTagCompound modifierNBT = new NBTTagCompound(); modifier.get(i).writeToNBT(modifierNBT); itemStackData.setTag("modifier" + i, modifierNBT); @@ -92,8 +82,7 @@ public class JewelryNBT { NBTTagCompound itemStackData; if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -102,12 +91,15 @@ public class JewelryNBT 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 - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -117,12 +109,17 @@ public class JewelryNBT 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 - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -135,12 +132,18 @@ public class JewelryNBT 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 - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -160,12 +163,16 @@ public class JewelryNBT 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 - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -176,12 +183,17 @@ public class JewelryNBT 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 - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -194,12 +206,19 @@ public class JewelryNBT 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 - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -216,24 +235,29 @@ public class JewelryNBT itemStackData.setTag("dimName", coords); } + /** + * @param item + */ public static void addFakeEnchantment(ItemStack item) { NBTTagCompound itemStackData; if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } itemStackData.setTag("ench", new NBTTagList()); } + /** + * @param item + * @param color + */ public static void addIngotColor(ItemStack item, int color) { NBTTagCompound itemStackData; if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -243,12 +267,15 @@ public class JewelryNBT } // TODO + /** + * @param item + * @param color + */ public static void addGemColor(ItemStack item, int color) { NBTTagCompound itemStackData; if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -257,35 +284,44 @@ public class JewelryNBT itemStackData.setTag("gemColor", colors); } - @SuppressWarnings("rawtypes") + /** + * @param item + * @param list + */ + @SuppressWarnings ("rawtypes") public static void addEntities(ItemStack item, List list) { NBTTagCompound itemStackData; if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else - { + 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); + 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 - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } itemStackData.removeTag(tag); } + /** + * @param item + */ public static void removeEntity(ItemStack item) { JewelryNBT.removeNBT(item, "entityID"); @@ -293,6 +329,9 @@ public class JewelryNBT JewelryNBT.removeNBT(item, "ench"); } + /** + * @param item + */ public static void removeBlock(ItemStack item) { JewelryNBT.removeNBT(item, "blockID"); @@ -304,12 +343,16 @@ public class JewelryNBT } // TODO NTB Tag Checking + /** + * @param item + * @param tag + * @return + */ public static boolean hasTag(ItemStack item, String tag) { NBTTagCompound itemStackData; if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else - { + else{ itemStackData = new NBTTagCompound(); item.setTagCompound(itemStackData); } @@ -317,53 +360,86 @@ public class JewelryNBT return false; } + /** + * @param stack + * @param gem + * @return + */ public static boolean isGemX(ItemStack stack, ItemStack gem) { if (gem(stack) != null && gem(stack).getItem() == gem.getItem() && gem(stack).getItemDamage() == gem.getItemDamage()) return true; return false; } - public static boolean isModifierX(ItemStack stack, ItemStack modifier) + /** + * @param stack + * @param modifier + * @return + */ + public static int doesModifierExist(ItemStack stack, ItemStack modifier) { - if (modifier(stack) != null) - { + if (modifier(stack) != null){ ArrayList<ItemStack> list = modifier(stack); - for (int i = 0; i < list.size(); i++) - if (list.get(i).getItem() == modifier.getItem() && list.get(i).getItemDamage() == modifier.getItemDamage()) return true; + for(int i = 0; i < list.size(); i++) + if (list.get(i).getItem() == modifier.getItem() && list.get(i).getItemDamage() == modifier.getItemDamage()) return i; } - return false; + return -1; } + /** + * @param stack + * @param ingot + * @return + */ 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; } + /** + * @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 + // TODO Return components based on NBT + /** + * @param stack + * @return + */ public static ItemStack gem(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("gem")) - { - NBTTagCompound jewelNBT = (NBTTagCompound) stack.getTagCompound().getTag("gem"); + if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("gem")){ + NBTTagCompound jewelNBT = (NBTTagCompound)stack.getTagCompound().getTag("gem"); ItemStack gem = new ItemStack(Item.getItemById(0), 0, 0); gem.readFromNBT(jewelNBT); return gem; @@ -371,16 +447,18 @@ public class JewelryNBT return null; } + /** + * @param stack + * @return + */ public static ArrayList<ItemStack> modifier(ItemStack stack) { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound()) - { + if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound()){ int size = stack.getTagCompound().getInteger("modifierSize"); ArrayList<ItemStack> list = new ArrayList<ItemStack>(); - for (int i = 0; i < size; i++) - { + for(int i = 0; i < size; i++){ ItemStack modifier = new ItemStack(Item.getItemById(0), 0, 0); - NBTTagCompound modifierNBT = (NBTTagCompound) stack.getTagCompound().getTag("modifier" + i); + NBTTagCompound modifierNBT = (NBTTagCompound)stack.getTagCompound().getTag("modifier" + i); modifier.readFromNBT(modifierNBT); list.add(modifier); } @@ -389,11 +467,14 @@ public class JewelryNBT return null; } + /** + * @param stack + * @return + */ 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"); + 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; @@ -401,167 +482,206 @@ 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"); + 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) - { + EntityLivingBase entity = (EntityLivingBase)EntityList.createEntityByID(entityID, player.worldObj); + if (entity != null && entity instanceof EntityLivingBase){ entity.readFromNBT(en); return entity; - } - else return null; + }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) TileEntity.createAndLoadEntity(tileNBT); - if (tile != null && tile instanceof TileEntity) - { + 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; + }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"); + 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"); + 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"); + 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"); + 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"); + 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"); + 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"); + 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"); + 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"); + 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"); + 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"); + 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"); + 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; } @@ -569,31 +689,36 @@ public class JewelryNBT } // TODO + /** + * @param stack + * @return + */ 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"); + 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; } return 16777215; } - @SuppressWarnings( - { "rawtypes", "unchecked", "null" }) + /** + * @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"); + 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); + for(int element: entityID){ + entity = (EntityLivingBase)EntityList.createEntityByID(element, player.worldObj); list.add(entity); } return list; diff --git a/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java b/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java index b61267e..70129f0 100644 --- a/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java +++ b/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java @@ -4,16 +4,19 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Random; - -import cpw.mods.fml.common.registry.GameData; -import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +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.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.oredict.OreDictionary; +import cpw.mods.fml.common.registry.GameData; +import darkknight.jewelrycraft.JewelrycraftMod; +import darkknight.jewelrycraft.events.EntityEventHandler; import darkknight.jewelrycraft.item.ItemList; -import darkknight.jewelrycraft.lib.Reference; +import darkknight.jewelrycraft.network.PacketRequestPlayerInfo; public class JewelrycraftUtil { @@ -22,26 +25,17 @@ public class JewelrycraftUtil 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<String, Integer> curseValues = new HashMap<String, Integer>(); - public static HashMap<Integer, String> curseNames = new HashMap<Integer, String>(); - public static HashMap<Integer, String> availableCurseNames = new HashMap<Integer, String>(); - public static HashMap<String, Integer> availableCurseValues = new HashMap<String, Integer>(); public static HashMap<Item, ItemStack> oreToIngot = new HashMap<Item, ItemStack>(); public static ArrayList<String> jamcraftPlayers = new ArrayList<String>(); public static Random rand = new Random(); + /** + * Adds gems and jewelry to their appropriate list + */ public static void addStuff() { - // Modifiers - for(Object item: GameData.getItemRegistry()) - { - ArrayList<ItemStack> items = new ArrayList<ItemStack>(); - ((Item)item).getSubItems((Item)item, null, items); - objects.addAll(items); - } - // Jewels - for (int i = 0; i < 16; i++) + for(int i = 0; i < 16; i++) gem.add(new ItemStack(ItemList.crystal, 1, i)); gem.add(new ItemStack(Blocks.redstone_block)); gem.add(new ItemStack(Blocks.lapis_block)); @@ -50,56 +44,73 @@ public class JewelrycraftUtil 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)); - - // Curses - addCurse(Reference.MODNAME + ":" + "Blind", 0); - addCurse(Reference.MODNAME + ":" + "Weak", 1); - addCurse(Reference.MODNAME + ":" + "Anemic", 2); - addCurse(Reference.MODNAME + ":" + "Scared", 3); - addCurse(Reference.MODNAME + ":" + "Brave", 4); + for(Object item: GameData.getItemRegistry()){ + ArrayList<ItemStack> items = new ArrayList<ItemStack>(); + if (((Item)item).getHasSubtypes()){ + for(int i = 0; i < ((Item)item).getMaxDamage(); i++) + items.add(new ItemStack((Item)item, 1, i)); + }else objects.add(new ItemStack((Item)item)); + if (!items.isEmpty()) objects.addAll(items); + } } - public static void jamcrafters() + /** + * 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) { - 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"); + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + playerInfo.setInteger("cursePoints", playerInfo.hasKey("cursePoints") ? (playerInfo.getInteger("cursePoints") + points) : points); + playerInfo.setBoolean("playerCursePointsChanged", true); } - public static void addCurse(String name, int val) + public static int getCursePoints(EntityPlayer player) { - curseValues.put(name, val); - curseNames.put(val, name); - availableCurseValues.put(name, val); - availableCurseNames.put(val, name); + NBTTagCompound playerInfo = PlayerUtils.getModPlayerPersistTag(player, "Jewelrycraft"); + return playerInfo.getInteger("cursePoints"); } + /** + * Adds the UUID's of the jamcrafters in a list + */ + public static void jamcrafters() + { + jamcraftPlayers.add("d3214311-7550-4c9c-a372-d9292c10b8a6"); + jamcraftPlayers.add("a690119f-c4a2-4bd6-a99d-d63679abb328"); + jamcraftPlayers.add("de7c9903-51fa-4a24-88cd-48faf122ca36"); + jamcraftPlayers.add("70aeb298-3a7b-46da-a393-ab10df9359f2"); + jamcraftPlayers.add("6fbe603c-14bf-4085-afdd-abe592c26e7c"); + jamcraftPlayers.add("b0d21306-36bf-4d85-84df-a956d183c45a"); + jamcraftPlayers.add("1733a31f-01f9-4f4d-82aa-7de30ca810d3"); + jamcraftPlayers.add("4833eacf-1d94-49a7-9f89-4cf88d69dcf9"); + jamcraftPlayers.add("718cf671-9084-4e78-b91f-033e80aa11bf"); + jamcraftPlayers.add("bea5e0c4-85c4-454d-a081-e1eaae6895ee"); + jamcraftPlayers.add("7ecf3e2f-fedf-4f7e-8d24-6731d078db4f"); + jamcraftPlayers.add("1b11ad3a-f0ca-4695-a019-2d7e5d83a5fd"); + jamcraftPlayers.add("3ec9ac58-2f1b-4d3f-b4eb-3b875da877ae"); + jamcraftPlayers.add("cf9fa23f-205e-4eed-aba3-9f2848cd6a4d"); + jamcraftPlayers.add("91880caa-b032-48e3-bfe8-c2c7ed31824e"); + jamcraftPlayers.add("8d0b3804-f71c-4219-897b-8c315448ea7c"); + jamcraftPlayers.add("bbb87dbe-690f-4205-bdc5-72ffb8ebc29d"); + } + + /** + * 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++) - { + 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); @@ -107,26 +118,22 @@ public class JewelrycraftUtil return list; } + /** + * Links ores with their appropriate ingot + */ public static void addMetals() { int index = 0; - while (index < OreDictionary.getOreNames().length) - { + while (index < OreDictionary.getOreNames().length){ Iterator<ItemStack> i = OreDictionary.getOres(OreDictionary.getOreNames()[index]).iterator(); - - while (i.hasNext()) - { + while (i.hasNext()){ ItemStack nextStack = i.next(); - - if ((nextStack.getItem().getUnlocalizedName().toLowerCase().contains("ingot") || nextStack.getItem().getUnlocalizedName().toLowerCase().contains("alloy")) && !nextStack.getItem().getUnlocalizedName().toLowerCase().contains("powder") && !nextStack.getItem().getUnlocalizedName().toLowerCase().contains("dust") && !nextStack.getItem().getUnlocalizedName().toLowerCase().contains("block") && !metal.contains(nextStack)) - { + if ((nextStack.getItem().getUnlocalizedName().toLowerCase().contains("ingot") || nextStack.getItem().getUnlocalizedName().toLowerCase().contains("alloy")) && !nextStack.getItem().getUnlocalizedName().toLowerCase().contains("powder") && !nextStack.getItem().getUnlocalizedName().toLowerCase().contains("dust") && !nextStack.getItem().getUnlocalizedName().toLowerCase().contains("block") && !metal.contains(nextStack)){ metal.add(nextStack); - if (OreDictionary.getOres(OreDictionary.getOreNames()[index].replace("ingot", "ore")) != null) - { + if (OreDictionary.getOres(OreDictionary.getOreNames()[index].replace("ingot", "ore")) != null){ ores.addAll(OreDictionary.getOres(OreDictionary.getOreNames()[index].replace("ingot", "ore"))); Iterator<ItemStack> ores = OreDictionary.getOres(OreDictionary.getOreNames()[index].replace("ingot", "ore")).iterator(); - while (ores.hasNext()) - { + while (ores.hasNext()){ ItemStack ore = ores.next(); oreToIngot.put(ore.getItem(), nextStack); } @@ -137,66 +144,76 @@ public class JewelrycraftUtil } } - public static boolean isModifier(ItemStack item) - { - Iterator<ItemStack> i = objects.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 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()) - { + 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()) - { + 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()) - { + 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()) - { + while (i.hasNext()){ ItemStack temp = i.next(); if (temp.getItem() == 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(Item ore) { return oreToIngot.get(ore); diff --git a/java/darkknight/jewelrycraft/util/PlayerUtils.java b/java/darkknight/jewelrycraft/util/PlayerUtils.java index 1135860..159ea98 100644 --- a/java/darkknight/jewelrycraft/util/PlayerUtils.java +++ b/java/darkknight/jewelrycraft/util/PlayerUtils.java @@ -2,42 +2,34 @@ 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 -{ +{ + /** + * Returns the NBTTag of the player + * + * @param player the player + * @param modName the mod name + * @return appropriate NBTTag + */ 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 - { + 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 - { + if (persistTag.hasKey(modName)) modTag = persistTag.getCompoundTag(modName); + else{ modTag = new NBTTagCompound(); persistTag.setTag(modName, modTag); } - return modTag; } }
\ No newline at end of file |
