From 185bd5a4903f19642dfd792a64680e4558f474f0 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:32:16 -0700 Subject: [PATCH] Rework Filters as Cover and Fluid Pipes with Covers (#2640) --- .../common/covers/CoverFluidFilter.java | 66 ++++++++++++++----- .../common/covers/CoverItemFilter.java | 60 +++++++++++++---- .../tile/TileEntityFluidPipeTickable.java | 3 +- .../resources/assets/gregtech/lang/en_us.lang | 4 ++ 4 files changed, 99 insertions(+), 34 deletions(-) diff --git a/src/main/java/gregtech/common/covers/CoverFluidFilter.java b/src/main/java/gregtech/common/covers/CoverFluidFilter.java index a103076e938..85b39ca1a9d 100644 --- a/src/main/java/gregtech/common/covers/CoverFluidFilter.java +++ b/src/main/java/gregtech/common/covers/CoverFluidFilter.java @@ -32,14 +32,19 @@ import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Matrix4; +import com.cleanroommc.modularui.api.drawable.IKey; import com.cleanroommc.modularui.drawable.Rectangle; import com.cleanroommc.modularui.factory.SidedPosGuiData; import com.cleanroommc.modularui.screen.ModularPanel; import com.cleanroommc.modularui.utils.Alignment; +import com.cleanroommc.modularui.utils.Color; +import com.cleanroommc.modularui.value.sync.BooleanSyncValue; import com.cleanroommc.modularui.value.sync.EnumSyncValue; import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.widgets.SlotGroupWidget; +import com.cleanroommc.modularui.widgets.ToggleButton; import com.cleanroommc.modularui.widgets.layout.Column; +import com.cleanroommc.modularui.widgets.layout.Row; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -51,7 +56,8 @@ public class CoverFluidFilter extends CoverBase implements CoverWithUI { protected final SimpleOverlayRenderer texture; protected final FluidFilterContainer fluidFilterContainer; protected FluidFilterMode filterMode; - protected FluidHandlerFiltered fluidHandler; + protected boolean allowFlow = false; + protected FluidHandlerDelegate fluidHandler; public CoverFluidFilter(@NotNull CoverDefinition definition, @NotNull CoverableView coverableView, @NotNull EnumFacing attachedSide, String titleLocale, SimpleOverlayRenderer texture) { @@ -146,7 +152,7 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan this.fluidFilterContainer.setMaxTransferSize(1); return getFilter().createPanel(guiSyncManager) - .size(176, 194).padding(7) + .size(176, 212).padding(7) .child(CoverWithUI.createTitleRow(getFilterContainer().getFilterStack())) .child(new Column().widthRel(1f).align(Alignment.TopLeft).top(22).coverChildrenHeight() .child(new EnumRowBuilder<>(FluidFilterMode.class) @@ -154,6 +160,24 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan .lang("cover.filter.mode.title") .overlay(16, GTGuiTextures.FILTER_MODE_OVERLAY) .build()) + .child(new Row() + .marginBottom(2) + .widthRel(1f) + .coverChildrenHeight() + .setEnabledIf(b -> getFilterMode() != FluidFilterMode.FILTER_BOTH) + .child(new ToggleButton() + .overlay(IKey.dynamic(() -> IKey.lang(allowFlow ? + "cover.generic.enabled" : + "cover.generic.disabled").get()) + .color(Color.WHITE.main).shadow(false)) + .tooltip(tooltip -> tooltip + .addLine(IKey.lang("cover.filter.allow_flow.tooltip"))) + .size(72, 18) + .value(new BooleanSyncValue(() -> allowFlow, b -> allowFlow = b))) + .child(IKey.lang("cover.filter.allow_flow.label") + .asWidget() + .height(18) + .alignX(1f))) .child(new Rectangle().setColor(UI_TEXT_COLOR).asWidget() .height(1).widthRel(0.95f).margin(0, 4)) .child(getFilter().createWidgets(guiSyncManager))) @@ -207,30 +231,36 @@ public FluidHandlerFiltered(@NotNull IFluidHandler delegate) { } public int fill(FluidStack resource, boolean doFill) { - if (getFilterMode() == FluidFilterMode.FILTER_DRAIN || !fluidFilterContainer.test(resource)) { - return 0; - } - return super.fill(resource, doFill); + // set to drain, but filling is allowed + if (getFilterMode() == FluidFilterMode.FILTER_DRAIN && allowFlow) + return super.fill(resource, doFill); + + // if set to insert or both, test the stack + if (getFilterMode() != FluidFilterMode.FILTER_DRAIN && fluidFilterContainer.test(resource)) + return super.fill(resource, doFill); + + // otherwise fail + return 0; } @Nullable public FluidStack drain(FluidStack resource, boolean doDrain) { - if (getFilterMode() == FluidFilterMode.FILTER_FILL || !fluidFilterContainer.test(resource)) { - return null; - } - return super.drain(resource, doDrain); + // set to fill, draining is allowed + if (getFilterMode() == FluidFilterMode.FILTER_FILL && allowFlow) + return super.drain(resource, doDrain); + + // if set to extract or both, test stack + if (getFilterMode() != FluidFilterMode.FILTER_FILL && fluidFilterContainer.test(resource)) + return super.drain(resource, doDrain); + + // otherwise fail + return null; } @Nullable public FluidStack drain(int maxDrain, boolean doDrain) { - if (getFilterMode() != FluidFilterMode.FILTER_FILL) { - FluidStack result = super.drain(maxDrain, false); - if (result == null || result.amount <= 0 || !fluidFilterContainer.test(result)) { - return null; - } - return doDrain ? super.drain(maxDrain, true) : result; - } - return super.drain(maxDrain, doDrain); + var f = super.drain(maxDrain, false); + return drain(f, doDrain); } } } diff --git a/src/main/java/gregtech/common/covers/CoverItemFilter.java b/src/main/java/gregtech/common/covers/CoverItemFilter.java index 043729ad075..18e6432bc07 100644 --- a/src/main/java/gregtech/common/covers/CoverItemFilter.java +++ b/src/main/java/gregtech/common/covers/CoverItemFilter.java @@ -31,14 +31,19 @@ import codechicken.lib.render.pipeline.IVertexOperation; import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Matrix4; +import com.cleanroommc.modularui.api.drawable.IKey; import com.cleanroommc.modularui.drawable.Rectangle; import com.cleanroommc.modularui.factory.SidedPosGuiData; import com.cleanroommc.modularui.screen.ModularPanel; import com.cleanroommc.modularui.utils.Alignment; +import com.cleanroommc.modularui.utils.Color; +import com.cleanroommc.modularui.value.sync.BooleanSyncValue; import com.cleanroommc.modularui.value.sync.EnumSyncValue; import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.widgets.SlotGroupWidget; +import com.cleanroommc.modularui.widgets.ToggleButton; import com.cleanroommc.modularui.widgets.layout.Column; +import com.cleanroommc.modularui.widgets.layout.Row; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -50,7 +55,8 @@ public class CoverItemFilter extends CoverBase implements CoverWithUI { protected final SimpleOverlayRenderer texture; protected final ItemFilterContainer itemFilterContainer; protected ItemFilterMode filterMode = ItemFilterMode.FILTER_INSERT; - protected ItemHandlerFiltered itemHandler; + protected boolean allowFlow = false; + protected ItemHandlerDelegate itemHandler; public CoverItemFilter(@NotNull CoverDefinition definition, @NotNull CoverableView coverableView, @NotNull EnumFacing attachedSide, String titleLocale, SimpleOverlayRenderer texture) { @@ -148,7 +154,7 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan guiSyncManager.syncValue("filtering_mode", filteringMode); return getFilter().createPanel(guiSyncManager) - .size(176, 194).padding(7) + .size(176, 212).padding(7) .child(CoverWithUI.createTitleRow(getFilterContainer().getFilterStack()).left(4)) .child(new Column().widthRel(1f).align(Alignment.TopLeft).top(22).coverChildrenHeight() .child(new EnumRowBuilder<>(ItemFilterMode.class) @@ -156,6 +162,24 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan .lang("cover.filter.mode.title") .overlay(16, GTGuiTextures.FILTER_MODE_OVERLAY) .build()) + .child(new Row() + .marginBottom(2) + .widthRel(1f) + .coverChildrenHeight() + .setEnabledIf(b -> getFilterMode() != ItemFilterMode.FILTER_BOTH) + .child(new ToggleButton() + .overlay(IKey.dynamic(() -> IKey.lang(allowFlow ? + "cover.generic.enabled" : + "cover.generic.disabled").get()) + .color(Color.WHITE.main).shadow(false)) + .tooltip(tooltip -> tooltip + .addLine(IKey.lang("cover.filter.allow_flow.tooltip"))) + .size(72, 18) + .value(new BooleanSyncValue(() -> allowFlow, b -> allowFlow = b))) + .child(IKey.lang("cover.filter.allow_flow.label") + .asWidget() + .height(18) + .alignX(1f))) .child(new Rectangle().setColor(UI_TEXT_COLOR).asWidget() .height(1).widthRel(0.95f).margin(0, 4)) .child(getFilter().createWidgets(guiSyncManager).left(0))) @@ -212,23 +236,31 @@ public ItemHandlerFiltered(IItemHandler delegate) { @NotNull @Override public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { - if (getFilterMode() == ItemFilterMode.FILTER_EXTRACT || !itemFilterContainer.test(stack)) { - return stack; - } - return super.insertItem(slot, stack, simulate); + // set to extract, but insertion is allowed + if (getFilterMode() == ItemFilterMode.FILTER_EXTRACT && allowFlow) + return super.insertItem(slot, stack, simulate); + + // if set to insert or both, test the stack + if (getFilterMode() != ItemFilterMode.FILTER_EXTRACT && itemFilterContainer.test(stack)) + return super.insertItem(slot, stack, simulate); + + // otherwise fail + return stack; } @NotNull @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { - if (getFilterMode() != ItemFilterMode.FILTER_INSERT) { - ItemStack result = super.extractItem(slot, amount, true); - if (result.isEmpty() || !itemFilterContainer.test(result)) { - return ItemStack.EMPTY; - } - return simulate ? result : super.extractItem(slot, amount, false); - } - return super.extractItem(slot, amount, simulate); + // set to insert, but extraction is allowed + if (getFilterMode() == ItemFilterMode.FILTER_INSERT && allowFlow) + return super.extractItem(slot, amount, simulate); + + // if set to extract or both, test stack + if (getFilterMode() != ItemFilterMode.FILTER_INSERT && itemFilterContainer.test(getStackInSlot(slot))) + return super.extractItem(slot, amount, simulate); + + // otherwise fail + return ItemStack.EMPTY; } } } diff --git a/src/main/java/gregtech/common/pipelike/fluidpipe/tile/TileEntityFluidPipeTickable.java b/src/main/java/gregtech/common/pipelike/fluidpipe/tile/TileEntityFluidPipeTickable.java index 038fef391f8..0fb23e4c309 100644 --- a/src/main/java/gregtech/common/pipelike/fluidpipe/tile/TileEntityFluidPipeTickable.java +++ b/src/main/java/gregtech/common/pipelike/fluidpipe/tile/TileEntityFluidPipeTickable.java @@ -13,7 +13,6 @@ import gregtech.api.util.EntityDamageUtil; import gregtech.api.util.TextFormattingUtil; import gregtech.common.covers.CoverPump; -import gregtech.common.covers.ManualImportExportMode; import gregtech.common.pipelike.fluidpipe.net.PipeTankList; import net.minecraft.entity.EntityLivingBase; @@ -202,7 +201,7 @@ private boolean checkForPumpCover(@Nullable Cover cover) { if (coverPump.getTransferRate() > pipeThroughput) { coverPump.setTransferRate(pipeThroughput); } - return coverPump.getManualImportExportMode() == ManualImportExportMode.DISABLED; + return true; // disable pushing completely if there's a pump } return false; } diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 389d68cd3ce..484c7e258ff 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -1280,6 +1280,8 @@ cover.filter.mode.title=Filter Mode cover.filter.mode.filter_insert=Filter Insert cover.filter.mode.filter_extract=Filter Extract cover.filter.mode.filter_both=Filter Insert/Extract +cover.filter.allow_flow.label=Allow Flow +cover.filter.allow_flow.tooltip=By default, Items/Fluids can only move in the direction\nof the filter with respect to the filter's setting.\n\nIf Enabled, Items/Fluids are allowed to pass unfiltered\nthrough the opposite direction of this filter. cover.item_filter.ignore_damage.enabled=Ignore Damage cover.item_filter.ignore_damage.disabled=Respect Damage cover.item_filter.ignore_nbt.enabled=Ignore NBT @@ -1309,6 +1311,8 @@ cover.smart_item_filter.filtering_mode.centrifuge=Centrifuge cover.smart_item_filter.filtering_mode.sifter=Sifter cover.smart_item_filter.filtering_mode.description=Select Machine this Smart Filter will use for filtering./nIt will automatically pick right portions of items for robotic arm. +cover.generic.disabled=Disabled +cover.generic.enabled=Enabled cover.generic.transfer_mode=Transfer Mode cover.generic.manual_io=Manual IO Mode cover.generic.io=IO Mode