2013-08-07 19:06:26 -07:00
|
|
|
package tconstruct.inventory;
|
|
|
|
|
|
2014-02-05 10:28:54 -05:00
|
|
|
import mantle.blocks.abstracts.InventoryLogic;
|
2013-08-07 19:06:26 -07:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
|
|
|
|
|
public class InventoryCraftingStation extends InventoryCrafting
|
|
|
|
|
{
|
|
|
|
|
/** the width of the crafting inventory */
|
|
|
|
|
private int inventoryWidth;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class containing the callbacks for the events on_GUIClosed and on_CraftMaxtrixChanged.
|
|
|
|
|
*/
|
|
|
|
|
private Container eventHandler;
|
|
|
|
|
private InventoryLogic logic;
|
|
|
|
|
|
|
|
|
|
public InventoryCraftingStation(Container par1Container, int size, int height, InventoryLogic logic)
|
|
|
|
|
{
|
|
|
|
|
super(par1Container, size, height);
|
|
|
|
|
this.eventHandler = par1Container;
|
|
|
|
|
this.inventoryWidth = size;
|
|
|
|
|
this.logic = logic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of slots in the inventory.
|
|
|
|
|
*/
|
2013-08-31 05:13:31 -07:00
|
|
|
public int getSizeInventory ()
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
return 9;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-31 05:13:31 -07:00
|
|
|
public ItemStack getStackInSlot (int slot)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
2013-08-31 05:13:31 -07:00
|
|
|
return slot >= this.getSizeInventory() + 1 ? null : logic.getStackInSlot(slot + 1);
|
2013-08-07 19:06:26 -07:00
|
|
|
}
|
|
|
|
|
|
2013-08-31 05:13:31 -07:00
|
|
|
public ItemStack getStackInRowAndColumn (int row, int column)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
if (row >= 0 && row < this.inventoryWidth)
|
|
|
|
|
{
|
|
|
|
|
int k = row + column * this.inventoryWidth;
|
|
|
|
|
return this.getStackInSlot(k);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-31 05:13:31 -07:00
|
|
|
public String getInvName ()
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
return "container.crafting";
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-31 05:13:31 -07:00
|
|
|
public boolean isInvNameLocalized ()
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-31 05:13:31 -07:00
|
|
|
public ItemStack getStackInSlotOnClosing (int par1)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes from an inventory slot (first arg) up to a specified number (second arg) of items and returns them in a
|
|
|
|
|
* new stack.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2013-08-31 05:13:31 -07:00
|
|
|
public ItemStack decrStackSize (int slotID, int par2)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
2013-08-31 05:13:31 -07:00
|
|
|
ItemStack stack = logic.getStackInSlot(slotID + 1);
|
2013-08-07 19:06:26 -07:00
|
|
|
if (stack != null)
|
|
|
|
|
{
|
|
|
|
|
ItemStack itemstack;
|
|
|
|
|
|
|
|
|
|
if (stack.stackSize <= par2)
|
|
|
|
|
{
|
|
|
|
|
itemstack = stack.copy();
|
|
|
|
|
stack = null;
|
2013-08-31 05:13:31 -07:00
|
|
|
logic.setInventorySlotContents(slotID + 1, null);
|
2013-08-07 19:06:26 -07:00
|
|
|
this.eventHandler.onCraftMatrixChanged(this);
|
|
|
|
|
return itemstack;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
itemstack = stack.splitStack(par2);
|
|
|
|
|
|
|
|
|
|
if (stack.stackSize == 0)
|
|
|
|
|
{
|
|
|
|
|
stack = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.eventHandler.onCraftMatrixChanged(this);
|
|
|
|
|
return itemstack;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections).
|
|
|
|
|
*/
|
2013-08-31 05:13:31 -07:00
|
|
|
public void setInventorySlotContents (int slot, ItemStack itemstack)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
2013-08-31 05:13:31 -07:00
|
|
|
logic.setInventorySlotContents(slot + 1, itemstack);
|
2013-08-07 19:06:26 -07:00
|
|
|
this.eventHandler.onCraftMatrixChanged(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. *Isn't
|
|
|
|
|
* this more of a set than a get?*
|
|
|
|
|
*/
|
2013-08-31 05:13:31 -07:00
|
|
|
public int getInventoryStackLimit ()
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
return 64;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Called when an the contents of an Inventory change, usually
|
|
|
|
|
*/
|
2013-08-31 05:13:31 -07:00
|
|
|
public void onInventoryChanged ()
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-08-07 19:06:26 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Do not make give this method the name canInteractWith because it clashes with Container
|
|
|
|
|
*/
|
2013-08-31 05:13:31 -07:00
|
|
|
public boolean isUseableByPlayer (EntityPlayer par1EntityPlayer)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-31 05:13:31 -07:00
|
|
|
public void openChest ()
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-08-07 19:06:26 -07:00
|
|
|
|
2013-08-31 05:13:31 -07:00
|
|
|
public void closeChest ()
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-08-07 19:06:26 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot.
|
|
|
|
|
*/
|
2013-08-31 05:13:31 -07:00
|
|
|
public boolean isStackValidForSlot (int par1, ItemStack par2ItemStack)
|
2013-08-07 19:06:26 -07:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|