aboutsummaryrefslogtreecommitdiff
path: root/src
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
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')
-rw-r--r--src/Java/gtPlusPlus/core/container/Container_ModularityTable.java1
-rw-r--r--src/Java/gtPlusPlus/core/gui/machine/GUI_ModularityTable.java11
-rw-r--r--src/Java/gtPlusPlus/core/inventories/modulartable/InventoryModularOutput.java123
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/machines/TileEntityModularityTable.java117
4 files changed, 173 insertions, 79 deletions
diff --git a/src/Java/gtPlusPlus/core/container/Container_ModularityTable.java b/src/Java/gtPlusPlus/core/container/Container_ModularityTable.java
index 244212ccb2..d870750039 100644
--- a/src/Java/gtPlusPlus/core/container/Container_ModularityTable.java
+++ b/src/Java/gtPlusPlus/core/container/Container_ModularityTable.java
@@ -41,6 +41,7 @@ public class Container_ModularityTable extends Container {
this.inventoryOutputs = tile.inventoryOutputs;
this.tile_entity.setContainer(this);
this.mRecipeTime = this.tile_entity.getRecipeTime();
+ Utils.LOG_INFO("Container: "+this.mRecipeTime);
int var6;
int var7;
diff --git a/src/Java/gtPlusPlus/core/gui/machine/GUI_ModularityTable.java b/src/Java/gtPlusPlus/core/gui/machine/GUI_ModularityTable.java
index a6fc8e70af..a11d6dc6d4 100644
--- a/src/Java/gtPlusPlus/core/gui/machine/GUI_ModularityTable.java
+++ b/src/Java/gtPlusPlus/core/gui/machine/GUI_ModularityTable.java
@@ -7,6 +7,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import gtPlusPlus.core.container.Container_ModularityTable;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.tileentities.machines.TileEntityModularityTable;
+import gtPlusPlus.core.util.Utils;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
@@ -33,11 +34,15 @@ public class GUI_ModularityTable extends GuiContainer {
@Override
protected void drawGuiContainerForegroundLayer(final int i, final int j){
+ if (this.mThisTile.getRecipeTime() > -1){
+ this.mRecipeTime = this.mThisTile.getRecipeTime();
+ }
+ //Utils.LOG_INFO("Container: "+this.mRecipeTime);
this.fontRendererObj.drawString(I18n.format("Modularity Table", new Object[0]), 8, 6, 4210752);
if (mRecipeTime > -1){
- this.fontRendererObj.drawString(I18n.format("Time", new Object[0]), 8, 6, 4210752);
- this.fontRendererObj.drawString(I18n.format("Remaining", new Object[0]), 8, 6, 4210752);
- this.fontRendererObj.drawString(I18n.format(""+this.mRecipeTime, new Object[0]), 8, 6, 4210752);
+ this.fontRendererObj.drawString(I18n.format("Time", new Object[0]), 84, 42, 4210752);
+ this.fontRendererObj.drawString(I18n.format("Remaining", new Object[0]), 84, 50, 4210752);
+ this.fontRendererObj.drawString(I18n.format(""+this.mRecipeTime+" Ticks", new Object[0]), 84, 58, 4210752);
}
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
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
diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityModularityTable.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityModularityTable.java
index 406d1c9fa2..0a0561ee73 100644
--- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityModularityTable.java
+++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityModularityTable.java
@@ -26,12 +26,14 @@ public class TileEntityModularityTable extends TileEntity {
public InventoryModularMain inventoryGrid;
public InventoryModularOutput inventoryOutputs;
+ public InventoryModularOutput mTempRecipeStorage;
private Container_ModularityTable container;
- private int mRecipeTimeRemaining = 0;
+ private int mRecipeTimeRemaining = -1;
public TileEntityModularityTable() {
this.inventoryGrid = new InventoryModularMain();
this.inventoryOutputs = new InventoryModularOutput();
+ this.mTempRecipeStorage = new InventoryModularOutput();
this.canUpdate();
generateAllValidUpgrades();
}
@@ -61,6 +63,8 @@ public class TileEntityModularityTable extends TileEntity {
super.writeToNBT(nbt);
nbt.setInteger("mRecipeTime", this.mRecipeTimeRemaining);
this.inventoryOutputs.writeToNBT(this.getTag(nbt, "ContentsOutput"));
+ this.inventoryGrid.writeToNBT(this.getTag(nbt, "ContentsGrid"));
+ this.mTempRecipeStorage.writeToNBT(this.getTag(nbt, "ContentsRecipeTemp"));
}
@@ -70,20 +74,41 @@ public class TileEntityModularityTable extends TileEntity {
super.readFromNBT(nbt);
this.mRecipeTimeRemaining = nbt.getInteger("mRecipeTime");
this.inventoryOutputs.readFromNBT(nbt.getCompoundTag("ContentsOutput"));
+ this.inventoryGrid.readFromNBT(nbt.getCompoundTag("ContentsGrid"));
+ this.mTempRecipeStorage.readFromNBT(nbt.getCompoundTag("ContentsRecipeTemp"));
}
@Override
public void updateEntity() {
if (!this.worldObj.isRemote) {
+
+ //Check for active recipe
+ if (this.mRecipeTimeRemaining > -1 || (this.mTempRecipeStorage != null) && (this.mTempRecipeStorage.getRecipeTime() > -1)){
+ if ((this.mTempRecipeStorage != null) && this.mTempRecipeStorage.getRecipeTime() > -1){
+ if (this.mRecipeTimeRemaining < this.mTempRecipeStorage.getRecipeTime()){
+ this.mRecipeTimeRemaining = this.mTempRecipeStorage.getRecipeTime();
+ this.markDirty();
+ }
+ }
+ if (this.mInputstackA != null && this.mInputstackB != null && this.mOutputStack != null){
+ this.mTempRecipeStorage.setInventorySlotContents(0, this.mInputstackA);
+ this.mTempRecipeStorage.setInventorySlotContents(1, this.mInputstackB);
+ this.mTempRecipeStorage.setInventorySlotContents(2, this.mOutputStack);
+ this.mTempRecipeStorage.setRecipeTime(this.mRecipeTimeRemaining);
+ this.markDirty();
+ }
+ }
+
boolean removeInputA = false;
boolean removeInputB = false;
// Data stick
ItemStack tBauble = this.inventoryOutputs.getStackInSlot(0);
ItemStack tUpgrade = this.inventoryOutputs.getStackInSlot(1);
if (tBauble != null && tUpgrade != null && this.container != null) {
- if (tBauble.getItem() instanceof ModularBauble) {
+ if (tBauble.getItem() instanceof ModularBauble && this.mRecipeTimeRemaining == -1) {
if (tUpgrade != null && tBauble != null) {
removeInputA = true;
+ this.setInputStacks(tBauble, tUpgrade);
try {
removeInputB = addUpgrade(tUpgrade, tBauble);
if (!removeInputB) {
@@ -91,15 +116,19 @@ public class TileEntityModularityTable extends TileEntity {
} catch (Throwable t) {
}
if (removeInputA && removeInputB) {
- if (this.inventoryOutputs.getStackInSlot(1).stackSize > 1) {
- ItemStack mTempStack = this.inventoryOutputs.getStackInSlot(1);
- mTempStack.stackSize--;
- this.inventoryOutputs.setInventorySlotContents(1, mTempStack);
- } else {
- this.inventoryOutputs.setInventorySlotContents(1, null);
- }
- this.inventoryOutputs.setInventorySlotContents(0, null);
- this.mRecipeTimeRemaining = 500;
+ if (this.setOutputStack(tBauble)){
+ if (this.inventoryOutputs.getStackInSlot(1).stackSize > 1) {
+ ItemStack mTempStack = this.inventoryOutputs.getStackInSlot(1);
+ mTempStack.stackSize--;
+ this.inventoryOutputs.setInventorySlotContents(1, mTempStack);
+ } else {
+ this.inventoryOutputs.setInventorySlotContents(1, null);
+ }
+ this.inventoryOutputs.setInventorySlotContents(0, null);
+
+ this.mRecipeTimeRemaining = 80;
+ this.markDirty();
+ }
} else {
Utils.LOG_INFO("1: " + removeInputA + " | 2: " + removeInputB);
}
@@ -108,18 +137,78 @@ public class TileEntityModularityTable extends TileEntity {
}
if (mRecipeTimeRemaining == 0){
- this.inventoryOutputs.setInventorySlotContents(2, tBauble);
+ this.inventoryOutputs.setInventorySlotContents(2, this.getPendingOutputItem());
+ clearRecipeData();
+ this.mTempRecipeStorage.setRecipeTime(this.mRecipeTimeRemaining);
+ this.markDirty();
}
- else if (mRecipeTimeRemaining == -1){
+ /*else if (mRecipeTimeRemaining == -1){
mRecipeTimeRemaining = -1;
- }
+ }*/
else if (mRecipeTimeRemaining > 0){
mRecipeTimeRemaining--;
+ this.mTempRecipeStorage.setRecipeTime(this.mRecipeTimeRemaining);
+ //Utils.LOG_INFO("Remaining: "+this.mRecipeTimeRemaining);
}
}
super.updateEntity();
}
+
+ protected ItemStack mOutputStack; //Upgraded Bauble
+ protected ItemStack mInputstackA; //Bauble
+ protected ItemStack mInputstackB; //Upgrade
+
+ public ItemStack getPendingOutputItem(){
+ this.mRecipeTimeRemaining--;
+ return this.mOutputStack;
+ }
+
+ public ItemStack[] getCurrentInputItems(){
+ if (this.mRecipeTimeRemaining < 0){
+ return null;
+ }
+ else {
+ return new ItemStack[]{this.mInputstackA, this.mInputstackB};
+ }
+ }
+
+ public boolean setInputStacks(ItemStack tBauble, ItemStack tUpgrade){
+ if (tBauble != null){
+ this.mInputstackA = tBauble;
+ }
+ else {
+ this.mInputstackA = null;
+ }
+ if (tUpgrade != null){
+ this.mInputstackB = tBauble;
+ }
+ else {
+ this.mInputstackB = null;
+ }
+ if (this.mInputstackA != null && this.mInputstackB != null){
+ return true;
+ }
+ return false;
+ }
+
+ public boolean setOutputStack(ItemStack mNewBauble){
+ if (mNewBauble != null){
+ this.mOutputStack = mNewBauble;
+ return true;
+ }
+ else {
+ this.mOutputStack = null;
+ return false;
+ }
+ }
+
+ public boolean clearRecipeData(){
+ this.mInputstackA = null;
+ this.mInputstackB = null;
+ this.mOutputStack = null;
+ return true;
+ }
@Override
public boolean canUpdate() {