From b079bed810ce8ea7cdcdbace0c992d25176e4812 Mon Sep 17 00:00:00 2001 From: "Aidan C. Brady" Date: Fri, 31 Jan 2014 14:59:12 -0500 Subject: [PATCH] Finished container code for new machinery --- .../client/gui/GuiChemicalCrystalizer.java | 4 + .../gui/GuiChemicalDissolutionChamber.java | 4 + .../client/gui/GuiChemicalWasher.java | 4 + common/mekanism/common/CommonProxy.java | 9 + .../ContainerChemicalCrystalizer.java | 152 ++++++++++++++++- .../ContainerChemicalDissolutionChamber.java | 155 +++++++++++++++++- .../container/ContainerChemicalWasher.java | 147 ++++++++++++++++- .../TileEntityChemicalInjectionChamber.java | 4 +- .../common/tile/TileEntityFactory.java | 4 +- 9 files changed, 473 insertions(+), 10 deletions(-) diff --git a/common/mekanism/client/gui/GuiChemicalCrystalizer.java b/common/mekanism/client/gui/GuiChemicalCrystalizer.java index b9e00b90b..41fb4c87f 100644 --- a/common/mekanism/client/gui/GuiChemicalCrystalizer.java +++ b/common/mekanism/client/gui/GuiChemicalCrystalizer.java @@ -1,5 +1,9 @@ package mekanism.client.gui; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) public class GuiChemicalCrystalizer { diff --git a/common/mekanism/client/gui/GuiChemicalDissolutionChamber.java b/common/mekanism/client/gui/GuiChemicalDissolutionChamber.java index 679c36e6f..ebacf9f9c 100644 --- a/common/mekanism/client/gui/GuiChemicalDissolutionChamber.java +++ b/common/mekanism/client/gui/GuiChemicalDissolutionChamber.java @@ -1,5 +1,9 @@ package mekanism.client.gui; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) public class GuiChemicalDissolutionChamber { diff --git a/common/mekanism/client/gui/GuiChemicalWasher.java b/common/mekanism/client/gui/GuiChemicalWasher.java index e609f2094..a45b2f58c 100644 --- a/common/mekanism/client/gui/GuiChemicalWasher.java +++ b/common/mekanism/client/gui/GuiChemicalWasher.java @@ -1,5 +1,9 @@ package mekanism.client.gui; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) public class GuiChemicalWasher { diff --git a/common/mekanism/common/CommonProxy.java b/common/mekanism/common/CommonProxy.java index effb0cf36..bf9e33d5a 100644 --- a/common/mekanism/common/CommonProxy.java +++ b/common/mekanism/common/CommonProxy.java @@ -6,8 +6,11 @@ import mekanism.api.MekanismAPI; import mekanism.common.entity.EntityRobit; import mekanism.common.inventory.container.ContainerAdvancedElectricMachine; import mekanism.common.inventory.container.ContainerChanceMachine; +import mekanism.common.inventory.container.ContainerChemicalCrystalizer; +import mekanism.common.inventory.container.ContainerChemicalDissolutionChamber; import mekanism.common.inventory.container.ContainerChemicalInfuser; import mekanism.common.inventory.container.ContainerChemicalOxidizer; +import mekanism.common.inventory.container.ContainerChemicalWasher; import mekanism.common.inventory.container.ContainerDictionary; import mekanism.common.inventory.container.ContainerDigitalMiner; import mekanism.common.inventory.container.ContainerDynamicTank; @@ -386,6 +389,12 @@ public class CommonProxy return new ContainerSalinationController(player.inventory, (TileEntitySalinationController)tileEntity); case 34: return new ContainerChanceMachine(player.inventory, (TileEntityChanceMachine)tileEntity); + case 35: + return new ContainerChemicalDissolutionChamber(player.inventory, (TileEntityChemicalDissolutionChamber)tileEntity); + case 36: + return new ContainerChemicalWasher(player.inventory, (TileEntityChemicalWasher)tileEntity); + case 37: + return new ContainerChemicalCrystalizer(player.inventory, (TileEntityChemicalCrystalizer)tileEntity); } return null; diff --git a/common/mekanism/common/inventory/container/ContainerChemicalCrystalizer.java b/common/mekanism/common/inventory/container/ContainerChemicalCrystalizer.java index 054538695..ccce71ea0 100644 --- a/common/mekanism/common/inventory/container/ContainerChemicalCrystalizer.java +++ b/common/mekanism/common/inventory/container/ContainerChemicalCrystalizer.java @@ -1,6 +1,154 @@ package mekanism.common.inventory.container; -public class ContainerChemicalCrystalizer +import mekanism.api.gas.IGasItem; +import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge; +import mekanism.common.inventory.slot.SlotOutput; +import mekanism.common.inventory.slot.SlotStorageTank; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.RecipeHandler.Recipe; +import mekanism.common.tile.TileEntityChemicalCrystalizer; +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 ContainerChemicalCrystalizer extends Container { - + private TileEntityChemicalCrystalizer tileEntity; + + public ContainerChemicalCrystalizer(InventoryPlayer inventory, TileEntityChemicalCrystalizer tentity) + { + tileEntity = tentity; + addSlotToContainer(new SlotStorageTank(tentity, null, true, 0, 6, 65)); + addSlotToContainer(new SlotOutput(tentity, 1, 131, 57)); + addSlotToContainer(new SlotDischarge(tentity, 2, 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.openChest(); + } + + @Override + public void onContainerClosed(EntityPlayer entityplayer) + { + super.onContainerClosed(entityplayer); + + tileEntity.close(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(slotStack.getItem() instanceof IGasItem) + { + if(slotID != 0) + { + if(!mergeItemStack(slotStack, 0, 1, false)) + { + return null; + } + } + else { + if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) + { + return null; + } + } + } + else if(slotID == 1) + { + if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) + { + return null; + } + } + else if(ChargeUtils.canBeDischarged(slotStack)) + { + if(slotID != 3) + { + if(!mergeItemStack(slotStack, 2, 3, false)) + { + return null; + } + } + else if(slotID == 3) + { + if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) + { + return null; + } + } + } + else { + if(slotID >= 3 && slotID <= 29) + { + if(!mergeItemStack(slotStack, 30, inventorySlots.size(), false)) + { + return null; + } + } + else if(slotID > 30) + { + if(!mergeItemStack(slotStack, 3, 29, false)) + { + return null; + } + } + else { + if(!mergeItemStack(slotStack, 3, 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; + } } diff --git a/common/mekanism/common/inventory/container/ContainerChemicalDissolutionChamber.java b/common/mekanism/common/inventory/container/ContainerChemicalDissolutionChamber.java index 0623cda71..c5470a19a 100644 --- a/common/mekanism/common/inventory/container/ContainerChemicalDissolutionChamber.java +++ b/common/mekanism/common/inventory/container/ContainerChemicalDissolutionChamber.java @@ -1,6 +1,157 @@ package mekanism.common.inventory.container; -public class ContainerChemicalDissolutionChamber +import mekanism.api.gas.IGasItem; +import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge; +import mekanism.common.inventory.slot.SlotStorageTank; +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, null, true, 0, 6, 65)); + addSlotToContainer(new Slot(tentity, 1, 26, 36)); + addSlotToContainer(new SlotStorageTank(tentity, null, true, 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.openChest(); + } + + @Override + public void onContainerClosed(EntityPlayer entityplayer) + { + super.onContainerClosed(entityplayer); + + tileEntity.close(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(RecipeHandler.getItemToGasOutput(slotStack, false, Recipe.CHEMICAL_DISSOLUTION_CHAMBER.get()) != null) + { + if(!mergeItemStack(slotStack, 1, 2, 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 > 31) + { + 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; + } } diff --git a/common/mekanism/common/inventory/container/ContainerChemicalWasher.java b/common/mekanism/common/inventory/container/ContainerChemicalWasher.java index 4ee70b7a5..f337f4de0 100644 --- a/common/mekanism/common/inventory/container/ContainerChemicalWasher.java +++ b/common/mekanism/common/inventory/container/ContainerChemicalWasher.java @@ -1,6 +1,149 @@ package mekanism.common.inventory.container; -public class ContainerChemicalWasher +import mekanism.api.gas.IGasItem; +import mekanism.common.inventory.slot.SlotEnergy.SlotDischarge; +import mekanism.common.inventory.slot.SlotStorageTank; +import mekanism.common.recipe.RecipeHandler; +import mekanism.common.recipe.RecipeHandler.Recipe; +import mekanism.common.tile.TileEntityChemicalWasher; +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 ContainerChemicalWasher extends Container { - + private TileEntityChemicalWasher tileEntity; + + public ContainerChemicalWasher(InventoryPlayer inventory, TileEntityChemicalWasher tentity) + { + tileEntity = tentity; + addSlotToContainer(new Slot(tentity, 0, 6, 65)); + addSlotToContainer(new SlotStorageTank(tentity, null, true, 1, 155, 56)); + addSlotToContainer(new SlotDischarge(tentity, 2, 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.openChest(); + } + + @Override + public void onContainerClosed(EntityPlayer entityplayer) + { + super.onContainerClosed(entityplayer); + + tileEntity.close(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(slotStack.getItem() instanceof IGasItem) + { + if(slotID != 0 && slotID != 1) + { + if(!mergeItemStack(slotStack, 0, 1, false)) + { + if(!mergeItemStack(slotStack, 1, 2, false)) + { + return null; + } + } + } + else { + if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) + { + return null; + } + } + } + else if(ChargeUtils.canBeDischarged(slotStack)) + { + if(slotID != 2) + { + if(!mergeItemStack(slotStack, 2, 3, false)) + { + return null; + } + } + else if(slotID == 2) + { + if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true)) + { + return null; + } + } + } + else { + if(slotID >= 3 && slotID <= 29) + { + if(!mergeItemStack(slotStack, 30, inventorySlots.size(), false)) + { + return null; + } + } + else if(slotID > 30) + { + if(!mergeItemStack(slotStack, 3, 29, false)) + { + return null; + } + } + else { + if(!mergeItemStack(slotStack, 3, 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; + } } diff --git a/common/mekanism/common/tile/TileEntityChemicalInjectionChamber.java b/common/mekanism/common/tile/TileEntityChemicalInjectionChamber.java index e245510d8..8c36de8b3 100644 --- a/common/mekanism/common/tile/TileEntityChemicalInjectionChamber.java +++ b/common/mekanism/common/tile/TileEntityChemicalInjectionChamber.java @@ -62,9 +62,9 @@ public class TileEntityChemicalInjectionChamber extends TileEntityAdvancedElectr { if(inventory[1] != null && gasTank.getNeeded() > 0 && inventory[1].getItem() instanceof IGasItem) { - Gas gas = ((IGasItem)inventory[1].getItem()).getGas(inventory[1]).getGas(); + GasStack gas = ((IGasItem)inventory[1].getItem()).getGas(inventory[1]); - if(isValidGas(gas)) + if(gas != null && isValidGas(gas.getGas())) { GasStack removed = GasTransmission.removeGas(inventory[1], gasTank.getGas() != null ? gasTank.getGas().getGas() : null, gasTank.getNeeded()); gasTank.receive(removed, true); diff --git a/common/mekanism/common/tile/TileEntityFactory.java b/common/mekanism/common/tile/TileEntityFactory.java index 162b16bf5..28f021d3b 100644 --- a/common/mekanism/common/tile/TileEntityFactory.java +++ b/common/mekanism/common/tile/TileEntityFactory.java @@ -345,9 +345,9 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip { if(inventory[4].getItem() instanceof IGasItem) { - Gas gas = ((IGasItem)inventory[4].getItem()).getGas(inventory[4]).getGas(); + GasStack gas = ((IGasItem)inventory[4].getItem()).getGas(inventory[4]); - if(RecipeType.values()[recipeType].isValidGas(gas)) + if(gas != null && RecipeType.values()[recipeType].isValidGas(gas.getGas())) { GasStack removed = GasTransmission.removeGas(inventory[4], gasTank.getGas() != null ? gasTank.getGas().getGas() : null, gasTank.getNeeded()); gasTank.receive(removed, true);