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

Rewrite OreDictExprFilter to fix tag filter functionality #2220

Merged
merged 6 commits into from
Oct 26, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.gregtechceu.gtceu.api.gui.GuiTextures;
import com.gregtechceu.gtceu.data.lang.LangHandler;
import com.gregtechceu.gtceu.utils.OreDictExprFilter;
import com.gregtechceu.gtceu.utils.TagExprFilter;

import com.lowdragmc.lowdraglib.gui.widget.ImageWidget;
import com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget;
Expand All @@ -13,8 +13,6 @@

import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.regex.Pattern;

Expand All @@ -38,7 +36,7 @@ public abstract class TagFilter<T, S extends Filter<T, S>> implements Filter<T,
protected Consumer<S> itemWriter = filter -> {};
protected Consumer<S> onUpdated = filter -> itemWriter.accept(filter);

protected final List<OreDictExprFilter.MatchRule> matchRules = new ArrayList<>();
protected TagExprFilter.TagExprParser.MatchExpr matchExpr = null;

protected TagFilter() {}

Expand All @@ -50,8 +48,7 @@ public CompoundTag saveFilter() {

public void setOreDict(String oreDict) {
this.oreDictFilterExpression = oreDict;
matchRules.clear();
OreDictExprFilter.parseExpression(matchRules, oreDictFilterExpression);
matchExpr = TagExprFilter.parseExpression(oreDictFilterExpression);
onUpdated.accept((S) this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.gregtechceu.gtceu.utils.OreDictExprFilter;
import com.gregtechceu.gtceu.utils.TagExprFilter;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -31,9 +31,9 @@ private static TagFluidFilter loadFilter(CompoundTag tag, Consumer<FluidFilter>
var handler = new TagFluidFilter();
handler.itemWriter = itemWriter;
handler.oreDictFilterExpression = tag.getString("oreDict");
handler.matchRules.clear();
handler.matchExpr = null;
handler.cache.clear();
OreDictExprFilter.parseExpression(handler.matchRules, handler.oreDictFilterExpression);
handler.matchExpr = TagExprFilter.parseExpression(handler.oreDictFilterExpression);
return handler;
}

Expand All @@ -46,7 +46,7 @@ public void setOreDict(String oreDict) {
public boolean test(FluidStack fluidStack) {
if (oreDictFilterExpression.isEmpty()) return true;
if (cache.containsKey(fluidStack.getFluid())) return cache.getOrDefault(fluidStack.getFluid(), false);
if (OreDictExprFilter.matchesOreDict(matchRules, fluidStack)) {
if (TagExprFilter.tagsMatch(matchExpr, fluidStack)) {
cache.put(fluidStack.getFluid(), true);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.gregtechceu.gtceu.api.cover.filter;

import com.gregtechceu.gtceu.utils.OreDictExprFilter;
import com.gregtechceu.gtceu.utils.TagExprFilter;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.item.Item;
Expand Down Expand Up @@ -30,9 +30,9 @@ private static TagItemFilter loadFilter(CompoundTag tag, Consumer<ItemFilter> it
var handler = new TagItemFilter();
handler.itemWriter = itemWriter;
handler.oreDictFilterExpression = tag.getString("oreDict");
handler.matchRules.clear();
handler.matchExpr = null;
handler.cache.clear();
OreDictExprFilter.parseExpression(handler.matchRules, handler.oreDictFilterExpression);
handler.matchExpr = TagExprFilter.parseExpression(handler.oreDictFilterExpression);
return handler;
}

Expand All @@ -45,7 +45,7 @@ public void setOreDict(String oreDict) {
public boolean test(ItemStack itemStack) {
if (oreDictFilterExpression.isEmpty()) return true;
if (cache.containsKey(itemStack.getItem())) return cache.getOrDefault(itemStack.getItem(), false);
if (OreDictExprFilter.matchesOreDict(matchRules, itemStack)) {
if (TagExprFilter.tagsMatch(matchExpr, itemStack)) {
cache.put(itemStack.getItem(), true);
return true;
}
Expand Down
302 changes: 0 additions & 302 deletions src/main/java/com/gregtechceu/gtceu/utils/OreDictExprFilter.java

This file was deleted.

Loading