diff options
Diffstat (limited to 'src/Java')
5 files changed, 441 insertions, 63 deletions
diff --git a/src/Java/gtPlusPlus/core/block/machine/Machine_TradeTable.java b/src/Java/gtPlusPlus/core/block/machine/Machine_TradeTable.java index 1551d2cddd..fc155765c6 100644 --- a/src/Java/gtPlusPlus/core/block/machine/Machine_TradeTable.java +++ b/src/Java/gtPlusPlus/core/block/machine/Machine_TradeTable.java @@ -9,7 +9,8 @@ import gtPlusPlus.GTplusplus; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.lib.LoadedMods; -import gtPlusPlus.core.tileentities.machines.TileEntityProjectTable; +import gtPlusPlus.core.tileentities.machines.TileEntityTradeTable; +import gtPlusPlus.core.tileentities.machines.TileEntityTradeTable; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbench; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.player.PlayerUtils; @@ -59,10 +60,10 @@ public class Machine_TradeTable extends BlockContainer @SideOnly(Side.CLIENT) public void registerBlockIcons(final IIconRegister p_149651_1_) { - this.blockIcon = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "machine_top"); - this.textureTop = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "cover_crafting"); - this.textureBottom = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "machine_top"); - this.textureFront = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "machine_top"); + this.blockIcon = p_149651_1_.registerIcon(CORE.MODID + ":" + "SwirlYellow"); + this.textureTop = p_149651_1_.registerIcon(CORE.MODID + ":" + "workbench_top"); + this.textureBottom = p_149651_1_.registerIcon(CORE.MODID + ":" + "SwirlYellow"); + this.textureFront = p_149651_1_.registerIcon(CORE.MODID + ":" + "SwirlYellow"); } /** @@ -88,7 +89,7 @@ public class Machine_TradeTable extends BlockContainer } final TileEntity te = world.getTileEntity(x, y, z); - if ((te != null) && (te instanceof TileEntityProjectTable)) + if ((te != null) && (te instanceof TileEntityTradeTable)) { if (!holdingWrench){ player.openGui(GTplusplus.instance, 6, world, x, y, z); @@ -101,7 +102,7 @@ public class Machine_TradeTable extends BlockContainer @Override public TileEntity createNewTileEntity(final World world, final int p_149915_2_) { - return new TileEntityProjectTable(); + return new TileEntityTradeTable(); } public static boolean isWrench(final ItemStack item){ diff --git a/src/Java/gtPlusPlus/core/container/Container_TradeTable.java b/src/Java/gtPlusPlus/core/container/Container_TradeTable.java index 1c516d0045..b0345ba8a6 100644 --- a/src/Java/gtPlusPlus/core/container/Container_TradeTable.java +++ b/src/Java/gtPlusPlus/core/container/Container_TradeTable.java @@ -1,8 +1,11 @@ package gtPlusPlus.core.container; import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.InventoryWorkbenchChest; import gtPlusPlus.core.inventories.projecttable.InventoryProjectMain; import gtPlusPlus.core.inventories.projecttable.InventoryProjectOutput; +import gtPlusPlus.core.inventories.tradetable.InventoryTradeMain; +import gtPlusPlus.core.inventories.tradetable.InventoryTradeOutput; import gtPlusPlus.core.slots.*; import gtPlusPlus.core.tileentities.machines.TileEntityProjectTable; import gtPlusPlus.core.tileentities.machines.TileEntityTradeTable; @@ -17,13 +20,9 @@ import net.minecraft.world.World; public class Container_TradeTable extends Container { - /** The crafting matrix inventory (3x3). */ - public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3); - public IInventory craftResult = new InventoryCraftResult(); - protected TileEntityTradeTable tile_entity; - public final InventoryProjectMain inventoryGrid; - public final InventoryProjectOutput inventoryOutputs; + public final InventoryTradeMain inventoryChest; + public final InventoryTradeOutput inventoryOutputs; private final World worldObj; private final int posX; @@ -36,7 +35,7 @@ public class Container_TradeTable extends Container { public Container_TradeTable(final InventoryPlayer inventory, final TileEntityTradeTable te){ this.tile_entity = te; - this.inventoryGrid = te.inventoryGrid; + this.inventoryChest = te.inventoryGrid; this.inventoryOutputs = te.inventoryOutputs; this.tile_entity.setContainer(this); @@ -48,15 +47,15 @@ public class Container_TradeTable extends Container { this.posZ = te.zCoord; int nextFreeSlot = 0; - + //Output slots - 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*4), 25)); - - + //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*4), 25)); + + int o = 0; //Storage Side for (var6 = 0; var6 < 3; ++var6) @@ -64,13 +63,12 @@ public class Container_TradeTable 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+18 + (var7 * 18), 8 + (var6 * 18))); + this.addSlotToContainer(new Slot(this.inventoryChest, nextFreeSlot, 8+18 + (var7 * 18), 8 + (var6 * 18))); this.slotGrid[o] = nextFreeSlot; nextFreeSlot++; o++; } - } - + } //Player Inventory for (var6 = 0; var6 < 3; ++var6) @@ -86,33 +84,25 @@ public class Container_TradeTable extends Container { { this.addSlotToContainer(new Slot(inventory, var6, 8 + (var6 * 18), 142)); } - - this.onCraftMatrixChanged(this.craftMatrix); + + //this.onCraftMatrixChanged(this.craftMatrix); } - + /** - * Callback for when the crafting matrix is changed. - */ - public void onCraftMatrixChanged(IInventory p_75130_1_) - { - this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, this.worldObj)); - } - - /** - * Called when the container is closed. - */ - public void onContainerClosed(EntityPlayer p_75134_1_){ - super.onContainerClosed(p_75134_1_); - if (!this.worldObj.isRemote){ - for (int i = 0; i < 9; ++i){ - ItemStack itemstack = this.craftMatrix.getStackInSlotOnClosing(i); - if (itemstack != null){ - p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false); - } - } - } - } + * Called when the container is closed. + */ + public void onContainerClosed(EntityPlayer p_75134_1_){ + super.onContainerClosed(p_75134_1_); + if (!this.worldObj.isRemote){ + for (int i = 0; i < 9; ++i){ + ItemStack itemstack = this.inventoryChest.getStackInSlotOnClosing(i); + if (itemstack != null){ + p_75134_1_.dropPlayerItemWithRandomChoice(itemstack, false); + } + } + } + } @Override public ItemStack slotClick(final int aSlotIndex, final int aMouseclick, final int aShifthold, final EntityPlayer aPlayer){ @@ -139,7 +129,7 @@ public class Container_TradeTable extends Container { //Utils.LOG_WARNING("Player Clicked slot "+aSlotIndex+" in the Grid"); return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); } - + @Override public boolean canInteractWith(final EntityPlayer par1EntityPlayer){ if (this.worldObj.getBlock(this.posX, this.posY, this.posZ) != ModBlocks.blockProjectTable){ @@ -153,9 +143,9 @@ public class Container_TradeTable extends Container { @Override public ItemStack transferStackInSlot(final EntityPlayer par1EntityPlayer, final int par2) { - + return null; - + /*ItemStack var3 = null; final Slot var4 = (Slot)this.inventorySlots.get(par2); @@ -212,13 +202,8 @@ public class Container_TradeTable extends Container { return var3;*/ } - //Can merge Slot - 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); + ItemStack output = this.inventoryOutputs.getStackInSlot(0); if (output != null){ return output; } @@ -227,8 +212,8 @@ public class Container_TradeTable extends Container { public ItemStack[] getInputComponents(){ ItemStack inputs[] = new ItemStack[9]; - for (int r=0;r<this.craftMatrix.getSizeInventory();r++){ - ItemStack temp = this.craftMatrix.getStackInSlot(r); + for (int r=0;r<this.inventoryChest.getSizeInventory();r++){ + ItemStack temp = this.inventoryChest.getStackInSlot(r); inputs[r] = temp; } return inputs; diff --git a/src/Java/gtPlusPlus/core/inventories/tradetable/InventoryTradeMain.java b/src/Java/gtPlusPlus/core/inventories/tradetable/InventoryTradeMain.java new file mode 100644 index 0000000000..7b125edcb0 --- /dev/null +++ b/src/Java/gtPlusPlus/core/inventories/tradetable/InventoryTradeMain.java @@ -0,0 +1,202 @@ +package gtPlusPlus.core.inventories.tradetable; + +import gtPlusPlus.core.util.Utils; +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 InventoryTradeMain implements IInventory{ + + private final String name = "Inventory Grid"; + + /** Defining your inventory size this way is handy */ + public static final int INV_SIZE = 9; + + /** 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 + */ + public InventoryTradeMain() + { + + } + + public void readFromNBT(final NBTTagCompound nbt) + { + final NBTTagList list = nbt.getTagList("Items", 10); + this.inventory = new ItemStack[INV_SIZE]; + 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)) + { + this.inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + } + + public void writeToNBT(final NBTTagCompound nbt) + { + final NBTTagList list = new NBTTagList(); + for(int i = 0;i<INV_SIZE;i++) + { + final ItemStack stack = this.inventory[i]; + if(stack != null) + { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + nbt.setTag("Items", list); + } + + @Override + public int getSizeInventory() + { + return this.inventory.length; + } + + public ItemStack[] getInventory(){ + return this.inventory; + } + + @Override + public ItemStack getStackInSlot(final int slot) + { + //Utils.LOG_INFO("getStackInSlot["+slot+"]"); + try { + if (slot>= this.inventory.length){ + //Utils.LOG_INFO("Returning invalid slot item."); + return null; + } + return this.inventory[slot]; + } catch (Throwable t){ + t.printStackTrace(); + return null; + } + } + + @Override + public ItemStack decrStackSize(final int slot, final int amount) + { + ItemStack stack = this.getStackInSlot(slot); + 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 + this.setInventorySlotContents(slot, null); + } + } + return stack; + } + + @Override + 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) + { + if (slot >= this.inventory.length){ + return; + } + this.inventory[slot] = stack; + + if ((stack != null) && (stack.stackSize > this.getInventoryStackLimit())) + { + stack.stackSize = this.getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + this.markDirty(); + } + + // 1.7.2+ renamed to getInventoryName + @Override + public String getInventoryName() + { + return this.name; + } + + // 1.7.2+ renamed to hasCustomInventoryName + @Override + public boolean hasCustomInventoryName() + { + return this.name.length() > 0; + } + + @Override + 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. + */ + // 1.7.2+ renamed to markDirty + @Override + 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) && (temp.stackSize == 0)) { + this.inventory[i] = null; + } + } + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer entityplayer) + { + return true; + } + + // 1.7.2+ renamed to openInventory(EntityPlayer player) + @Override + public void openInventory() {} + + // 1.7.2+ renamed to closeInventory(EntityPlayer player) + @Override + 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 + */ + @Override + 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 + return true; + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/inventories/tradetable/InventoryTradeOutput.java b/src/Java/gtPlusPlus/core/inventories/tradetable/InventoryTradeOutput.java new file mode 100644 index 0000000000..fb4329e11a --- /dev/null +++ b/src/Java/gtPlusPlus/core/inventories/tradetable/InventoryTradeOutput.java @@ -0,0 +1,188 @@ +package gtPlusPlus.core.inventories.tradetable; + +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 InventoryTradeOutput implements IInventory{ + + private final String name = "Inventory Output"; + + /** Defining your inventory size this way is handy */ + public static final int INV_SIZE = 2; + + /** 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 + */ + public InventoryTradeOutput() + { + + } + + public void readFromNBT(final NBTTagCompound nbt) + { + final NBTTagList list = nbt.getTagList("Items", 10); + this.inventory = new ItemStack[INV_SIZE]; + 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)) + { + this.inventory[slot] = ItemStack.loadItemStackFromNBT(data); + } + } + } + + public void writeToNBT(final NBTTagCompound nbt) + { + final NBTTagList list = new NBTTagList(); + for(int i = 0;i<INV_SIZE;i++) + { + final ItemStack stack = this.inventory[i]; + if(stack != null) + { + final NBTTagCompound data = new NBTTagCompound(); + stack.writeToNBT(data); + data.setInteger("Slot", i); + list.appendTag(data); + } + } + nbt.setTag("Items", list); + } + + @Override + public int getSizeInventory() + { + return this.inventory.length; + } + + public ItemStack[] getInventory(){ + return this.inventory; + } + + @Override + public ItemStack getStackInSlot(final int slot) + { + return this.inventory[slot]; + } + + @Override + public ItemStack decrStackSize(final int slot, final int amount) + { + ItemStack stack = this.getStackInSlot(slot); + 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 + this.setInventorySlotContents(slot, null); + } + } + return stack; + } + + @Override + 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) + { + this.inventory[slot] = stack; + + if ((stack != null) && (stack.stackSize > this.getInventoryStackLimit())) + { + stack.stackSize = this.getInventoryStackLimit(); + } + + // Don't forget this line or your inventory will not be saved! + this.markDirty(); + } + + // 1.7.2+ renamed to getInventoryName + @Override + public String getInventoryName() + { + return this.name; + } + + // 1.7.2+ renamed to hasCustomInventoryName + @Override + public boolean hasCustomInventoryName() + { + return this.name.length() > 0; + } + + @Override + 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. + */ + // 1.7.2+ renamed to markDirty + @Override + 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) && (temp.stackSize == 0)) { + this.inventory[i] = null; + } + } + } + + @Override + public boolean isUseableByPlayer(final EntityPlayer entityplayer) + { + return true; + } + + // 1.7.2+ renamed to openInventory(EntityPlayer player) + @Override + public void openInventory() {} + + // 1.7.2+ renamed to closeInventory(EntityPlayer player) + @Override + 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 + */ + @Override + 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 + return true; + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java index b3ed225e31..911fb7b40e 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java @@ -8,6 +8,8 @@ import gtPlusPlus.core.container.Container_TradeTable; import gtPlusPlus.core.inventories.*; import gtPlusPlus.core.inventories.projecttable.InventoryProjectMain; import gtPlusPlus.core.inventories.projecttable.InventoryProjectOutput; +import gtPlusPlus.core.inventories.tradetable.InventoryTradeMain; +import gtPlusPlus.core.inventories.tradetable.InventoryTradeOutput; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.nbt.NBTUtils; import ic2.api.network.INetworkDataProvider; @@ -26,8 +28,8 @@ import net.minecraft.tileentity.TileEntity; public class TileEntityTradeTable extends TileEntity implements INetworkDataProvider, INetworkUpdateListener, IWrenchable{ - public InventoryProjectMain inventoryGrid; - public InventoryProjectOutput inventoryOutputs; + public InventoryTradeMain inventoryGrid; + public InventoryTradeOutput inventoryOutputs; /** The crafting matrix inventory (3x3). */ public InventoryCrafting craftMatrix; @@ -35,8 +37,8 @@ public class TileEntityTradeTable extends TileEntity implements INetworkDataProv private Container_TradeTable container; public TileEntityTradeTable(){ - this.inventoryGrid = new InventoryProjectMain();//number of slots - without product slot - this.inventoryOutputs = new InventoryProjectOutput();//number of slots - without product slot + this.inventoryGrid = new InventoryTradeMain();//number of slots - without product slot + this.inventoryOutputs = new InventoryTradeOutput();//number of slots - without product slot this.canUpdate(); } |