/*
* Copyright (c) CovertJaguar, 2014 http://railcraft.info
*
* This code is the property of CovertJaguar
* and may only be used with explicit written
* permission unless otherwise specified on the
* license page at http://railcraft.info/wiki/info:license.
*/
package mods.railcraft.common.gui.containers;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCraftResult;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotCrafting;
import mods.railcraft.common.carts.EntityCartWork;
import mods.railcraft.common.gui.slots.SlotUnshiftable;
public class ContainerWorkCart extends RailcraftContainer {
/**
* The crafting matrix inventory (3x3).
*/
public InventoryCrafting craftMatrix = new InventoryCrafting(this, 3, 3);
public IInventory craftResult = new InventoryCraftResult();
private EntityCartWork cart;
public ContainerWorkCart(InventoryPlayer inv, EntityCartWork cart) {
this.cart = cart;
this.addSlot(new SlotCrafting(inv.player, this.craftMatrix, this.craftResult, 0, 124, 35));
int var6;
int var7;
for (var6 = 0; var6 < 3; ++var6) {
for (var7 = 0; var7 < 3; ++var7) {
this.addSlot(new SlotUnshiftable(this.craftMatrix, var7 + var6 * 3, 30 + var7 * 18, 17 + var6 * 18));
}
}
for (var6 = 0; var6 < 3; ++var6) {
for (var7 = 0; var7 < 9; ++var7) {
this.addSlot(new Slot(inv, var7 + var6 * 9 + 9, 8 + var7 * 18, 84 + var6 * 18));
}
}
for (var6 = 0; var6 < 9; ++var6) {
this.addSlot(new Slot(inv, var6, 8 + var6 * 18, 142));
}
this.onCraftMatrixChanged(this.craftMatrix);
}
/**
* Callback for when the crafting matrix is changed.
*/
@Override
public void onCraftMatrixChanged(IInventory par1IInventory) {
this.craftResult.setInventorySlotContents(0, CraftingManager.getInstance().findMatchingRecipe(this.craftMatrix, cart.worldObj));
}
/**
* Callback for when the crafting gui is closed.
*/
@Override
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
super.onContainerClosed(par1EntityPlayer);
if (!cart.worldObj.isRemote)
for (int var2 = 0; var2 < 9; ++var2) {
ItemStack var3 = this.craftMatrix.getStackInSlotOnClosing(var2);
if (var3 != null)
par1EntityPlayer.dropPlayerItemWithRandomChoice(var3, false);
}
}
}