From bab1fcaa3a6b84f0901015f3afbe52d5a6c5383e Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sat, 28 Jan 2023 21:36:46 -0800 Subject: [PATCH 1/3] Add REA filters --- .../registry/api/BlockContentRegistries.java | 1 + .../api/RegistryEntryAttachment.java | 27 +++++++++++++++++-- ...tedDefaultRegistryEntryAttachmentImpl.java | 6 +++-- ...antDefaultRegistryEntryAttachmentImpl.java | 6 +++-- .../impl/RegistryEntryAttachmentImpl.java | 15 ++++++++++- .../registry/api/ItemContentRegistries.java | 8 ++++++ .../ItemContentRegistriesInitializer.java | 11 +------- 7 files changed, 57 insertions(+), 17 deletions(-) diff --git a/library/block/block_content_registry/src/main/java/org/quiltmc/qsl/block/content/registry/api/BlockContentRegistries.java b/library/block/block_content_registry/src/main/java/org/quiltmc/qsl/block/content/registry/api/BlockContentRegistries.java index d4497cf514..6eeccef0e9 100644 --- a/library/block/block_content_registry/src/main/java/org/quiltmc/qsl/block/content/registry/api/BlockContentRegistries.java +++ b/library/block/block_content_registry/src/main/java/org/quiltmc/qsl/block/content/registry/api/BlockContentRegistries.java @@ -105,6 +105,7 @@ public class BlockContentRegistries { return DataResult.success(block); })) + .filter(block -> block.getDefaultState().contains(Properties.AXIS)) .build(); /** diff --git a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/api/RegistryEntryAttachment.java b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/api/RegistryEntryAttachment.java index ae77a1cc3e..cc4604f7ad 100644 --- a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/api/RegistryEntryAttachment.java +++ b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/api/RegistryEntryAttachment.java @@ -20,6 +20,7 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; +import java.util.function.Predicate; import com.mojang.serialization.Codec; import org.jetbrains.annotations.ApiStatus; @@ -287,6 +288,15 @@ default Optional get(R entry) { */ boolean remove(TagKey tag); + /** + * The entry filter can prevent entries from being shown in the attachment. + * This can be used to prevent values from tags leaking into the registry entry attachment when not intended, + * such as nether wood in furnace fuels. + * + * @return the associated entry filter. + */ + Predicate entryFilter(); + /** * {@return this attachment's "value associated with entry" event} */ @@ -444,6 +454,8 @@ final class Builder { private @Nullable V defaultValue; private @Nullable DefaultValueProvider defaultValueProvider; + private Predicate filter = o -> true; + private Builder(Registry registry, Identifier id, Class valueClass, Codec codec) { this.registry = registry; this.id = id; @@ -501,6 +513,17 @@ public Builder defaultValueProvider(@Nullable DefaultValueProvider d return this; } + /** + * Sets the filter for the attachment. + * + * @param filter the entry filter + * @return this builder + */ + public Builder filter(Predicate filter) { + this.filter = filter; + return this; + } + /** * Builds a new attachment. * @@ -510,10 +533,10 @@ public RegistryEntryAttachment build() { RegistryEntryAttachment attachment; if (this.defaultValueProvider == null) { attachment = new ConstantDefaultRegistryEntryAttachmentImpl<>(this.registry, this.id, this.valueClass, - this.codec, this.side, this.defaultValue); + this.codec, this.side, this.defaultValue, this.filter); } else { attachment = new ComputedDefaultRegistryEntryAttachmentImpl<>(this.registry, this.id, this.valueClass, - this.codec, this.side, this.defaultValueProvider); + this.codec, this.side, this.defaultValueProvider, this.filter); } RegistryEntryAttachmentHolder.registerAttachment(this.registry, attachment); return attachment; diff --git a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ComputedDefaultRegistryEntryAttachmentImpl.java b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ComputedDefaultRegistryEntryAttachmentImpl.java index fea6343998..0d9d4596a6 100644 --- a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ComputedDefaultRegistryEntryAttachmentImpl.java +++ b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ComputedDefaultRegistryEntryAttachmentImpl.java @@ -16,6 +16,8 @@ package org.quiltmc.qsl.registry.attachment.impl; +import java.util.function.Predicate; + import com.mojang.serialization.Codec; import com.mojang.serialization.JsonOps; import org.jetbrains.annotations.NotNull; @@ -33,8 +35,8 @@ public final class ComputedDefaultRegistryEntryAttachmentImpl extends Regi private final @NotNull DefaultValueProvider defaultValueProvider; - public ComputedDefaultRegistryEntryAttachmentImpl(Registry registry, Identifier id, Class valueClass, Codec codec, Side side, @NotNull DefaultValueProvider defaultValueProvider) { - super(registry, id, valueClass, codec, side); + public ComputedDefaultRegistryEntryAttachmentImpl(Registry registry, Identifier id, Class valueClass, Codec codec, Side side, @NotNull DefaultValueProvider defaultValueProvider, Predicate filter) { + super(registry, id, valueClass, codec, side, filter); this.defaultValueProvider = defaultValueProvider; } diff --git a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ConstantDefaultRegistryEntryAttachmentImpl.java b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ConstantDefaultRegistryEntryAttachmentImpl.java index a4f1c4eea1..2aff1b2eea 100644 --- a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ConstantDefaultRegistryEntryAttachmentImpl.java +++ b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ConstantDefaultRegistryEntryAttachmentImpl.java @@ -16,6 +16,8 @@ package org.quiltmc.qsl.registry.attachment.impl; +import java.util.function.Predicate; + import com.mojang.serialization.Codec; import com.mojang.serialization.JsonOps; import org.jetbrains.annotations.Nullable; @@ -27,8 +29,8 @@ public final class ConstantDefaultRegistryEntryAttachmentImpl extends Regi private final @Nullable V defaultValue; public ConstantDefaultRegistryEntryAttachmentImpl(Registry registry, Identifier id, Class valueClass, - Codec codec, Side side, @Nullable V defaultValue) { - super(registry, id, valueClass, codec, side); + Codec codec, Side side, @Nullable V defaultValue, Predicate filter) { + super(registry, id, valueClass, codec, side, filter); if (defaultValue != null) { var encoded = this.codec.encodeStart(JsonOps.INSTANCE, defaultValue); diff --git a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java index 07415ef6a3..6d2a4c1116 100644 --- a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java +++ b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java @@ -19,6 +19,7 @@ import java.util.Iterator; import java.util.Objects; import java.util.Set; +import java.util.function.Predicate; import com.mojang.serialization.Codec; import it.unimi.dsi.fastutil.objects.ReferenceOpenHashBigSet; @@ -44,14 +45,16 @@ public abstract class RegistryEntryAttachmentImpl implements RegistryEntry protected final Event> tagValueAddedEvent; protected final Event> valueRemovedEvent; protected final Event> tagValueRemovedEvent; + protected final Predicate filter; public RegistryEntryAttachmentImpl(Registry registry, Identifier id, Class valueClass, Codec codec, - Side side) { + Side side, Predicate filter) { this.registry = registry; this.id = id; this.valueClass = valueClass; this.codec = codec; this.side = side; + this.filter = filter; this.valueAddedEvent = Event.create(ValueAdded.class, listeners -> (entry, value) -> { for (var listener : listeners) { @@ -108,6 +111,10 @@ public Side side() { ClientSideGuard.assertAccessAllowed(); } + if (this.filter.test(entry)) { + return null; + } + V value = RegistryEntryAttachmentHolder.getData(this.registry).getValue(this, entry); if (value != null) { return value; @@ -130,6 +137,7 @@ public Set keySet() { Set set = new ReferenceOpenHashBigSet<>(); set.addAll(RegistryEntryAttachmentHolder.getData(this.registry).valueTable.row(this).keySet()); set.addAll(RegistryEntryAttachmentHolder.getBuiltin(this.registry).valueTable.row(this).keySet()); + set.removeIf(this.filter); return set; } @@ -213,6 +221,11 @@ public boolean remove(TagKey tag) { return false; } + @Override + public Predicate entryFilter() { + return this.filter; + } + @Override public Event> valueAddedEvent() { return this.valueAddedEvent; diff --git a/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java b/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java index 6af0a3a163..3dce05e348 100644 --- a/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java +++ b/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java @@ -20,6 +20,8 @@ import net.minecraft.item.Item; import net.minecraft.registry.Registries; +import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.tag.TagKey; import net.minecraft.util.Identifier; import org.quiltmc.qsl.registry.attachment.api.RegistryEntryAttachment; @@ -39,6 +41,11 @@ public class ItemContentRegistries { */ public static final String NAMESPACE = "quilt"; + /** + * A tag that filters out values from being included as furnace fuels. + */ + public static final TagKey FUEL_FILTERS = TagKey.of(RegistryKeys.ITEM, new Identifier("quilt", "fuel_filters")); + /** * A {@link RegistryEntryAttachment} for how long different items burn in a furnace. The value is stored in ticks. *

@@ -49,6 +56,7 @@ public class ItemContentRegistries { new Identifier(NAMESPACE, "fuel_times"), Integer.class, Codec.intRange(0, Integer.MAX_VALUE)) + .filter(item -> item.getBuiltInRegistryHolder().isIn(FUEL_FILTERS)) .build(); /** diff --git a/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/impl/ItemContentRegistriesInitializer.java b/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/impl/ItemContentRegistriesInitializer.java index daa62b57c2..15e216bff2 100644 --- a/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/impl/ItemContentRegistriesInitializer.java +++ b/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/impl/ItemContentRegistriesInitializer.java @@ -29,9 +29,7 @@ import net.minecraft.block.entity.AbstractFurnaceBlockEntity; import net.minecraft.item.Item; import net.minecraft.item.ItemConvertible; -import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.TagKey; -import net.minecraft.util.Identifier; import org.quiltmc.loader.api.ModContainer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; @@ -47,8 +45,6 @@ public class ItemContentRegistriesInitializer implements ModInitializer { public static final Map INITIAL_COMPOST_CHANCE = ImmutableMap.copyOf(ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE); - public static final TagKey FUEL_FILTERS = TagKey.of(RegistryKeys.ITEM, new Identifier("quilt", "fuel_filters")); - private static boolean collectInitialTags = false; @Override @@ -62,12 +58,7 @@ public void onInitialize(ModContainer mod) { ResourceLoaderEvents.END_DATA_PACK_RELOAD.register((server, resourceManager, error) -> { FUEL_MAP.clear(); - // Fill the fuel map with all entries on the FUEL_TIMES registry attachment but filter using the #quilt:fuel_filters tag - for (var entry : ItemContentRegistries.FUEL_TIMES) { - if (!entry.entry().getBuiltInRegistryHolder().isIn(FUEL_FILTERS)) { - FUEL_MAP.put(entry.entry(), entry.value()); - } - } + setMapFromAttachment(FUEL_MAP::put, ItemContentRegistries.FUEL_TIMES); ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE.clear(); setMapFromAttachment(ComposterBlock.ITEM_TO_LEVEL_INCREASE_CHANCE::put, ItemContentRegistries.COMPOST_CHANCES); From 42d931291db5f8d8599f29bd2d726c2ce6b93f25 Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Sat, 28 Jan 2023 21:55:04 -0800 Subject: [PATCH 2/3] Fix some logic inconsistencies --- .../registry/attachment/impl/RegistryEntryAttachmentImpl.java | 4 ++-- .../qsl/item/content/registry/api/ItemContentRegistries.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java index 6d2a4c1116..64e8d8e030 100644 --- a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java +++ b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java @@ -111,7 +111,7 @@ public Side side() { ClientSideGuard.assertAccessAllowed(); } - if (this.filter.test(entry)) { + if (!this.filter.test(entry)) { return null; } @@ -137,7 +137,7 @@ public Set keySet() { Set set = new ReferenceOpenHashBigSet<>(); set.addAll(RegistryEntryAttachmentHolder.getData(this.registry).valueTable.row(this).keySet()); set.addAll(RegistryEntryAttachmentHolder.getBuiltin(this.registry).valueTable.row(this).keySet()); - set.removeIf(this.filter); + set.removeIf(Predicate.not(this.filter)); return set; } diff --git a/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java b/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java index 3dce05e348..3419484738 100644 --- a/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java +++ b/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java @@ -56,7 +56,7 @@ public class ItemContentRegistries { new Identifier(NAMESPACE, "fuel_times"), Integer.class, Codec.intRange(0, Integer.MAX_VALUE)) - .filter(item -> item.getBuiltInRegistryHolder().isIn(FUEL_FILTERS)) + .filter(item -> !item.getBuiltInRegistryHolder().isIn(FUEL_FILTERS)) .build(); /** From 8b036166de7889a1f156e7404d5ed5ff04f3f73b Mon Sep 17 00:00:00 2001 From: Eli Orona Date: Thu, 9 Mar 2023 09:50:48 -0800 Subject: [PATCH 3/3] Switch to tag system for filters and a validator predicate --- .../registry/api/BlockContentRegistries.java | 2 +- .../registry_entry_attachment/build.gradle | 3 ++ .../api/RegistryEntryAttachment.java | 37 +++++++++++++------ ...tedDefaultRegistryEntryAttachmentImpl.java | 4 +- ...antDefaultRegistryEntryAttachmentImpl.java | 4 +- .../impl/RegistryEntryAttachmentImpl.java | 24 ++++++++---- .../registry/api/ItemContentRegistries.java | 6 --- .../tags/items/{ => filter}/fuel_filters.json | 0 8 files changed, 50 insertions(+), 30 deletions(-) rename library/item/item_content_registry/src/main/resources/data/quilt/tags/items/{ => filter}/fuel_filters.json (100%) diff --git a/library/block/block_content_registry/src/main/java/org/quiltmc/qsl/block/content/registry/api/BlockContentRegistries.java b/library/block/block_content_registry/src/main/java/org/quiltmc/qsl/block/content/registry/api/BlockContentRegistries.java index 6eeccef0e9..de1a74557e 100644 --- a/library/block/block_content_registry/src/main/java/org/quiltmc/qsl/block/content/registry/api/BlockContentRegistries.java +++ b/library/block/block_content_registry/src/main/java/org/quiltmc/qsl/block/content/registry/api/BlockContentRegistries.java @@ -105,7 +105,7 @@ public class BlockContentRegistries { return DataResult.success(block); })) - .filter(block -> block.getDefaultState().contains(Properties.AXIS)) + .validator(block -> block.getDefaultState().contains(Properties.AXIS)) .build(); /** diff --git a/library/data/registry_entry_attachment/build.gradle b/library/data/registry_entry_attachment/build.gradle index ce05bb95a6..a6378ac558 100644 --- a/library/data/registry_entry_attachment/build.gradle +++ b/library/data/registry_entry_attachment/build.gradle @@ -15,6 +15,9 @@ qslModule { impl("resource_loader") impl("networking") } + data { + impl("tags") + } management { compileOnly("command") testmodOnly("command") diff --git a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/api/RegistryEntryAttachment.java b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/api/RegistryEntryAttachment.java index cc4604f7ad..0f1603d85a 100644 --- a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/api/RegistryEntryAttachment.java +++ b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/api/RegistryEntryAttachment.java @@ -289,13 +289,24 @@ default Optional get(R entry) { boolean remove(TagKey tag); /** - * The entry filter can prevent entries from being shown in the attachment. - * This can be used to prevent values from tags leaking into the registry entry attachment when not intended, - * such as nether wood in furnace fuels. + * The entry validation can prevent entries from being shown in the attachment. + * This can be used to prevent values that are not supported by the attachment, such as blocks without + * the AXIS property for log stripping. * - * @return the associated entry filter. + * @return the associated entry validator. */ - Predicate entryFilter(); + Predicate entryValidator(); + + /** + * This tag, at "[namespace]:filter/[path]" will filter entries from being shown in the attachment. + * This can be used to prevent values that are not supported by the attachment, such as items that are + * not burnable from acting as furnace fuels. + * + * @return the {@link TagKey} that filters the entry. + */ + default TagKey entryFilter() { + return TagKey.of(this.registry().getKey(), this.id().withPath(s -> "filter/" + s)); + } /** * {@return this attachment's "value associated with entry" event} @@ -454,7 +465,7 @@ final class Builder { private @Nullable V defaultValue; private @Nullable DefaultValueProvider defaultValueProvider; - private Predicate filter = o -> true; + private Predicate validator = o -> true; private Builder(Registry registry, Identifier id, Class valueClass, Codec codec) { this.registry = registry; @@ -514,13 +525,15 @@ public Builder defaultValueProvider(@Nullable DefaultValueProvider d } /** - * Sets the filter for the attachment. + * Sets the registry entry validator for the attachment. + * + * @see RegistryEntryAttachment#entryValidator() * - * @param filter the entry filter + * @param validator the entry validator * @return this builder */ - public Builder filter(Predicate filter) { - this.filter = filter; + public Builder validator(Predicate validator) { + this.validator = validator; return this; } @@ -533,10 +546,10 @@ public RegistryEntryAttachment build() { RegistryEntryAttachment attachment; if (this.defaultValueProvider == null) { attachment = new ConstantDefaultRegistryEntryAttachmentImpl<>(this.registry, this.id, this.valueClass, - this.codec, this.side, this.defaultValue, this.filter); + this.codec, this.side, this.defaultValue, this.validator); } else { attachment = new ComputedDefaultRegistryEntryAttachmentImpl<>(this.registry, this.id, this.valueClass, - this.codec, this.side, this.defaultValueProvider, this.filter); + this.codec, this.side, this.defaultValueProvider, this.validator); } RegistryEntryAttachmentHolder.registerAttachment(this.registry, attachment); return attachment; diff --git a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ComputedDefaultRegistryEntryAttachmentImpl.java b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ComputedDefaultRegistryEntryAttachmentImpl.java index 0d9d4596a6..45424f5ca0 100644 --- a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ComputedDefaultRegistryEntryAttachmentImpl.java +++ b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ComputedDefaultRegistryEntryAttachmentImpl.java @@ -35,8 +35,8 @@ public final class ComputedDefaultRegistryEntryAttachmentImpl extends Regi private final @NotNull DefaultValueProvider defaultValueProvider; - public ComputedDefaultRegistryEntryAttachmentImpl(Registry registry, Identifier id, Class valueClass, Codec codec, Side side, @NotNull DefaultValueProvider defaultValueProvider, Predicate filter) { - super(registry, id, valueClass, codec, side, filter); + public ComputedDefaultRegistryEntryAttachmentImpl(Registry registry, Identifier id, Class valueClass, Codec codec, Side side, @NotNull DefaultValueProvider defaultValueProvider, Predicate validator) { + super(registry, id, valueClass, codec, side, validator); this.defaultValueProvider = defaultValueProvider; } diff --git a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ConstantDefaultRegistryEntryAttachmentImpl.java b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ConstantDefaultRegistryEntryAttachmentImpl.java index 2aff1b2eea..1ee0d79b0a 100644 --- a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ConstantDefaultRegistryEntryAttachmentImpl.java +++ b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/ConstantDefaultRegistryEntryAttachmentImpl.java @@ -29,8 +29,8 @@ public final class ConstantDefaultRegistryEntryAttachmentImpl extends Regi private final @Nullable V defaultValue; public ConstantDefaultRegistryEntryAttachmentImpl(Registry registry, Identifier id, Class valueClass, - Codec codec, Side side, @Nullable V defaultValue, Predicate filter) { - super(registry, id, valueClass, codec, side, filter); + Codec codec, Side side, @Nullable V defaultValue, Predicate validator) { + super(registry, id, valueClass, codec, side, validator); if (defaultValue != null) { var encoded = this.codec.encodeStart(JsonOps.INSTANCE, defaultValue); diff --git a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java index 64e8d8e030..e02b6f6ef1 100644 --- a/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java +++ b/library/data/registry_entry_attachment/src/main/java/org/quiltmc/qsl/registry/attachment/impl/RegistryEntryAttachmentImpl.java @@ -33,6 +33,7 @@ import org.quiltmc.qsl.base.api.event.Event; import org.quiltmc.qsl.registry.attachment.api.RegistryEntryAttachment; +import org.quiltmc.qsl.tag.api.TagRegistry; @ApiStatus.Internal public abstract class RegistryEntryAttachmentImpl implements RegistryEntryAttachment { @@ -45,16 +46,16 @@ public abstract class RegistryEntryAttachmentImpl implements RegistryEntry protected final Event> tagValueAddedEvent; protected final Event> valueRemovedEvent; protected final Event> tagValueRemovedEvent; - protected final Predicate filter; + protected final Predicate validator; public RegistryEntryAttachmentImpl(Registry registry, Identifier id, Class valueClass, Codec codec, - Side side, Predicate filter) { + Side side, Predicate validator) { this.registry = registry; this.id = id; this.valueClass = valueClass; this.codec = codec; this.side = side; - this.filter = filter; + this.validator = validator; this.valueAddedEvent = Event.create(ValueAdded.class, listeners -> (entry, value) -> { for (var listener : listeners) { @@ -111,7 +112,7 @@ public Side side() { ClientSideGuard.assertAccessAllowed(); } - if (!this.filter.test(entry)) { + if (!this.validator.test(entry) || TagRegistry.getTag(this.entryFilter()).stream().anyMatch(holder -> holder.value().equals(entry))) { return null; } @@ -137,7 +138,12 @@ public Set keySet() { Set set = new ReferenceOpenHashBigSet<>(); set.addAll(RegistryEntryAttachmentHolder.getData(this.registry).valueTable.row(this).keySet()); set.addAll(RegistryEntryAttachmentHolder.getBuiltin(this.registry).valueTable.row(this).keySet()); - set.removeIf(Predicate.not(this.filter)); + set.removeIf(Predicate.not(this.validator)); + + this.registry.getTagOrEmpty(this.entryFilter()).forEach(holder -> { + set.remove(holder.value()); + }); + return set; } @@ -188,6 +194,10 @@ public void put(R entry, V value) { throw new IllegalArgumentException("Entry hasn't been registered"); } + if (!this.validator.test(entry)) { + throw new IllegalArgumentException(String.format("Entry %s does not pass validation for REA %s", this.registry.getId(entry), this.id)); + } + CodecUtils.assertValid(this.codec, value); RegistryEntryAttachmentHolder.getBuiltin(this.registry).putValue(this, entry, value, BuiltinRegistryEntryAttachmentHolder.FLAG_NONE); @@ -222,8 +232,8 @@ public boolean remove(TagKey tag) { } @Override - public Predicate entryFilter() { - return this.filter; + public Predicate entryValidator() { + return this.validator; } @Override diff --git a/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java b/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java index 3419484738..3d59c4bd76 100644 --- a/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java +++ b/library/item/item_content_registry/src/main/java/org/quiltmc/qsl/item/content/registry/api/ItemContentRegistries.java @@ -41,11 +41,6 @@ public class ItemContentRegistries { */ public static final String NAMESPACE = "quilt"; - /** - * A tag that filters out values from being included as furnace fuels. - */ - public static final TagKey FUEL_FILTERS = TagKey.of(RegistryKeys.ITEM, new Identifier("quilt", "fuel_filters")); - /** * A {@link RegistryEntryAttachment} for how long different items burn in a furnace. The value is stored in ticks. *

@@ -56,7 +51,6 @@ public class ItemContentRegistries { new Identifier(NAMESPACE, "fuel_times"), Integer.class, Codec.intRange(0, Integer.MAX_VALUE)) - .filter(item -> !item.getBuiltInRegistryHolder().isIn(FUEL_FILTERS)) .build(); /** diff --git a/library/item/item_content_registry/src/main/resources/data/quilt/tags/items/fuel_filters.json b/library/item/item_content_registry/src/main/resources/data/quilt/tags/items/filter/fuel_filters.json similarity index 100% rename from library/item/item_content_registry/src/main/resources/data/quilt/tags/items/fuel_filters.json rename to library/item/item_content_registry/src/main/resources/data/quilt/tags/items/filter/fuel_filters.json