From 8522412f4e415028c37d945365f4edf913299639 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 31 Jan 2021 18:52:08 +0800 Subject: BasicMachine fluid tank manipulations in GUI Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../api/gui/GT_Container_BasicMachine.java | 98 +++++++++++++++++++++- src/main/java/gregtech/api/gui/GT_Slot_Render.java | 2 + 2 files changed, 96 insertions(+), 4 deletions(-) (limited to 'src/main/java/gregtech/api/gui') 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..6cd7f9e8e3 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,18 @@ 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 net.minecraftforge.fluids.IFluidTank; + +import static gregtech.api.enums.GT_Values.NI; +import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine.OTHER_SLOT_COUNT; /** * NEVER INCLUDE THIS FILE IN YOUR MOD!!! @@ -179,18 +186,101 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { @Override public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { + if (mTileEntity.getMetaTileEntity() == null) return null; + GT_MetaTileEntity_BasicMachine machine = (GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity(); 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: + return pickupFluid(machine.getDrainableStack(), aPlayer); default: - return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + if (aSlotIndex == OTHER_SLOT_COUNT + 1 + machine.mInputSlotCount + machine.mOutputItems.length) { + // input fluid slot + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); + if (tStackSizedOne == null) return null; + FluidStack tInputFluid = machine.getFillableStack(); + FluidStack tFluidHeld = GT_Utility.getFluidForFilledItem(tStackSizedOne, true); + if (tInputFluid == null) { + if (tFluidHeld == null) + // both null -> no op + return null; + return fillFluid(machine, aPlayer, tFluidHeld); + } else { + if (tFluidHeld != null) { + // both nonnull. actually both pickup and fill is reasonable, but I'll go with fill here + return fillFluid(machine, aPlayer, tFluidHeld); + } else { + return pickupFluid(machine.getFillableStack(), aPlayer); + } + } + } else { + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + } + } + + private ItemStack pickupFluid(FluidStack aTankStack, EntityPlayer aPlayer) { + if (aTankStack == null) return null; + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); + if (tStackSizedOne == null) return null; + 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) { + reduceStackSizeInHandByOne(aPlayer); + GT_Utility.addItemToPlayerInventory(aPlayer, tFilled); } + return tFilled; + } + + private ItemStack fillFluid(IFluidTank aTank, EntityPlayer aPlayer, FluidStack aFluidHeld) { + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); + if (tStackSizedOne == null) + return null; + + int tFilled = aTank.fill(aFluidHeld, false); + if (tFilled == 0) // filled nothing + return null; + ItemStack tStackEmptied = null; + if (tFilled == 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); + if (tStackEmptied == null && tStackHeld.getItem() instanceof IFluidContainerItem) { + IFluidContainerItem container = (IFluidContainerItem) tStackHeld.getItem(); + FluidStack tDrained = container.drain(tStackSizedOne, tFilled, true); + if (tDrained != null && tDrained.amount > 0) + // something is actually drained - change the cell and drop it to player + tStackEmptied = tStackSizedOne; + } + if (tStackEmptied == null) + // somehow the cell refuse to take that amount of fluid, no op then + return null; + aTank.fill(aFluidHeld, true); + GT_Utility.addItemToPlayerInventory(aPlayer, tStackEmptied); + reduceStackSizeInHandByOne(aPlayer); + return tStackEmptied; + } + + private void reduceStackSizeInHandByOne(EntityPlayer aPlayer) { + ItemStack tStackHeld = aPlayer.inventory.getItemStack(); + tStackHeld.stackSize -= 1; + if (tStackHeld.stackSize == 0) + aPlayer.inventory.setItemStack(NI); } @Override 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..8dd19a0e8e 100644 --- a/src/main/java/gregtech/api/gui/GT_Slot_Render.java +++ b/src/main/java/gregtech/api/gui/GT_Slot_Render.java @@ -1,5 +1,7 @@ package gregtech.api.gui; +import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -- cgit From 3d4a402564b5a862866f6826d4b26179658d7221 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Sun, 31 Jan 2021 20:00:03 +0800 Subject: Address reviews Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java | 4 ++-- src/main/java/gregtech/api/gui/GT_Slot_Render.java | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src/main/java/gregtech/api/gui') 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 6cd7f9e8e3..7e4e105353 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java @@ -186,8 +186,8 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { @Override public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer) { - if (mTileEntity.getMetaTileEntity() == null) return null; GT_MetaTileEntity_BasicMachine machine = (GT_MetaTileEntity_BasicMachine) mTileEntity.getMetaTileEntity(); + if (machine == null) return null; switch (aSlotIndex) { case 0: machine.mFluidTransfer = !machine.mFluidTransfer; @@ -216,7 +216,7 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { // both nonnull. actually both pickup and fill is reasonable, but I'll go with fill here return fillFluid(machine, aPlayer, tFluidHeld); } else { - return pickupFluid(machine.getFillableStack(), aPlayer); + return pickupFluid(tInputFluid, aPlayer); } } } else { 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 8dd19a0e8e..92927e284e 100644 --- a/src/main/java/gregtech/api/gui/GT_Slot_Render.java +++ b/src/main/java/gregtech/api/gui/GT_Slot_Render.java @@ -1,7 +1,5 @@ package gregtech.api.gui; -import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_Hatch_Maintenance; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -- cgit From eede79b1f210eec76f3b223353ab06a3398919ef Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 9 Feb 2021 02:14:26 +0800 Subject: Fix size 0 fluid stack Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/main/java/gregtech/api/gui') 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 7e4e105353..da528d67fc 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java @@ -188,6 +188,7 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { 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: machine.mFluidTransfer = !machine.mFluidTransfer; @@ -197,7 +198,10 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { machine.mItemTransfer = !machine.mItemTransfer; return null; case 2: - return pickupFluid(machine.getDrainableStack(), aPlayer); + tResultStack = pickupFluid(machine.getDrainableStack(), aPlayer); + if (machine.getDrainableStack().amount == 0) + machine.setDrainableStack(null); + return tResultStack; default: if (aSlotIndex == OTHER_SLOT_COUNT + 1 + machine.mInputSlotCount + machine.mOutputItems.length) { // input fluid slot @@ -216,7 +220,10 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { // both nonnull. actually both pickup and fill is reasonable, but I'll go with fill here return fillFluid(machine, aPlayer, tFluidHeld); } else { - return pickupFluid(tInputFluid, aPlayer); + tResultStack = pickupFluid(tInputFluid, aPlayer); + if (tInputFluid.amount == 0) + machine.setFillableStack(null); + return tResultStack; } } } else { -- cgit From 3dfd906868ee4a02caa7aa97438ccb25f15c0843 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 9 Feb 2021 03:57:57 +0800 Subject: Allows manipulating multiple cell worth of fluid Left click to do as many manipulation as possible. Right click to just manipulate once. Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../api/gui/GT_Container_BasicMachine.java | 98 ++++++++++++++++------ 1 file changed, 71 insertions(+), 27 deletions(-) (limited to 'src/main/java/gregtech/api/gui') 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 da528d67fc..665be8b8ce 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java @@ -12,9 +12,7 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; -import net.minecraftforge.fluids.IFluidTank; -import static gregtech.api.enums.GT_Values.NI; import static gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine.OTHER_SLOT_COUNT; /** @@ -198,12 +196,16 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { machine.mItemTransfer = !machine.mItemTransfer; return null; case 2: - tResultStack = pickupFluid(machine.getDrainableStack(), aPlayer); - if (machine.getDrainableStack().amount == 0) + 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: 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); @@ -214,13 +216,13 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { if (tFluidHeld == null) // both null -> no op return null; - return fillFluid(machine, aPlayer, tFluidHeld); + return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 0); } else { if (tFluidHeld != null) { // both nonnull. actually both pickup and fill is reasonable, but I'll go with fill here - return fillFluid(machine, aPlayer, tFluidHeld); + return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 1); } else { - tResultStack = pickupFluid(tInputFluid, aPlayer); + tResultStack = pickupFluid(tInputFluid, aPlayer, aMouseclick == 0); if (tInputFluid.amount == 0) machine.setFillableStack(null); return tResultStack; @@ -232,11 +234,12 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { } } - private ItemStack pickupFluid(FluidStack aTankStack, EntityPlayer 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) 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(); @@ -247,47 +250,88 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { } } if (tFilled != null) { - reduceStackSizeInHandByOne(aPlayer); - GT_Utility.addItemToPlayerInventory(aPlayer, tFilled); + if (aProcessFullStack) { + int tFilledAmount = tOriginalFluidAmount - aTankStack.amount; + /* + work out how many more items we can fill + 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, aTankStack.amount / tFilledAmount); + aTankStack.amount -= tFilledAmount * tAdditionalParallel; + tFilled.stackSize += tAdditionalParallel; + } + replaceCursorItemStack(aPlayer, tFilled); } return tFilled; } - private ItemStack fillFluid(IFluidTank aTank, EntityPlayer aPlayer, FluidStack aFluidHeld) { + 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 tFilled = aTank.fill(aFluidHeld, false); - if (tFilled == 0) // filled nothing + 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; - if (tFilled == aFluidHeld.amount) + 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); - if (tStackEmptied == null && tStackHeld.getItem() instanceof IFluidContainerItem) { - IFluidContainerItem container = (IFluidContainerItem) tStackHeld.getItem(); - FluidStack tDrained = container.drain(tStackSizedOne, tFilled, true); - if (tDrained != null && tDrained.amount > 0) + 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 take that amount of fluid, no op then + // somehow the cell refuse to give out that amount of fluid, no op then return null; - aTank.fill(aFluidHeld, true); - GT_Utility.addItemToPlayerInventory(aPlayer, tStackEmptied); - reduceStackSizeInHandByOne(aPlayer); + + // 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 reduceStackSizeInHandByOne(EntityPlayer aPlayer) { - ItemStack tStackHeld = aPlayer.inventory.getItemStack(); - tStackHeld.stackSize -= 1; - if (tStackHeld.stackSize == 0) - aPlayer.inventory.setItemStack(NI); + private void replaceCursorItemStack(EntityPlayer aPlayer, ItemStack tStackResult) { + 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); + } } @Override -- cgit From 533f8d6f2cea05ba94d1b829e1f90769cd7ce2ab Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Wed, 10 Feb 2021 14:34:42 +0800 Subject: Fix bucket gui fluid manipulation Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- .../java/gregtech/api/gui/GT_Container_BasicMachine.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/main/java/gregtech/api/gui') 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 665be8b8ce..38f8bd3b35 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java @@ -209,7 +209,7 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { // input fluid slot ItemStack tStackHeld = aPlayer.inventory.getItemStack(); ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); - if (tStackSizedOne == null) return null; + if (tStackSizedOne == null || tStackHeld.stackSize == 0) return null; FluidStack tInputFluid = machine.getFillableStack(); FluidStack tFluidHeld = GT_Utility.getFluidForFilledItem(tStackSizedOne, true); if (tInputFluid == null) { @@ -220,7 +220,7 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { } else { if (tFluidHeld != null) { // both nonnull. actually both pickup and fill is reasonable, but I'll go with fill here - return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 1); + return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 0); } else { tResultStack = pickupFluid(tInputFluid, aPlayer, aMouseclick == 0); if (tInputFluid.amount == 0) @@ -238,7 +238,7 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { if (aTankStack == null) return null; ItemStack tStackHeld = aPlayer.inventory.getItemStack(); ItemStack tStackSizedOne = GT_Utility.copyAmount(1, tStackHeld); - if (tStackSizedOne == null) return null; + 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) { @@ -254,11 +254,12 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { 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, aTankStack.amount / tFilledAmount); + int tAdditionalParallel = Math.min(tStackHeld.stackSize - 1, aTankStack.amount / tFilledAmount); aTankStack.amount -= tFilledAmount * tAdditionalParallel; tFilled.stackSize += tAdditionalParallel; } @@ -285,7 +286,7 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { // some cells cannot be partially filled ItemStack tStackEmptied = null; int tAmountTaken = 0; - if (tFreeSpace == aFluidHeld.amount) { + 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); @@ -322,6 +323,11 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { } 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); -- cgit From e2d26747b7fcbdf04d079d0657b2febe6284b635 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Mon, 22 Feb 2021 13:48:11 +0800 Subject: Pickup fluid instead if the input tank is full Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/main/java/gregtech/api/gui') 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 38f8bd3b35..4939c975d5 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java @@ -218,8 +218,9 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { return null; return fillFluid(machine, aPlayer, tFluidHeld, aMouseclick == 0); } else { - if (tFluidHeld != null) { - // both nonnull. actually both pickup and fill is reasonable, but I'll go with fill here + 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); -- cgit From 32a49d1cbbae44cac7ec6094e4bf8f94ae8ab46a Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Mon, 22 Feb 2021 13:05:05 +0800 Subject: Fix bottled water filling Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main/java/gregtech/api/gui') 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 38f8bd3b35..d4ecc19189 100644 --- a/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_Container_BasicMachine.java @@ -212,6 +212,8 @@ public class GT_Container_BasicMachine extends GT_Container_BasicTank { 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 -- cgit From ae3b94a7c943aa2c393eaf82dfcff8879c0e06af Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Tue, 30 Mar 2021 02:22:23 +0800 Subject: Only update fluid display items when necessary Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/gui/GT_Container.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/main/java/gregtech/api/gui') diff --git a/src/main/java/gregtech/api/gui/GT_Container.java b/src/main/java/gregtech/api/gui/GT_Container.java index 4ce583cff5..671d68b917 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); } -- cgit From 4c8cf9986d75f91b13281de1d9d476d6dd392d50 Mon Sep 17 00:00:00 2001 From: Léa Gris Date: Tue, 27 Apr 2021 23:13:38 +0200 Subject: fix(textfiles): add missing neline at end of files git and diff tools will complain if text file does not end with a newline. Fixed all text files in the repository with Linux bash shell: ```sh git ls-files -z | while IFS= read -rd '' f; do mime="$(file --brief --mime "$f")"; if [ -z "${mime##text/*}" ]; then tail -c1 "$f" | read -r _ || printf '\n' >>"$f"; fi; done ``` --- src/main/java/gregtech/api/gui/GT_Container.java | 2 +- src/main/java/gregtech/api/gui/GT_ContainerMetaTile_Machine.java | 2 +- src/main/java/gregtech/api/gui/GT_Container_MaintenanceHatch.java | 2 +- src/main/java/gregtech/api/gui/GT_GUIContainerMetaTile_Machine.java | 2 +- src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java | 2 +- src/main/java/gregtech/api/gui/GT_Slot_DataOrb.java | 2 +- src/main/java/gregtech/api/gui/GT_Slot_Render.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/main/java/gregtech/api/gui') diff --git a/src/main/java/gregtech/api/gui/GT_Container.java b/src/main/java/gregtech/api/gui/GT_Container.java index 671d68b917..608c6015d5 100644 --- a/src/main/java/gregtech/api/gui/GT_Container.java +++ b/src/main/java/gregtech/api/gui/GT_Container.java @@ -558,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_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..a27ee175ef 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java @@ -115,4 +115,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_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 +} -- cgit From a4e104881944bbc03eddeacb24a6b7bd94cc53ce Mon Sep 17 00:00:00 2001 From: Léa Gris Date: Mon, 24 May 2021 15:37:22 +0200 Subject: feat(glow): iconset machines glow support - Add glow support for all sides and states of iconset machines (same as with basicmachines). Automated code cleanup with IDEA of: - Optiimise all imports (remove unused, sort) - Reorder all modifiers to the canonical preferred order (as stated in the Java Language Specification) - Add all missing @Override annotations --- src/main/java/gregtech/api/gui/GT_GUICover.java | 8 +++++++- src/main/java/gregtech/api/gui/widgets/GT_GuiIconButton.java | 2 ++ src/main/java/gregtech/api/gui/widgets/GT_GuiIconCheckButton.java | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/gui') diff --git a/src/main/java/gregtech/api/gui/GT_GUICover.java b/src/main/java/gregtech/api/gui/GT_GUICover.java index f1232c9432..1e51cf0758 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) { } @@ -295,6 +300,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/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; -- cgit From ad450c8a3f2234bf392b8bb175d1eace8ad2ca20 Mon Sep 17 00:00:00 2001 From: Yannick Marcotte-Gourde Date: Sat, 12 Jun 2021 11:19:19 -0400 Subject: No auto-output rendering for steam basic machines --- .../gregtech/api/gui/GT_GUIContainer_BasicMachine.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/main/java/gregtech/api/gui') 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 a27ee175ef..3d7247b673 100644 --- a/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java +++ b/src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java @@ -23,6 +23,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 +36,15 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin mProgressBarAmount = (byte) Math.max(1, aProgressBarAmount); mName = aName; mNEI = aNEI; + mRenderAutoOutputSlots = !(aTextureFile.startsWith("Steel") || aTextureFile.startsWith("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 +77,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); -- cgit From 35f33298f8420dd47496d029cfc8209c896b5de4 Mon Sep 17 00:00:00 2001 From: Yannick Marcotte-Gourde Date: Mon, 14 Jun 2021 19:09:45 -0400 Subject: Using explicit steam machine check --- src/main/java/gregtech/api/gui/GT_GUIContainer_BasicMachine.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/gui') 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 3d7247b673..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; @@ -36,7 +37,7 @@ public class GT_GUIContainer_BasicMachine extends GT_GUIContainerMetaTile_Machin mProgressBarAmount = (byte) Math.max(1, aProgressBarAmount); mName = aName; mNEI = aNEI; - mRenderAutoOutputSlots = !(aTextureFile.startsWith("Steel") || aTextureFile.startsWith("Bronze")); + mRenderAutoOutputSlots = !(aTileEntity.getMetaTileEntity() instanceof GT_MetaTileEntity_BasicMachine_Bronze); } @Override -- cgit From e49a886b31e826a32b973ba3f2324063f6fe66a3 Mon Sep 17 00:00:00 2001 From: Glease <4586901+Glease@users.noreply.github.com> Date: Fri, 25 Jun 2021 14:49:25 +0800 Subject: Fix redstone cover UX being weird Signed-off-by: Glease <4586901+Glease@users.noreply.github.com> --- src/main/java/gregtech/api/gui/GT_GUICover.java | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/main/java/gregtech/api/gui') diff --git a/src/main/java/gregtech/api/gui/GT_GUICover.java b/src/main/java/gregtech/api/gui/GT_GUICover.java index 1e51cf0758..2e9d082ebf 100644 --- a/src/main/java/gregtech/api/gui/GT_GUICover.java +++ b/src/main/java/gregtech/api/gui/GT_GUICover.java @@ -252,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, NOT 0. + */ public void resetTextBox(GT_GuiIntegerTextBox box) { } -- cgit