aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/core
diff options
context:
space:
mode:
authorAlkalus <draknyte1@hotmail.com>2017-09-12 17:04:35 +1000
committerAlkalus <draknyte1@hotmail.com>2017-09-12 17:04:35 +1000
commitcdc728c5b606d6d3d49dce77c18f875a1f8379c6 (patch)
tree8e48d0e8fe2aa88547b9a00b56bce51a3022ea3f /src/Java/gtPlusPlus/core
parent72905a7d18b0c5fca8a8edf3ed38b17d7f11f415 (diff)
downloadGT5-Unofficial-cdc728c5b606d6d3d49dce77c18f875a1f8379c6.tar.gz
GT5-Unofficial-cdc728c5b606d6d3d49dce77c18f875a1f8379c6.tar.bz2
GT5-Unofficial-cdc728c5b606d6d3d49dce77c18f875a1f8379c6.zip
+ Auto Crafter now consumes items when found for a recipe.
+ Auto Crafter now outputs item when all 9 inputs are valid. + Added Read & Write to NBT functions to NBTUtils class. % Project Table now stores inputs and output to a Data Stick.
Diffstat (limited to 'src/Java/gtPlusPlus/core')
-rw-r--r--src/Java/gtPlusPlus/core/container/Container_ProjectTable.java30
-rw-r--r--src/Java/gtPlusPlus/core/tileentities/machines/TileEntityProjectTable.java25
-rw-r--r--src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java37
3 files changed, 83 insertions, 9 deletions
diff --git a/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java b/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java
index 0100a422c1..3a256d07a9 100644
--- a/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java
+++ b/src/Java/gtPlusPlus/core/container/Container_ProjectTable.java
@@ -37,6 +37,7 @@ public class Container_ProjectTable extends Container {
this.tile_entity = tile;
this.inventoryGrid = tile.inventoryGrid;
this.inventoryOutputs = tile.inventoryOutputs;
+ this.tile_entity.setContainer(this);
int var6;
int var7;
@@ -49,10 +50,10 @@ public class Container_ProjectTable extends Container {
//Output slots
- this.addSlotToContainer(new SlotDataStick(this.inventoryOutputs, 0, 26+(18*4), 7));
- this.addSlotToContainer(new SlotNoInput(this.inventoryOutputs, 1, 26+(18*4), 43));
+ this.addSlotToContainer(new SlotDataStick(this.inventoryOutputs, 0, 26+(18*6), 7));
+ this.addSlotToContainer(new SlotNoInput(this.inventoryOutputs, 1, 26+(18*6), 43));
- this.addSlotToContainer(new SlotCraftingNoCollect(inventory.player, this.craftMatrix, this.craftResult, 0, 26+(18*3), 25));
+ this.addSlotToContainer(new SlotCraftingNoCollect(inventory.player, this.craftMatrix, this.craftResult, 0, 26+(18*4), 25));
int o = 0;
@@ -62,7 +63,7 @@ public class Container_ProjectTable extends Container {
for (var7 = 0; var7 < 3; ++var7)
{
//Utils.LOG_WARNING("Adding slots at var:"+(var7 + var6 * 4)+" x:"+(8 + var7 * 18)+" y:"+(7 + var6 * 18));
- this.addSlotToContainer(new Slot(this.craftMatrix, nextFreeSlot, 8 + (var7 * 18), 7 + (var6 * 18)));
+ this.addSlotToContainer(new Slot(this.craftMatrix, nextFreeSlot, 8+18 + (var7 * 18), 8 + (var6 * 18)));
this.slotGrid[o] = nextFreeSlot;
nextFreeSlot++;
o++;
@@ -105,9 +106,9 @@ public class Container_ProjectTable extends Container {
if (!this.worldObj.isRemote){
for (int i = 0; i < 9; ++i){
ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i);
- /* if (itemstack != null){
+ if (itemstack != null){
p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false);
- }*/
+ }
}
}
}
@@ -214,6 +215,23 @@ public class Container_ProjectTable extends Container {
public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_){
return p_94530_2_.inventory != this.craftResult && super.func_94530_a(p_94530_1_, p_94530_2_);
}
+
+ public ItemStack getOutputContent(){
+ ItemStack output = this.craftResult.getStackInSlot(0);
+ if (output != null){
+ return output;
+ }
+ return null;
+ }
+
+ public ItemStack[] getInputComponents(){
+ ItemStack inputs[] = new ItemStack[9];
+ for (int r=0;r<this.craftMatrix.getSizeInventory();r++){
+ ItemStack temp = this.craftMatrix.getStackInSlot(r);
+ inputs[r] = temp;
+ }
+ return inputs;
+ }
} \ No newline at end of file
diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityProjectTable.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityProjectTable.java
index 9a1f52b0be..31277a763e 100644
--- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityProjectTable.java
+++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityProjectTable.java
@@ -3,6 +3,7 @@ package gtPlusPlus.core.tileentities.machines;
import java.util.List;
import java.util.Vector;
+import gtPlusPlus.core.container.Container_ProjectTable;
import gtPlusPlus.core.inventories.*;
import gtPlusPlus.core.inventories.projecttable.InventoryProjectMain;
import gtPlusPlus.core.inventories.projecttable.InventoryProjectOutput;
@@ -13,8 +14,10 @@ import ic2.api.network.INetworkUpdateListener;
import ic2.api.tile.IWrenchable;
import ic2.core.IC2;
import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
+import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@@ -24,12 +27,21 @@ public class TileEntityProjectTable extends TileEntity implements INetworkDataPr
public InventoryProjectMain inventoryGrid;
public InventoryProjectOutput inventoryOutputs;
+
+ /** The crafting matrix inventory (3x3). */
+ public InventoryCrafting craftMatrix;
+ public IInventory craftResult;
+ private Container_ProjectTable container;
public TileEntityProjectTable(){
this.inventoryGrid = new InventoryProjectMain();//number of slots - without product slot
this.inventoryOutputs = new InventoryProjectOutput();//number of slots - without product slot
this.canUpdate();
}
+
+ public void setContainer(Container_ProjectTable container){
+ this.container = container;
+ }
@SuppressWarnings("static-method")
public NBTTagCompound getTag(final NBTTagCompound nbt, final String tag){
@@ -114,9 +126,16 @@ public class TileEntityProjectTable extends TileEntity implements INetworkDataPr
//Data stick
ItemStack dataStick = this.inventoryOutputs.getStackInSlot(0);
- if (dataStick != null){
- Utils.LOG_INFO("Found Data Stick.");
- ItemStack newStick = NBTUtils.writeItemsToNBT(dataStick, this.inventoryGrid.getInventory());
+ if (dataStick != null && this.container != null){
+ Utils.LOG_INFO("Found Data Stick and valid container.");
+
+
+ ItemStack outputComponent = container.getOutputContent();
+ ItemStack[] craftInputComponent = container.getInputComponents();
+
+
+ ItemStack newStick = NBTUtils.writeItemsToNBT(dataStick, new ItemStack[]{outputComponent}, "Output");
+ newStick = NBTUtils.writeItemsToNBT(newStick, craftInputComponent);
NBTUtils.setBookTitle(newStick, "Encrypted Project Data");
int slotm=0;
Utils.LOG_INFO("Uploading to Data Stick.");
diff --git a/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java
index 010016d5f1..64653f7c56 100644
--- a/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java
+++ b/src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java
@@ -46,6 +46,26 @@ public class NBTUtils {
}
return inventory;
}
+
+ public static ItemStack[] readItemsFromNBT(ItemStack itemstack, String customkey){
+ NBTTagCompound tNBT = getNBT(itemstack);
+ final NBTTagList list = tNBT.getTagList(customkey, 10);
+ ItemStack inventory[] = new ItemStack[list.tagCount()];
+ for(int i = 0;i<list.tagCount();i++){
+ final NBTTagCompound data = list.getCompoundTagAt(i);
+ final int slot = data.getInteger("Slot");
+ if((slot >= 0) && (slot < list.tagCount())){
+ if (ItemStack.loadItemStackFromNBT(data) == ItemUtils.getSimpleStack(ZZZ_Empty)){
+ inventory[slot] = null;
+ }
+ else {
+ inventory[slot] = ItemStack.loadItemStackFromNBT(data);
+ }
+
+ }
+ }
+ return inventory;
+ }
public static ItemStack writeItemsToNBT(ItemStack itemstack, ItemStack[] stored){
NBTTagCompound tNBT = getNBT(itemstack);
@@ -70,6 +90,23 @@ public class NBTUtils {
itemstack.setTagCompound(tNBT);
return itemstack;
}
+
+ public static ItemStack writeItemsToNBT(ItemStack itemstack, ItemStack[] stored, String customkey){
+ NBTTagCompound tNBT = getNBT(itemstack);
+ final NBTTagList list = new NBTTagList();
+ for(int i = 0;i<stored.length;i++){
+ final ItemStack stack = stored[i];
+ if(stack != null){
+ final NBTTagCompound data = new NBTTagCompound();
+ stack.writeToNBT(data);
+ data.setInteger("Slot", i);
+ list.appendTag(data);
+ }
+ }
+ tNBT.setTag(customkey, list);
+ itemstack.setTagCompound(tNBT);
+ return itemstack;
+ }
}