aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/item/general
diff options
context:
space:
mode:
authorDraknyte1 <Draknyte1@hotmail.com>2016-10-17 01:39:50 +1000
committerDraknyte1 <Draknyte1@hotmail.com>2016-10-17 01:39:50 +1000
commitd6bf108b40f0b281ff7c3c2bc91e43ed2b9883f7 (patch)
tree0f00f90ad75043f47aac4cf68431f038adc5071d /src/Java/gtPlusPlus/core/item/general
parentb1aa7032fe9e6bfedccf1bb08952c68100002489 (diff)
downloadGT5-Unofficial-d6bf108b40f0b281ff7c3c2bc91e43ed2b9883f7.tar.gz
GT5-Unofficial-d6bf108b40f0b281ff7c3c2bc91e43ed2b9883f7.tar.bz2
GT5-Unofficial-d6bf108b40f0b281ff7c3c2bc91e43ed2b9883f7.zip
+ Added Tesseract Generators and Terminals.
+ Added a handful of new, old textures from GT4. % Rewrote portions of the Blueprint item again, to try make it work better with NBT. + Added an Example NBT item for myself~ because I am a derp. + Added some custom textures for the Industrial Centrifuge. % Moved all the GT4 Tile Entities to their own loading class.
Diffstat (limited to 'src/Java/gtPlusPlus/core/item/general')
-rw-r--r--src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java225
1 files changed, 176 insertions, 49 deletions
diff --git a/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java b/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java
index a15616711d..b721672aa4 100644
--- a/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java
+++ b/src/Java/gtPlusPlus/core/item/general/ItemBlueprint.java
@@ -4,6 +4,7 @@ import gtPlusPlus.core.creative.AddToCreativeTab;
import gtPlusPlus.core.interfaces.IItemBlueprint;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.Utils;
+import gtPlusPlus.core.util.item.UtilsItems;
import gtPlusPlus.core.util.math.MathUtils;
import java.util.List;
@@ -21,49 +22,59 @@ import cpw.mods.fml.common.registry.GameRegistry;
public class ItemBlueprint extends Item implements IItemBlueprint{
- protected String mName = "";
- protected boolean mHasBlueprint = false;
- private final int bpID;
-
- /**
- * The inventory of items the blueprint holds~
- */
- protected ItemStack[] blueprint = new ItemStack[9];
-
public ItemBlueprint(String unlocalizedName) {
this.setUnlocalizedName(unlocalizedName);
this.setTextureName(CORE.MODID + ":" + unlocalizedName);
this.setMaxStackSize(1);
this.setCreativeTab(AddToCreativeTab.tabMachines);
- this.bpID = MathUtils.randInt(0, 1000);
+ //this.bpID = MathUtils.randInt(0, 1000);
GameRegistry.registerItem(this, unlocalizedName);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
- public void addInformation(ItemStack stack, EntityPlayer aPlayer, List list, boolean bool) {
- if (bpID >= 0){
- list.add(EnumChatFormatting.GRAY+"Technical Document No. "+bpID);
+ public void addInformation(ItemStack itemStack, EntityPlayer aPlayer, List list, boolean bool) {
+ //Create some NBT if it's not there, otherwise this does nothing.
+ if (!itemStack.hasTagCompound()){
+ createNBT(itemStack);
}
- if(mHasBlueprint){
- list.add(EnumChatFormatting.BLUE+"Currently holding a blueprint for "+mName);
+ //Set up some default variables.
+ int id = -1;
+ String name = "";
+ boolean blueprint = false;
+ //Get proper display vars from NBT if it's there
+ if (itemStack.hasTagCompound()){
+ //Utils.LOG_INFO("Found TagCompound");
+ id = (int) getNBT(itemStack, "mID");
+ name = (String) getNBT(itemStack, "mName");
+ blueprint = (boolean) getNBT(itemStack, "mBlueprint");
}
+ //Write to tooltip list for each viable setting.
+ if (itemStack.hasTagCompound()) {
+ if (id != -1){
+ list.add(EnumChatFormatting.GRAY+"Technical Document No. "+id);
+ }
+ if(blueprint){
+ list.add(EnumChatFormatting.BLUE+"Currently holding a blueprint for "+name);
+ }
+ else {
+ list.add(EnumChatFormatting.RED+"Currently not holding a blueprint for anything.");
+ }
+ }
else {
list.add(EnumChatFormatting.RED+"Currently not holding a blueprint for anything.");
}
- super.addInformation(stack, aPlayer, list, bool);
+ super.addInformation(itemStack, aPlayer, list, bool);
}
-
+
@Override
public String getItemStackDisplayName(ItemStack p_77653_1_) {
- return "Blueprint";
+ return "Blueprint";
}
@Override
- public void onCreated(ItemStack itemStack, World world, EntityPlayer player) {
- itemStack.stackTagCompound = new NBTTagCompound();
- //this.inventory = null;
- //itemStack.stackTagCompound.set("pos_x", bed_X); TODO
+ public void onCreated(ItemStack itemStack, World world, EntityPlayer player) {
+ createNBT(itemStack);
}
@Override
@@ -74,38 +85,59 @@ public class ItemBlueprint extends Item implements IItemBlueprint{
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer par3Entity) {
//Let the player know what blueprint is held
- Utils.messagePlayer(par3Entity, "This is a placeholder.");
+ if (itemStack.hasTagCompound()) {
+ Utils.messagePlayer(par3Entity, "This Blueprint holds NBT data. "+"|"+getNBT(itemStack, "mID")+"|"+getNBT(itemStack, "mBlueprint")+"|"+getNBT(itemStack, "mName")+"|"+UtilsItems.getArrayStackNames(readItemsFromNBT(itemStack)));
+ }
+ else {
+ createNBT(itemStack);
+ Utils.messagePlayer(par3Entity, "This is a placeholder. "+getNBT(itemStack, "mID"));
+ }
+
+
return super.onItemRightClick(itemStack, world, par3Entity);
}
- public void readFromNBT(NBTTagCompound nbt){
- NBTTagList list = nbt.getTagList("Items", 10);
- blueprint = new ItemStack[INV_SIZE];
- for(int i = 0;i<list.tagCount();i++)
- {
- NBTTagCompound data = list.getCompoundTagAt(i);
- int slot = data.getInteger("Slot");
- if(slot >= 0 && slot < INV_SIZE)
+ public ItemStack[] readItemsFromNBT(ItemStack itemStack){
+ ItemStack[] blueprint = new ItemStack[9];
+ if (itemStack.hasTagCompound()){
+ NBTTagCompound nbt = itemStack.getTagCompound();
+ NBTTagList list = nbt.getTagList("Items", 10);
+ blueprint = new ItemStack[INV_SIZE];
+ for(int i = 0;i<list.tagCount();i++)
{
- blueprint[slot] = ItemStack.loadItemStackFromNBT(data);
+ NBTTagCompound data = list.getCompoundTagAt(i);
+ int slot = data.getInteger("Slot");
+ if(slot >= 0 && slot < INV_SIZE)
+ {
+ blueprint[slot] = ItemStack.loadItemStackFromNBT(data);
+ }
}
+ return blueprint;
}
+ return null;
}
- public void writeToNBT(NBTTagCompound nbt){
- NBTTagList list = new NBTTagList();
- for(int i = 0;i<INV_SIZE;i++)
- {
- ItemStack stack = blueprint[i];
- if(stack != null)
+ public ItemStack writeItemsToNBT(ItemStack itemStack, ItemStack[] craftingGrid){
+ ItemStack[] blueprint = craftingGrid;
+ if (itemStack.hasTagCompound()){
+ NBTTagCompound nbt = itemStack.getTagCompound();
+ NBTTagList list = new NBTTagList();
+ for(int i = 0;i<INV_SIZE;i++)
{
- NBTTagCompound data = new NBTTagCompound();
- stack.writeToNBT(data);
- data.setInteger("Slot", i);
- list.appendTag(data);
+ ItemStack stack = blueprint[i];
+ if(stack != null)
+ {
+ NBTTagCompound data = new NBTTagCompound();
+ stack.writeToNBT(data);
+ data.setInteger("Slot", i);
+ list.appendTag(data);
+ }
}
+ nbt.setTag("Items", list);
+ itemStack.setTagCompound(nbt);
+ return itemStack;
}
- nbt.setTag("Items", list);
+ return null;
}
@Override
@@ -115,7 +147,15 @@ public class ItemBlueprint extends Item implements IItemBlueprint{
@Override
public boolean setBlueprint(ItemStack stack, IInventory craftingTable, ItemStack output) {
- if (!mHasBlueprint){
+ boolean hasBP = false;
+ ItemStack[] blueprint = new ItemStack[9];
+
+ if (stack.hasTagCompound()){
+ hasBP = (boolean) getNBT(stack, "mBlueprint");
+ blueprint = readItemsFromNBT(stack);
+ }
+
+ if (!hasBP){
try {
for (int o=0; o<craftingTable.getSizeInventory(); o++){
blueprint[o] = craftingTable.getStackInSlot(o);
@@ -123,9 +163,20 @@ public class ItemBlueprint extends Item implements IItemBlueprint{
blueprint[0].stackSize = 0;
}
}
+ writeItemsToNBT(stack, blueprint);
+ if (stack.hasTagCompound()){
+ if(stack.getTagCompound().getCompoundTag("Items") != null){
+ stack.stackTagCompound.setBoolean("mBlueprint", true);
+ }
+ else {
+ //Invalid BP saved?
+ }
+ hasBP = (boolean) getNBT(stack, "mBlueprint");
+ }
+
if (output != null){
- setBlueprintName(output.getDisplayName());
- return (mHasBlueprint = true);
+ setBlueprintName(stack, output.getDisplayName());
+ return (hasBP = true);
}
return false;
} catch (Throwable t){
@@ -136,17 +187,24 @@ public class ItemBlueprint extends Item implements IItemBlueprint{
}
@Override
- public void setBlueprintName(String name) {
- this.mName = name;
+ public void setBlueprintName(ItemStack stack, String name) {
+ stack.stackTagCompound.setString("mName", name);
}
@Override
public boolean hasBlueprint(ItemStack stack) {
- return mHasBlueprint;
+ if (stack.hasTagCompound()){
+ return (boolean) getNBT(stack, "mBlueprint");
+ }
+ return false;
}
@Override
public ItemStack[] getBlueprint(ItemStack stack) {
+ ItemStack[] blueprint = new ItemStack[9];
+ if (stack.hasTagCompound()){
+ blueprint = readItemsFromNBT(stack);
+ }
try {
ItemStack[] returnStack = new ItemStack[9];
for (int o=0; o<blueprint.length; o++){
@@ -161,4 +219,73 @@ public class ItemBlueprint extends Item implements IItemBlueprint{
}
}
+ public boolean createNBT(ItemStack itemStack){
+ if (itemStack.hasTagCompound()){
+ if (!itemStack.stackTagCompound.getBoolean("mBlueprint") && !itemStack.stackTagCompound.getString("mName").equals("")){
+ //No Blueprint and no name Set
+ Utils.LOG_INFO("No Blueprint and no name Set");
+ return false;
+ }
+ else if (itemStack.stackTagCompound.getBoolean("mBlueprint") && !itemStack.stackTagCompound.getString("mName").equals("")){
+ //Has Blueprint but invalid name set
+ Utils.LOG_INFO("Has Blueprint but invalid name set");
+ //itemStack.stackTagCompound = null;
+ //createNBT(itemStack);
+ return false;
+ }
+ else if (!itemStack.stackTagCompound.getBoolean("mBlueprint") && itemStack.stackTagCompound.getString("mName").equals("")){
+ //Has no Blueprint, but strangely has a name
+ Utils.LOG_INFO("Has no Blueprint, but strangely has a name");
+ //itemStack.stackTagCompound = null;
+ //createNBT(itemStack);
+ return false;
+ }
+ return false;
+ }
+ else if(!itemStack.hasTagCompound()){
+ int bpID = MathUtils.randInt(0, 1000);
+ boolean hasRecipe = false;
+ String recipeName = "";
+ Utils.LOG_INFO("Creating Blueprint, setting up it's NBT data. "+bpID);
+ itemStack.stackTagCompound = new NBTTagCompound();
+ itemStack.stackTagCompound.setInteger("mID", bpID);
+ itemStack.stackTagCompound.setBoolean("mBlueprint", hasRecipe);
+ itemStack.stackTagCompound.setString("mName", recipeName);
+ return true;
+ }
+ else {
+ int bpID = MathUtils.randInt(0, 1000);
+ boolean hasRecipe = false;
+ String recipeName = "";
+ Utils.LOG_INFO("Creating a Blueprint, setting up it's NBT data. "+bpID);
+ itemStack.stackTagCompound = new NBTTagCompound();
+ itemStack.stackTagCompound.setInteger("mID", bpID);
+ itemStack.stackTagCompound.setBoolean("mBlueprint", hasRecipe);
+ itemStack.stackTagCompound.setString("mName", recipeName);
+ return true;
+ }
+ }
+
+ public Object getNBT(ItemStack itemStack, String tagNBT){
+ if (!itemStack.hasTagCompound()){
+ return null;
+ }
+ Object o = null;
+ if (tagNBT.equals("mID")){
+ o = itemStack.stackTagCompound.getInteger(tagNBT);
+ }
+ else if (tagNBT.equals("mBlueprint")){
+ o = itemStack.stackTagCompound.getBoolean(tagNBT);
+ }
+ else if (tagNBT.equals("mName")){
+ o = itemStack.stackTagCompound.getString(tagNBT);
+ }
+ else if (tagNBT.equals("")){
+ //For More Tag Support
+ //o = itemStack.stackTagCompound.getInteger(tagNBT);
+ }
+ if (o != null)
+ return o;
+ return null; }
+
}