From cdc728c5b606d6d3d49dce77c18f875a1f8379c6 Mon Sep 17 00:00:00 2001 From: Alkalus Date: Tue, 12 Sep 2017 17:04:35 +1000 Subject: + 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. --- .../core/container/Container_ProjectTable.java | 30 ++++++++-- .../machines/TileEntityProjectTable.java | 25 +++++++- src/Java/gtPlusPlus/core/util/nbt/NBTUtils.java | 37 ++++++++++++ .../machines/multi/GT4Entity_AutoCrafter.java | 68 +++++++++++++++++++--- 4 files changed, 144 insertions(+), 16 deletions(-) (limited to 'src/Java/gtPlusPlus') 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= 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= 16; } @@ -267,11 +267,12 @@ extends GT_MetaTileEntity_MultiBlockBase } //Read stored data from encrypter data stick. - ItemStack storedData[] = NBTUtils.readItemsFromNBT(aStack); + ItemStack storedData_Output[] = NBTUtils.readItemsFromNBT(aStack, "Output"); + ItemStack storedData_Input[] = NBTUtils.readItemsFromNBT(aStack); ItemStack loadedData[] = new ItemStack[9]; - if (storedData.length >= 1){ + if (storedData_Input.length >= 1){ int number = 0; - for (ItemStack a : storedData){ + for (ItemStack a : storedData_Input){ if (a.getItem() == ModItems.ZZZ_Empty){ Utils.LOG_INFO("Allocating free memory into crafting manager slot "+number+"."); loadedData[number] = null; @@ -287,12 +288,65 @@ extends GT_MetaTileEntity_MultiBlockBase number++; } } + + if (storedData_Output.length >= 1){ + int number = 0; + for (ItemStack a : storedData_Output){ + if (a.getItem() == ModItems.ZZZ_Empty){ + Utils.LOG_INFO("Allocating free memory into crafting manager Output slot "+number+"."); + loadedData[number] = null; + //ContainerWorkbench.craftMatrix.setInventorySlotContents(number, null); + //ContainerWorkbench.craftMatrix.markDirty(); + } + else { + Utils.LOG_INFO("Downloading "+a.getDisplayName()+" into crafting manager Output slot "+number+"."); + loadedData[number] = a; + //ContainerWorkbench.craftMatrix.setInventorySlotContents(number, a); + //ContainerWorkbench.craftMatrix.markDirty(); + } + number++; + } + } + + boolean areInputsCorrect[] = new boolean[9]; + int counter=0; + for (ItemStack inputItem : loadedData){ + + if (inputItem == null){ + areInputsCorrect[counter] = true; + } + + //Check input busses for recipe components + for (GT_MetaTileEntity_Hatch_InputBus x : this.mInputBusses){ + if (x.mInventory.length > 0){ + for (ItemStack r : x.mInventory){ + if (r == inputItem){ + this.depleteInput(inputItem); + areInputsCorrect[counter] = true; + } + } + } + } + counter++; + } + + int mCorrectInputs=0; + for (boolean isValid : areInputsCorrect){ + if (isValid){ + mCorrectInputs++; + } + } - if (mInventoryCrafter != null){ - Utils.LOG_INFO("Now crafting with "+mInventoryCrafter.mInventoryName); - this.mInventoryCrafter.inventory.putItemsIntoGrid(loadedData); + if (mCorrectInputs == 9){ + this.addOutput(storedData_Output[0]); } + + //if the are all found remove inputs + + //if they are all found produce output + + //Do Crafting //Utils.LOG_INFO("Crafting Grid Size: "+ContainerWorkbench.craftMatrix.getSizeInventory()); //Utils.LOG_INFO("Crafting Grid Result: "+ContainerWorkbench.craftResult.getSizeInventory()); -- cgit