Work on container code
This commit is contained in:
parent
a4e8158448
commit
7e48fa2743
7 changed files with 329 additions and 0 deletions
common/mekanism
client/gui
common
inventory/container
tileentity
resources/assets/mekanism/gui
6
common/mekanism/client/gui/GuiChemicalFormulator.java
Normal file
6
common/mekanism/client/gui/GuiChemicalFormulator.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package mekanism.client.gui;
|
||||
|
||||
public class GuiChemicalFormulator
|
||||
{
|
||||
|
||||
}
|
6
common/mekanism/client/gui/GuiChemicalInfuser.java
Normal file
6
common/mekanism/client/gui/GuiChemicalInfuser.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package mekanism.client.gui;
|
||||
|
||||
public class GuiChemicalInfuser
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package mekanism.common.inventory.container;
|
||||
|
||||
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
|
||||
import mekanism.common.inventory.slot.SlotStorageTank;
|
||||
import mekanism.common.item.ItemMachineUpgrade;
|
||||
import mekanism.common.tileentity.TileEntityChemicalInfuser;
|
||||
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 ContainerChemicalFormulator extends Container
|
||||
{
|
||||
private TileEntityChemicalInfuser tileEntity;
|
||||
|
||||
public ContainerChemicalFormulator(InventoryPlayer inventory, TileEntityChemicalInfuser tentity)
|
||||
{
|
||||
tileEntity = tentity;
|
||||
addSlotToContainer(new SlotStorageTank(tentity, null, true, 0, 5, 25));
|
||||
addSlotToContainer(new SlotStorageTank(tentity, null, true, 1, 5, 56));
|
||||
addSlotToContainer(new SlotStorageTank(tentity, null, true, 2, 155, 25));
|
||||
addSlotToContainer(new SlotStorageTank(tentity, null, true, 3, 155, 56));
|
||||
addSlotToContainer(new SlotDischarge(tentity, 4, 155, 5));
|
||||
|
||||
int slotX;
|
||||
|
||||
for(slotX = 0; slotX < 3; slotX++)
|
||||
{
|
||||
for(int slotY = 0; slotY < 9; slotY++)
|
||||
{
|
||||
addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(slotX = 0; slotX < 9; ++slotX)
|
||||
{
|
||||
addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142));
|
||||
}
|
||||
|
||||
tileEntity.playersUsing.add(inventory.player);
|
||||
tileEntity.openChest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityplayer)
|
||||
{
|
||||
super.onContainerClosed(entityplayer);
|
||||
|
||||
tileEntity.playersUsing.remove(entityplayer);
|
||||
tileEntity.closeChest();
|
||||
}
|
||||
|
||||
@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(slotID == 2)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(ChargeUtils.canBeDischarged(slotStack))
|
||||
{
|
||||
if(slotID != 1)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 1, 2, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(slotID == 1)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(slotStack.getItem() instanceof ItemMachineUpgrade)
|
||||
{
|
||||
if(slotID != 0 && slotID != 1 && slotID != 2 && slotID != 3)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 3, 4, 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,155 @@
|
|||
package mekanism.common.inventory.container;
|
||||
|
||||
import mekanism.common.RecipeHandler;
|
||||
import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge;
|
||||
import mekanism.common.inventory.slot.SlotMachineUpgrade;
|
||||
import mekanism.common.inventory.slot.SlotOutput;
|
||||
import mekanism.common.inventory.slot.SlotStorageTank;
|
||||
import mekanism.common.item.ItemMachineUpgrade;
|
||||
import mekanism.common.tileentity.TileEntityChemicalInfuser;
|
||||
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 ContainerChemicalInfuser extends Container
|
||||
{
|
||||
private TileEntityChemicalInfuser tileEntity;
|
||||
|
||||
public ContainerChemicalInfuser(InventoryPlayer inventory, TileEntityChemicalInfuser tentity)
|
||||
{
|
||||
tileEntity = tentity;
|
||||
addSlotToContainer(new Slot(tentity, 0, 26, 36));
|
||||
addSlotToContainer(new SlotDischarge(tentity, 1, 155, 5));
|
||||
addSlotToContainer(new SlotStorageTank(tentity, null, true, 2, 155, 25));
|
||||
addSlotToContainer(new SlotStorageTank(tentity, null, true, 3, 155, 56));
|
||||
|
||||
int slotX;
|
||||
|
||||
for(slotX = 0; slotX < 3; ++slotX)
|
||||
{
|
||||
for(int slotY = 0; slotY < 9; ++slotY)
|
||||
{
|
||||
addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18));
|
||||
}
|
||||
}
|
||||
|
||||
for(slotX = 0; slotX < 9; ++slotX)
|
||||
{
|
||||
addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142));
|
||||
}
|
||||
|
||||
tileEntity.playersUsing.add(inventory.player);
|
||||
tileEntity.openChest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onContainerClosed(EntityPlayer entityplayer)
|
||||
{
|
||||
super.onContainerClosed(entityplayer);
|
||||
|
||||
tileEntity.playersUsing.remove(entityplayer);
|
||||
tileEntity.closeChest();
|
||||
}
|
||||
|
||||
@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(slotID == 2)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(ChargeUtils.canBeDischarged(slotStack))
|
||||
{
|
||||
if(slotID != 1)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 1, 2, false))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if(slotID == 1)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 4, inventorySlots.size(), true))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(slotStack.getItem() instanceof ItemMachineUpgrade)
|
||||
{
|
||||
if(slotID != 0 && slotID != 1 && slotID != 2 && slotID != 3)
|
||||
{
|
||||
if(!mergeItemStack(slotStack, 3, 4, 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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package mekanism.common.tileentity;
|
||||
|
||||
public class TileEntityChemicalFormulator extends TileEntityElectricBlock
|
||||
{
|
||||
public TileEntityChemicalFormulator()
|
||||
{
|
||||
super("ChemicalFormulator", 0 /*TODO*/);
|
||||
}
|
||||
}
|
Binary file not shown.
Before ![]() (image error) Size: 4.1 KiB After ![]() (image error) Size: 4 KiB ![]() ![]() |
Binary file not shown.
Before ![]() (image error) Size: 4.2 KiB After ![]() (image error) Size: 4.2 KiB ![]() ![]() |
Loading…
Add table
Reference in a new issue