diff options
5 files changed, 788 insertions, 801 deletions
diff --git a/src/main/java/darkknight/jewelrycraft/events/PlayerRenderHandler.java b/src/main/java/darkknight/jewelrycraft/events/PlayerRenderHandler.java index 0ff7be6..3ed98c9 100644 --- a/src/main/java/darkknight/jewelrycraft/events/PlayerRenderHandler.java +++ b/src/main/java/darkknight/jewelrycraft/events/PlayerRenderHandler.java @@ -65,7 +65,7 @@ public class PlayerRenderHandler { if (playerInfo != null && event.entityPlayer != null && player != null && playerInfo.hasKey("ext" + i) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())) {
gem = -1;
ingot = -1;
- if (no > 4) arm = leftArm;
+ if (i > 4) arm = leftArm;
float s = 0.055F;
NBTTagCompound nbt = (NBTTagCompound) playerInfo.getTag("ext" + i);
ItemStack item = ItemStack.loadItemStackFromNBT(nbt);
@@ -83,22 +83,22 @@ public class PlayerRenderHandler { if (JewelryNBT.gem(item) != null) gem = JewelrycraftUtil.getColor(JewelryNBT.gem(item));
float scale = 0.1f;
if (Loader.isModLoaded("alpaca") /*&& fiskfille.alpaca.AlpacaAPI.isAlpacaClient(event.entityPlayer)*/) {
- if (no <= 4) {
- GL11.glTranslatef(0.35F, -4.35F, -2.8F + 0.15F * no);
+ if (i <= 4) {
+ GL11.glTranslatef(0.35F, -4.35F, -2.8F + 0.15F * i);
GL11.glRotatef(90f, 0F, 1F, 0F);
} else {
- GL11.glTranslatef(-0.35F, -4.35F, 1.48F + 0.15F * no);
+ GL11.glTranslatef(-0.35F, -4.35F, 1.48F + 0.15F * i);
GL11.glRotatef(-90f, 0F, 1F, 0F);
}
scale = 0.3F;
} else {
- if (no <= 4) GL11.glTranslatef(0.64F + 0.05F * no, -1.15F, 0.07F);
- else GL11.glTranslatef(0.59F + 0.05F * no, -1.15F, 0.07F);
+ if (i <= 4) GL11.glTranslatef(0.64F + 0.05F * i, -1.15F, 0.07F);
+ else GL11.glTranslatef(0.59F + 0.05F * i, -1.15F, 0.07F);
}
GL11.glScalef(scale, scale + scale / 2, scale);
ring.doRender(event.entityPlayer, 0F, 0F, (float) ingot, (float) gem, 0F);
GL11.glPopMatrix();
- no++;
+// no++;
}
for (int i = 10; i <= 13; i++)
if (playerInfo != null && event.entityPlayer != null && player != null && playerInfo.hasKey("ext" + i) && event.entityPlayer.getDisplayName().equals(player.getDisplayName())) {
diff --git a/src/main/java/darkknight/jewelrycraft/item/ItemTest.java b/src/main/java/darkknight/jewelrycraft/item/ItemTest.java index 1f6dab1..5005d89 100644 --- a/src/main/java/darkknight/jewelrycraft/item/ItemTest.java +++ b/src/main/java/darkknight/jewelrycraft/item/ItemTest.java @@ -1,26 +1,9 @@ package darkknight.jewelrycraft.item;
import java.util.List;
-import cpw.mods.fml.relauncher.Side;
-import cpw.mods.fml.relauncher.SideOnly;
-import darkknight.jewelrycraft.JewelrycraftMod;
-import darkknight.jewelrycraft.achievements.AchievementsList;
+import com.pahimar.repackage.cofh.lib.util.helpers.MathHelper;
import darkknight.jewelrycraft.api.Curse;
-import darkknight.jewelrycraft.item.ItemSpawnEgg.EggData;
import darkknight.jewelrycraft.util.Variables;
-import net.minecraft.block.material.Material;
-import net.minecraft.client.renderer.texture.IIconRegister;
-import net.minecraft.creativetab.CreativeTabs;
-import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.item.Item;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.tileentity.TileEntity;
-import net.minecraft.util.IIcon;
-import net.minecraft.util.MathHelper;
-import net.minecraft.util.MovingObjectPosition;
-import net.minecraft.util.MovingObjectPosition.MovingObjectType;
-import net.minecraft.world.World;
public class ItemTest extends Item
{
diff --git a/src/main/java/darkknight/jewelrycraft/thirdparty/WailaHandler.java b/src/main/java/darkknight/jewelrycraft/thirdparty/WailaHandler.java index d86f00a..b7b06f5 100644 --- a/src/main/java/darkknight/jewelrycraft/thirdparty/WailaHandler.java +++ b/src/main/java/darkknight/jewelrycraft/thirdparty/WailaHandler.java @@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.StatCollector; import net.minecraft.world.World; public class WailaHandler implements IWailaDataProvider{ @@ -29,7 +30,7 @@ public class WailaHandler implements IWailaDataProvider{ @Override public List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { TileEntityMoltenMetal te = (TileEntityMoltenMetal)accessor.getTileEntity(); - String metalName = SpecialChars.WHITE + "Molten " + te.getMetal().getDisplayName(); + String metalName = SpecialChars.WHITE + StatCollector.translateToLocal("tile.jewelrycraft2.moltenMetal.name") + " " + te.getMetal().getDisplayName(); currenttip.remove(0); currenttip.add(0, metalName); return currenttip; diff --git a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java index 295a776..1944510 100644 --- a/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelryNBT.java @@ -1,770 +1,772 @@ -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 -{ - // TODO NBT Tag Adding - public static void addItem(ItemStack item, ItemStack target) - { - if (target != null){ - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound targetNBT = new NBTTagCompound(); - target.writeToNBT(targetNBT); - itemStackData.setTag("target", targetNBT); - } - } - - /** - * @param item The item you want to add the NBT data on - * @param metal The metal you want to add on the item - */ - public static void addMetal(ItemStack item, ItemStack metal) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound ingotNBT = new NBTTagCompound(); - metal.writeToNBT(ingotNBT); - itemStackData.setTag("ingot", ingotNBT); - } - - /** - * @param item The item you want to add the NBT data on - * @param gem The gem you want to add on the item - */ - public static void addGem(ItemStack item, ItemStack gem) - { - if (gem != null){ - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound gemNBT = new NBTTagCompound(); - gem.writeToNBT(gemNBT); - itemStackData.setTag("gem", gemNBT); - } - } - - /** - * @param item The item you want to add the NBT data on - * @param modifier The modifier you want to add on the item - */ - public static void addModifiers(ItemStack item, ArrayList<ItemStack> modifier) - { - if (modifier != null){ - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - for(int i = 0; i < modifier.size(); i++){ - NBTTagCompound modifierNBT = new NBTTagCompound(); - modifier.get(i).writeToNBT(modifierNBT); - itemStackData.setTag("modifier" + i, modifierNBT); - } - 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 - */ - public static void addIngotColor(ItemStack item, int color) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound colors = new NBTTagCompound(); - colors.setInteger("ingotColor", color); - itemStackData.setTag("ingotColor", colors); - } - - // TODO - /** - * @param item - * @param color - */ - public static void addGemColor(ItemStack item, int color) - { - NBTTagCompound itemStackData; - if (item.hasTagCompound()) itemStackData = item.getTagCompound(); - else{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - NBTTagCompound colors = new NBTTagCompound(); - colors.setInteger("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"); - } - - // 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{ - itemStackData = new NBTTagCompound(); - item.setTagCompound(itemStackData); - } - if (itemStackData.hasKey(tag)) return true; - 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; - } - - /** - * @param stack - * @param modifier - * @return - */ - public static boolean doesModifierExist(ItemStack stack, ItemStack modifier) - { - 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; - } - return false; - } - - public static int modifierSize(ItemStack stack, ItemStack modifier) - { - 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 list.get(i).stackSize; - } - return -1; - } - - public static int numberOfModifiers(ItemStack stack) - { - if (modifier(stack) != null) return modifier(stack).size(); - 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 - public static ItemStack item(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("target")){ - NBTTagCompound itemNBT = (NBTTagCompound)stack.getTagCompound().getTag("target"); - ItemStack target = new ItemStack(Item.getItemById(0), 0, 0); - target.readFromNBT(itemNBT); - return target; - } - return null; - } - - /** - * @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"); - ItemStack gem = new ItemStack(Item.getItemById(0), 0, 0); - gem.readFromNBT(jewelNBT); - return gem; - } - 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()){ - int size = stack.getTagCompound().getInteger("modifierSize"); - ArrayList<ItemStack> list = new ArrayList<ItemStack>(); - for(int i = 0; i < size; i++){ - ItemStack modifier = new ItemStack(Item.getItemById(0), 0, 0); - NBTTagCompound modifierNBT = (NBTTagCompound)stack.getTagCompound().getTag("modifier" + i); - modifier.readFromNBT(modifierNBT); - list.add(modifier); - } - return list; - } - 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"); - ItemStack ingot = new ItemStack(Item.getItemById(0), 0, 0); - ingot.readFromNBT(ingotNBT); - return ingot; - } - return null; - } - - /** - * @param stack - * @param player - * @return - */ - public static EntityLivingBase entity(ItemStack stack, EntityPlayer player) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("entityID") && stack.getTagCompound().hasKey("entity")){ - NBTTagCompound enID = (NBTTagCompound)stack.getTagCompound().getTag("entityID"); - NBTTagCompound en = (NBTTagCompound)stack.getTagCompound().getTag("entity"); - int entityID = 0; - entityID = enID.getInteger("entityID"); - EntityLivingBase entity = (EntityLivingBase)EntityList.createEntityByID(entityID, player.worldObj); - if (entity != null && entity instanceof EntityLivingBase){ - entity.readFromNBT(en); - return entity; - }else return null; - } - return null; - } - - /** - * @param stack - * @return - */ - public static TileEntity tileEntity(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("tile")){ - NBTTagCompound tileNBT = (NBTTagCompound)stack.getTagCompound().getTag("tile"); - TileEntity tile = TileEntity.createAndLoadEntity(tileNBT); - if (tile != null && tile instanceof TileEntity){ - tile.readFromNBT(tileNBT); - return tile; - }else return null; - } - return null; - } - - /** - * @param stack - * @return - */ - public static String dimName(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("dimName")){ - NBTTagCompound dim = (NBTTagCompound)stack.getTagCompound().getTag("dimName"); - String name = dim.getString("dimName"); - return name; - } - return null; - } - - /** - * @param stack - * @return - */ - public static String modeName(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("mode")){ - NBTTagCompound dim = (NBTTagCompound)stack.getTagCompound().getTag("mode"); - String name = dim.getString("mode"); - return name; - } - return null; - } - - /** - * @param stack - * @return - */ - public static int dimension(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("dimension")){ - NBTTagCompound dim = (NBTTagCompound)stack.getTagCompound().getTag("dimension"); - int dimension = dim.getInteger("dimension"); - return dimension; - } - return -2; - } - - /** - * @param stack - * @return - */ - public static int blockCoordX(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockX")){ - NBTTagCompound x = (NBTTagCompound)stack.getTagCompound().getTag("blockX"); - int posX = x.getInteger("blockX"); - return posX; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static int blockCoordY(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockY")){ - NBTTagCompound y = (NBTTagCompound)stack.getTagCompound().getTag("blockY"); - int posY = y.getInteger("blockY"); - return posY; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static int blockCoordZ(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockZ")){ - NBTTagCompound z = (NBTTagCompound)stack.getTagCompound().getTag("blockZ"); - int posZ = z.getInteger("blockZ"); - return posZ; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static int blockID(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockID")){ - NBTTagCompound blockID = (NBTTagCompound)stack.getTagCompound().getTag("blockID"); - int blockId = blockID.getInteger("blockID"); - return blockId; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static int blockMetadata(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("metadata")){ - NBTTagCompound metadataNBT = (NBTTagCompound)stack.getTagCompound().getTag("metadata"); - int metadata = metadataNBT.getInteger("metadata"); - return metadata; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static double playerPosX(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("x")){ - NBTTagCompound x = (NBTTagCompound)stack.getTagCompound().getTag("x"); - double posX = x.getDouble("x"); - return posX; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static double playerPosY(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("y")){ - NBTTagCompound y = (NBTTagCompound)stack.getTagCompound().getTag("y"); - double posY = y.getDouble("y"); - return posY; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static double playerPosZ(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("z")){ - NBTTagCompound z = (NBTTagCompound)stack.getTagCompound().getTag("z"); - double posZ = z.getDouble("z"); - return posZ; - } - return -1; - } - - /** - * @param stack - * @return - */ - public static int ingotColor(ItemStack stack) - { - if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("ingotColor")){ - NBTTagCompound colors = (NBTTagCompound)stack.getTagCompound().getTag("ingotColor"); - int color = colors.getInteger("ingotColor"); - return color; - } - return 16777215; - } - - // 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"); - int color = colors.getInteger("gemColor"); - return color; - } - 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; - } -} +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
+{
+ // TODO NBT Tag Adding
+ public static void addItem(ItemStack item, ItemStack target)
+ {
+ if (target != null){
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound()) itemStackData = item.getTagCompound();
+ else{
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound targetNBT = new NBTTagCompound();
+ target.writeToNBT(targetNBT);
+ itemStackData.setTag("target", targetNBT);
+ }
+ }
+
+ /**
+ * @param item The item you want to add the NBT data on
+ * @param metal The metal you want to add on the item
+ */
+ public static void addMetal(ItemStack item, ItemStack metal)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound()) itemStackData = item.getTagCompound();
+ else{
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ if(metal != null){
+ NBTTagCompound ingotNBT = new NBTTagCompound();
+ metal.writeToNBT(ingotNBT);
+ itemStackData.setTag("ingot", ingotNBT);
+ }
+ }
+
+ /**
+ * @param item The item you want to add the NBT data on
+ * @param gem The gem you want to add on the item
+ */
+ public static void addGem(ItemStack item, ItemStack gem)
+ {
+ if (gem != null){
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound()) itemStackData = item.getTagCompound();
+ else{
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound gemNBT = new NBTTagCompound();
+ gem.writeToNBT(gemNBT);
+ itemStackData.setTag("gem", gemNBT);
+ }
+ }
+
+ /**
+ * @param item The item you want to add the NBT data on
+ * @param modifier The modifier you want to add on the item
+ */
+ public static void addModifiers(ItemStack item, ArrayList<ItemStack> modifier)
+ {
+ if (modifier != null){
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound()) itemStackData = item.getTagCompound();
+ else{
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ for(int i = 0; i < modifier.size(); i++){
+ NBTTagCompound modifierNBT = new NBTTagCompound();
+ modifier.get(i).writeToNBT(modifierNBT);
+ itemStackData.setTag("modifier" + i, modifierNBT);
+ }
+ 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
+ */
+ public static void addIngotColor(ItemStack item, int color)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound()) itemStackData = item.getTagCompound();
+ else{
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound colors = new NBTTagCompound();
+ colors.setInteger("ingotColor", color);
+ itemStackData.setTag("ingotColor", colors);
+ }
+
+ // TODO
+ /**
+ * @param item
+ * @param color
+ */
+ public static void addGemColor(ItemStack item, int color)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound()) itemStackData = item.getTagCompound();
+ else{
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound colors = new NBTTagCompound();
+ colors.setInteger("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");
+ }
+
+ // 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{
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ if (itemStackData.hasKey(tag)) return true;
+ 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;
+ }
+
+ /**
+ * @param stack
+ * @param modifier
+ * @return
+ */
+ public static boolean doesModifierExist(ItemStack stack, ItemStack modifier)
+ {
+ 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;
+ }
+ return false;
+ }
+
+ public static int modifierSize(ItemStack stack, ItemStack modifier)
+ {
+ 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 list.get(i).stackSize;
+ }
+ return -1;
+ }
+
+ public static int numberOfModifiers(ItemStack stack)
+ {
+ if (modifier(stack) != null) return modifier(stack).size();
+ 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
+ public static ItemStack item(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("target")){
+ NBTTagCompound itemNBT = (NBTTagCompound)stack.getTagCompound().getTag("target");
+ ItemStack target = new ItemStack(Item.getItemById(0), 0, 0);
+ target.readFromNBT(itemNBT);
+ return target;
+ }
+ return null;
+ }
+
+ /**
+ * @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");
+ ItemStack gem = new ItemStack(Item.getItemById(0), 0, 0);
+ gem.readFromNBT(jewelNBT);
+ return gem;
+ }
+ 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()){
+ int size = stack.getTagCompound().getInteger("modifierSize");
+ ArrayList<ItemStack> list = new ArrayList<ItemStack>();
+ for(int i = 0; i < size; i++){
+ ItemStack modifier = new ItemStack(Item.getItemById(0), 0, 0);
+ NBTTagCompound modifierNBT = (NBTTagCompound)stack.getTagCompound().getTag("modifier" + i);
+ modifier.readFromNBT(modifierNBT);
+ list.add(modifier);
+ }
+ return list;
+ }
+ 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");
+ ItemStack ingot = new ItemStack(Item.getItemById(0), 0, 0);
+ ingot.readFromNBT(ingotNBT);
+ return ingot;
+ }
+ return null;
+ }
+
+ /**
+ * @param stack
+ * @param player
+ * @return
+ */
+ public static EntityLivingBase entity(ItemStack stack, EntityPlayer player)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("entityID") && stack.getTagCompound().hasKey("entity")){
+ NBTTagCompound enID = (NBTTagCompound)stack.getTagCompound().getTag("entityID");
+ NBTTagCompound en = (NBTTagCompound)stack.getTagCompound().getTag("entity");
+ int entityID = 0;
+ entityID = enID.getInteger("entityID");
+ EntityLivingBase entity = (EntityLivingBase)EntityList.createEntityByID(entityID, player.worldObj);
+ if (entity != null && entity instanceof EntityLivingBase){
+ entity.readFromNBT(en);
+ return entity;
+ }else return null;
+ }
+ return null;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static TileEntity tileEntity(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("tile")){
+ NBTTagCompound tileNBT = (NBTTagCompound)stack.getTagCompound().getTag("tile");
+ TileEntity tile = TileEntity.createAndLoadEntity(tileNBT);
+ if (tile != null && tile instanceof TileEntity){
+ tile.readFromNBT(tileNBT);
+ return tile;
+ }else return null;
+ }
+ return null;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static String dimName(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("dimName")){
+ NBTTagCompound dim = (NBTTagCompound)stack.getTagCompound().getTag("dimName");
+ String name = dim.getString("dimName");
+ return name;
+ }
+ return null;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static String modeName(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("mode")){
+ NBTTagCompound dim = (NBTTagCompound)stack.getTagCompound().getTag("mode");
+ String name = dim.getString("mode");
+ return name;
+ }
+ return null;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static int dimension(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("dimension")){
+ NBTTagCompound dim = (NBTTagCompound)stack.getTagCompound().getTag("dimension");
+ int dimension = dim.getInteger("dimension");
+ return dimension;
+ }
+ return -2;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static int blockCoordX(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockX")){
+ NBTTagCompound x = (NBTTagCompound)stack.getTagCompound().getTag("blockX");
+ int posX = x.getInteger("blockX");
+ return posX;
+ }
+ return -1;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static int blockCoordY(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockY")){
+ NBTTagCompound y = (NBTTagCompound)stack.getTagCompound().getTag("blockY");
+ int posY = y.getInteger("blockY");
+ return posY;
+ }
+ return -1;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static int blockCoordZ(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockZ")){
+ NBTTagCompound z = (NBTTagCompound)stack.getTagCompound().getTag("blockZ");
+ int posZ = z.getInteger("blockZ");
+ return posZ;
+ }
+ return -1;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static int blockID(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("blockID")){
+ NBTTagCompound blockID = (NBTTagCompound)stack.getTagCompound().getTag("blockID");
+ int blockId = blockID.getInteger("blockID");
+ return blockId;
+ }
+ return -1;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static int blockMetadata(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("metadata")){
+ NBTTagCompound metadataNBT = (NBTTagCompound)stack.getTagCompound().getTag("metadata");
+ int metadata = metadataNBT.getInteger("metadata");
+ return metadata;
+ }
+ return -1;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static double playerPosX(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("x")){
+ NBTTagCompound x = (NBTTagCompound)stack.getTagCompound().getTag("x");
+ double posX = x.getDouble("x");
+ return posX;
+ }
+ return -1;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static double playerPosY(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("y")){
+ NBTTagCompound y = (NBTTagCompound)stack.getTagCompound().getTag("y");
+ double posY = y.getDouble("y");
+ return posY;
+ }
+ return -1;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static double playerPosZ(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.getTagCompound().hasKey("z")){
+ NBTTagCompound z = (NBTTagCompound)stack.getTagCompound().getTag("z");
+ double posZ = z.getDouble("z");
+ return posZ;
+ }
+ return -1;
+ }
+
+ /**
+ * @param stack
+ * @return
+ */
+ public static int ingotColor(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(Item.getItemById(0), 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("ingotColor")){
+ NBTTagCompound colors = (NBTTagCompound)stack.getTagCompound().getTag("ingotColor");
+ int color = colors.getInteger("ingotColor");
+ return color;
+ }
+ return 16777215;
+ }
+
+ // 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");
+ int color = colors.getInteger("gemColor");
+ return color;
+ }
+ 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 4342907..818a526 100644 --- a/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java +++ b/src/main/java/darkknight/jewelrycraft/util/JewelrycraftUtil.java @@ -26,6 +26,7 @@ import darkknight.jewelrycraft.random.WeightedRandomCurse; import darkknight.jewelrycraft.worldGen.Generation;
import darkknight.jewelrycraft.worldGen.WorldGenStructure;
import net.minecraft.block.Block;
+import net.minecraft.block.BlockAir;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IResourceManager;
@@ -35,6 +36,7 @@ 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;
@@ -42,7 +44,6 @@ import net.minecraft.stats.Achievement; import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
-import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.oredict.OreDictionary;
public class JewelrycraftUtil {
@@ -121,14 +122,13 @@ public class JewelrycraftUtil { items.removeAll(items);
}
catch (Exception e) {
- JewelrycraftMod.logger.info("Error, tried to add color of the item " + ((Item) item).getUnlocalizedName() + " but it failed.");
+ 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) {
- if (Item.getIdFromItem(item.getItem()) == Block.getIdFromBlock(Blocks.stained_glass) || Item.getIdFromItem(item.getItem()) == Block.getIdFromBlock(Blocks.stained_hardened_clay) || Item.getIdFromItem(item.getItem()) == Block.getIdFromBlock(Blocks.wool) || Item.getIdFromItem(item.getItem()) == Block.getIdFromBlock(Blocks.carpet)) item.setItemDamage(15 - item.getItemDamage());
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;
@@ -139,7 +139,7 @@ public class JewelrycraftUtil { IResourceManager rm = Minecraft.getMinecraft().getResourceManager();
ResourceLocation ingot;
BufferedImage icon;
- if (stack != null && Item.getIdFromItem(stack.getItem()) > 0 && stack.getIconIndex() != null && stack.getItem().getColorFromItemStack(stack, pass) == 16777215) {
+ if (stack != null && Item.getIdFromItem(stack.getItem()) > 0 && stack.getItem().getColorFromItemStack(stack, pass) == 16777215) {
try {
ingot = getLocation(stack);
}
@@ -170,6 +170,7 @@ public class JewelrycraftUtil { 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";
@@ -285,7 +286,7 @@ public class JewelrycraftUtil { 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\n");
+ JewelrycraftMod.logger.info(ingot + " Adding ingot " + ingot.getDisplayName() + " with damage value " + ingot.getItemDamage() + " and with " + ingot.stackSize + " in stack");
}
}
}
|
