equivalent-exchange-3/ee3_common/ee3/common/container/ContainerCalcinator.java
2012-09-28 16:05:29 -04:00

123 lines
3.9 KiB
Java

package ee3.common.container;
import ee3.common.tile.TileCalcinator;
import net.minecraft.src.Container;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.FurnaceRecipes;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Slot;
import net.minecraft.src.TileEntityFurnace;
public class ContainerCalcinator extends Container {
private TileCalcinator calcinator;
public ContainerCalcinator(InventoryPlayer inventoryPlayer, TileCalcinator calcinator) {
// Set the instance of the TileCalcinator for the container
this.calcinator = calcinator;
// Add the calcinator "to be calcined" slot to the container
this.addSlotToContainer(new Slot(calcinator, 0, 56, 17));
// Add the calcinator fuel slot to the container
this.addSlotToContainer(new Slot(calcinator, 1, 56, 62));
// Add the calcined results slot to the container
// TODO Add a slot here
// Add the player's inventory slots to the container
for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex)
{
for (int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex)
{
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 84 + inventoryRowIndex * 18));
}
}
// Add the player's action bar slots to the container
for (int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex)
{
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 142));
}
}
public boolean canInteractWith(EntityPlayer player) {
//return calcinator.isUseableByPlayer(player);
return true;
}
// TODO Write our own version - this is taken from ContainerFurnace
public ItemStack transferStackInSlot(int par1)
{
ItemStack var2 = null;
Slot var3 = (Slot)this.inventorySlots.get(par1);
if (var3 != null && var3.getHasStack())
{
ItemStack var4 = var3.getStack();
var2 = var4.copy();
if (par1 == 2)
{
if (!this.mergeItemStack(var4, 3, 39, true))
{
return null;
}
var3.onSlotChange(var4, var2);
}
else if (par1 != 1 && par1 != 0)
{
if (FurnaceRecipes.smelting().getSmeltingResult(var4) != null)
{
if (!this.mergeItemStack(var4, 0, 1, false))
{
return null;
}
}
else if (TileEntityFurnace.isItemFuel(var4))
{
if (!this.mergeItemStack(var4, 1, 2, false))
{
return null;
}
}
else if (par1 >= 3 && par1 < 30)
{
if (!this.mergeItemStack(var4, 30, 39, false))
{
return null;
}
}
else if (par1 >= 30 && par1 < 39 && !this.mergeItemStack(var4, 3, 30, false))
{
return null;
}
}
else if (!this.mergeItemStack(var4, 3, 39, false))
{
return null;
}
if (var4.stackSize == 0)
{
var3.putStack((ItemStack)null);
}
else
{
var3.onSlotChanged();
}
if (var4.stackSize == var2.stackSize)
{
return null;
}
var3.onPickupFromSlot(var4);
}
return var2;
}
}