package net.minecraft.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.world.World;
public class ContainerWorkbench extends Container
{
/** The crafting matrix inventory (3x3). */
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
public IInventory craftResult = new InventoryCraftResult();
private World worldObj;
private int posX;
private int posY;
private int posZ;
private static final String __OBFID = "CL_00001744";
public ContainerWorkbench(InventoryPlayer p_i1808_1_, World p_i1808_2_, int p_i1808_3_, int p_i1808_4_, int p_i1808_5_)
{
this.worldObj = p_i1808_2_;
this.posX = p_i1808_3_;
this.posY = p_i1808_4_;
this.posZ = p_i1808_5_;
this.addSlotToContainer(new SlotCrafting(p_i1808_1_.player, this.craftMatrix, this.craftResult, 0, 124, 35));
int l;
int i1;
for (l = 0; l < 3; ++l)
{
for (i1 = 0; i1 < 3; ++i1)
{
this.addSlotToContainer(new Slot(this.craftMatrix, i1 + l * 3, 30 + i1 * 18, 17 + l * 18));
}
}
for (l = 0; l < 3; ++l)
{
for (i1 = 0; i1 < 9; ++i1)
{
this.addSlotToContainer(new Slot(p_i1808_1_, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18));
}
}
for (l = 0; l < 9; ++l)
{
this.addSlotToContainer(new Slot(p_i1808_1_, l, 8 + l * 18, 142));
}
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);
}
}
}
}
public boolean canInteractWith(EntityPlayer player)
{
return this.worldObj.getBlock(this.posX, this.posY, this.posZ) != Blocks.crafting_table ? false : player.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
}
/**
* Take a stack from the specified inventory slot.
*/
public ItemStack transferStackInSlot(EntityPlayer player, 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 == 0)
{
if (!this.mergeItemStack(itemstack1, 10, 46, true))
{
return null;
}
slot.onSlotChange(itemstack1, itemstack);
}
else if (index >= 10 && index < 37)
{
if (!this.mergeItemStack(itemstack1, 37, 46, false))
{
return null;
}
}
else if (index >= 37 && index < 46)
{
if (!this.mergeItemStack(itemstack1, 10, 37, false))
{
return null;
}
}
else if (!this.mergeItemStack(itemstack1, 10, 46, false))
{
return null;
}
if (itemstack1.stackSize == 0)
{
slot.putStack((ItemStack)null);
}
else
{
slot.onSlotChanged();
}
if (itemstack1.stackSize == itemstack.stackSize)
{
return null;
}
slot.onPickupFromSlot(player, itemstack1);
}
return itemstack;
}
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_);
}
}