2014-04-11 01:59:04 +02:00
|
|
|
package com.pahimar.ee3.inventory;
|
|
|
|
|
2014-04-30 03:46:59 +02:00
|
|
|
import com.pahimar.ee3.tileentity.TileEntityAlchemicalChest;
|
2014-04-11 01:59:04 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public class ContainerAlchemicalChest extends ContainerEE {
|
2014-04-11 01:59:04 +02:00
|
|
|
// Small Chest
|
|
|
|
public static final int SMALL_CHEST_INVENTORY_ROWS = 4;
|
|
|
|
public static final int SMALL_CHEST_INVENTORY_COLUMNS = 12;
|
2023-01-03 17:47:36 +01:00
|
|
|
public static final int SMALL_INVENTORY_SIZE
|
|
|
|
= SMALL_CHEST_INVENTORY_ROWS * SMALL_CHEST_INVENTORY_COLUMNS;
|
2014-04-11 01:59:04 +02:00
|
|
|
// Medium Chest
|
|
|
|
public static final int MEDIUM_CHEST_INVENTORY_ROWS = 7;
|
|
|
|
public static final int MEDIUM_CHEST_INVENTORY_COLUMNS = 12;
|
2023-01-03 17:47:36 +01:00
|
|
|
public static final int MEDIUM_INVENTORY_SIZE
|
|
|
|
= MEDIUM_CHEST_INVENTORY_ROWS * MEDIUM_CHEST_INVENTORY_COLUMNS;
|
2014-04-11 01:59:04 +02:00
|
|
|
// Large Chest
|
|
|
|
public static final int LARGE_CHEST_INVENTORY_ROWS = 9;
|
|
|
|
public static final int LARGE_CHEST_INVENTORY_COLUMNS = 13;
|
2023-01-03 17:47:36 +01:00
|
|
|
public static final int LARGE_INVENTORY_SIZE
|
|
|
|
= LARGE_CHEST_INVENTORY_ROWS * LARGE_CHEST_INVENTORY_COLUMNS;
|
2014-07-17 21:20:53 +02:00
|
|
|
|
2014-04-30 03:46:59 +02:00
|
|
|
private TileEntityAlchemicalChest tileEntityAlchemicalChest;
|
2014-04-11 01:59:04 +02:00
|
|
|
private int chestInventoryRows;
|
|
|
|
private int chestInventoryColumns;
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
public ContainerAlchemicalChest(
|
|
|
|
InventoryPlayer inventoryPlayer,
|
|
|
|
TileEntityAlchemicalChest tileEntityAlchemicalChest
|
|
|
|
) {
|
2014-04-30 03:46:59 +02:00
|
|
|
this.tileEntityAlchemicalChest = tileEntityAlchemicalChest;
|
|
|
|
tileEntityAlchemicalChest.openInventory();
|
2014-04-11 01:59:04 +02:00
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
if (this.tileEntityAlchemicalChest.getState() == 0) {
|
2014-04-11 01:59:04 +02:00
|
|
|
chestInventoryRows = SMALL_CHEST_INVENTORY_ROWS;
|
|
|
|
chestInventoryColumns = SMALL_CHEST_INVENTORY_COLUMNS;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if (this.tileEntityAlchemicalChest.getState() == 1) {
|
2014-04-11 01:59:04 +02:00
|
|
|
chestInventoryRows = MEDIUM_CHEST_INVENTORY_ROWS;
|
|
|
|
chestInventoryColumns = MEDIUM_CHEST_INVENTORY_COLUMNS;
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if (this.tileEntityAlchemicalChest.getState() == 2) {
|
2014-04-11 01:59:04 +02:00
|
|
|
chestInventoryRows = LARGE_CHEST_INVENTORY_ROWS;
|
|
|
|
chestInventoryColumns = LARGE_CHEST_INVENTORY_COLUMNS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the Alchemical Chest slots to the container
|
2023-01-03 17:47:36 +01:00
|
|
|
for (int chestRowIndex = 0; chestRowIndex < chestInventoryRows; ++chestRowIndex) {
|
|
|
|
for (int chestColumnIndex = 0; chestColumnIndex < chestInventoryColumns;
|
|
|
|
++chestColumnIndex) {
|
|
|
|
if (this.tileEntityAlchemicalChest.getState() == 0) {
|
|
|
|
this.addSlotToContainer(new Slot(
|
|
|
|
tileEntityAlchemicalChest,
|
|
|
|
chestColumnIndex + chestRowIndex * chestInventoryColumns,
|
|
|
|
8 + chestColumnIndex * 18,
|
|
|
|
18 + chestRowIndex * 18
|
|
|
|
));
|
|
|
|
} else if (this.tileEntityAlchemicalChest.getState() == 1) {
|
|
|
|
this.addSlotToContainer(new Slot(
|
|
|
|
tileEntityAlchemicalChest,
|
|
|
|
chestColumnIndex + chestRowIndex * chestInventoryColumns,
|
|
|
|
8 + chestColumnIndex * 18,
|
|
|
|
18 + chestRowIndex * 18
|
|
|
|
));
|
|
|
|
} else if (this.tileEntityAlchemicalChest.getState() == 2) {
|
|
|
|
this.addSlotToContainer(new Slot(
|
|
|
|
tileEntityAlchemicalChest,
|
|
|
|
chestColumnIndex + chestRowIndex * chestInventoryColumns,
|
|
|
|
8 + chestColumnIndex * 18,
|
|
|
|
8 + chestRowIndex * 18
|
|
|
|
));
|
2014-04-11 01:59:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the player's inventory slots to the container
|
2023-01-03 17:47:36 +01:00
|
|
|
for (int inventoryRowIndex = 0; inventoryRowIndex < PLAYER_INVENTORY_ROWS;
|
|
|
|
++inventoryRowIndex) {
|
|
|
|
for (int inventoryColumnIndex = 0;
|
|
|
|
inventoryColumnIndex < PLAYER_INVENTORY_COLUMNS;
|
|
|
|
++inventoryColumnIndex) {
|
|
|
|
if (this.tileEntityAlchemicalChest.getState() == 0) {
|
|
|
|
this.addSlotToContainer(new Slot(
|
|
|
|
inventoryPlayer,
|
|
|
|
inventoryColumnIndex + inventoryRowIndex * 9 + 9,
|
|
|
|
35 + inventoryColumnIndex * 18,
|
|
|
|
104 + inventoryRowIndex * 18
|
|
|
|
));
|
|
|
|
} else if (this.tileEntityAlchemicalChest.getState() == 1) {
|
|
|
|
this.addSlotToContainer(new Slot(
|
|
|
|
inventoryPlayer,
|
|
|
|
inventoryColumnIndex + inventoryRowIndex * 9 + 9,
|
|
|
|
35 + inventoryColumnIndex * 18,
|
|
|
|
158 + inventoryRowIndex * 18
|
|
|
|
));
|
|
|
|
} else if (this.tileEntityAlchemicalChest.getState() == 2) {
|
|
|
|
this.addSlotToContainer(new Slot(
|
|
|
|
inventoryPlayer,
|
|
|
|
inventoryColumnIndex + inventoryRowIndex * 9 + 9,
|
|
|
|
44 + inventoryColumnIndex * 18,
|
|
|
|
174 + inventoryRowIndex * 18
|
|
|
|
));
|
2014-04-11 01:59:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the player's action bar slots to the container
|
2023-01-03 17:47:36 +01:00
|
|
|
for (int actionBarSlotIndex = 0; actionBarSlotIndex < PLAYER_INVENTORY_COLUMNS;
|
|
|
|
++actionBarSlotIndex) {
|
|
|
|
if (this.tileEntityAlchemicalChest.getState() == 0) {
|
|
|
|
this.addSlotToContainer(new Slot(
|
|
|
|
inventoryPlayer, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 162
|
|
|
|
));
|
|
|
|
} else if (this.tileEntityAlchemicalChest.getState() == 1) {
|
|
|
|
this.addSlotToContainer(new Slot(
|
|
|
|
inventoryPlayer, actionBarSlotIndex, 35 + actionBarSlotIndex * 18, 216
|
|
|
|
));
|
|
|
|
} else if (this.tileEntityAlchemicalChest.getState() == 2) {
|
|
|
|
this.addSlotToContainer(new Slot(
|
|
|
|
inventoryPlayer, actionBarSlotIndex, 44 + actionBarSlotIndex * 18, 232
|
|
|
|
));
|
2014-04-11 01:59:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when the crafting gui is closed.
|
|
|
|
*/
|
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public void onContainerClosed(EntityPlayer entityPlayer) {
|
2014-04-11 01:59:04 +02:00
|
|
|
super.onContainerClosed(entityPlayer);
|
2014-04-30 03:46:59 +02:00
|
|
|
tileEntityAlchemicalChest.closeInventory();
|
2014-04-11 01:59:04 +02:00
|
|
|
}
|
|
|
|
|
2015-05-28 03:37:55 +02:00
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public boolean canInteractWith(EntityPlayer entityPlayer) {
|
2015-05-28 03:37:55 +02:00
|
|
|
return this.tileEntityAlchemicalChest.isUseableByPlayer(entityPlayer);
|
|
|
|
}
|
|
|
|
|
2014-04-11 01:59:04 +02:00
|
|
|
@Override
|
2023-01-03 17:47:36 +01:00
|
|
|
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
|
2014-04-11 01:59:04 +02:00
|
|
|
ItemStack newItemStack = null;
|
|
|
|
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
if (slot != null && slot.getHasStack()) {
|
2014-04-11 01:59:04 +02:00
|
|
|
ItemStack itemStack = slot.getStack();
|
|
|
|
newItemStack = itemStack.copy();
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
if (slotIndex < chestInventoryRows * chestInventoryColumns) {
|
|
|
|
if (!this.mergeItemStack(
|
|
|
|
itemStack,
|
|
|
|
chestInventoryRows * chestInventoryColumns,
|
|
|
|
inventorySlots.size(),
|
|
|
|
false
|
|
|
|
)) {
|
2014-04-11 01:59:04 +02:00
|
|
|
return null;
|
|
|
|
}
|
2023-01-03 17:47:36 +01:00
|
|
|
} else if (!this.mergeItemStack(
|
|
|
|
itemStack, 0, chestInventoryRows * chestInventoryColumns, false
|
|
|
|
)) {
|
2014-04-11 01:59:04 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2023-01-03 17:47:36 +01:00
|
|
|
if (itemStack.stackSize == 0) {
|
2014-04-11 01:59:04 +02:00
|
|
|
slot.putStack(null);
|
2023-01-03 17:47:36 +01:00
|
|
|
} else {
|
2014-04-11 01:59:04 +02:00
|
|
|
slot.onSlotChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newItemStack;
|
|
|
|
}
|
|
|
|
}
|