equivalent-exchange-3/ee3_common/com/pahimar/ee3/inventory/ContainerCalcinator.java

107 lines
3.6 KiB
Java
Raw Normal View History

package com.pahimar.ee3.inventory;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
2012-09-16 07:34:33 +02:00
import com.pahimar.ee3.tileentity.TileCalcinator;
2012-10-27 23:41:02 +02:00
/**
* Equivalent-Exchange-3
2012-10-27 23:41:02 +02:00
*
* ContainerCalcinator
2012-10-27 23:41:02 +02:00
*
* @author pahimar
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
*
*/
2012-09-16 07:34:33 +02:00
public class ContainerCalcinator extends Container {
2012-09-17 05:04:14 +02:00
public ContainerCalcinator(InventoryPlayer inventoryPlayer, TileCalcinator 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
2013-02-13 03:47:17 +01:00
this.addSlotToContainer(new SlotCalcinator(calcinator, 2, 116, 35));
// 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, 94 + 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, 152));
}
2012-09-16 07:34:33 +02:00
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
2012-09-16 07:34:33 +02:00
}
// TODO Write our own version - this is taken from ContainerFurnace
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
2012-10-22 04:39:43 +02:00
ItemStack var3 = null;
Slot var4 = (Slot) inventorySlots.get(par2);
if (var4 != null && var4.getHasStack()) {
2012-10-22 04:39:43 +02:00
ItemStack var5 = var4.getStack();
var3 = var5.copy();
if (par2 == 2) {
if (!this.mergeItemStack(var5, 3, 39, true))
return null;
2012-10-22 04:39:43 +02:00
var4.onSlotChange(var5, var3);
}
else if (par2 != 1 && par2 != 0) {
if (FurnaceRecipes.smelting().getSmeltingResult(var5) != null) {
if (!this.mergeItemStack(var5, 0, 1, false))
return null;
}
else if (TileEntityFurnace.isItemFuel(var5)) {
if (!this.mergeItemStack(var5, 1, 2, false))
return null;
}
else if (par2 >= 3 && par2 < 30) {
if (!this.mergeItemStack(var5, 30, 39, false))
return null;
}
else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false))
return null;
}
else if (!this.mergeItemStack(var5, 3, 39, false))
return null;
if (var5.stackSize == 0) {
var4.putStack((ItemStack) null);
}
else {
2012-10-22 04:39:43 +02:00
var4.onSlotChanged();
}
if (var5.stackSize == var3.stackSize)
return null;
2012-11-02 21:06:08 +01:00
var4.onPickupFromSlot(par1EntityPlayer, var5);
}
2012-10-22 04:39:43 +02:00
return var3;
}
2012-09-16 07:34:33 +02:00
}