diff options
author | Glease <4586901+Glease@users.noreply.github.com> | 2023-01-08 19:44:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-08 11:44:52 +0000 |
commit | 0a6de05bd45621922245f044483ffc78722c1d6b (patch) | |
tree | c24f7deece90812c8d79fd069487bd368fb61409 /src | |
parent | 859968c7cc823784a793b6d6457fca198bec897a (diff) | |
download | GT5-Unofficial-0a6de05bd45621922245f044483ffc78722c1d6b.tar.gz GT5-Unofficial-0a6de05bd45621922245f044483ffc78722c1d6b.tar.bz2 GT5-Unofficial-0a6de05bd45621922245f044483ffc78722c1d6b.zip |
allow filtering what is accepted in a fluid slot (#1641)
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/gregtech/common/gui/modularui/widget/FluidDisplaySlotWidget.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main/java/gregtech/common/gui/modularui/widget/FluidDisplaySlotWidget.java b/src/main/java/gregtech/common/gui/modularui/widget/FluidDisplaySlotWidget.java index 99200e5e8d..427947d39c 100644 --- a/src/main/java/gregtech/common/gui/modularui/widget/FluidDisplaySlotWidget.java +++ b/src/main/java/gregtech/common/gui/modularui/widget/FluidDisplaySlotWidget.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.function.BiFunction; +import java.util.function.Predicate; import java.util.function.Supplier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -27,6 +28,7 @@ public class FluidDisplaySlotWidget extends SlotWidget { private Supplier<IFluidAccess> fluidAccessConstructor; private Supplier<Boolean> canDrainGetter; private Supplier<Boolean> canFillGetter; + private Predicate<Fluid> canFillFilter; private Action actionRealClick = Action.NONE; private Action actionDragAndDrop = Action.NONE; private BiFunction<ClickData, FluidDisplaySlotWidget, Boolean> beforeRealClick; @@ -176,6 +178,8 @@ public class FluidDisplaySlotWidget extends SlotWidget { if (tFluidHeld == null) // no fluid to fill return null; + // apply filter here + if (!canFillFilter.test(tFluidHeld.getFluid())) return null; return fillFluid(aFluidAccess, aPlayer, tFluidHeld, aProcessFullStack); } // tank not empty, both action possible @@ -183,6 +187,8 @@ public class FluidDisplaySlotWidget extends SlotWidget { // both nonnull and have space left for filling. if (aCanFill) // actually both pickup and fill is reasonable, but I'll go with fill here + // there is already fluid in here. so we assume the slot will not accept this fluid anyway if it doesn't + // pass the filter. return fillFluid(aFluidAccess, aPlayer, tFluidHeld, aProcessFullStack); if (!aCanDrain) // cannot take AND cannot fill, why make this call then? @@ -396,6 +402,15 @@ public class FluidDisplaySlotWidget extends SlotWidget { } /** + * Add a predicate on whether a client stack will be accepted. Note this will only be called when this slot is already + * empty. It is assumed whatever is already in the slot will pass the filter. + */ + public FluidDisplaySlotWidget setEmptyCanFillFilter(Predicate<Fluid> canFillFilter) { + this.canFillFilter = canFillFilter; + return this; + } + + /** * Sets action called on drag-and-drop from NEI. * You can't use {@link Action#TRANSFER} here. */ |