aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core/inventories
diff options
context:
space:
mode:
authorAlkalus <draknyte1@hotmail.com>2017-11-12 16:09:36 +1000
committerAlkalus <draknyte1@hotmail.com>2017-11-12 16:09:36 +1000
commitda9ccc16d90b6e5e9e7e2547b67af3327751d5d4 (patch)
treeb5179b1db2e62c821d0949c25a4272d02c5da5cd /src/Java/gtPlusPlus/core/inventories
parentba953bf8c399cbb0fceccb44495bb88c4cc64213 (diff)
downloadGT5-Unofficial-da9ccc16d90b6e5e9e7e2547b67af3327751d5d4.tar.gz
GT5-Unofficial-da9ccc16d90b6e5e9e7e2547b67af3327751d5d4.tar.bz2
GT5-Unofficial-da9ccc16d90b6e5e9e7e2547b67af3327751d5d4.zip
% More changes to Modularity recipe handling.
$ Fixed issue where the recipe time remaining would not save to nbt correctly.
Diffstat (limited to 'src/Java/gtPlusPlus/core/inventories')
-rw-r--r--src/Java/gtPlusPlus/core/inventories/modulartable/InventoryModularOutput.java123
1 files changed, 61 insertions, 62 deletions
diff --git a/src/Java/gtPlusPlus/core/inventories/modulartable/InventoryModularOutput.java b/src/Java/gtPlusPlus/core/inventories/modulartable/InventoryModularOutput.java
index 0a4dc07a39..3501b7ae47 100644
--- a/src/Java/gtPlusPlus/core/inventories/modulartable/InventoryModularOutput.java
+++ b/src/Java/gtPlusPlus/core/inventories/modulartable/InventoryModularOutput.java
@@ -6,47 +6,51 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
-public class InventoryModularOutput implements IInventory{
+public class InventoryModularOutput implements IInventory {
private final String name = "Inventory Output";
/** Defining your inventory size this way is handy */
public static final int INV_SIZE = 3;
+ private int mRecpeTime = -1;
- /** Inventory's size must be same as number of slots you add to the Container class */
+ /**
+ * Inventory's size must be same as number of slots you add to the Container
+ * class
+ */
private ItemStack[] inventory = new ItemStack[INV_SIZE];
/**
- * @param itemstack - the ItemStack to which this inventory belongs
+ * @param itemstack
+ * - the ItemStack to which this inventory belongs
*/
- public InventoryModularOutput()
- {
+ public InventoryModularOutput() {
}
- public void readFromNBT(final NBTTagCompound nbt)
- {
+ public void readFromNBT(final NBTTagCompound nbt) {
+ if (this.mRecpeTime > -1) {
+ nbt.setInteger("mRecipeTime", this.mRecpeTime);
+ }
final NBTTagList list = nbt.getTagList("Items", 10);
this.inventory = new ItemStack[INV_SIZE];
- for(int i = 0;i<list.tagCount();i++)
- {
+ for (int i = 0; i < list.tagCount(); i++) {
final NBTTagCompound data = list.getCompoundTagAt(i);
final int slot = data.getInteger("Slot");
- if((slot >= 0) && (slot < INV_SIZE))
- {
+ if ((slot >= 0) && (slot < INV_SIZE)) {
this.inventory[slot] = ItemStack.loadItemStackFromNBT(data);
}
}
}
- public void writeToNBT(final NBTTagCompound nbt)
- {
+ public void writeToNBT(final NBTTagCompound nbt) {
final NBTTagList list = new NBTTagList();
- for(int i = 0;i<INV_SIZE;i++)
- {
+ if (nbt.hasKey("mRecipeTime")) {
+ this.mRecpeTime = nbt.getInteger("mRecipeTime");
+ }
+ for (int i = 0; i < INV_SIZE; i++) {
final ItemStack stack = this.inventory[i];
- if(stack != null)
- {
+ if (stack != null) {
final NBTTagCompound data = new NBTTagCompound();
stack.writeToNBT(data);
data.setInteger("Slot", i);
@@ -56,37 +60,39 @@ public class InventoryModularOutput implements IInventory{
nbt.setTag("Items", list);
}
+ public int setRecipeTime(int mTime) {
+ return (this.mRecpeTime = mTime);
+ }
+
+ public int getRecipeTime() {
+ return this.mRecpeTime;
+ }
+
@Override
- public int getSizeInventory()
- {
+ public int getSizeInventory() {
return this.inventory.length;
}
- public ItemStack[] getInventory(){
+ public ItemStack[] getInventory() {
return this.inventory;
}
@Override
- public ItemStack getStackInSlot(final int slot)
- {
+ public ItemStack getStackInSlot(final int slot) {
return this.inventory[slot];
}
@Override
- public ItemStack decrStackSize(final int slot, final int amount)
- {
+ public ItemStack decrStackSize(final int slot, final int amount) {
ItemStack stack = this.getStackInSlot(slot);
- if(stack != null)
- {
- if(stack.stackSize > amount)
- {
+ if (stack != null) {
+ if (stack.stackSize > amount) {
stack = stack.splitStack(amount);
// Don't forget this line or your inventory will not be saved!
this.markDirty();
- }
- else
- {
- // this method also calls markDirty, so we don't need to call it again
+ } else {
+ // this method also calls markDirty, so we don't need to call it
+ // again
this.setInventorySlotContents(slot, null);
}
}
@@ -94,20 +100,17 @@ public class InventoryModularOutput implements IInventory{
}
@Override
- public ItemStack getStackInSlotOnClosing(final int slot)
- {
+ public ItemStack getStackInSlotOnClosing(final int slot) {
final ItemStack stack = this.getStackInSlot(slot);
this.setInventorySlotContents(slot, null);
return stack;
}
@Override
- public void setInventorySlotContents(final int slot, final ItemStack stack)
- {
+ public void setInventorySlotContents(final int slot, final ItemStack stack) {
this.inventory[slot] = stack;
- if ((stack != null) && (stack.stackSize > this.getInventoryStackLimit()))
- {
+ if ((stack != null) && (stack.stackSize > this.getInventoryStackLimit())) {
stack.stackSize = this.getInventoryStackLimit();
}
@@ -117,38 +120,35 @@ public class InventoryModularOutput implements IInventory{
// 1.7.2+ renamed to getInventoryName
@Override
- public String getInventoryName()
- {
+ public String getInventoryName() {
return this.name;
}
// 1.7.2+ renamed to hasCustomInventoryName
@Override
- public boolean hasCustomInventoryName()
- {
+ public boolean hasCustomInventoryName() {
return this.name.length() > 0;
}
@Override
- public int getInventoryStackLimit()
- {
+ public int getInventoryStackLimit() {
return 64;
}
/**
- * 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 < this.getSizeInventory(); ++i)
- {
+ 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) {
+ // Utils.LOG_INFO("Slot "+i+" contains "+temp.getDisplayName()+"
+ // x"+temp.stackSize);
}
if ((temp != null) && (temp.stackSize == 0)) {
@@ -158,27 +158,26 @@ public class InventoryModularOutput implements IInventory{
}
@Override
- public boolean isUseableByPlayer(final EntityPlayer entityplayer)
- {
+ public boolean isUseableByPlayer(final EntityPlayer entityplayer) {
return true;
}
// 1.7.2+ renamed to openInventory(EntityPlayer player)
@Override
- public void openInventory() {}
+ public void openInventory() {
+ }
// 1.7.2+ renamed to closeInventory(EntityPlayer player)
@Override
- public void closeInventory() {}
+ public void closeInventory() {
+ }
/**
- * 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
+ * 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(final int slot, final ItemStack itemstack)
- {
+ 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