Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework Filters as Cover and Fluid Pipes with Covers #2640

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 48 additions & 18 deletions src/main/java/gregtech/common/covers/CoverFluidFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -146,14 +152,32 @@ 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)
.value(filteringMode)
.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)))
Expand Down Expand Up @@ -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);
}
}
}
60 changes: 46 additions & 14 deletions src/main/java/gregtech/common/covers/CoverItemFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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) {
Expand Down Expand Up @@ -148,14 +154,32 @@ 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)
.value(filteringMode)
.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)))
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +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.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
Expand Down Expand Up @@ -1294,6 +1296,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
Expand Down