2012-12-17 21:21:53 +01:00
|
|
|
package com.pahimar.ee3.inventory;
|
|
|
|
|
2012-12-13 16:01:41 +01:00
|
|
|
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
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
import com.pahimar.ee3.tileentity.TileCalcinator;
|
|
|
|
|
2012-10-27 23:41:02 +02:00
|
|
|
/**
|
|
|
|
* ContainerCalcinator
|
|
|
|
*
|
|
|
|
* The container class for the Calcinator
|
|
|
|
*
|
|
|
|
* @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
|
|
|
private TileCalcinator calcinator;
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-09-17 05:04:14 +02:00
|
|
|
public ContainerCalcinator(InventoryPlayer inventoryPlayer, TileCalcinator calcinator) {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-09-28 22:05:29 +02:00
|
|
|
// Set the instance of the TileCalcinator for the container
|
2012-12-19 19:09:56 +01:00
|
|
|
this.calcinator = calcinator;
|
|
|
|
|
|
|
|
// Add the calcinator "to be calcined" slot to the container
|
2012-09-28 22:05:29 +02:00
|
|
|
this.addSlotToContainer(new Slot(calcinator, 0, 56, 17));
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-09-28 22:05:29 +02:00
|
|
|
// Add the calcinator fuel slot to the container
|
|
|
|
this.addSlotToContainer(new Slot(calcinator, 1, 56, 62));
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-09-28 22:05:29 +02:00
|
|
|
// Add the calcined results slot to the container
|
2013-02-13 03:47:17 +01:00
|
|
|
this.addSlotToContainer(new SlotCalcinator(calcinator, 2, 116, 35));
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-09-28 22:05:29 +02:00
|
|
|
// Add the player's inventory slots to the container
|
2012-12-19 19:09:56 +01:00
|
|
|
for (int inventoryRowIndex = 0; inventoryRowIndex < 3; ++inventoryRowIndex) {
|
|
|
|
for (int inventoryColumnIndex = 0; inventoryColumnIndex < 9; ++inventoryColumnIndex) {
|
2012-10-01 21:18:38 +02:00
|
|
|
this.addSlotToContainer(new Slot(inventoryPlayer, inventoryColumnIndex + inventoryRowIndex * 9 + 9, 8 + inventoryColumnIndex * 18, 94 + inventoryRowIndex * 18));
|
2012-09-28 22:05:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the player's action bar slots to the container
|
2012-12-19 19:09:56 +01:00
|
|
|
for (int actionBarSlotIndex = 0; actionBarSlotIndex < 9; ++actionBarSlotIndex) {
|
2012-10-01 21:18:38 +02:00
|
|
|
this.addSlotToContainer(new Slot(inventoryPlayer, actionBarSlotIndex, 8 + actionBarSlotIndex * 18, 152));
|
2012-09-28 22:05:29 +02:00
|
|
|
}
|
2012-09-16 07:34:33 +02:00
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-09-28 22:05:29 +02:00
|
|
|
public boolean canInteractWith(EntityPlayer player) {
|
2012-12-19 19:09:56 +01:00
|
|
|
|
|
|
|
return true;
|
2012-09-16 07:34:33 +02:00
|
|
|
}
|
|
|
|
|
2012-09-28 22:05:29 +02:00
|
|
|
// TODO Write our own version - this is taken from ContainerFurnace
|
2012-12-19 19:09:56 +01:00
|
|
|
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
|
|
|
|
|
2012-10-22 04:39:43 +02:00
|
|
|
ItemStack var3 = null;
|
2012-12-19 19:09:56 +01:00
|
|
|
Slot var4 = (Slot) this.inventorySlots.get(par2);
|
2012-09-28 22:05:29 +02:00
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
if (var4 != null && var4.getHasStack()) {
|
2012-10-22 04:39:43 +02:00
|
|
|
ItemStack var5 = var4.getStack();
|
|
|
|
var3 = var5.copy();
|
2012-09-28 22:05:29 +02:00
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
if (par2 == 2) {
|
|
|
|
if (!this.mergeItemStack(var5, 3, 39, true)) {
|
2012-09-28 22:05:29 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-10-22 04:39:43 +02:00
|
|
|
var4.onSlotChange(var5, var3);
|
2012-09-28 22:05:29 +02:00
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
else if (par2 != 1 && par2 != 0) {
|
|
|
|
if (FurnaceRecipes.smelting().getSmeltingResult(var5) != null) {
|
|
|
|
if (!this.mergeItemStack(var5, 0, 1, false)) {
|
2012-09-28 22:05:29 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
else if (TileEntityFurnace.isItemFuel(var5)) {
|
|
|
|
if (!this.mergeItemStack(var5, 1, 2, false)) {
|
2012-09-28 22:05:29 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
else if (par2 >= 3 && par2 < 30) {
|
|
|
|
if (!this.mergeItemStack(var5, 30, 39, false)) {
|
2012-09-28 22:05:29 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false)) {
|
2012-09-28 22:05:29 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
else if (!this.mergeItemStack(var5, 3, 39, false)) {
|
2012-09-28 22:05:29 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
if (var5.stackSize == 0) {
|
|
|
|
var4.putStack((ItemStack) null);
|
2012-09-28 22:05:29 +02:00
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
else {
|
2012-10-22 04:39:43 +02:00
|
|
|
var4.onSlotChanged();
|
2012-09-28 22:05:29 +02:00
|
|
|
}
|
|
|
|
|
2012-12-19 19:09:56 +01:00
|
|
|
if (var5.stackSize == var3.stackSize) {
|
2012-09-28 22:05:29 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-11-02 21:06:08 +01:00
|
|
|
var4.onPickupFromSlot(par1EntityPlayer, var5);
|
2012-09-28 22:05:29 +02:00
|
|
|
}
|
|
|
|
|
2012-10-22 04:39:43 +02:00
|
|
|
return var3;
|
2012-09-28 22:05:29 +02:00
|
|
|
}
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-09-16 07:34:33 +02:00
|
|
|
}
|