From b89f29863d482c2d5a8e1b817882704fca0f2bb7 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Sat, 4 May 2024 21:51:03 +0300 Subject: [PATCH] fix fluid locking --- settings.gradle | 2 +- .../api/cover/filter/SimpleFluidFilter.java | 2 +- .../widget/ScrollablePhantomFluidWidget.java | 16 +++------ .../machine/trait/NotifiableFluidTank.java | 36 +++++++++++++------ .../part/FluidHatchPartMachine.java | 31 ++++++++-------- .../machine/storage/CreativeTankMachine.java | 3 +- .../machine/storage/QuantumTankMachine.java | 6 ++-- 7 files changed, 51 insertions(+), 45 deletions(-) diff --git a/settings.gradle b/settings.gradle index 6ce234bc1d..dd754eedea 100644 --- a/settings.gradle +++ b/settings.gradle @@ -43,7 +43,7 @@ dependencyResolutionManagement { def vineFlowerVersion = "1.+" def macheteVersion = "1.+" def configurationVersion = "2.2.0" - def ldLibVersion = "1.0.25.e" + def ldLibVersion = "1.0.25.g" def mixinextrasVersion = "0.2.0" def shimmerVersion = "0.2.2" diff --git a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/SimpleFluidFilter.java b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/SimpleFluidFilter.java index 931fd9a58e..e8b807ec6a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/cover/filter/SimpleFluidFilter.java +++ b/src/main/java/com/gregtechceu/gtceu/api/cover/filter/SimpleFluidFilter.java @@ -101,7 +101,7 @@ public WidgetGroup openConfigurator(int x, int y) { fluidStorageSlots[index] = new FluidStorage(maxStackSize); fluidStorageSlots[index].setFluid(matches[index]); - var tank = new ScrollablePhantomFluidWidget(fluidStorageSlots[index], i * 18, j * 18) { + var tank = new ScrollablePhantomFluidWidget(fluidStorageSlots[index], 0, i * 18, j * 18, 18, 18, () -> fluidStorageSlots[index].getFluid(), (fluid) -> fluidStorageSlots[index].setFluid(fluid)) { @Override public void updateScreen() { super.updateScreen(); diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java index a825f4f466..b7b2089769 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/ScrollablePhantomFluidWidget.java @@ -4,28 +4,22 @@ import com.lowdragmc.lowdraglib.gui.widget.PhantomFluidWidget; import com.lowdragmc.lowdraglib.side.fluid.FluidHelper; import com.lowdragmc.lowdraglib.side.fluid.FluidStack; -import com.lowdragmc.lowdraglib.side.fluid.IFluidStorage; import com.lowdragmc.lowdraglib.side.fluid.IFluidTransfer; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.util.Mth; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import org.jetbrains.annotations.Nullable; +import java.util.function.Consumer; +import java.util.function.Supplier; + public class ScrollablePhantomFluidWidget extends PhantomFluidWidget { private static final int SCROLL_ACTION_ID = 0x0001_0001; private static final long MILLIBUCKETS = FluidHelper.getBucket() / 1000; - public ScrollablePhantomFluidWidget() { - } - - public ScrollablePhantomFluidWidget(IFluidStorage fluidTank, int x, int y) { - super(fluidTank, x, y); - } - - public ScrollablePhantomFluidWidget(@Nullable IFluidStorage fluidTank, int x, int y, int width, int height) { - super(fluidTank, x, y, width, height); + public ScrollablePhantomFluidWidget(@Nullable IFluidTransfer fluidTank, int tank, int x, int y, int width, int height, Supplier phantomFluidGetter, Consumer phantomFluidSetter) { + super(fluidTank, tank, x, y, width, height, phantomFluidGetter, phantomFluidSetter); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java index 317aea6394..72dff22f31 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java @@ -42,9 +42,6 @@ public class NotifiableFluidTank extends NotifiableRecipeHandlerTrait handleIngredient(IO io, List stack.isFluidEqual(this.lockedFluid.getFluid())); - return; + } else { + this.lockedFluid.setFluid(FluidStack.empty()); + setFilter(stack -> true); + onContentsChanged(); + } + } + + public void setLocked(boolean locked, FluidStack fluidStack) { + if (this.isLocked() == locked) return; + if (locked && !fluidStack.isEmpty()) { + this.lockedFluid.setFluid(fluidStack.copy()); + this.lockedFluid.getFluid().setAmount(1); + onContentsChanged(); + setFilter(stack -> stack.isFluidEqual(this.lockedFluid.getFluid())); + } else { + this.lockedFluid.setFluid(FluidStack.empty()); + setFilter(stack -> true); + onContentsChanged(); } - this.lockedFluid.setFluid(FluidStack.empty()); - setFilter(stack -> true); - onContentsChanged(); } public NotifiableFluidTank setFilter(Predicate filter) { diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java index aa1151cf4d..fdb72e5417 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/part/FluidHatchPartMachine.java @@ -155,20 +155,19 @@ protected Widget createSingleSlotGUI() { // Add input/output-specific widgets if (this.io == IO.OUT) { // if this is an output hatch, assign tankWidget to the phantom widget displaying the locked fluid... - group.addWidget(tankWidget = new PhantomFluidWidget(this.tank.getLockedFluid(), 67, 40, 18, 18) - .setIFluidStackUpdater(f -> { - if (this.tank.getFluidInTank(0).getAmount() != 0) { - return; - } - if (f.isEmpty()) { - this.tank.setLocked(false); - } else { - this.tank.setLocked(true); - FluidStack newFluid = f.copy(); - newFluid.setAmount(1); - this.tank.getLockedFluid().setFluid(newFluid); - } - }).setShowAmount(true).setDrawHoverTips(false).setBackground(GuiTextures.FLUID_SLOT)); + group.addWidget(tankWidget = new PhantomFluidWidget(this.tank.getLockedFluid(), 0, 67, 40, 18, 18, + () -> this.tank.getLockedFluid().getFluid(), f -> { + if (!this.tank.getFluidInTank(0).isEmpty()) { + return; + } + if (f == null || f.isEmpty()) { + this.tank.setLocked(false); + } else { + FluidStack newFluid = f.copy(); + newFluid.setAmount(1); + this.tank.setLocked(true, newFluid); + } + }).setShowAmount(true).setDrawHoverTips(true).setBackground(GuiTextures.FLUID_SLOT)); group.addWidget(new ToggleButtonWidget(7, 40, 18, 18, GuiTextures.BUTTON_LOCK, this.tank::isLocked, this.tank::setLocked) @@ -176,10 +175,10 @@ protected Widget createSingleSlotGUI() { .setShouldUseBaseBackground()) // ...and add the actual tank widget separately. .addWidget(new TankWidget(tank.getStorages()[0], 67, 22, 18, 18, true, io.support(IO.IN)) - .setShowAmount(true).setDrawHoverTips(false).setBackground(GuiTextures.FLUID_SLOT)); + .setShowAmount(true).setDrawHoverTips(true).setBackground(GuiTextures.FLUID_SLOT)); } else { group.addWidget(tankWidget = new TankWidget(tank.getStorages()[0], 67, 22, 18, 18, true, io.support(IO.IN)) - .setShowAmount(true).setDrawHoverTips(false).setBackground(GuiTextures.FLUID_SLOT)); + .setShowAmount(true).setDrawHoverTips(true).setBackground(GuiTextures.FLUID_SLOT)); } group.addWidget(new LabelWidget(8, 8, "gtceu.gui.fluid_amount")) diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java index 82d58398af..caf7b6648f 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/CreativeTankMachine.java @@ -77,7 +77,8 @@ protected void checkAutoOutput() { @Override public WidgetGroup createUIWidget() { var group = new WidgetGroup(0, 0, 176, 131); - group.addWidget(new PhantomFluidWidget(this.cache.getStorages()[0], 36, 6, 18, 18).setShowAmount(false).setBackground(GuiTextures.FLUID_SLOT)); + group.addWidget(new PhantomFluidWidget(this.cache.getStorages()[0], 0, 36, 6, 18, 18, () -> this.cache.getStorages()[0].getFluid(), (fluid) -> this.cache.getStorages()[0].setFluid(fluid)) + .setShowAmount(false).setBackground(GuiTextures.FLUID_SLOT)); group.addWidget(new LabelWidget(7, 9, "gtceu.creative.tank.fluid")); group.addWidget(new ImageWidget(7, 45, 154, 14, GuiTextures.DISPLAY)); group.addWidget(new TextFieldWidget(9, 47, 152, 10, () -> String.valueOf(mBPerCycle), value -> { diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java index d742f7ee19..eddc2189f9 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/storage/QuantumTankMachine.java @@ -298,10 +298,8 @@ protected void setLocked(boolean locked) { if (!stored.isEmpty() && locked) { var copied = stored.copy(); copied.setAmount(cache.getLockedFluid().getCapacity()); - cache.getLockedFluid().setFluid(copied); - cache.setLocked(true); + cache.setLocked(true, copied); } else if (!locked) { - cache.getLockedFluid().setFluid(FluidStack.empty()); cache.setLocked(false); } } @@ -318,7 +316,7 @@ public Widget createUIWidget() { ).setTextColor(-1).setDropShadow(true)) .addWidget(new TankWidget(cache.getStorages()[0], 68, 23, true, true) .setBackground(GuiTextures.FLUID_SLOT)) - .addWidget(new PhantomFluidWidget(cache.getLockedFluid(), 68, 41, 18, 18) + .addWidget(new PhantomFluidWidget(cache.getLockedFluid(), 0, 68, 41, 18, 18, () -> cache.getLockedFluid().getFluid(), (fluid) -> cache.getLockedFluid().setFluid(fluid)) .setShowAmount(false) .setBackground(ColorPattern.T_GRAY.rectTexture())) .addWidget(new ToggleButtonWidget(4, 41, 18, 18,