initial commit
This commit is contained in:
parent
3c9ee26b06
commit
22186c33b9
1458 changed files with 282792 additions and 0 deletions
85
java/src/game/inventory/ContainerDispenser.java
Executable file
85
java/src/game/inventory/ContainerDispenser.java
Executable file
|
@ -0,0 +1,85 @@
|
|||
package game.inventory;
|
||||
|
||||
import game.entity.npc.EntityNPC;
|
||||
import game.item.ItemStack;
|
||||
|
||||
public class ContainerDispenser extends Container
|
||||
{
|
||||
private IInventory dispenserInventory;
|
||||
|
||||
public ContainerDispenser(IInventory playerInventory, IInventory dispenserInventoryIn)
|
||||
{
|
||||
this.dispenserInventory = dispenserInventoryIn;
|
||||
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(dispenserInventoryIn, j + i * 3, 62 + j * 18, 17 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int k = 0; k < 3; ++k)
|
||||
{
|
||||
for (int i1 = 0; i1 < 9; ++i1)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(playerInventory, i1 + k * 9 + 9, 8 + i1 * 18, 84 + k * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for (int l = 0; l < 9; ++l)
|
||||
{
|
||||
this.addSlotToContainer(new Slot(playerInventory, l, 8 + l * 18, 142));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canInteractWith(EntityNPC playerIn)
|
||||
{
|
||||
return this.dispenserInventory.isUseableByPlayer(playerIn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a stack from the specified inventory slot.
|
||||
*/
|
||||
public ItemStack transferStackInSlot(EntityNPC playerIn, int index)
|
||||
{
|
||||
ItemStack itemstack = null;
|
||||
Slot slot = (Slot)this.inventorySlots.get(index);
|
||||
|
||||
if (slot != null && slot.getHasStack())
|
||||
{
|
||||
ItemStack itemstack1 = slot.getStack();
|
||||
itemstack = itemstack1.copy();
|
||||
|
||||
if (index < 9)
|
||||
{
|
||||
if (!this.mergeItemStack(itemstack1, 9, 45, true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if (!this.mergeItemStack(itemstack1, 0, 9, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == 0)
|
||||
{
|
||||
slot.putStack((ItemStack)null);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.onSlotChanged();
|
||||
}
|
||||
|
||||
if (itemstack1.stackSize == itemstack.stackSize)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||
}
|
||||
|
||||
return itemstack;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue