aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/inventories
diff options
context:
space:
mode:
authordraknyte1 <draknyte1@hotmail.com>2016-11-04 15:23:26 +1000
committerdraknyte1 <draknyte1@hotmail.com>2016-11-04 15:23:26 +1000
commit0669f5eb9d5029a8b94ec552171b0837605f7747 (patch)
tree6b40e64c04d51b7a33cf2f0b35f7232cf37c4247 /src/Java/gtPlusPlus/core/inventories
parent3654052fb63a571c5eaca7f20714b87c17f7e966 (diff)
downloadGT5-Unofficial-0669f5eb9d5029a8b94ec552171b0837605f7747.tar.gz
GT5-Unofficial-0669f5eb9d5029a8b94ec552171b0837605f7747.tar.bz2
GT5-Unofficial-0669f5eb9d5029a8b94ec552171b0837605f7747.zip
$ Cleaned up the entire project.
> Much neat, very nices.
Diffstat (limited to 'src/Java/gtPlusPlus/core/inventories')
-rw-r--r--src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java252
-rw-r--r--src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java231
-rw-r--r--src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java256
-rw-r--r--src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java180
-rw-r--r--src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java344
-rw-r--r--src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchTools.java232
-rw-r--r--src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchToolsElectric.java234
7 files changed, 791 insertions, 938 deletions
diff --git a/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java b/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java
index 3513e34a63..64e7c9cef5 100644
--- a/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java
+++ b/src/Java/gtPlusPlus/core/inventories/BaseInventoryBackpack.java
@@ -10,40 +10,44 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
-public class BaseInventoryBackpack implements IInventory{
+public class BaseInventoryBackpack implements IInventory {
- private String name = "Inventory Item";
+ /** Defining your inventory size this way is handy */
+ public static final int INV_SIZE = 8;
- /** Provides NBT Tag Compound to reference */
- private final ItemStack invItem;
+ private final String name = "Inventory Item";
- /** Defining your inventory size this way is handy */
- public static final int INV_SIZE = 8;
+ /** Provides NBT Tag Compound to reference */
+ private final ItemStack invItem;
- /** Inventory's size must be same as number of slots you add to the Container class */
- private ItemStack[] inventory = new ItemStack[INV_SIZE];
+ /**
+ * Inventory's size must be same as number of slots you add to the Container
+ * class
+ */
+ private final ItemStack[] inventory = new ItemStack[BaseInventoryBackpack.INV_SIZE];
// declaration of variable:
- protected String uniqueID;
+ protected String uniqueID;
/**
- * @param itemstack - the ItemStack to which this inventory belongs
+ * @param itemstack
+ * - the ItemStack to which this inventory belongs
*/
- public BaseInventoryBackpack(ItemStack stack)
- {
- invItem = stack;
+ public BaseInventoryBackpack(final ItemStack stack) {
+ this.invItem = stack;
/** initialize variable within the constructor: */
- uniqueID = "";
+ this.uniqueID = "";
- if (!stack.hasTagCompound())
- {
+ if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
- // no tag compound means the itemstack does not yet have a UUID, so assign one:
- uniqueID = UUID.randomUUID().toString();
- }
-
- // Create a new NBT Tag Compound if one doesn't already exist, or you will crash
+ // no tag compound means the itemstack does not yet have a UUID, so
+ // assign one:
+ this.uniqueID = UUID.randomUUID().toString();
+ }
+
+ // Create a new NBT Tag Compound if one doesn't already exist, or you
+ // will crash
if (!stack.hasTagCompound()) {
stack.setTagCompound(new NBTTagCompound());
}
@@ -52,189 +56,175 @@ public class BaseInventoryBackpack implements IInventory{
// either reference will change in the other
// Read the inventory contents from NBT
- readFromNBT(stack.getTagCompound());
- }
- @Override
- public int getSizeInventory()
- {
- return inventory.length;
+ this.readFromNBT(stack.getTagCompound());
}
+ // 1.7.2+ renamed to closeInventory(EntityPlayer player)
@Override
- public ItemStack getStackInSlot(int slot)
- {
- return inventory[slot];
+ public void closeInventory() {
}
@Override
- public ItemStack decrStackSize(int slot, int amount)
- {
- ItemStack stack = getStackInSlot(slot);
- if(stack != null)
- {
- if(stack.stackSize > amount)
- {
+ public ItemStack decrStackSize(final int slot, final int amount) {
+ ItemStack stack = this.getStackInSlot(slot);
+ if (stack != null) {
+ if (stack.stackSize > amount) {
stack = stack.splitStack(amount);
// Don't forget this line or your inventory will not be saved!
- markDirty();
+ this.markDirty();
}
- else
- {
- // this method also calls markDirty, so we don't need to call it again
- setInventorySlotContents(slot, null);
+ else {
+ // this method also calls markDirty, so we don't need to call it
+ // again
+ this.setInventorySlotContents(slot, null);
}
}
return stack;
}
+ // 1.7.2+ renamed to getInventoryName
@Override
- public ItemStack getStackInSlotOnClosing(int slot)
- {
- ItemStack stack = getStackInSlot(slot);
- setInventorySlotContents(slot, null);
- return stack;
+ public String getInventoryName() {
+ return this.name;
}
@Override
- public void setInventorySlotContents(int slot, ItemStack stack)
- {
- inventory[slot] = stack;
-
- if (stack != null && stack.stackSize > getInventoryStackLimit())
- {
- stack.stackSize = getInventoryStackLimit();
- }
+ public int getInventoryStackLimit() {
+ return 64;
+ }
- // Don't forget this line or your inventory will not be saved!
- markDirty();
+ @Override
+ public int getSizeInventory() {
+ return this.inventory.length;
}
- // 1.7.2+ renamed to getInventoryName
@Override
- public String getInventoryName()
- {
- return name;
+ public ItemStack getStackInSlot(final int slot) {
+ return this.inventory[slot];
}
- // 1.7.2+ renamed to hasCustomInventoryName
@Override
- public boolean hasCustomInventoryName()
- {
- return name.length() > 0;
+ public ItemStack getStackInSlotOnClosing(final int slot) {
+ final ItemStack stack = this.getStackInSlot(slot);
+ this.setInventorySlotContents(slot, null);
+ return stack;
}
+ // 1.7.2+ renamed to hasCustomInventoryName
@Override
- public int getInventoryStackLimit()
- {
- return 64;
+ public boolean hasCustomInventoryName() {
+ return this.name.length() > 0;
}
/**
- * This is the method that will handle saving the inventory contents, as it is called (or should be called!)
- * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also
- * let you change things in your inventory without ever opening a Gui, if you want.
+ * This method doesn't seem to do what it claims to do, as items can still
+ * be left-clicked and placed in the inventory even when this returns false
*/
- // 1.7.2+ renamed to markDirty
@Override
- public void markDirty()
- {
- for (int i = 0; i < getSizeInventory(); ++i)
- {
- if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) {
- inventory[i] = null;
- }
- }
-
- // This line here does the work:
- writeToNBT(invItem.getTagCompound());
+ public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) {
+ // Don't want to be able to store the inventory item within itself
+ // Bad things will happen, like losing your inventory
+ // Actually, this needs a custom Slot to work
+ return !(itemstack.getItem() instanceof BaseItemBackpack);
}
@Override
- public boolean isUseableByPlayer(EntityPlayer entityplayer)
- {
+ public boolean isUseableByPlayer(final EntityPlayer entityplayer) {
return true;
}
- // 1.7.2+ renamed to openInventory(EntityPlayer player)
+ /**
+ * This is the method that will handle saving the inventory contents, as it
+ * is called (or should be called!) anytime the inventory changes. Perfect.
+ * Much better than using onUpdate in an Item, as this will also let you
+ * change things in your inventory without ever opening a Gui, if you want.
+ */
+ // 1.7.2+ renamed to markDirty
@Override
- public void openInventory() {}
+ public void markDirty() {
+ for (int i = 0; i < this.getSizeInventory(); ++i) {
+ if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) {
+ this.inventory[i] = null;
+ }
+ }
- // 1.7.2+ renamed to closeInventory(EntityPlayer player)
- @Override
- public void closeInventory() {}
+ // This line here does the work:
+ this.writeToNBT(this.invItem.getTagCompound());
+ }
- /**
- * This method doesn't seem to do what it claims to do, as
- * items can still be left-clicked and placed in the inventory
- * even when this returns false
- */
+ // 1.7.2+ renamed to openInventory(EntityPlayer player)
@Override
- public boolean isItemValidForSlot(int slot, ItemStack itemstack)
- {
- // Don't want to be able to store the inventory item within itself
- // Bad things will happen, like losing your inventory
- // Actually, this needs a custom Slot to work
- return !(itemstack.getItem() instanceof BaseItemBackpack);
+ public void openInventory() {
}
/**
* A custom method to read our inventory from an ItemStack's NBT compound
*/
- public void readFromNBT(NBTTagCompound compound)
- {
+ public void readFromNBT(final NBTTagCompound compound) {
// Gets the custom taglist we wrote to this compound, if any
- // 1.7.2+ change to compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);
- NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);
-
- if ("".equals(uniqueID))
- {
+ // 1.7.2+ change to compound.getTagList("ItemInventory",
+ // Constants.NBT.TAG_COMPOUND);
+ final NBTTagList items = compound.getTagList("ItemInventory", Constants.NBT.TAG_COMPOUND);
+
+ if ("".equals(this.uniqueID)) {
// try to read unique ID from NBT
- uniqueID = compound.getString("uniqueID");
+ this.uniqueID = compound.getString("uniqueID");
// if it's still "", assign a new one:
- if ("".equals(uniqueID))
- {
- uniqueID = UUID.randomUUID().toString();
+ if ("".equals(this.uniqueID)) {
+ this.uniqueID = UUID.randomUUID().toString();
}
}
- for (int i = 0; i < items.tagCount(); ++i)
- {
+ for (int i = 0; i < items.tagCount(); ++i) {
// 1.7.2+ change to items.getCompoundTagAt(i)
- NBTTagCompound item = (NBTTagCompound) items.getCompoundTagAt(i);
- int slot = item.getInteger("Slot");
+ final NBTTagCompound item = items.getCompoundTagAt(i);
+ final int slot = item.getInteger("Slot");
- // Just double-checking that the saved slot index is within our inventory array bounds
- if (slot >= 0 && slot < getSizeInventory()) {
- inventory[slot] = ItemStack.loadItemStackFromNBT(item);
+ // Just double-checking that the saved slot index is within our
+ // inventory array bounds
+ if (slot >= 0 && slot < this.getSizeInventory()) {
+ this.inventory[slot] = ItemStack.loadItemStackFromNBT(item);
}
}
}
+ @Override
+ public void setInventorySlotContents(final int slot, final ItemStack stack) {
+ this.inventory[slot] = stack;
+
+ if (stack != null && stack.stackSize > this.getInventoryStackLimit()) {
+ stack.stackSize = this.getInventoryStackLimit();
+ }
+
+ // Don't forget this line or your inventory will not be saved!
+ this.markDirty();
+ }
+
/**
* A custom method to write our inventory to an ItemStack's NBT compound
*/
- public void writeToNBT(NBTTagCompound tagcompound)
- {
+ public void writeToNBT(final NBTTagCompound tagcompound) {
// Create a new NBT Tag List to store itemstacks as NBT Tags
- NBTTagList items = new NBTTagList();
+ final NBTTagList items = new NBTTagList();
- for (int i = 0; i < getSizeInventory(); ++i)
- {
+ for (int i = 0; i < this.getSizeInventory(); ++i) {
// Only write stacks that contain items
- if (getStackInSlot(i) != null)
- {
- // Make a new NBT Tag Compound to write the itemstack and slot index to
- NBTTagCompound item = new NBTTagCompound();
+ if (this.getStackInSlot(i) != null) {
+ // Make a new NBT Tag Compound to write the itemstack and slot
+ // index to
+ final NBTTagCompound item = new NBTTagCompound();
item.setInteger("Slot", i);
- // Writes the itemstack in slot(i) to the Tag Compound we just made
- getStackInSlot(i).writeToNBT(item);
+ // Writes the itemstack in slot(i) to the Tag Compound we just
+ // made
+ this.getStackInSlot(i).writeToNBT(item);
// add the tag compound to our tag list
items.appendTag(item);
}
}
tagcompound.setString("uniqueID", this.uniqueID);
- // Add the TagList to the ItemStack's Tag Compound with the name "ItemInventory"
+ // Add the TagList to the ItemStack's Tag Compound with the name
+ // "ItemInventory"
tagcompound.setTag("ItemInventory", items);
}
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java
index 8d147ad21c..7a3507ec55 100644
--- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java
+++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchChest.java
@@ -6,183 +6,168 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
-public class InventoryWorkbenchChest implements IInventory{
-
- private String name = "Inventory Chest";
+public class InventoryWorkbenchChest implements IInventory {
/** Defining your inventory size this way is handy */
- public static final int INV_SIZE = 16;
+ public static final int INV_SIZE = 16;
- /** Inventory's size must be same as number of slots you add to the Container class */
- private ItemStack[] inventory = new ItemStack[INV_SIZE];
+ private final String name = "Inventory Chest";
/**
- * @param itemstack - the ItemStack to which this inventory belongs
+ * Inventory's size must be same as number of slots you add to the Container
+ * class
*/
- public InventoryWorkbenchChest()
- {
-
- }
-
- public void readFromNBT(NBTTagCompound nbt)
- {
- NBTTagList list = nbt.getTagList("Items", 10);
- inventory = 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)
- {
- inventory[slot] = ItemStack.loadItemStackFromNBT(data);
- }
- }
- }
-
- public void writeToNBT(NBTTagCompound nbt)
- {
- NBTTagList list = new NBTTagList();
- for(int i = 0;i<INV_SIZE;i++)
- {
- ItemStack stack = inventory[i];
- if(stack != null)
- {
- NBTTagCompound data = new NBTTagCompound();
- stack.writeToNBT(data);
- data.setInteger("Slot", i);
- list.appendTag(data);
- }
- }
- nbt.setTag("Items", list);
- }
-
- @Override
- public int getSizeInventory()
- {
- return inventory.length;
- }
-
- public ItemStack[] getInventory(){
- return inventory;
+ private ItemStack[] inventory = new ItemStack[InventoryWorkbenchChest.INV_SIZE];
+
+ /**
+ * @param itemstack
+ * - the ItemStack to which this inventory belongs
+ */
+ public InventoryWorkbenchChest() {
+
}
+ // 1.7.2+ renamed to closeInventory(EntityPlayer player)
@Override
- public ItemStack getStackInSlot(int slot)
- {
- return inventory[slot];
+ public void closeInventory() {
}
@Override
- public ItemStack decrStackSize(int slot, int amount)
- {
- ItemStack stack = getStackInSlot(slot);
- if(stack != null)
- {
- if(stack.stackSize > amount)
- {
+ public ItemStack decrStackSize(final int slot, final int amount) {
+ ItemStack stack = this.getStackInSlot(slot);
+ if (stack != null) {
+ if (stack.stackSize > amount) {
stack = stack.splitStack(amount);
// Don't forget this line or your inventory will not be saved!
- markDirty();
+ this.markDirty();
}
- else
- {
- // this method also calls markDirty, so we don't need to call it again
- setInventorySlotContents(slot, null);
+ else {
+ // this method also calls markDirty, so we don't need to call it
+ // again
+ this.setInventorySlotContents(slot, null);
}
}
return stack;
}
+ public ItemStack[] getInventory() {
+ return this.inventory;
+ }
+
+ // 1.7.2+ renamed to getInventoryName
@Override
- public ItemStack getStackInSlotOnClosing(int slot)
- {
- ItemStack stack = getStackInSlot(slot);
- setInventorySlotContents(slot, null);
- return stack;
+ public String getInventoryName() {
+ return this.name;
}
@Override
- public void setInventorySlotContents(int slot, ItemStack stack)
- {
- inventory[slot] = stack;
+ public int getInventoryStackLimit() {
+ return 64;
+ }
- if (stack != null && stack.stackSize > getInventoryStackLimit())
- {
- stack.stackSize = getInventoryStackLimit();
- }
+ @Override
+ public int getSizeInventory() {
+ return this.inventory.length;
+ }
- // Don't forget this line or your inventory will not be saved!
- markDirty();
+ @Override
+ public ItemStack getStackInSlot(final int slot) {
+ return this.inventory[slot];
}
- // 1.7.2+ renamed to getInventoryName
@Override
- public String getInventoryName()
- {
- return name;
+ public ItemStack getStackInSlotOnClosing(final int slot) {
+ final ItemStack stack = this.getStackInSlot(slot);
+ this.setInventorySlotContents(slot, null);
+ return stack;
}
// 1.7.2+ renamed to hasCustomInventoryName
@Override
- public boolean hasCustomInventoryName()
- {
- return name.length() > 0;
+ public boolean hasCustomInventoryName() {
+ return this.name.length() > 0;
}
+ /**
+ * This method doesn't seem to do what it claims to do, as items can still
+ * be left-clicked and placed in the inventory even when this returns false
+ */
@Override
- public int getInventoryStackLimit()
- {
- return 64;
+ public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) {
+ // Don't want to be able to store the inventory item within itself
+ // Bad things will happen, like losing your inventory
+ // Actually, this needs a custom Slot to work
+ return true;
+ }
+
+ @Override
+ public boolean isUseableByPlayer(final EntityPlayer entityplayer) {
+ return true;
}
/**
- * This is the method that will handle saving the inventory contents, as it is called (or should be called!)
- * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also
- * let you change things in your inventory without ever opening a Gui, if you want.
+ * This is the method that will handle saving the inventory contents, as it
+ * is called (or should be called!) anytime the inventory changes. Perfect.
+ * Much better than using onUpdate in an Item, as this will also let you
+ * change things in your inventory without ever opening a Gui, if you want.
*/
// 1.7.2+ renamed to markDirty
@Override
- public void markDirty()
- {
- for (int i = 0; i < getSizeInventory(); ++i)
- {
- ItemStack temp = getStackInSlot(i);
- if (temp != null){
- //Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+" x"+temp.stackSize);
+ public void markDirty() {
+ for (int i = 0; i < this.getSizeInventory(); ++i) {
+ final ItemStack temp = this.getStackInSlot(i);
+ if (temp != null) {
+ // Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+"
+ // x"+temp.stackSize);
}
-
+
if (temp != null && temp.stackSize == 0) {
- inventory[i] = null;
+ this.inventory[i] = null;
}
}
}
+ // 1.7.2+ renamed to openInventory(EntityPlayer player)
@Override
- public boolean isUseableByPlayer(EntityPlayer entityplayer)
- {
- return true;
+ public void openInventory() {
}
- // 1.7.2+ renamed to openInventory(EntityPlayer player)
- @Override
- public void openInventory() {}
+ public void readFromNBT(final NBTTagCompound nbt) {
+ final NBTTagList list = nbt.getTagList("Items", 10);
+ this.inventory = new ItemStack[InventoryWorkbenchChest.INV_SIZE];
+ for (int i = 0; i < list.tagCount(); i++) {
+ final NBTTagCompound data = list.getCompoundTagAt(i);
+ final int slot = data.getInteger("Slot");
+ if (slot >= 0 && slot < InventoryWorkbenchChest.INV_SIZE) {
+ this.inventory[slot] = ItemStack.loadItemStackFromNBT(data);
+ }
+ }
+ }
- // 1.7.2+ renamed to closeInventory(EntityPlayer player)
@Override
- public void closeInventory() {}
+ public void setInventorySlotContents(final int slot, final ItemStack stack) {
+ this.inventory[slot] = stack;
- /**
- * This method doesn't seem to do what it claims to do, as
- * items can still be left-clicked and placed in the inventory
- * even when this returns false
- */
- @Override
- public boolean isItemValidForSlot(int slot, ItemStack itemstack)
- {
- // Don't want to be able to store the inventory item within itself
- // Bad things will happen, like losing your inventory
- // Actually, this needs a custom Slot to work
- return true;
+ if (stack != null && stack.stackSize > this.getInventoryStackLimit()) {
+ stack.stackSize = this.getInventoryStackLimit();
+ }
+
+ // Don't forget this line or your inventory will not be saved!
+ this.markDirty();
+ }
+
+ public void writeToNBT(final NBTTagCompound nbt) {
+ final NBTTagList list = new NBTTagList();
+ for (int i = 0; i < InventoryWorkbenchChest.INV_SIZE; i++) {
+ final ItemStack stack = this.inventory[i];
+ if (stack != null) {
+ final NBTTagCompound data = new NBTTagCompound();
+ stack.writeToNBT(data);
+ data.setInteger("Slot", i);
+ list.appendTag(data);
+ }
+ }
+ nbt.setTag("Items", list);
}
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java
index 8c0738cab9..ff39d3a241 100644
--- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java
+++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchCrafting.java
@@ -6,194 +6,178 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
-public class InventoryWorkbenchCrafting implements IInventory{
-
- private String name = "Inventory Crafting";
+public class InventoryWorkbenchCrafting implements IInventory {
/** Defining your inventory size this way is handy */
- public static final int INV_SIZE = 9;
+ public static final int INV_SIZE = 9;
- /** Inventory's size must be same as number of slots you add to the Container class */
- private ItemStack[] inventory = new ItemStack[INV_SIZE];
- public final InventoryCrafting craftMatrix;
- public final Container parentContainer;
-
- public InventoryCrafting getCrafting(){
- return craftMatrix;
- }
+ private final String name = "Inventory Crafting";
+
+ /**
+ * Inventory's size must be same as number of slots you add to the Container
+ * class
+ */
+ private ItemStack[] inventory = new ItemStack[InventoryWorkbenchCrafting.INV_SIZE];
+ public final InventoryCrafting craftMatrix;
+ public final Container parentContainer;
/**
- * @param itemstack - the ItemStack to which this inventory belongs
+ * @param itemstack
+ * - the ItemStack to which this inventory belongs
*/
- public InventoryWorkbenchCrafting(Container containerR)
- {
+ public InventoryWorkbenchCrafting(final Container containerR) {
this.parentContainer = containerR;
- this.craftMatrix = new InventoryCrafting(parentContainer, 3, 3);
- }
-
- private ItemStack[] getArrayOfCraftingItems(){
- ItemStack[] array = new ItemStack[9];
- for (int i=0; i<craftMatrix.getSizeInventory();i++){
- if(craftMatrix.getStackInSlot(i) != null){
- array[i] = craftMatrix.getStackInSlot(i);
- }
- }
- return array;
- }
-
- public void readFromNBT(NBTTagCompound nbt)
- {
- NBTTagList list = nbt.getTagList("Items", 10);
- inventory = 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)
- {
- getInventory()[slot] = ItemStack.loadItemStackFromNBT(data);
- }
- }
- }
-
- public void writeToNBT(NBTTagCompound nbt)
- {
- NBTTagList list = new NBTTagList();
- for(int i = 0;i<INV_SIZE;i++)
- {
- ItemStack stack = getInventory()[i];
- if(stack != null)
- {
- NBTTagCompound data = new NBTTagCompound();
- stack.writeToNBT(data);
- data.setInteger("Slot", i);
- list.appendTag(data);
- }
- }
- nbt.setTag("Items", list);
- }
-
- @Override
- public int getSizeInventory()
- {
- return getInventory().length;
- }
-
- public ItemStack[] getInventory(){
- return getArrayOfCraftingItems();
+ this.craftMatrix = new InventoryCrafting(this.parentContainer, 3, 3);
}
+ // 1.7.2+ renamed to closeInventory(EntityPlayer player)
@Override
- public ItemStack getStackInSlot(int slot)
- {
- return getInventory()[slot];
+ public void closeInventory() {
}
@Override
- public ItemStack decrStackSize(int slot, int amount)
- {
- ItemStack stack = getStackInSlot(slot);
- if(stack != null)
- {
- if(stack.stackSize > amount)
- {
+ public ItemStack decrStackSize(final int slot, final int amount) {
+ ItemStack stack = this.getStackInSlot(slot);
+ if (stack != null) {
+ if (stack.stackSize > amount) {
stack = stack.splitStack(amount);
// Don't forget this line or your inventory will not be saved!
- markDirty();
+ this.markDirty();
}
- else
- {
- // this method also calls markDirty, so we don't need to call it again
- setInventorySlotContents(slot, null);
+ else {
+ // this method also calls markDirty, so we don't need to call it
+ // again
+ this.setInventorySlotContents(slot, null);
}
}
return stack;
}
+ private ItemStack[] getArrayOfCraftingItems() {
+ final ItemStack[] array = new ItemStack[9];
+ for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) {
+ if (this.craftMatrix.getStackInSlot(i) != null) {
+ array[i] = this.craftMatrix.getStackInSlot(i);
+ }
+ }
+ return array;
+ }
+
+ public InventoryCrafting getCrafting() {
+ return this.craftMatrix;
+ }
+
+ public ItemStack[] getInventory() {
+ return this.getArrayOfCraftingItems();
+ }
+
+ // 1.7.2+ renamed to getInventoryName
@Override
- public ItemStack getStackInSlotOnClosing(int slot)
- {
- ItemStack stack = getStackInSlot(slot);
- setInventorySlotContents(slot, null);
- return stack;
+ public String getInventoryName() {
+ return this.name;
}
@Override
- public void setInventorySlotContents(int slot, ItemStack stack)
- {
- getInventory()[slot] = stack;
+ public int getInventoryStackLimit() {
+ return 64;
+ }
- if (stack != null && stack.stackSize > getInventoryStackLimit())
- {
- stack.stackSize = getInventoryStackLimit();
- }
+ @Override
+ public int getSizeInventory() {
+ return this.getInventory().length;
+ }
- // Don't forget this line or your inventory will not be saved!
- markDirty();
+ @Override
+ public ItemStack getStackInSlot(final int slot) {
+ return this.getInventory()[slot];
}
- // 1.7.2+ renamed to getInventoryName
@Override
- public String getInventoryName()
- {
- return name;
+ public ItemStack getStackInSlotOnClosing(final int slot) {
+ final ItemStack stack = this.getStackInSlot(slot);
+ this.setInventorySlotContents(slot, null);
+ return stack;
}
// 1.7.2+ renamed to hasCustomInventoryName
@Override
- public boolean hasCustomInventoryName()
- {
- return name.length() > 0;
+ public boolean hasCustomInventoryName() {
+ return this.name.length() > 0;
}
+ /**
+ * This method doesn't seem to do what it claims to do, as items can still
+ * be left-clicked and placed in the inventory even when this returns false
+ */
@Override
- public int getInventoryStackLimit()
- {
- return 64;
+ public boolean isItemValidForSlot(final int slot, final ItemStack itemstack) {
+ // Don't want to be able to store the inventory item within itself
+ // Bad things will happen, like losing your inventory
+ // Actually, this needs a custom Slot to work
+ return true;
+ }
+
+ @Override
+ public boolean isUseableByPlayer(final EntityPlayer entityplayer) {
+ return true;
}
/**
- * This is the method that will handle saving the inventory contents, as it is called (or should be called!)
- * anytime the inventory changes. Perfect. Much better than using onUpdate in an Item, as this will also
- * let you change things in your inventory without ever opening a Gui, if you want.
+ * This is the method that will handle saving the inventory contents, as it
+ * is called (or should be called!) anytime the inventory changes. Perfect.
+ * Much better than using onUpdate in an Item, as this will also let you
+ * change things in your inventory without ever opening a Gui, if you want.
*/
// 1.7.2+ renamed to markDirty
@Override
- public void markDirty()
- {
- for (int i = 0; i < getSizeInventory(); ++i)
- {
- if (getStackInSlot(i) != null && getStackInSlot(i).stackSize == 0) {
- getInventory()[i] = null;
+ public void markDirty() {
+ for (int i = 0; i < this.getSizeInventory(); ++i) {
+ if (this.getStackInSlot(i) != null && this.getStackInSlot(i).stackSize == 0) {
+ this.getInventory()[i] = null;
}
}
}
+ // 1.7.2+ renamed to openInventory(EntityPlayer player)
@Override
- public boolean isUseableByPlayer(EntityPlayer entityplayer)
- {
- return true;
+ public void openInventory() {
}
- // 1.7.2+ renamed to openInventory(EntityPlayer player)
- @Override
- public void openInventory() {}
+ public void readFromNBT(final NBTTagCompound nbt) {
+ final NBTTagList list = nbt.getTagList("Items", 10);
+ this.inventory = new ItemStack[InventoryWorkbenchCrafting.INV_SIZE];
+ for (int i = 0; i < list.tagCount(); i++) {
+ final NBTTagCompound data = list.getCompoundTagAt(i);
+ final int slot = data.getInteger("Slot");
+ if (slot >= 0 && slot < InventoryWorkbenchCrafting.INV_SIZE) {
+ this.getInventory()[slot] = ItemStack.loadItemStackFromNBT(data);
+ }
+ }
+ }
- // 1.7.2+ renamed to closeInventory(EntityPlayer player)
@Override
- public void closeInventory() {}
+ public void setInventorySlotContents(final int slot, final ItemStack stack) {
+ this.getInventory()[slot] = stack;
- /**
- * This method doesn't seem to do what it claims to do, as
- * items can still be left-clicked and placed in the inventory
- * even when this returns false
- */
- @Override
- public boolean isItemValidForSlot(int slot, ItemStack itemstack)
- {
- // Don't want to be able to store the inventory item within itself
- // Bad things will happen, like losing your inventory
- // Actually, this needs a custom Slot to work
- return true;
+ if (stack != null && stack.stackSize > this.getInventoryStackLimit()) {
+ stack.stackSize = this.getInventoryStackLimit();
+ }
+
+ // Don't forget this line or your inventory will not be saved!
+ this.markDirty();
+ }
+
+ public void writeToNBT(final NBTTagCompound nbt) {
+ final NBTTagList list = new NBTTagList();
+ for (int i = 0; i < InventoryWorkbenchCrafting.INV_SIZE; i++) {
+ final ItemStack stack = this.getInventory()[i];
+ if (stack != null) {
+ final NBTTagCompound data = new NBTTagCompound();
+ stack.writeToNBT(data);
+ data.setInteger("Slot", i);
+ list.appendTag(data);
+ }
+ }
+ nbt.setTag("Items", list);
}
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java
index f4fe78d458..9cfa57ec08 100644
--- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java
+++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java
@@ -4,161 +4,133 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
-public class InventoryWorkbenchHoloCrafting implements IInventory{
-
- private String name = "Inventory Crafting";
+public class InventoryWorkbenchHo