summaryrefslogtreecommitdiff
path: root/common/darkknight/jewelrycraft/util/JewelryNBT.java
diff options
context:
space:
mode:
authorOnyxDarkKnight <sor1n.iliutza16@gmail.com>2014-03-23 19:01:47 +0200
committerOnyxDarkKnight <sor1n.iliutza16@gmail.com>2014-03-23 19:01:47 +0200
commit5fce447142b3c0f4a214ca7eb208d9e5c25e6377 (patch)
tree2b29a935e47c8ba65d753b4161cfc51d053a23e6 /common/darkknight/jewelrycraft/util/JewelryNBT.java
parent3e0556ee7aadfbb7695f87063662a9ca0d28175f (diff)
Added necklaces, Altar Block, new stuff, better Shadow Ingot texture
Diffstat (limited to 'common/darkknight/jewelrycraft/util/JewelryNBT.java')
-rw-r--r--common/darkknight/jewelrycraft/util/JewelryNBT.java367
1 files changed, 261 insertions, 106 deletions
diff --git a/common/darkknight/jewelrycraft/util/JewelryNBT.java b/common/darkknight/jewelrycraft/util/JewelryNBT.java
index 263b6b6..d7d396d 100644
--- a/common/darkknight/jewelrycraft/util/JewelryNBT.java
+++ b/common/darkknight/jewelrycraft/util/JewelryNBT.java
@@ -1,5 +1,7 @@
package darkknight.jewelrycraft.util;
+import java.util.List;
+
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@@ -7,10 +9,17 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
+import net.minecraft.tileentity.TileEntity;
+import net.minecraft.world.World;
public class JewelryNBT
{
-
+ //TODO NBT Tag Adding
+ /**
+ *
+ * @param item The item you want to add the NBT data on
+ * @param metal The metal you want to add on the item
+ */
public static void addMetal(ItemStack item, ItemStack metal)
{
NBTTagCompound itemStackData;
@@ -26,34 +35,50 @@ public class JewelryNBT
itemStackData.setTag("ingot", ingotNBT);
}
+ /**
+ *
+ * @param item The item you want to add the NBT data on
+ * @param jewel The jewel you want to add on the item
+ */
public static void addJewel(ItemStack item, ItemStack jewel)
{
- NBTTagCompound itemStackData;
- if (item.hasTagCompound())
- itemStackData = item.getTagCompound();
- else
+ if(jewel != null)
{
- itemStackData = new NBTTagCompound();
- item.setTagCompound(itemStackData);
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound jewelNBT = new NBTTagCompound();
+ jewel.writeToNBT(jewelNBT);
+ itemStackData.setTag("jewel", jewelNBT);
}
- NBTTagCompound jewelNBT = new NBTTagCompound();
- jewel.writeToNBT(jewelNBT);
- itemStackData.setTag("jewel", jewelNBT);
}
+ /**
+ *
+ * @param item The item you want to add the NBT data on
+ * @param modifier The modifier you want to add on the item
+ */
public static void addModifier(ItemStack item, ItemStack modifier)
{
- NBTTagCompound itemStackData;
- if (item.hasTagCompound())
- itemStackData = item.getTagCompound();
- else
+ if(modifier != null)
{
- itemStackData = new NBTTagCompound();
- item.setTagCompound(itemStackData);
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound modifierNBT = new NBTTagCompound();
+ modifier.writeToNBT(modifierNBT);
+ itemStackData.setTag("modifier", modifierNBT);
}
- NBTTagCompound modifierNBT = new NBTTagCompound();
- modifier.writeToNBT(modifierNBT);
- itemStackData.setTag("modifier", modifierNBT);
}
public static void addEntity(ItemStack item, EntityLivingBase entity)
@@ -106,6 +131,49 @@ public class JewelryNBT
itemStackData.setTag("z", coords);
}
+ public static void addTileEntityBlock(ItemStack item, World world, int x, int y, int z)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound tileNBT = new NBTTagCompound();
+ NBTTagCompound block = new NBTTagCompound();
+ world.getBlockTileEntity(x, y, z).writeToNBT(tileNBT);
+ itemStackData.setTag("tile", tileNBT);
+ block.setInteger("blockID", world.getBlockId(x, y, z));
+ block.setInteger("metadata", world.getBlockMetadata(x, y, z));
+ block.setInteger("blockX", x);
+ block.setInteger("blockY", y);
+ block.setInteger("blockZ", z);
+ itemStackData.setTag("metadata", block);
+ itemStackData.setTag("blockID", block);
+ itemStackData.setTag("blockX", block);
+ itemStackData.setTag("blockY", block);
+ itemStackData.setTag("blockZ", block);
+ }
+
+ public static void addBlock(ItemStack item, int block, int metadata)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound blockNBT = new NBTTagCompound();
+ blockNBT.setInteger("blockID", block);
+ itemStackData.setTag("blockID", blockNBT);
+ blockNBT.setInteger("metadata", metadata);
+ itemStackData.setTag("metadata", blockNBT);
+ }
+
public static void addBlockCoordonates(ItemStack item, int x, int y, int z)
{
NBTTagCompound itemStackData;
@@ -162,8 +230,8 @@ public class JewelryNBT
mode.setString("mode", modeN);
itemStackData.setTag("mode", mode);
}
-
- public static void removeNBT(ItemStack item, String tag)
+
+ public static void addFakeEnchantment(ItemStack item)
{
NBTTagCompound itemStackData;
if (item.hasTagCompound())
@@ -173,10 +241,10 @@ public class JewelryNBT
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
- itemStackData.removeTag(tag);
+ itemStackData.setTag("ench", new NBTTagList("ench"));
}
-
- public static boolean hasTag(ItemStack item, String tag)
+
+ public static void addIngotColor(ItemStack item, int color)
{
NBTTagCompound itemStackData;
if (item.hasTagCompound())
@@ -186,10 +254,56 @@ public class JewelryNBT
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
- if(itemStackData.hasKey(tag)) return true;
- return false;
+ NBTTagCompound colors = new NBTTagCompound();
+ colors.setInteger("ingotColor", color);
+ itemStackData.setTag("ingotColor", colors);
}
-
+
+ public static void addJewelColor(ItemStack item, int color)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound colors = new NBTTagCompound();
+ colors.setInteger("jewelColor", color);
+ itemStackData.setTag("jewelColor", colors);
+ }
+
+ @SuppressWarnings("rawtypes")
+ public static void addEntities(ItemStack item, List list)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ NBTTagCompound entityNBT = new NBTTagCompound();
+ for(int i=0; i < list.size(); i++) ((EntityLivingBase) list.get(i)).writeToNBT(entityNBT);
+ itemStackData.setTag("entities", entityNBT);
+ }
+
+ //TODO NBT Tag Removing
+ public static void removeNBT(ItemStack item, String tag)
+ {
+ NBTTagCompound itemStackData;
+ if (item.hasTagCompound())
+ itemStackData = item.getTagCompound();
+ else
+ {
+ itemStackData = new NBTTagCompound();
+ item.setTagCompound(itemStackData);
+ }
+ itemStackData.removeTag(tag);
+ }
+
public static void removeEntity(ItemStack item)
{
JewelryNBT.removeNBT(item, "entityID");
@@ -197,7 +311,18 @@ public class JewelryNBT
JewelryNBT.removeNBT(item, "ench");
}
- public static void addFakeEnchantment(ItemStack 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
+ public static boolean hasTag(ItemStack item, String tag)
{
NBTTagCompound itemStackData;
if (item.hasTagCompound())
@@ -207,9 +332,62 @@ public class JewelryNBT
itemStackData = new NBTTagCompound();
item.setTagCompound(itemStackData);
}
- itemStackData.setTag("ench", new NBTTagList("ench"));
+ if(itemStackData.hasKey(tag)) return true;
+ return false;
+ }
+
+ public static boolean isJewelX(ItemStack stack, ItemStack jewel)
+ {
+ if(jewel(stack) != null && jewel(stack).itemID == jewel.itemID && jewel(stack).getItemDamage() == jewel.getItemDamage()) return true;
+ return false;
+ }
+
+ public static boolean isModifierX(ItemStack stack, ItemStack modifier)
+ {
+ if(modifier(stack) != null && modifier(stack).itemID == modifier.itemID && modifier(stack).getItemDamage() == modifier.getItemDamage()) return true;
+ return false;
}
+ public static boolean isModifierEffectType(ItemStack stack)
+ {
+ if(modifier(stack) != null && (isModifierX(stack, new ItemStack(Item.blazePowder)) || isModifierX(stack, new ItemStack(Item.sugar))
+ || isModifierX(stack, new ItemStack(Item.pickaxeIron)) || isModifierX(stack, new ItemStack(Item.feather))
+ || isModifierX(stack, new ItemStack(Item.potion, 1, 8270)))) return true;
+ return false;
+ }
+
+ public static boolean isIngotX(ItemStack stack, ItemStack ingot)
+ {
+ if(ingot(stack) != null && ingot(stack).itemID == ingot.itemID && ingot(stack).getItemDamage() == ingot.getItemDamage()) return true;
+ return false;
+ }
+
+ public static boolean isModeX(ItemStack stack, String modeN)
+ {
+ if(modeName(stack) != null && modeName(stack).equals(modeN)) return true;
+ return false;
+ }
+
+ public static boolean isEntityX(ItemStack stack, EntityPlayer player, EntityLivingBase entity)
+ {
+ if(entity != null && entity instanceof EntityLivingBase && entity(stack, player) != null && entity(stack, player).equals(entity)) return true;
+ return false;
+ }
+
+ public static boolean isDimNameX(ItemStack stack, String dimName)
+ {
+ if(ingot(stack) != null && dimName(stack).equals(dimName)) return true;
+ return false;
+ }
+
+ public static boolean isDimensionX(ItemStack stack, int dimension)
+ {
+ if(dimension(stack) != -2 && dimension(stack) == dimension) return true;
+ return false;
+ }
+
+ //TODO Return components based on NBT
+
public static ItemStack jewel(ItemStack stack)
{
if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("jewel"))
@@ -222,12 +400,6 @@ public class JewelryNBT
return null;
}
- public static boolean isJewelX(ItemStack stack, ItemStack jewel)
- {
- if(jewel(stack) != null && jewel(stack).itemID == jewel.itemID && jewel(stack).getItemDamage() == jewel.getItemDamage()) return true;
- return false;
- }
-
public static ItemStack modifier(ItemStack stack)
{
if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("modifier"))
@@ -240,20 +412,6 @@ public class JewelryNBT
return null;
}
- public static boolean isModifierX(ItemStack stack, ItemStack modifier)
- {
- if(modifier(stack) != null && modifier(stack).itemID == modifier.itemID && modifier(stack).getItemDamage() == modifier.getItemDamage()) return true;
- return false;
- }
-
- public static boolean isModifierEffectType(ItemStack stack)
- {
- if(modifier(stack) != null && (isModifierX(stack, new ItemStack(Item.blazePowder)) || isModifierX(stack, new ItemStack(Item.sugar))
- || isModifierX(stack, new ItemStack(Item.pickaxeIron)) || isModifierX(stack, new ItemStack(Item.feather))
- || isModifierX(stack, new ItemStack(Item.potion, 1, 8270)))) return true;
- return false;
- }
-
public static ItemStack ingot(ItemStack stack)
{
if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("ingot"))
@@ -266,18 +424,6 @@ public class JewelryNBT
return null;
}
- public static boolean isIngotX(ItemStack stack, ItemStack ingot)
- {
- if(ingot(stack) != null && ingot(stack).itemID == ingot.itemID && ingot(stack).getItemDamage() == ingot.getItemDamage()) return true;
- return false;
- }
-
- public static boolean isModeX(ItemStack stack, String modeN)
- {
- if(modeName(stack) != null && modeName(stack).equals(modeN)) return true;
- return false;
- }
-
public static EntityLivingBase entity(ItemStack stack, EntityPlayer player)
{
if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("entityID") && stack.getTagCompound().hasKey("entity"))
@@ -297,10 +443,20 @@ public class JewelryNBT
return null;
}
- public static boolean isEntityX(ItemStack stack, EntityPlayer player, EntityLivingBase entity)
+ public static TileEntity tileEntity(ItemStack stack)
{
- if(entity != null && entity instanceof EntityLivingBase && entity(stack, player) != null && entity(stack, player).equals(entity)) return true;
- return false;
+ if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("tile"))
+ {
+ NBTTagCompound tileNBT = (NBTTagCompound) stack.getTagCompound().getTag("tile");
+ TileEntity tile = (TileEntity) TileEntity.createAndLoadEntity(tileNBT);
+ if(tile != null && tile instanceof TileEntity)
+ {
+ tile.readFromNBT(tileNBT);
+ return tile;
+ }
+ else return null;
+ }
+ return null;
}
public static String dimName(ItemStack stack)
@@ -325,12 +481,6 @@ public class JewelryNBT
return null;
}
- public static boolean isDimNameX(ItemStack stack, String dimName)
- {
- if(ingot(stack) != null && dimName(stack).equals(dimName)) return true;
- return false;
- }
-
public static int dimension(ItemStack stack)
{
if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("dimension"))
@@ -342,12 +492,6 @@ public class JewelryNBT
return -2;
}
- public static boolean isDimensionX(ItemStack stack, int dimension)
- {
- if(dimension(stack) != -2 && dimension(stack) == dimension) return true;
- return false;
- }
-
public static int blockCoordX(ItemStack stack)
{
if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("blockX"))
@@ -381,6 +525,28 @@ public class JewelryNBT
return -1;
}
+ public static int blockID(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("blockID"))
+ {
+ NBTTagCompound blockID = (NBTTagCompound) stack.getTagCompound().getTag("blockID");
+ int blockId = blockID.getInteger("blockID");
+ return blockId;
+ }
+ return -1;
+ }
+
+ public static int blockMetadata(ItemStack stack)
+ {
+ if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("metadata"))
+ {
+ NBTTagCompound metadataNBT = (NBTTagCompound) stack.getTagCompound().getTag("metadata");
+ int metadata = metadataNBT.getInteger("metadata");
+ return metadata;
+ }
+ return -1;
+ }
+
public static double playerPosX(ItemStack stack)
{
if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("x"))
@@ -414,21 +580,6 @@ public class JewelryNBT
return -1;
}
- public static void addIngotColor(ItemStack item, int color)
- {
- NBTTagCompound itemStackData;
- if (item.hasTagCompound())
- itemStackData = item.getTagCompound();
- else
- {
- itemStackData = new NBTTagCompound();
- item.setTagCompound(itemStackData);
- }
- NBTTagCompound colors = new NBTTagCompound();
- colors.setInteger("ingotColor", color);
- itemStackData.setTag("ingotColor", colors);
- }
-
public static int ingotColor(ItemStack stack)
{
if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("ingotColor"))
@@ -440,21 +591,6 @@ public class JewelryNBT
return 16777215;
}
- public static void addJewelColor(ItemStack item, int color)
- {
- NBTTagCompound itemStackData;
- if (item.hasTagCompound())
- itemStackData = item.getTagCompound();
- else
- {
- itemStackData = new NBTTagCompound();
- item.setTagCompound(itemStackData);
- }
- NBTTagCompound colors = new NBTTagCompound();
- colors.setInteger("jewelColor", color);
- itemStackData.setTag("jewelColor", colors);
- }
-
public static int jewelColor(ItemStack stack)
{
if(stack != null && stack != new ItemStack(0, 0, 0) && stack.hasTagCompound() && stack.getTagCompound().hasKey("jewelColor"))
@@ -465,4 +601,23 @@ public class JewelryNBT
}
return 16777215;
}
+
+ @SuppressWarnings({ "rawtypes", "unchecked", "null" })
+ public static List entities(ItemStack stack, EntityPlayer player)
+ {
+ if (stack != null && stack != new ItemStack(0, 0, 0) && stack.getTagCompound().hasKey("entities"))
+ {
+ NBTTagCompound enID = (NBTTagCompound) stack.getTagCompound().getTag("entitiesID");
+ List list = null;
+ int[] entityID;
+ EntityLivingBase entity;
+ entityID = enID.getIntArray("entitiesID");
+ for(int i = 0; i < entityID.length; i++){
+ entity = (EntityLivingBase) EntityList.createEntityByID(entityID[i], player.worldObj);
+ list.add(entity);
+ }
+ return list;
+ }
+ return null;
+ }
}