From bfebd4e3fd0d34285fc0b4615e5aeca9193070ec Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:42:07 -0700 Subject: [PATCH 1/5] always prevent pipe pushing when there's a cover --- .../pipelike/fluidpipe/tile/TileEntityFluidPipeTickable.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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; } From d126a38f7bb966186dfa664794eb91facdd0e087 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Mon, 14 Oct 2024 17:06:00 -0700 Subject: [PATCH 2/5] rework fluid filter covers slightly --- .../common/covers/CoverFluidFilter.java | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/main/java/gregtech/common/covers/CoverFluidFilter.java b/src/main/java/gregtech/common/covers/CoverFluidFilter.java index a103076e938..00151b6a542 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,17 @@ 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 ? "Enabled" : "Disabled") + .get()).color(Color.WHITE.main).shadow(false)) + .size(72, 18) + .value(new BooleanSyncValue(() -> allowFlow, b -> allowFlow = b))) + .child(IKey.lang("Allow Flow").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 +224,26 @@ 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); + if (getFilterMode() == FluidFilterMode.FILTER_DRAIN && allowFlow) + return super.fill(resource, doFill); + + // fill or both, or not allow flow + return fluidFilterContainer.test(resource) ? super.fill(resource, doFill) : 0; } @Nullable public FluidStack drain(FluidStack resource, boolean doDrain) { - if (getFilterMode() == FluidFilterMode.FILTER_FILL || !fluidFilterContainer.test(resource)) { - return null; - } - return super.drain(resource, doDrain); + if (getFilterMode() == FluidFilterMode.FILTER_FILL && allowFlow) + return super.drain(resource, doDrain); + + // drain or both, or not allow flow + return fluidFilterContainer.test(resource) ? super.drain(resource, doDrain) : 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); } } } From 80ff647cf8c2feb96e99566cf76e3bb8ceecbd08 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:05:38 -0700 Subject: [PATCH 3/5] add button to CoverItemFilter fix issues with logic add lang --- .../common/covers/CoverFluidFilter.java | 24 ++++++--- .../common/covers/CoverItemFilter.java | 53 ++++++++++++++----- .../resources/assets/gregtech/lang/en_us.lang | 3 ++ 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/main/java/gregtech/common/covers/CoverFluidFilter.java b/src/main/java/gregtech/common/covers/CoverFluidFilter.java index 00151b6a542..5a057b7e2b9 100644 --- a/src/main/java/gregtech/common/covers/CoverFluidFilter.java +++ b/src/main/java/gregtech/common/covers/CoverFluidFilter.java @@ -166,11 +166,13 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan .coverChildrenHeight() .setEnabledIf(b -> getFilterMode() != FluidFilterMode.FILTER_BOTH) .child(new ToggleButton() - .overlay(IKey.dynamic(() -> IKey.lang(allowFlow ? "Enabled" : "Disabled") - .get()).color(Color.WHITE.main).shadow(false)) + .overlay(IKey.dynamic(() -> IKey.lang(allowFlow ? + "cover.generic.enabled" : + "cover.generic.disabled").get()) + .color(Color.WHITE.main).shadow(false)) .size(72, 18) .value(new BooleanSyncValue(() -> allowFlow, b -> allowFlow = b))) - .child(IKey.lang("Allow Flow").asWidget().height(18).alignX(1f))) + .child(IKey.lang("cover.filter.allow_flow").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))) @@ -224,20 +226,28 @@ public FluidHandlerFiltered(@NotNull IFluidHandler delegate) { } public int fill(FluidStack resource, boolean doFill) { + // set to drain, but filling is allowed if (getFilterMode() == FluidFilterMode.FILTER_DRAIN && allowFlow) return super.fill(resource, doFill); - // fill or both, or not allow flow - return fluidFilterContainer.test(resource) ? super.fill(resource, doFill) : 0; + // otherwise test + if (getFilterMode() != FluidFilterMode.FILTER_DRAIN && fluidFilterContainer.test(resource)) + return super.fill(resource, doFill); + + return 0; } @Nullable public FluidStack drain(FluidStack resource, boolean doDrain) { + // set to fill, draining is allowed if (getFilterMode() == FluidFilterMode.FILTER_FILL && allowFlow) return super.drain(resource, doDrain); - // drain or both, or not allow flow - return fluidFilterContainer.test(resource) ? super.drain(resource, doDrain) : null; + // otherwise test + if (getFilterMode() != FluidFilterMode.FILTER_FILL && fluidFilterContainer.test(resource)) + return super.drain(resource, doDrain); + + return null; } @Nullable diff --git a/src/main/java/gregtech/common/covers/CoverItemFilter.java b/src/main/java/gregtech/common/covers/CoverItemFilter.java index 043729ad075..b6f7ba574db 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,19 @@ 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)) + .size(72, 18) + .value(new BooleanSyncValue(() -> allowFlow, b -> allowFlow = b))) + .child(IKey.lang("cover.filter.allow_flow").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 +231,29 @@ 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); + + // otherwise test + if (getFilterMode() != ItemFilterMode.FILTER_EXTRACT && itemFilterContainer.test(stack)) + return super.insertItem(slot, stack, simulate); + + 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); + + // otherwise test + if (getFilterMode() != ItemFilterMode.FILTER_EXTRACT && itemFilterContainer.test(getStackInSlot(slot))) + return super.extractItem(slot, amount, simulate); + + return ItemStack.EMPTY; } } } diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 5c78797a406..0013e5969b4 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -1265,6 +1265,7 @@ 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=Allow Flow cover.item_filter.ignore_damage.enabled=Ignore Damage cover.item_filter.ignore_damage.disabled=Respect Damage cover.item_filter.ignore_nbt.enabled=Ignore NBT @@ -1294,6 +1295,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 From 76eac71e2939833610aafda5d08d6665961c68f4 Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sun, 20 Oct 2024 18:05:19 -0700 Subject: [PATCH 4/5] add tooltip and lang --- src/main/java/gregtech/common/covers/CoverFluidFilter.java | 7 ++++++- src/main/java/gregtech/common/covers/CoverItemFilter.java | 7 ++++++- src/main/resources/assets/gregtech/lang/en_us.lang | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/common/covers/CoverFluidFilter.java b/src/main/java/gregtech/common/covers/CoverFluidFilter.java index 5a057b7e2b9..189d545e2b2 100644 --- a/src/main/java/gregtech/common/covers/CoverFluidFilter.java +++ b/src/main/java/gregtech/common/covers/CoverFluidFilter.java @@ -170,9 +170,14 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan "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").asWidget().height(18).alignX(1f))) + .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))) diff --git a/src/main/java/gregtech/common/covers/CoverItemFilter.java b/src/main/java/gregtech/common/covers/CoverItemFilter.java index b6f7ba574db..66df8579a7f 100644 --- a/src/main/java/gregtech/common/covers/CoverItemFilter.java +++ b/src/main/java/gregtech/common/covers/CoverItemFilter.java @@ -172,9 +172,14 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan "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").asWidget().height(18).alignX(1f))) + .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))) diff --git a/src/main/resources/assets/gregtech/lang/en_us.lang b/src/main/resources/assets/gregtech/lang/en_us.lang index 0013e5969b4..232726c2837 100644 --- a/src/main/resources/assets/gregtech/lang/en_us.lang +++ b/src/main/resources/assets/gregtech/lang/en_us.lang @@ -1265,7 +1265,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=Allow Flow +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 From f3f021f22e47c8587abb59f75af31c4a4962ae1d Mon Sep 17 00:00:00 2001 From: Ghzdude <44148655+ghzdude@users.noreply.github.com> Date: Sat, 2 Nov 2024 18:13:38 -0700 Subject: [PATCH 5/5] fix issue in CoverItemFilter improve comments --- .../java/gregtech/common/covers/CoverFluidFilter.java | 6 ++++-- src/main/java/gregtech/common/covers/CoverItemFilter.java | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/common/covers/CoverFluidFilter.java b/src/main/java/gregtech/common/covers/CoverFluidFilter.java index 189d545e2b2..85b39ca1a9d 100644 --- a/src/main/java/gregtech/common/covers/CoverFluidFilter.java +++ b/src/main/java/gregtech/common/covers/CoverFluidFilter.java @@ -235,10 +235,11 @@ public int fill(FluidStack resource, boolean doFill) { if (getFilterMode() == FluidFilterMode.FILTER_DRAIN && allowFlow) return super.fill(resource, doFill); - // otherwise test + // 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; } @@ -248,10 +249,11 @@ public FluidStack drain(FluidStack resource, boolean doDrain) { if (getFilterMode() == FluidFilterMode.FILTER_FILL && allowFlow) return super.drain(resource, doDrain); - // otherwise test + // 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; } diff --git a/src/main/java/gregtech/common/covers/CoverItemFilter.java b/src/main/java/gregtech/common/covers/CoverItemFilter.java index 66df8579a7f..18e6432bc07 100644 --- a/src/main/java/gregtech/common/covers/CoverItemFilter.java +++ b/src/main/java/gregtech/common/covers/CoverItemFilter.java @@ -240,10 +240,11 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate if (getFilterMode() == ItemFilterMode.FILTER_EXTRACT && allowFlow) return super.insertItem(slot, stack, simulate); - // otherwise test + // 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; } @@ -254,10 +255,11 @@ public ItemStack extractItem(int slot, int amount, boolean simulate) { if (getFilterMode() == ItemFilterMode.FILTER_INSERT && allowFlow) return super.extractItem(slot, amount, simulate); - // otherwise test - if (getFilterMode() != ItemFilterMode.FILTER_EXTRACT && itemFilterContainer.test(getStackInSlot(slot))) + // 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; } }