Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 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
5 changes: 5 additions & 0 deletions src/main/java/com/gregtechceu/gtceu/GTCEu.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import me.shedaniel.rei.api.client.REIRuntime;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.mariuszgromada.math.mxparser.License;

import java.nio.file.Path;

Expand All @@ -32,6 +33,10 @@ public class GTCEu {
public static final String NAME = "GregTechCEu";
public static final Logger LOGGER = LogManager.getLogger(NAME);

static {
License.iConfirmNonCommercialUse("GTCEu");
}

public GTCEu() {
GTCEu.init();
GTCEuAPI.instance = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void onAttached(ItemStack itemStack, @Nullable ServerPlayer player) {
attachItem = itemStack.copy();
attachItem.setCount(1);
syncDataHolder.markClientSyncFieldDirty("attachItem");
markAsChanged();
}

public void onLoad() {}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/gregtechceu/gtceu/api/cover/IMuiCover.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ default CoverBehavior self() {
return (CoverBehavior) this;
}

default boolean isRemote() {
return self().coverHolder.isRemote();
}

default boolean isRemoved() {
return self().coverHolder.isRemoved() || self().coverHolder.getCoverAtSide(self().attachedSide) != self();
}
Expand Down Expand Up @@ -131,7 +135,7 @@ class EnumRowBuilder<T extends Enum<T>> {

private EnumSyncValue<T> syncValue;
private final Class<T> enumValue;
private String lang;
private IKey lang;
private IDrawable[] background;
private IDrawable selectedBackground;
private IDrawable[] overlay;
Expand All @@ -145,7 +149,7 @@ public EnumRowBuilder<T> value(EnumSyncValue<T> syncValue) {
return this;
}

public EnumRowBuilder<T> lang(String lang) {
public EnumRowBuilder<T> lang(IKey lang) {
this.lang = lang;
return this;
}
Expand Down Expand Up @@ -204,8 +208,8 @@ public Flow build() {
}
}

if (this.lang != null && !this.lang.isEmpty())
row.child(IKey.lang(this.lang).asWidget().align(Alignment.CenterRight).height(18));
if (this.lang != null)
row.child(this.lang.asWidget().align(Alignment.CenterRight).height(18));

return row;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;

import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;

import net.minecraft.nbt.CompoundTag;
Expand All @@ -11,6 +14,11 @@ public interface Filter<T, S extends Filter<T, S>> extends Predicate<T> {

WidgetGroup openConfigurator(int x, int y);

/**
* @return Filter panel when opened by itself (including the player inventory)
*/
ModularPanel getPanel(PanelSyncManager syncManager);
Comment thread
YoungOnionMC marked this conversation as resolved.
Outdated

CompoundTag saveFilter();

void setOnUpdated(Consumer<S> onUpdated);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public FilterHandler(ISyncManaged container) {

protected abstract F getEmptyFilter();

protected abstract boolean canInsertFilterItem(ItemStack itemStack);

//////////////////////////////////
// ***** PUBLIC API ******//
//////////////////////////////////

public abstract boolean canInsertFilterItem(ItemStack itemStack);

public Widget createFilterSlotUI(int xPos, int yPos) {
return new SlotWidget(getFilterSlot(), 0, xPos, yPos)
.setChangeListener(this::updateFilter)
Expand Down Expand Up @@ -117,7 +117,7 @@ public FilterHandler<T, F> onFilterUpdated(Consumer<F> onFilterUpdated) {
// ***** FILTER HANDLING ******//
///////////////////////////////////////

private CustomItemStackHandler getFilterSlot() {
public CustomItemStackHandler getFilterSlot() {
if (this.filterSlot == null) {
this.filterSlot = new CustomItemStackHandler(this.filterItem) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected ItemFilter getEmptyFilter() {
}

@Override
protected boolean canInsertFilterItem(ItemStack itemStack) {
public boolean canInsertFilterItem(ItemStack itemStack) {
return ItemFilter.FILTERS.containsKey(itemStack.getItem());
}
};
Expand All @@ -41,7 +41,7 @@ protected FluidFilter getEmptyFilter() {
}

@Override
protected boolean canInsertFilterItem(ItemStack itemStack) {
public boolean canInsertFilterItem(ItemStack itemStack) {
return FluidFilter.FILTERS.containsKey(itemStack.getItem());
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;

import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;

import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -58,6 +61,11 @@ public WidgetGroup openConfigurator(int x, int y) {
throw new NotImplementedException("Not available for empty fluid filter");
}

@Override
public ModularPanel getPanel(PanelSyncManager syncManager) {
return null;
}

@Override
public CompoundTag saveFilter() {
throw new NotImplementedException("Not available for empty fluid filter");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;

import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;

import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -57,6 +60,11 @@ public WidgetGroup openConfigurator(int x, int y) {
throw new NotImplementedException("Not available for empty item filter");
}

@Override
public ModularPanel getPanel(PanelSyncManager syncManager) {
return null;
}

@Override
public CompoundTag saveFilter() {
throw new NotImplementedException("Not available for empty item filter");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.widget.ScrollablePhantomFluidWidget;
import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget;
import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.api.transfer.fluid.CustomFluidTank;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;

import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;

Expand Down Expand Up @@ -140,6 +142,11 @@ public void detectAndSendChanges() {
return group;
}

@Override
public ModularPanel getPanel(PanelSyncManager syncManager) {
return null;
}

@Override
public boolean test(FluidStack other) {
return testFluidAmount(other) > 0L;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.api.gui.widget.PhantomSlotWidget;
import com.gregtechceu.gtceu.api.gui.widget.ToggleButtonWidget;
import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.api.mui.value.sync.PhantomItemSlotSyncHandler;
import com.gregtechceu.gtceu.api.mui.widgets.Dialog;
import com.gregtechceu.gtceu.api.mui.widgets.SlotGroupWidget;
import com.gregtechceu.gtceu.api.mui.widgets.layout.Flow;
import com.gregtechceu.gtceu.api.mui.widgets.layout.Grid;
import com.gregtechceu.gtceu.api.mui.widgets.slot.ModularSlot;
import com.gregtechceu.gtceu.api.mui.widgets.slot.PhantomItemSlot;
import com.gregtechceu.gtceu.api.transfer.item.CustomItemStackHandler;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;
import com.gregtechceu.gtceu.common.data.GTItems;
import com.gregtechceu.gtceu.common.data.mui.GTMuiWidgets;
import com.gregtechceu.gtceu.common.mui.GTGuiTextures;
import com.gregtechceu.gtceu.utils.GTUtil;

import com.lowdragmc.lowdraglib.gui.widget.WidgetGroup;
Expand All @@ -15,6 +24,7 @@
import net.minecraft.world.item.ItemStack;

import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.function.Consumer;
Expand Down Expand Up @@ -97,42 +107,76 @@ public void setIgnoreNbt(boolean ingoreNbt) {
onUpdated.accept(this);
}

@Override
public WidgetGroup openConfigurator(int x, int y) {
WidgetGroup group = new WidgetGroup(x, y, 18 * 3 + 25, 18 * 3); // 80 55
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
final int index = i * 3 + j;

var handler = new CustomItemStackHandler(matches[index]);

var slot = new PhantomSlotWidget(handler, 0, i * 18, j * 18) {

@Override
public void updateScreen() {
super.updateScreen();
setMaxStackSize(maxStackSize);
}

@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
setMaxStackSize(maxStackSize);
}
};

slot.setChangeListener(() -> {
matches[index] = handler.getStackInSlot(0);
onUpdated.accept(this);
}).setBackground(GuiTextures.SLOT);

group.addWidget(slot);
return null;
}

@Override
public ModularPanel getPanel(PanelSyncManager syncManager) {
FilterItemStackHandler handler = new FilterItemStackHandler(matches, this);

Grid filterGrid = new Grid()
.coverChildren()
.mapTo(3, 9, i -> new PhantomItemSlot()
.size(16)
.syncHandler(new PhantomItemSlotSyncHandler(new ModularSlot(handler, i)
.changeListener((stack, amount, client, init) -> {
handler.setStackInSlot(i, stack);
}).ignoreMaxStackSize(true).accessibility(true, false))));

return new Dialog<>("simple_item_filter")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have a hash of the current data of some sort, so you can open two dialogs of two different item filters at the same time

.setDisablePanelsBelow(false)
.setDraggable(true)
.setCloseOnOutOfBoundsClick(true)
.child(GTMuiWidgets.createTitleBar(GTItems.ITEM_FILTER.asStack(), 176, GTGuiTextures.BACKGROUND))
.child(Flow.row()
.top(10)
.coverChildrenHeight()
.child(filterGrid.horizontalCenter()))
.child(SlotGroupWidget.playerInventory(false).left(7).bottom(7));
}

private static class FilterItemStackHandler extends CustomItemStackHandler {

private ItemStack[] matches;
private SimpleItemFilter filter;

public FilterItemStackHandler(ItemStack[] matches, SimpleItemFilter simpleItemFilter) {
super(matches.length);
this.matches = matches;
this.filter = simpleItemFilter;
}

@Override
public @NotNull ItemStack getStackInSlot(int slot) {
return matches[slot];
}

@Override
protected int getStackLimit(int slot, @NotNull ItemStack stack) {
return 1;
}

@Override
public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) {
if (amount >= matches[slot].getCount()) {
matches[slot] = ItemStack.EMPTY;
}
return matches[slot];
}

@Override
public @NotNull ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) {
return stack;
}

@Override
public void setStackInSlot(int slot, @NotNull ItemStack stack) {
super.setStackInSlot(slot, stack);
matches[slot] = stack.copyWithCount(1);
filter.onUpdated.accept(filter);
}
group.addWidget(new ToggleButtonWidget(18 * 3 + 5, 0, 20, 20,
GuiTextures.BUTTON_BLACKLIST, this::isBlackList, this::setBlackList));
group.addWidget(new ToggleButtonWidget(18 * 3 + 5, 20, 20, 20,
GuiTextures.BUTTON_FILTER_NBT, this::isIgnoreNbt, this::setIgnoreNbt));
return group;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability;
import com.gregtechceu.gtceu.api.gui.widget.EnumSelectorWidget;
import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.api.recipe.GTRecipeType;
import com.gregtechceu.gtceu.api.recipe.content.Content;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;
import com.gregtechceu.gtceu.common.data.GTRecipeTypes;
import com.gregtechceu.gtceu.utils.ItemStackHashStrategy;

Expand Down Expand Up @@ -76,6 +78,11 @@ public WidgetGroup openConfigurator(int x, int y) {
return group;
}

@Override
public ModularPanel getPanel(PanelSyncManager syncManager) {
return null;
}

@Override
public boolean test(ItemStack itemStack) {
return testItemCount(itemStack) > 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;
import com.gregtechceu.gtceu.utils.TagExprFilter;

import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -60,4 +62,9 @@ public int testFluidAmount(FluidStack fluidStack) {
public boolean supportsAmounts() {
return false;
}

@Override
public ModularPanel getPanel(PanelSyncManager syncManager) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.gregtechceu.gtceu.api.mui.value.sync.PanelSyncManager;
import com.gregtechceu.gtceu.client.mui.screen.ModularPanel;
import com.gregtechceu.gtceu.utils.TagExprFilter;

import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -59,4 +61,9 @@ public int testItemCount(ItemStack itemStack) {
public boolean supportsAmounts() {
return false;
}

@Override
public ModularPanel getPanel(PanelSyncManager syncManager) {
return null;
}
}
Loading