aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/gui')
-rw-r--r--src/main/java/gregtech/api/gui/GT_Container.java4
-rw-r--r--src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java2
-rw-r--r--src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java158
-rw-r--r--src/main/java/gregtech/api/gui/GT_Container_MaintenanceHatch.java2
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java2
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java20
-rw-r--r--src/main/java/gregtech/api/gui/GT_GUICover.java15
-rw-r--r--src/main/java/gregtech/api/gui/GT_Slot_DataOrb.java2
-rw-r--r--src/main/java/gregtech/api/gui/GT_Slot_Render.java2
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java2
-rw-r--r--src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java1
11 files changed, 193 insertions, 17 deletions
diff --git a/src/main/java/gregtech/api/gui/GT_Container.java b/src/main/java/gregtech/api/gui/GT_Container.java
index 4ce583cff5..608c6015d5 100644
--- a/src/main/java/gregtech/api/gui/GT_Container.java
+++ b/src/main/java/gregtech/api/gui/GT_Container.java
@@ -26,6 +26,7 @@ public class GT_Container extends Container {
mTileEntity = aTileEntityInventory;
mPlayerInventory = aPlayerInventory;
+ mTileEntity.openInventory();
}
/**
@@ -468,6 +469,7 @@ public class GT_Container extends Container {
public void onContainerClosed(EntityPlayer par1EntityPlayer) {
try {
super.onContainerClosed(par1EntityPlayer);
+ mTileEntity.closeInventory();
} catch (Throwable e) {
e.printStackTrace(GT_Log.err);
}
@@ -556,4 +558,4 @@ public class GT_Container extends Container {
}
return true;
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java b/src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java
index 33bdec53e1..5903550a91 100644
--- a/src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java
+++ b/src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java
@@ -209,4 +209,4 @@ public class GT_ContainerMetaTile_Machine extends GT_Container {
public String trans(String aKey, String aEnglish) {
return GT_LanguageManager.addStringLocalization("Interaction_DESCRIPTION_Index_" + aKey, aEnglish, false);
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java
index 7e14061d2f..28fd2983f4 100644
--- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java
+++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java
@@ -4,11 +4,16 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
+import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.FluidStack;
+import net.minecraftforge.fluids.IFluidContainerItem;
+
+import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine.OTHER_SLOT_COUNT;
/**
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
@@ -179,17 +184,162 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank {
@Override
public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) {
+ GT_MetaTileEntity_BasicMachine machine = (GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity();
+ if (machine == null) return null;
+ ItemStack tResultStack;
switch (aSlotIndex) {
case 0:
- if (mTileEntity.getMetaTileEntity() == null) return null;
- ((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mFluidTransfer = !((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mFluidTransfer;
+ machine.mFluidTransfer = !machine.mFluidTransfer;
return null;
case 1:
if (mTileEntity.getMetaTileEntity() == null) return null;
- ((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mItemTransfer = !((GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity()).mItemTransfer;
+ machine.mItemTransfer = !machine.mItemTransfer;
return null;
+ case 2:
+ if (aMouseclick > 1)
+ return null;
+ tResultStack = pickupFluid(machine.getDrainableStack(), aPlayer, aMouseclick == 0);
+ if (machine.getDrainableStack() != null && machine.getDrainableStack().amount == 0)
+ machine.setDrainableStack(null);
+ return tResultStack;
default:
- return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
+ if (aSlotIndex == OTHER_SLOT_COUNT + 1 + machine.mInputSlotCount + machine.mOutputItems.length) {
+ if (aMouseclick > 1)
+ return null;
+ // input fluid slot
+ ItemStack tStackHeld = aPlayer.inventory.getItemStack();
+ ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld);
+ if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null;
+ FluidStack tInputFluid = machine.getFillableStack();
+ FluidStack tFluidHeld = GT_Utility.getFluidForFilledItem(tStackSizedOne, true);
+ if (tFluidHeld != null && tFluidHeld.amount <= 0)
+ tFluidHeld = null;
+ if (tInputFluid == null) {
+ if (tFluidHeld == null)
+ // both null -> no op
+ return null;
+ return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 0);
+ } else {
+ if (tFluidHeld != null && tInputFluid.amount < machine.getCapacity()) {
+ // both nonnull and have space left for filling.
+ // actually both pickup and fill is reasonable, but I'll go with fill here
+ return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 0);
+ } else {
+ tResultStack = pickupFluid(tInputFluid, aPlayer, aMouseclick == 0);
+ if (tInputFluid.amount == 0)
+ machine.setFillableStack(null);
+ return tResultStack;
+ }
+ }
+ } else {
+ return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer);
+ }
+ }
+ }
+
+ private ItemStack pickupFluid(FluidStack aTankStack, EntityPlayer aPlayer, boolean aProcessFullStack) {
+ if (aTankStack == null) return null;
+ ItemStack tStackHeld = aPlayer.inventory.getItemStack();
+ ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld);
+ if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null;
+ int tOriginalFluidAmount = aTankStack.amount;
+ ItemStack tFilled = GT_Utility.fillFluidContainer(aTankStack, tStackSizedOne, true, false);
+ if (tFilled == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) {
+ IFluidContainerItem tContainerItem = (IFluidContainerItem) tStackSizedOne.getItem();
+ int tFilledAmount = tContainerItem.fill(tStackSizedOne, aTankStack, true);
+ if (tFilledAmount > 0) {
+ tFilled = tStackSizedOne;
+ aTankStack.amount -= tFilledAmount;
+ }
+ }
+ if (tFilled != null) {
+ if (aProcessFullStack) {
+ int tFilledAmount = tOriginalFluidAmount - aTankStack.amount;
+ /*
+ work out how many more items we can fill
+ one cell is already used, so account for that
+ the round down behavior will left over a fraction of a cell worth of fluid
+ the user then get to decide what to do with it
+ it will not be too fancy if it spills out partially filled cells
+ */
+ int tAdditionalParallel = Math.min(tStackHeld.stackSize - 1, aTankStack.amount / tFilledAmount);
+ aTankStack.amount -= tFilledAmount * tAdditionalParallel;
+ tFilled.stackSize += tAdditionalParallel;
+ }
+ replaceCursorItemStack(aPlayer, tFilled);
+ }
+ return tFilled;
+ }
+
+ private ItemStack fillFluid(GT_MetaTileEntity_BasicMachine aMachine, EntityPlayer aPlayer, FluidStack aFluidHeld, boolean aProcessFullStack) {
+ // we are not using aMachine.fill() here any more, so we need to check for fluid type here ourselves
+ if (aMachine.getFillableStack() != null && !aMachine.getFillableStack().isFluidEqual(aFluidHeld))
+ return null;
+ ItemStack tStackHeld = aPlayer.inventory.getItemStack();
+ ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld);
+ if (tStackSizedOne == null)
+ return null;
+
+ int tFreeSpace = aMachine.getCapacity() - (aMachine.getFillableStack() != null ? aMachine.getFillableStack().amount : 0);
+ if (tFreeSpace <= 0)
+ // no space left
+ return null;
+
+ // find out how much fluid can be taken
+ // some cells cannot be partially filled
+ ItemStack tStackEmptied = null;
+ int tAmountTaken = 0;
+ if (tFreeSpace >= aFluidHeld.amount) {
+ // fully accepted - try take it from item now
+ // IFluidContainerItem is intentionally not checked here. it will be checked later
+ tStackEmptied = GT_Utility.getContainerForFilledItem(tStackSizedOne, false);
+ tAmountTaken = aFluidHeld.amount;
+ }
+ if (tStackEmptied == null && tStackSizedOne.getItem() instanceof IFluidContainerItem) {
+ // either partially accepted, or is IFluidContainerItem
+ IFluidContainerItem container = (IFluidContainerItem) tStackSizedOne.getItem();
+ FluidStack tDrained = container.drain(tStackSizedOne, tFreeSpace, true);
+ if (tDrained != null && tDrained.amount > 0) {
+ // something is actually drained - change the cell and drop it to player
+ tStackEmptied = tStackSizedOne;
+ tAmountTaken = tDrained.amount;
+ }
+ }
+ if (tStackEmptied == null)
+ // somehow the cell refuse to give out that amount of fluid, no op then
+ return null;
+
+ // find out how many fill can we do
+ // same round down behavior as above
+ // however here the fluid stack is not changed at all, so the exact code will slightly differ
+ int tParallel = aProcessFullStack ? Math.min(tFreeSpace / tAmountTaken, tStackHeld.stackSize) : 1;
+ if (aMachine.getFillableStack() == null) {
+ FluidStack tNewFillableStack = aFluidHeld.copy();
+ tNewFillableStack.amount = tAmountTaken * tParallel;
+ aMachine.setFillableStack(tNewFillableStack);
+ } else {
+ aMachine.getFillableStack().amount += tAmountTaken * tParallel;
+ }
+ tStackEmptied.stackSize = tParallel;
+ replaceCursorItemStack(aPlayer, tStackEmptied);
+ return tStackEmptied;
+ }
+
+ private void replaceCursorItemStack(EntityPlayer aPlayer, ItemStack tStackResult) {
+ int tStackResultMaxStackSize = tStackResult.getMaxStackSize();
+ while (tStackResult.stackSize > tStackResultMaxStackSize) {
+ aPlayer.inventory.getItemStack().stackSize -= tStackResultMaxStackSize;
+ GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult.splitStack(tStackResultMaxStackSize));
+ }
+ if (aPlayer.inventory.getItemStack().stackSize == tStackResult.stackSize) {
+ // every cell is mutated. it could just stay on the cursor.
+ aPlayer.inventory.setItemStack(tStackResult);
+ } else {
+ // some cells not mutated. The mutated cells must go into the inventory
+ // or drop into the world if there isn't enough space.
+ ItemStack tStackHeld = aPlayer.inventory.getItemStack();
+ tStackHeld.stackSize -= tStackResult.stackSize;
+ GT_Utility.addItemToPlayerInventory(aPlayer, tStackResult);
}
}
diff --git a/src/main/java/gregtech/api/gui/GT_Container_MaintenanceHatch.java b/src/main/java/gregtech/api/gui/GT_Container_MaintenanceHatch.java
index c8a70e71f2..c3758486ba 100644
--- a/src/main/java/gregtech/api/gui/GT_Container_MaintenanceHatch.java
+++ b/src/main/java/gregtech/api/gui/GT_Container_MaintenanceHatch.java
@@ -29,4 +29,4 @@ public class GT_Container_MaintenanceHatch extends GT_ContainerMetaTile_Machine
}
return null;
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java b/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java
index 532ce85146..a54aa2e526 100644
--- a/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java
+++ b/src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java
@@ -38,4 +38,4 @@ public class GT_GUIContainerMetaTile_Machine extends GT_GUIContainer {
} else
GL11.glColor3ub((byte) 255, (byte) 255, (byte) 255);
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java
index 3bb802fcf7..bd28bb11e9 100644
--- a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java
+++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java
@@ -1,6 +1,7 @@
package gregtech.api.gui;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
+import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine_Bronze;
import net.minecraft.entity.player.InventoryPlayer;
import java.util.ArrayList;
@@ -23,6 +24,8 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin
public final byte
mProgressBarDirection,
mProgressBarAmount;
+ public final boolean
+ mRenderAutoOutputSlots;
public GT_GUIContainer_BasicMachine(InventoryPlayer aInventoryPlayer, IGregTechTileEntity aTileEntity, String aName, String aTextureFile, String aNEI) {
this(aInventoryPlayer, aTileEntity, aName, aTextureFile, aNEI, (byte) 0, (byte) 1);
@@ -34,12 +37,15 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin
mProgressBarAmount = (byte) Math.max(1, aProgressBarAmount);
mName = aName;
mNEI = aNEI;
+ mRenderAutoOutputSlots = !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_BasicMachine_Bronze);
}
@Override
public void drawScreen(int par1, int par2, float par3) {
super.drawScreen(par1, par2, par3);
- drawTooltip(par1, par2);
+ if (mRenderAutoOutputSlots){
+ drawTooltip(par1, par2);
+ }
}
@Override
@@ -72,10 +78,12 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin
int y = (height - ySize) / 2;
drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
if (mContainer != null) {
- if (((GT_Container_BasicMachine) mContainer).mFluidTransfer)
- drawTexturedModalRect(x + 7, y + 62, 176, 18, 18, 18);
- if (((GT_Container_BasicMachine) mContainer).mItemTransfer)
- drawTexturedModalRect(x + 25, y + 62, 176, 36, 18, 18);
+ if (mRenderAutoOutputSlots){
+ if (((GT_Container_BasicMachine) mContainer).mFluidTransfer)
+ drawTexturedModalRect(x + 7, y + 62, 176, 18, 18, 18);
+ if (((GT_Container_BasicMachine) mContainer).mItemTransfer)
+ drawTexturedModalRect(x + 25, y + 62, 176, 36, 18, 18);
+ }
if (((GT_Container_BasicMachine) mContainer).mStuttering)
drawTexturedModalRect(x + 79, y + 44, 176, 54, 18, 18);
@@ -115,4 +123,4 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin
}
}
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/gui/GT_GUICover.java b/src/main/java/gregtech/api/gui/GT_GUICover.java
index f1232c9432..2e9d082ebf 100644
--- a/src/main/java/gregtech/api/gui/GT_GUICover.java
+++ b/src/main/java/gregtech/api/gui/GT_GUICover.java
@@ -154,6 +154,7 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender
}
}
+ @Override
public void mouseClicked(int x, int y, int button) {
for (GT_GuiIntegerTextBox tBox : textBoxes) {
boolean hadFocus = tBox.isFocused();
@@ -195,7 +196,7 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender
return;
}
}
- if (textBoxes.size() > 0 )
+ if (!textBoxes.isEmpty())
setFocusedTextBox(textBoxes.get(0));
return;
}
@@ -226,15 +227,19 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender
* Button
*/
+ @Override
public void actionPerformed(GuiButton button) {
selectedButton = button;
}
+ @Override
public void clearSelectedButton() {
selectedButton = null;
}
+ @Override
public GuiButton getSelectedButton(){return selectedButton;}
+ @Override
public void buttonClicked(GuiButton button) {
}
@@ -247,10 +252,17 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender
textBox.setFocused(textBox.equals(boxToFocus) && textBox.isEnabled());
}
}
+
+ /**
+ * Given textbox's value might have changed.
+ */
public void applyTextBox(GT_GuiIntegerTextBox box) {
}
+ /**
+ * Reset the given textbox to the last valid value, <b>NOT</b> 0.
+ */
public void resetTextBox(GT_GuiIntegerTextBox box) {
}
@@ -295,6 +307,7 @@ public abstract class GT_GUICover extends GuiScreen implements GT_IToolTipRender
return gui_height;
}
+ @Override
public RenderItem getItemRenderer() {
return itemRender;
}
diff --git a/src/main/java/gregtech/api/gui/GT_Slot_DataOrb.java b/src/main/java/gregtech/api/gui/GT_Slot_DataOrb.java
index 28b4d2828c..ae30f3a5bb 100644
--- a/src/main/java/gregtech/api/gui/GT_Slot_DataOrb.java
+++ b/src/main/java/gregtech/api/gui/GT_Slot_DataOrb.java
@@ -14,4 +14,4 @@ public class GT_Slot_DataOrb extends Slot {
public boolean isItemValid(ItemStack aStack) {
return ItemList.Tool_DataOrb.isStackEqual(aStack, false, true);
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/gui/GT_Slot_Render.java b/src/main/java/gregtech/api/gui/GT_Slot_Render.java
index 92927e284e..270c758536 100644
--- a/src/main/java/gregtech/api/gui/GT_Slot_Render.java
+++ b/src/main/java/gregtech/api/gui/GT_Slot_Render.java
@@ -19,4 +19,4 @@ public class GT_Slot_Render extends GT_Slot_Holo {
}
onSlotChanged();
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java
index e081c4227d..91f611b9b6 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java
@@ -27,6 +27,7 @@ public class GT_GuiIconButton extends GuiButton implements IGuiScreen.IGuiElemen
gui.addElement(this);
}
+ @Override
public void onInit() {
if (tooltip != null)
gui.addToolTip(tooltip);
@@ -39,6 +40,7 @@ public class GT_GuiIconButton extends GuiButton implements IGuiScreen.IGuiElemen
drawButton(Minecraft.getMinecraft(), mouseX, mouseY);
}
+ @Override
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
if (this.tooltip != null)
this.tooltip.enabled = true;
diff --git a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java
index 4e6fd86f55..010ac78654 100644
--- a/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java
+++ b/src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java
@@ -12,6 +12,7 @@ public class GT_GuiIconCheckButton extends GT_GuiIconButton {
this.normalIcon = normalIcon;
}
+ @Override
public GT_GuiIcon getButtonTexture(boolean mouseOver) {
if (!enabled)
return GT_GuiIcon.BUTTON_DISABLED;