mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 22:34:21 +00:00
169 lines
3.9 KiB
Java
169 lines
3.9 KiB
Java
package mekanism.common.inventory.container;
|
|
|
|
import mekanism.api.gas.IGasItem;
|
|
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
|
|
import mekanism.common.inventory.slot.SlotMachineUpgrade;
|
|
import mekanism.common.inventory.slot.SlotStorageTank;
|
|
import mekanism.common.item.ItemMachineUpgrade;
|
|
import mekanism.common.recipe.RecipeHandler;
|
|
import mekanism.common.recipe.RecipeHandler.Recipe;
|
|
import mekanism.common.tile.TileEntityChemicalDissolutionChamber;
|
|
import mekanism.common.util.ChargeUtils;
|
|
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;
|
|
|
|
public class ContainerChemicalDissolutionChamber extends Container
|
|
{
|
|
private TileEntityChemicalDissolutionChamber tileEntity;
|
|
|
|
public ContainerChemicalDissolutionChamber(InventoryPlayer inventory, TileEntityChemicalDissolutionChamber tentity)
|
|
{
|
|
tileEntity = tentity;
|
|
addSlotToContainer(new SlotStorageTank(tentity, 0, 6, 65));
|
|
addSlotToContainer(new Slot(tentity, 1, 26, 36));
|
|
addSlotToContainer(new SlotStorageTank(tentity, 2, 155, 25));
|
|
addSlotToContainer(new SlotDischarge(tentity, 3, 155, 5));
|
|
|
|
int slotY;
|
|
|
|
for(slotY = 0; slotY < 3; slotY++)
|
|
{
|
|
for(int slotX = 0; slotX < 9; slotX++)
|
|
{
|
|
addSlotToContainer(new Slot(inventory, slotX + slotY * 9 + 9, 8 + slotX * 18, 84 + slotY * 18));
|
|
}
|
|
}
|
|
|
|
for(slotY = 0; slotY < 9; slotY++)
|
|
{
|
|
addSlotToContainer(new Slot(inventory, slotY, 8 + slotY * 18, 142));
|
|
}
|
|
|
|
tileEntity.open(inventory.player);
|
|
tileEntity.openInventory();
|
|
}
|
|
|
|
@Override
|
|
public void onContainerClosed(EntityPlayer entityplayer)
|
|
{
|
|
super.onContainerClosed(entityplayer);
|
|
|
|
tileEntity.close(entityplayer);
|
|
tileEntity.closeInventory();
|
|
}
|
|
|
|
@Override
|
|
public boolean canInteractWith(EntityPlayer entityplayer)
|
|
{
|
|
return tileEntity.isUseableByPlayer(entityplayer);
|
|
}
|
|
|
|
@Override
|
|
public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
|
|
{
|
|
ItemStack stack = null;
|
|
Slot currentSlot = (Slot)inventorySlots.get(slotID);
|
|
|
|
if(currentSlot != null && currentSlot.getHasStack())
|
|
{
|
|
ItemStack slotStack = currentSlot.getStack();
|
|
stack = slotStack.copy();
|
|
|
|
if(RecipeHandler.getItemToGasOutput(slotStack, false, Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get()) != null)
|
|
{
|
|
if(slotID != 1)
|
|
{
|
|
if(!mergeItemStack(slotStack, 1, 2, true))
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
else {
|
|
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
else if(ChargeUtils.canBeDischarged(slotStack))
|
|
{
|
|
if(slotID != 3)
|
|
{
|
|
if(!mergeItemStack(slotStack, 3, 4, false))
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
else if(slotID == 3)
|
|
{
|
|
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
else if(slotStack.getItem() instanceof IGasItem)
|
|
{
|
|
if(slotID != 0 && slotID != 2)
|
|
{
|
|
if(!mergeItemStack(slotStack, 0, 1, false))
|
|
{
|
|
if(!mergeItemStack(slotStack, 2, 3, false))
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(slotID >= 4 && slotID <= 30)
|
|
{
|
|
if(!mergeItemStack(slotStack, 31, inventorySlots.size(), false))
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
else if(slotID > 30)
|
|
{
|
|
if(!mergeItemStack(slotStack, 4, 30, false))
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
else {
|
|
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(slotStack.stackSize == 0)
|
|
{
|
|
currentSlot.putStack((ItemStack)null);
|
|
}
|
|
else {
|
|
currentSlot.onSlotChanged();
|
|
}
|
|
|
|
if(slotStack.stackSize == stack.stackSize)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
currentSlot.onPickupFromSlot(player, slotStack);
|
|
}
|
|
|
|
return stack;
|
|
}
|
|
}
|