diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2016-10-20 16:43:59 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-10-20 16:43:59 +1000 |
commit | 604023eb80fe0c50fac956e93625c9be88bb9cd8 (patch) | |
tree | da73122574d7358b7ac07f21a8d6664a2ac68348 /src | |
parent | b5268f7c54426ddc8289df99be5b1e81934536ba (diff) | |
download | GT5-Unofficial-604023eb80fe0c50fac956e93625c9be88bb9cd8.tar.gz GT5-Unofficial-604023eb80fe0c50fac956e93625c9be88bb9cd8.tar.bz2 GT5-Unofficial-604023eb80fe0c50fac956e93625c9be88bb9cd8.zip |
$ Fixed the workbench crafting grid/output doing odd things (Client side item dupes & actual item dupes)
% Changed the workbench textures.
Diffstat (limited to 'src')
7 files changed, 300 insertions, 124 deletions
diff --git a/src/Java/gtPlusPlus/core/block/machine/Machine_Workbench.java b/src/Java/gtPlusPlus/core/block/machine/Machine_Workbench.java index 308413d81f..270d0d1820 100644 --- a/src/Java/gtPlusPlus/core/block/machine/Machine_Workbench.java +++ b/src/Java/gtPlusPlus/core/block/machine/Machine_Workbench.java @@ -8,7 +8,6 @@ import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; @@ -22,6 +21,8 @@ public class Machine_Workbench extends BlockContainer @SideOnly(Side.CLIENT) private IIcon textureTop; @SideOnly(Side.CLIENT) + private IIcon textureBottom; + @SideOnly(Side.CLIENT) private IIcon textureFront; @SuppressWarnings("deprecation") @@ -42,16 +43,17 @@ public class Machine_Workbench extends BlockContainer @SideOnly(Side.CLIENT) public IIcon getIcon(int p_149691_1_, int p_149691_2_) { - return p_149691_1_ == 1 ? this.textureTop : (p_149691_1_ == 0 ? Blocks.planks.getBlockTextureFromSide(p_149691_1_) : (p_149691_1_ != 2 && p_149691_1_ != 4 ? this.blockIcon : this.textureFront)); + return p_149691_1_ == 1 ? this.textureTop : (p_149691_1_ == 0 ? this.textureBottom : (p_149691_1_ != 2 && p_149691_1_ != 4 ? this.blockIcon : this.textureFront)); } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister p_149651_1_) { - this.blockIcon = p_149651_1_.registerIcon(CORE.MODID + ":" + "workbench"); - this.textureTop = p_149651_1_.registerIcon(CORE.MODID + ":" + "workbench" + "_top"); - this.textureFront = p_149651_1_.registerIcon(CORE.MODID + ":" + "workbench"); + this.blockIcon = p_149651_1_.registerIcon(CORE.MODID + ":" + " /TileEntities/" + "bronze_side_cabinet"); + this.textureTop = p_149651_1_.registerIcon(CORE.MODID + ":" + " /TileEntities/" + "bronze_top_crafting"); + this.textureBottom = p_149651_1_.registerIcon(CORE.MODID + ":" + " /TileEntities/" + "bronze_side"); + this.textureFront = p_149651_1_.registerIcon(CORE.MODID + ":" + " /TileEntities/" + "bronze_side_cabinet"); } /** diff --git a/src/Java/gtPlusPlus/core/container/Container_Workbench.java b/src/Java/gtPlusPlus/core/container/Container_Workbench.java index b3b024f52c..aa1fd1b509 100644 --- a/src/Java/gtPlusPlus/core/container/Container_Workbench.java +++ b/src/Java/gtPlusPlus/core/container/Container_Workbench.java @@ -11,6 +11,7 @@ import gtPlusPlus.core.item.general.ItemBlueprint; import gtPlusPlus.core.slots.SlotBlueprint; import gtPlusPlus.core.slots.SlotGeneric; import gtPlusPlus.core.slots.SlotGtTool; +import gtPlusPlus.core.slots.SlotOutput; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbench; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.item.UtilsItems; @@ -18,7 +19,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -34,8 +34,6 @@ public class Container_Workbench extends Container { public final InventoryWorkbenchHoloSlots inventoryHolo; public final InventoryWorkbenchHoloCrafting inventoryCrafting; - public IInventory craftResult = new InventoryCraftResult(); - private World worldObj; private int posX; private int posY; @@ -96,7 +94,7 @@ public class Container_Workbench extends Container { this.inventoryTool = tile.inventoryTool; this.inventoryHolo = tile.inventoryHolo; this.inventoryCrafting = tile.inventoryCrafting; - + int var6; int var7; worldObj = tile.getWorldObj(); @@ -107,7 +105,7 @@ public class Container_Workbench extends Container { int o=0; //Output slot - addSlotToContainer(new SlotGeneric(inventoryHolo, 0, 136, 64)); + addSlotToContainer(new SlotOutput(inventory.player, this.craftMatrix, tile.inventoryCraftResult, 0, 136, 64)); //Util Slots addSlotToContainer(new SlotBlueprint(inventoryHolo, 1, 136, 28)); //Blueprint addSlotToContainer(new GT_Slot_Holo(inventoryHolo, 2, 154, 28, false, false, 1)); //Hopper @@ -123,17 +121,19 @@ public class Container_Workbench extends Container { o=0; + updateCraftingMatrix(); + //Crafting Grid for (var6 = 0; var6 < 3; ++var6) { for (var7 = 0; var7 < 3; ++var7) { this.addSlotToContainer(new Slot(this.craftMatrix, var7 + var6 * 3, 82 + var7 * 18, 28 + var6 * 18)); - - if (this.inventoryCrafting.getStackInSlot(o) != null){ + + /*if (this.inventoryCrafting.getStackInSlot(o) != null){ this.craftMatrix.setInventorySlotContents(o, inventoryCrafting.getStackInSlot(o)); this.inventoryCrafting.setInventorySlotContents(o, null); - } + } */ slotCrafting[o] = o+6; o++; } @@ -189,86 +189,114 @@ public class Container_Workbench extends Container { public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer){ if (!aPlayer.worldObj.isRemote){ - if (aSlotIndex == 999 || aSlotIndex == -999){ - //Utils.LOG_INFO("??? - "+aSlotIndex); - } + if (aSlotIndex == 999 || aSlotIndex == -999){ + //Utils.LOG_INFO("??? - "+aSlotIndex); + } - if (aSlotIndex == slotOutput){ - Utils.LOG_INFO("Player Clicked on the output slot"); - } + if (aSlotIndex == slotOutput){ + Utils.LOG_INFO("Player Clicked on the output slot"); + //TODO + } - for (int x : slotHolo){ - if (aSlotIndex == x){ - Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the Holo Grid"); - if (x == 1){ - Utils.LOG_INFO("Player Clicked Blueprint slot in the Holo Grid"); - } - else if (x == 2){ - Utils.LOG_INFO("Player Clicked Right Arrow slot in the Holo Grid"); - if (inventoryHolo.getStackInSlot(1) != null){ - Utils.LOG_INFO("Found an ItemStack."); - if (inventoryHolo.getStackInSlot(1).getItem() instanceof IItemBlueprint){ - Utils.LOG_INFO("Found a blueprint."); - ItemStack tempBlueprint = inventoryHolo.getStackInSlot(1); - ItemBlueprint tempItemBlueprint = (ItemBlueprint) tempBlueprint.getItem(); - if (inventoryHolo.getStackInSlot(0) != null && !tempItemBlueprint.hasBlueprint(tempBlueprint)){ - Utils.LOG_INFO("Output slot was not empty."); - Utils.LOG_INFO("Trying to manipulate NBT data on the blueprint stack, then replace it with the new one."); - tempItemBlueprint.setBlueprint(inventoryHolo.getStackInSlot(1), craftMatrix, inventoryHolo.getStackInSlot(0)); - ItemStack newTempBlueprint = UtilsItems.getSimpleStack(tempItemBlueprint); - inventoryHolo.setInventorySlotContents(1, newTempBlueprint); - Utils.LOG_INFO(UtilsItems.getArrayStackNames(tempItemBlueprint.getBlueprint(newTempBlueprint))); - } - else { - if (tempItemBlueprint.hasBlueprint(tempBlueprint)){ - Utils.LOG_INFO("Blueprint already holds a recipe."); + for (int x : slotHolo){ + if (aSlotIndex == x){ + Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the Holo Grid"); + if (x == 1){ + Utils.LOG_INFO("Player Clicked Blueprint slot in the Holo Grid"); + } + else if (x == 2){ + Utils.LOG_INFO("Player Clicked Right Arrow slot in the Holo Grid"); + if (inventoryHolo.getStackInSlot(1) != null){ + Utils.LOG_INFO("Found an ItemStack."); + if (inventoryHolo.getStackInSlot(1).getItem() instanceof IItemBlueprint){ + Utils.LOG_INFO("Found a blueprint."); + ItemStack tempBlueprint = inventoryHolo.getStackInSlot(1); + ItemBlueprint tempItemBlueprint = (ItemBlueprint) tempBlueprint.getItem(); + if (inventoryHolo.getStackInSlot(0) != null && !tempItemBlueprint.hasBlueprint(tempBlueprint)){ + Utils.LOG_INFO("Output slot was not empty."); + Utils.LOG_INFO("Trying to manipulate NBT data on the blueprint stack, then replace it with the new one."); + tempItemBlueprint.setBlueprint(inventoryHolo.getStackInSlot(1), craftMatrix, inventoryHolo.getStackInSlot(0)); + ItemStack newTempBlueprint = UtilsItems.getSimpleStack(tempItemBlueprint); + inventoryHolo.setInventorySlotContents(1, newTempBlueprint); + Utils.LOG_INFO(UtilsItems.getArrayStackNames(tempItemBlueprint.getBlueprint(newTempBlueprint))); } else { - Utils.LOG_INFO("Output slot was empty."); + if (tempItemBlueprint.hasBlueprint(tempBlueprint)){ + Utils.LOG_INFO("Blueprint already holds a recipe."); + } + else { + Utils.LOG_INFO("Output slot was empty."); + } } } + else { + Utils.LOG_INFO("ItemStack found was not a blueprint."); + } } else { - Utils.LOG_INFO("ItemStack found was not a blueprint."); + Utils.LOG_INFO("No ItemStack found in Blueprint slot."); } } - else { - Utils.LOG_INFO("No ItemStack found in Blueprint slot."); + else if (x == 3){ + Utils.LOG_INFO("Player Clicked Big [P] slot in the Holo Grid"); + } + else if (x == 4){ + Utils.LOG_INFO("Player Clicked Transfer to Crafting Grid slot in the Holo Grid"); + } + else if (x == 5){ + Utils.LOG_INFO("Player Clicked Transfer to Storage Grid slot in the Holo Grid"); } - } - else if (x == 3){ - Utils.LOG_INFO("Player Clicked Big [P] slot in the Holo Grid"); - } - else if (x == 4){ - Utils.LOG_INFO("Player Clicked Transfer to Crafting Grid slot in the Holo Grid"); - } - else if (x == 5){ - Utils.LOG_INFO("Player Clicked Transfer to Storage Grid slot in the Holo Grid"); } } - } - for (int x : slotCrafting){ - if (aSlotIndex == x){ - Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the crafting Grid"); + for (int x : slotCrafting){ + if (aSlotIndex == x){ + Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the crafting Grid"); + } } - } - for (int x : slotStorage){ - if (aSlotIndex == x){ - Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the storage Grid"); + for (int x : slotStorage){ + if (aSlotIndex == x){ + Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the storage Grid"); + } } - } - for (int x : slotTools){ - if (aSlotIndex == x){ - Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the tool Grid"); + for (int x : slotTools){ + if (aSlotIndex == x){ + Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the tool Grid"); + } } } - } //Utils.LOG_INFO("Player Clicked slot "+aSlotIndex+" in the Grid"); return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); } + private void updateCraftingMatrix() { + for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { + craftMatrix.setInventorySlotContents(i, tile_entity.inventoryCrafting.getStackInSlot(i)); + } + } + + @Override + public void onCraftMatrixChanged(IInventory iiventory) { + tile_entity.inventoryCraftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj)); + } + @Override + public void onContainerClosed(EntityPlayer par1EntityPlayer) + { + super.onContainerClosed(par1EntityPlayer); + saveCraftingMatrix(); + } + + private void saveCraftingMatrix() { + for (int i = 0; i < craftMatrix.getSizeInventory(); i++) { + tile_entity.inventoryCrafting.setInventorySlotContents(i, craftMatrix.getStackInSlot(i)); + } + } + + + + + /*@Override public void onCraftMatrixChanged(IInventory par1IInventory){ //Custom Recipe Handler //craftResult.setInventorySlotContents(0, Workbench_CraftingHandler.getInstance().findMatchingRecipe(craftMatrix, worldObj)); @@ -278,25 +306,25 @@ public class Container_Workbench extends Container { ItemStack temp = CraftingManager.getInstance().findMatchingRecipe(craftMatrix, worldObj); if (temp != null){ Utils.LOG_INFO("Output found. "+temp.getDisplayName()+" x"+temp.stackSize); - inventoryHolo.setInventorySlotContents(slotOutput, temp); + craftResult.setInventorySlotContents(slotOutput, temp); } else { Utils.LOG_INFO("No Valid output found."); + craftResult.setInventorySlotContents(slotOutput, null); } - } + }*/ - - @Override + /*@Override public void onContainerClosed(EntityPlayer par1EntityPlayer) { for (int o=0; o<craftMatrix.getSizeInventory(); o++){ this.inventoryCrafting.setInventorySlotContents(o, craftMatrix.getStackInSlot(o)); this.craftMatrix.setInventorySlotContents(o, null); - } - - //super.onContainerClosed(par1EntityPlayer); + }*/ - /*if (worldObj.isRemote) + //super.onContainerClosed(par1EntityPlayer); + + /*if (worldObj.isRemote) { return; } @@ -311,9 +339,6 @@ public class Container_Workbench extends Container { } }*/ - } - - @Override public boolean canInteractWith(EntityPlayer par1EntityPlayer){ if (worldObj.getBlock(posX, posY, posZ) != ModBlocks.blockWorkbench){ @@ -382,7 +407,12 @@ public class Container_Workbench extends Container { return var3; } - - - + + //Can merge Slot + @Override + public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_) { + return p_94530_2_.inventory != tile_entity.inventoryCraftResult && super.func_94530_a(p_94530_1_, p_94530_2_); + } + + }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/gui/machine/GUI_Workbench.java b/src/Java/gtPlusPlus/core/gui/machine/GUI_Workbench.java index 0507e9099e..86388a2632 100644 --- a/src/Java/gtPlusPlus/core/gui/machine/GUI_Workbench.java +++ b/src/Java/gtPlusPlus/core/gui/machine/GUI_Workbench.java @@ -16,7 +16,7 @@ import cpw.mods.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class GUI_Workbench extends GuiContainer { - private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation(CORE.MODID, "textures/gui/Workbench.png"); + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation(CORE.MODID, "textures/gui/BronzeCraftingTable.png"); public boolean moveItemsToChest = false; public boolean moveItemsToCrafting = false; diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java index 39d9113a31..f4fe78d458 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloCrafting.java @@ -3,8 +3,6 @@ package gtPlusPlus.core.inventories; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; public class InventoryWorkbenchHoloCrafting implements IInventory{ @@ -24,7 +22,7 @@ public class InventoryWorkbenchHoloCrafting implements IInventory{ } - public void readFromNBT(NBTTagCompound nbt) + /*public void readFromNBT(NBTTagCompound nbt) { NBTTagList list = nbt.getTagList("Items", 10); inventory = new ItemStack[INV_SIZE]; @@ -54,7 +52,7 @@ public class InventoryWorkbenchHoloCrafting implements IInventory{ } } nbt.setTag("Items", list); - } + }*/ @Override public int getSizeInventory() diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java index 2bc84f492d..c5da273a11 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryWorkbenchHoloSlots.java @@ -3,6 +3,7 @@ package gtPlusPlus.core.inventories; import gtPlusPlus.core.util.Utils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -11,6 +12,9 @@ public class InventoryWorkbenchHoloSlots implements IInventory{ private String name = "Inventory Holo"; + //Output Slot + public IInventory craftResult = new InventoryCraftResult(); + /** Defining your inventory size this way is handy */ public static final int INV_SIZE = 6; @@ -33,7 +37,7 @@ public class InventoryWorkbenchHoloSlots implements IInventory{ { NBTTagCompound data = list.getCompoundTagAt(i); int slot = data.getInteger("Slot"); - if(slot >= 0 && slot < INV_SIZE) + if(slot >= 1 && slot < INV_SIZE) { inventory[slot] = ItemStack.loadItemStackFromNBT(data); } @@ -46,7 +50,7 @@ public class InventoryWorkbenchHoloSlots implements IInventory{ for(int i = 0;i<INV_SIZE;i++) { ItemStack stack = inventory[i]; - if(stack != null) + if(stack != null && i != 0) { NBTTagCompound data = new NBTTagCompound(); stack.writeToNBT(data); @@ -204,7 +208,7 @@ public class InventoryWorkbenchHoloSlots implements IInventory{ if (this.stackResult[0] != null) { - Utils.LOG_INFO("this.stackResult[0] == null - Really never should be here though. - Returning "+this.stackResult[0].getDisplayName()); + Utils.LOG_INFO("this.stackResult[0] != null - Really never should be though. - Returning "+this.stackResult[0].getDisplayName()); ItemStack itemstack = this.stackResult[0]; this.stackResult[0] = null; return itemstack; diff --git a/src/Java/gtPlusPlus/core/slots/SlotOutput.java b/src/Java/gtPlusPlus/core/slots/SlotOutput.java new file mode 100644 index 0000000000..a0f895d554 --- /dev/null +++ b/src/Java/gtPlusPlus/core/slots/SlotOutput.java @@ -0,0 +1,101 @@ +package gtPlusPlus.core.slots; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; +import cpw.mods.fml.common.FMLCommonHandler; + +public class SlotOutput extends SlotCrafting{ + + private final IInventory craftMatrix; + private final EntityPlayer thePlayer; + private int amountCrafted; + + + public SlotOutput(EntityPlayer player, InventoryCrafting craftingInventory, IInventory p_i45790_3_, int slotIndex, int xPosition, int yPosition) + { + super(player, craftingInventory, p_i45790_3_, slotIndex, xPosition, yPosition); + this.thePlayer = player; + this.craftMatrix = craftingInventory; + } + /** + * Check if the stack is a valid item for this slot. Always true beside for the armor slots. + */ + @Override + public boolean isItemValid(ItemStack par1ItemStack) + { + return false; + } + /** + * Decrease the size of the stack in slot (first int arg) by the amount of the second int arg. Returns the new + * stack. + */ + @Override + public ItemStack decrStackSize(int par1) + { + if (this.getHasStack()) + { + this.amountCrafted += Math.min(par1, this.getStack().stackSize); + } + return super.decrStackSize(par1); + } + /** + * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an + * internal count then calls onCrafting(item). + */ + @Override + protected void onCrafting(ItemStack par1ItemStack, int par2) + { + this.amountCrafted += par2; + this.onCrafting(par1ItemStack); + } + /** + * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. + */ + @Override + protected void onCrafting(ItemStack stack) + { + stack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.amountCrafted); + this.amountCrafted = 0; + } + + @Override + public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) + { + { + FMLCommonHandler.instance().firePlayerCraftingEvent(playerIn, stack, craftMatrix); + this.onCrafting(stack); + for (int i = 0; i < this.craftMatrix.getSizeInventory(); ++i) + { + ItemStack itemstack1 = this.craftMatrix.getStackInSlot(i); + if (itemstack1 != null) + { + this.craftMatrix.decrStackSize(i, 1); + if (itemstack1.getItem().hasContainerItem(itemstack1)) + { + ItemStack itemstack2 = itemstack1.getItem().getContainerItem(itemstack1); + if (itemstack2.isItemStackDamageable() && itemstack2.getItemDamage() > itemstack2.getMaxDamage()) + { + MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(thePlayer, itemstack2)); + itemstack2 = null; + } + if (!this.thePlayer.inventory.addItemStackToInventory(itemstack2)) + { + if (this.craftMatrix.getStackInSlot(i) == null) + { + this.craftMatrix.setInventorySlotContents(i, itemstack2); + } + else + { + this.thePlayer.dropPlayerItemWithRandomChoice(itemstack2, false); + } + } + } + } + } + } + } +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbench.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbench.java index b0c4fefbf0..725967c31e 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbench.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityWorkbench.java @@ -4,16 +4,24 @@ import gtPlusPlus.core.inventories.InventoryWorkbenchChest; import gtPlusPlus.core.inventories.InventoryWorkbenchHoloCrafting; import gtPlusPlus.core.inventories.InventoryWorkbenchHoloSlots; import gtPlusPlus.core.inventories.InventoryWorkbenchTools; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryCraftResult; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; public class TileEntityWorkbench extends TileEntity { + + //Credit to NovaViper in http://www.minecraftforge.net/forum/index.php?topic=26439.0 - Helped me restructure my Inventory system and now the crafting matrix works better. public InventoryWorkbenchChest inventoryChest; public InventoryWorkbenchTools inventoryTool; public InventoryWorkbenchHoloSlots inventoryHolo; - public InventoryWorkbenchHoloCrafting inventoryCrafting; - + public InventoryWorkbenchHoloCrafting inventoryCrafting; + + public IInventory inventoryCraftResult = new InventoryCraftResult(); + public TileEntityWorkbench(){ this.inventoryTool = new InventoryWorkbenchTools();//number of slots - without product slot this.inventoryChest = new InventoryWorkbenchChest();//number of slots - without product slot @@ -21,38 +29,71 @@ public class TileEntityWorkbench extends TileEntity { this.inventoryCrafting = new InventoryWorkbenchHoloCrafting(); this.canUpdate(); } - + @SuppressWarnings("static-method") public NBTTagCompound getTag(NBTTagCompound nbt, String tag) - { - if(!nbt.hasKey(tag)) - { - nbt.setTag(tag, new NBTTagCompound()); + { + if(!nbt.hasKey(tag)) + { + nbt.setTag(tag, new NBTTagCompound()); + } + return nbt.getCompoundTag(tag); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) + { + super.writeToNBT(nbt); + inventoryChest.writeToNBT(getTag(nbt, "ContentsChest")); + inventoryTool.writeToNBT(getTag(nbt, "ContentsTools")); + //inventoryCrafting.writeToNBT(getTag(nbt, "ContentsCrafting")); + inventoryHolo.writeToNBT(getTag(nbt, "ContentsHolo")); + + // Write Crafting Matrix to NBT + NBTTagList craftingTag = new NBTTagList(); + for (int currentIndex = 0; currentIndex < inventoryCrafting.getSizeInventory(); ++currentIndex) { + if (inventoryCrafting.getStackInSlot(currentIndex) != null) { + NBTTagCompound tagCompound = new NBTTagCompound(); + tagCompound.setByte("Slot", (byte) currentIndex); + inventoryCrafting.getStackInSlot(currentIndex).writeToNBT(tagCompound); + craftingTag.appendTag(tagCompound); + } } - return nbt.getCompoundTag(tag); - } - - @Override - public void writeToNBT(NBTTagCompound nbt) - { - super.writeToNBT(nbt); - inventoryChest.writeToNBT(getTag(nbt, "ContentsChest")); - inventoryTool.writeToNBT(getTag(nbt, "ContentsTools")); - inventoryCrafting.writeToNBT(getTag(nbt, "ContentsCrafting")); - inventoryHolo.writeToNBT(getTag(nbt, "ContentsHolo")); - - } - - @Override - public void readFromNBT(NBTTagCompound nbt) - { - super.readFromNBT(nbt); - inventoryChest.readFromNBT(nbt.getCompoundTag("ContentsChest")); - inventoryTool.readFromNBT(nbt.getCompoundTag("ContentsTools")); - inventoryCrafting.readFromNBT(nbt.getCompoundTag("ContentsCrafting")); - inventoryHolo.readFromNBT(nbt.getCompoundTag("ContentsHolo")); - } - - + + nbt.setTag("CraftingMatrix", craftingTag); + // Write craftingResult to NBT + if (inventoryCraftResult.getStackInSlot(0) != null) + nbt.setTag("CraftingResult", inventoryCraftResult.getStackInSlot(0).writeToNBT(new NBTTagCompound())); + + } + + @Override + public void readFromNBT(NBTTagCompound nbt) + { + super.readFromNBT(nbt); + inventoryChest.readFromNBT(nbt.getCompoundTag("ContentsChest")); + inventoryTool.readFromNBT(nbt.getCompoundTag("ContentsTools")); + //inventoryCrafting.readFromNBT(nbt.getCompoundTag("ContentsCrafting")); + inventoryHolo.readFromNBT(nbt.getCompoundTag("ContentsHolo")); + + // Read in the Crafting Matrix from NBT + NBTTagList craftingTag = nbt.getTagList("CraftingMatrix", 10); + inventoryCrafting = new InventoryWorkbenchHoloCrafting(); //TODO: magic number + for (int i = 0; i < craftingTag.tagCount(); ++i) { + NBTTagCompound tagCompound = (NBTTagCompound) craftingTag.getCompoundTagAt(i); + byte slot = tagCompound.getByte("Slot"); + if (slot >= 0 && slot < inventoryCrafting.getSizeInventory()) { + inventoryCrafting.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(tagCompound)); + } + } + + + // Read craftingResult from NBT + NBTTagCompound tagCraftResult = nbt.getCompoundTag("CraftingResult"); + inventoryCraftResult.setInventorySlotContents(0, ItemStack.loadItemStackFromNBT(tagCraftResult)); + + } + + }
\ No newline at end of file |