equivalent-exchange-3/src/main/java/com/pahimar/ee3/inventory/ContainerAlchemicalChest.java

175 lines
7.4 KiB
Java
Raw Normal View History

package com.pahimar.ee3.inventory;
2014-04-30 03:46:59 +02:00
import com.pahimar.ee3.tileentity.TileEntityAlchemicalChest;
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 {
// 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;
// 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;
// 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-04-30 03:46:59 +02:00
private TileEntityAlchemicalChest tileEntityAlchemicalChest;
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();
2023-01-03 17:47:36 +01:00
if (this.tileEntityAlchemicalChest.getState() == 0) {
chestInventoryRows = SMALL_CHEST_INVENTORY_ROWS;
chestInventoryColumns = SMALL_CHEST_INVENTORY_COLUMNS;
2023-01-03 17:47:36 +01:00
} else if (this.tileEntityAlchemicalChest.getState() == 1) {
chestInventoryRows = MEDIUM_CHEST_INVENTORY_ROWS;
chestInventoryColumns = MEDIUM_CHEST_INVENTORY_COLUMNS;
2023-01-03 17:47:36 +01:00
} else if (this.tileEntityAlchemicalChest.getState() == 2) {
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
));
}
}
}
// 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
));
}
}
}
// 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
));
}
}
}
/**
* Callback for when the crafting gui is closed.
*/
@Override
2023-01-03 17:47:36 +01:00
public void onContainerClosed(EntityPlayer entityPlayer) {
super.onContainerClosed(entityPlayer);
2014-04-30 03:46:59 +02:00
tileEntityAlchemicalChest.closeInventory();
}
@Override
2023-01-03 17:47:36 +01:00
public boolean canInteractWith(EntityPlayer entityPlayer) {
return this.tileEntityAlchemicalChest.isUseableByPlayer(entityPlayer);
}
@Override
2023-01-03 17:47:36 +01:00
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex) {
ItemStack newItemStack = null;
Slot slot = (Slot) inventorySlots.get(slotIndex);
2023-01-03 17:47:36 +01:00
if (slot != null && slot.getHasStack()) {
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
)) {
return null;
}
2023-01-03 17:47:36 +01:00
} else if (!this.mergeItemStack(
itemStack, 0, chestInventoryRows * chestInventoryColumns, false
)) {
return null;
}
2023-01-03 17:47:36 +01:00
if (itemStack.stackSize == 0) {
slot.putStack(null);
2023-01-03 17:47:36 +01:00
} else {
slot.onSlotChanged();
}
}
return newItemStack;
}
}