From 4c89a6c13551894cee1d65ebf749a45662e3cb3f Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Sun, 18 Aug 2024 15:08:03 +0100 Subject: [PATCH] Even more fixes --- .../conditions/v1/ResourceCondition.java | 7 ++-- .../conditions/ResourceConditionsImpl.java | 21 +++++++----- .../AllModsLoadedResourceCondition.java | 5 ++- .../conditions/AndResourceCondition.java | 7 ++-- .../AnyModsLoadedResourceCondition.java | 5 ++- .../FeaturesEnabledResourceCondition.java | 5 ++- .../conditions/NotResourceCondition.java | 7 ++-- .../conditions/OrResourceCondition.java | 7 ++-- .../RegistryContainsResourceCondition.java | 7 ++-- .../TagsPopulatedResourceCondition.java | 5 ++- .../conditions/TrueResourceCondition.java | 5 ++- .../conditions/JsonDataLoaderMixin.java | 5 ++- .../conditions/RecipeManagerMixin.java | 5 +-- .../conditions/RegistryLoaderMixin.java | 33 +++++++------------ .../conditions/ReloadableRegistriesMixin.java | 2 +- .../ServerAdvancementLoaderMixin.java | 6 ++-- ...inglePreparationResourceReloaderMixin.java | 6 ++-- ...c-resource-conditions-api-v1.accesswidener | 1 + .../DefaultResourceConditionsTest.java | 3 +- .../recipe/features_enabled.json | 4 +-- 20 files changed, 90 insertions(+), 56 deletions(-) diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/api/resource/conditions/v1/ResourceCondition.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/api/resource/conditions/v1/ResourceCondition.java index 6798f3793..abf145853 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/api/resource/conditions/v1/ResourceCondition.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/api/resource/conditions/v1/ResourceCondition.java @@ -19,6 +19,9 @@ package net.fabricmc.fabric.api.resource.conditions.v1; import java.util.List; import com.mojang.serialization.Codec; + +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import net.minecraft.registry.RegistryWrapper; @@ -56,8 +59,8 @@ public interface ResourceCondition { * (such as recipes or advancements). However, it may be {@code null} in client-side * resources, or for non-vanilla resource types. * - * @param registryLookup the registry lookup, or {@code null} in case registry is unavailable + * @param registryInfo the registry lookup, or {@code null} in case registry is unavailable * @return whether the condition was successful */ - boolean test(@Nullable RegistryWrapper.WrapperLookup registryLookup); + boolean test(@Nullable RegistryOps.RegistryInfoGetter registryInfo); } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/ResourceConditionsImpl.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/ResourceConditionsImpl.java index 03cae81da..1b90d3413 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/ResourceConditionsImpl.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/ResourceConditionsImpl.java @@ -27,6 +27,11 @@ import java.util.stream.Collectors; import com.google.gson.JsonObject; import com.mojang.serialization.DataResult; import com.mojang.serialization.JsonOps; + +import net.minecraft.registry.RegistryEntryLookup; +import net.minecraft.registry.RegistryOps; +import net.minecraft.registry.entry.RegistryEntryInfo; + import org.apache.commons.lang3.mutable.MutableBoolean; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; @@ -62,14 +67,14 @@ public final class ResourceConditionsImpl implements ModInitializer { ResourceConditions.register(DefaultResourceConditionTypes.REGISTRY_CONTAINS); } - public static boolean applyResourceConditions(JsonObject obj, String dataType, Identifier key, @Nullable RegistryWrapper.WrapperLookup registryLookup) { + public static boolean applyResourceConditions(JsonObject obj, String dataType, Identifier key, @Nullable RegistryOps.RegistryInfoGetter registryInfo) { boolean debugLogEnabled = ResourceConditionsImpl.LOGGER.isDebugEnabled(); if (obj.has(ResourceConditions.CONDITIONS_KEY)) { DataResult conditions = ResourceCondition.CONDITION_CODEC.parse(JsonOps.INSTANCE, obj.get(ResourceConditions.CONDITIONS_KEY)); if (conditions.isSuccess()) { - boolean matched = conditions.getOrThrow().test(registryLookup); + boolean matched = conditions.getOrThrow().test(registryInfo); if (debugLogEnabled) { String verdict = matched ? "Allowed" : "Rejected"; @@ -87,9 +92,9 @@ public final class ResourceConditionsImpl implements ModInitializer { // Condition implementations - public static boolean conditionsMet(List conditions, @Nullable RegistryWrapper.WrapperLookup registryLookup, boolean and) { + public static boolean conditionsMet(List conditions, @Nullable RegistryOps.RegistryInfoGetter registryInfo, boolean and) { for (ResourceCondition condition : conditions) { - if (condition.test(registryLookup) != and) { + if (condition.test(registryInfo) != and) { return !and; } } @@ -164,19 +169,19 @@ public final class ResourceConditionsImpl implements ModInitializer { return set.isSubsetOf(currentFeatures); } - public static boolean registryContains(@Nullable RegistryWrapper.WrapperLookup registryLookup, Identifier registryId, List entries) { + public static boolean registryContains(@Nullable RegistryOps.RegistryInfoGetter registryInfo, Identifier registryId, List entries) { RegistryKey> registryKey = RegistryKey.ofRegistry(registryId); - if (registryLookup == null) { + if (registryInfo == null) { LOGGER.warn("Can't retrieve registry {}, failing registry_contains resource condition check", registryId); return false; } - Optional> wrapper = registryLookup.getOptionalWrapper(registryKey); + Optional> wrapper = registryInfo.getRegistryInfo(registryKey); if (wrapper.isPresent()) { for (Identifier id : entries) { - if (wrapper.get().getOptional(RegistryKey.of(registryKey, id)).isEmpty()) { + if (wrapper.get().entryLookup().getOptional(RegistryKey.of(registryKey, id)).isEmpty()) { return false; } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AllModsLoadedResourceCondition.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AllModsLoadedResourceCondition.java index 807d3e840..e92f616ec 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AllModsLoadedResourceCondition.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AllModsLoadedResourceCondition.java @@ -21,6 +21,9 @@ import java.util.List; import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import net.minecraft.registry.RegistryWrapper; @@ -41,7 +44,7 @@ public record AllModsLoadedResourceCondition(List modIds) implements Res } @Override - public boolean test(@Nullable RegistryWrapper.WrapperLookup registryLookup) { + public boolean test(@Nullable RegistryOps.RegistryInfoGetter registryInfo) { return ResourceConditionsImpl.modsLoaded(this.modIds(), true); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AndResourceCondition.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AndResourceCondition.java index f3b86fb01..ca66cf2d0 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AndResourceCondition.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AndResourceCondition.java @@ -20,6 +20,9 @@ import java.util.List; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import net.minecraft.registry.RegistryWrapper; @@ -40,7 +43,7 @@ public record AndResourceCondition(List conditions) implement } @Override - public boolean test(@Nullable RegistryWrapper.WrapperLookup registryLookup) { - return ResourceConditionsImpl.conditionsMet(this.conditions(), registryLookup, true); + public boolean test(@Nullable RegistryOps.RegistryInfoGetter registryInfo) { + return ResourceConditionsImpl.conditionsMet(this.conditions(), registryInfo, true); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AnyModsLoadedResourceCondition.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AnyModsLoadedResourceCondition.java index da9dfe9fd..1cc77e8a7 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AnyModsLoadedResourceCondition.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/AnyModsLoadedResourceCondition.java @@ -21,6 +21,9 @@ import java.util.List; import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import net.minecraft.registry.RegistryWrapper; @@ -41,7 +44,7 @@ public record AnyModsLoadedResourceCondition(List modIds) implements Res } @Override - public boolean test(@Nullable RegistryWrapper.WrapperLookup registryLookup) { + public boolean test(@Nullable RegistryOps.RegistryInfoGetter registryInfo) { return ResourceConditionsImpl.modsLoaded(this.modIds(), false); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/FeaturesEnabledResourceCondition.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/FeaturesEnabledResourceCondition.java index a4ddecc22..5be6d2e7b 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/FeaturesEnabledResourceCondition.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/FeaturesEnabledResourceCondition.java @@ -21,6 +21,9 @@ import java.util.List; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import net.minecraft.registry.RegistryWrapper; @@ -52,7 +55,7 @@ public record FeaturesEnabledResourceCondition(Collection features) } @Override - public boolean test(@Nullable RegistryWrapper.WrapperLookup registryLookup) { + public boolean test(@Nullable RegistryOps.RegistryInfoGetter registryInfo) { return ResourceConditionsImpl.featuresEnabled(this.features()); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/NotResourceCondition.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/NotResourceCondition.java index 3e37c8f55..2ce36747b 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/NotResourceCondition.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/NotResourceCondition.java @@ -18,6 +18,9 @@ package net.fabricmc.fabric.impl.resource.conditions.conditions; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import net.minecraft.registry.RegistryWrapper; @@ -37,7 +40,7 @@ public record NotResourceCondition(ResourceCondition condition) implements Resou } @Override - public boolean test(@Nullable RegistryWrapper.WrapperLookup registryLookup) { - return !this.condition().test(registryLookup); + public boolean test(@Nullable RegistryOps.RegistryInfoGetter registryInfo) { + return !this.condition().test(registryInfo); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/OrResourceCondition.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/OrResourceCondition.java index aefbf995e..591c8f088 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/OrResourceCondition.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/OrResourceCondition.java @@ -20,6 +20,9 @@ import java.util.List; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import net.minecraft.registry.RegistryWrapper; @@ -40,7 +43,7 @@ public record OrResourceCondition(List conditions) implements } @Override - public boolean test(@Nullable RegistryWrapper.WrapperLookup registryLookup) { - return ResourceConditionsImpl.conditionsMet(this.conditions(), registryLookup, false); + public boolean test(@Nullable RegistryOps.RegistryInfoGetter registryInfo) { + return ResourceConditionsImpl.conditionsMet(this.conditions(), registryInfo, false); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/RegistryContainsResourceCondition.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/RegistryContainsResourceCondition.java index 34b9a7d42..99ac59f70 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/RegistryContainsResourceCondition.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/impl/resource/conditions/conditions/RegistryContainsResourceCondition.java @@ -21,6 +21,9 @@ import java.util.List; import com.mojang.serialization.MapCodec; import com.mojang.serialization.codecs.RecordCodecBuilder; + +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import net.minecraft.registry.RegistryKey; @@ -56,7 +59,7 @@ public record RegistryContainsResourceCondition(Identifier registry, List> it = ((Map) object).entrySet().iterator(); diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/RecipeManagerMixin.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/RecipeManagerMixin.java index a351ea581..3ce8bd252 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/RecipeManagerMixin.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/RecipeManagerMixin.java @@ -22,6 +22,7 @@ import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import net.minecraft.recipe.RecipeManager; +import net.minecraft.registry.RegistryOps; import net.minecraft.registry.RegistryWrapper; @Mixin(RecipeManager.class) @@ -31,7 +32,7 @@ public class RecipeManagerMixin extends SinglePreparationResourceReloaderMixin { private RegistryWrapper.WrapperLookup registryLookup; @Override - protected @Nullable RegistryWrapper.WrapperLookup fabric_getRegistryLookup() { - return this.registryLookup; + protected @Nullable RegistryOps.RegistryInfoGetter fabric_getRegistryLookup() { + return new RegistryOps.CachedRegistryInfoGetter(registryLookup); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/RegistryLoaderMixin.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/RegistryLoaderMixin.java index 9a2da4ad6..fcd424f27 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/RegistryLoaderMixin.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/RegistryLoaderMixin.java @@ -18,7 +18,7 @@ package net.fabricmc.fabric.mixin.resource.conditions; import java.io.IOException; import java.io.Reader; -import java.util.List; +import java.util.Map; import com.google.gson.JsonElement; import com.llamalad7.mixinextras.sugar.Local; @@ -28,14 +28,11 @@ import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.MutableRegistry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryLoader; import net.minecraft.registry.RegistryOps; -import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.entry.RegistryEntryInfo; import net.minecraft.resource.Resource; import net.minecraft.resource.ResourceManager; @@ -45,26 +42,20 @@ import net.fabricmc.fabric.impl.resource.conditions.ResourceConditionsImpl; @Mixin(RegistryLoader.class) public class RegistryLoaderMixin { @Unique - private static final ThreadLocal REGISTRIES = new ThreadLocal<>(); + private static final ThreadLocal REGISTRY_INFO = new ThreadLocal<>(); /** * Capture the current registries, so they can be passed to the resource conditions. */ - @Inject(method = "loadFromResource(Lnet/minecraft/resource/ResourceManager;Ljava/util/List;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;", at = @At("RETURN")) - private static void captureRegistries(ResourceManager resourceManager, List> registries, List> entries, CallbackInfoReturnable cir) { - REGISTRIES.set(cir.getReturnValue()); + @Inject(method = "loadFromResource(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/RegistryOps$RegistryInfoGetter;Lnet/minecraft/registry/MutableRegistry;Lcom/mojang/serialization/Decoder;Ljava/util/Map;)V", at = @At("HEAD")) + private static void captureRegistries(ResourceManager resourceManager, RegistryOps.RegistryInfoGetter infoGetter, MutableRegistry registry, Decoder elementDecoder, Map, Exception> errors, CallbackInfo ci) { + REGISTRY_INFO.set(infoGetter); } - // TODO 24w33a - Double Check if replacement above will work - it doesnt - /*@WrapOperation(method = "loadFromResource(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;", at = @At(value = "INVOKE", target = "Lnet/minecraft/registry/RegistryLoader;load(Lnet/minecraft/registry/RegistryLoader$RegistryLoadable;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;")) - private static DynamicRegistryManager.Immutable captureRegistries(@Coerce Object registryLoadable, DynamicRegistryManager baseRegistryManager, List> entries, Operation original) { - try { - REGISTRIES.set(baseRegistryManager); - return original.call(registryLoadable, baseRegistryManager, entries); - } finally { - REGISTRIES.remove(); - } - }*/ + @Inject(method = "loadFromResource(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/RegistryOps$RegistryInfoGetter;Lnet/minecraft/registry/MutableRegistry;Lcom/mojang/serialization/Decoder;Ljava/util/Map;)V", at = @At("RETURN")) + private static void releaseRegistries(ResourceManager resourceManager, RegistryOps.RegistryInfoGetter infoGetter, MutableRegistry registry, Decoder elementDecoder, Map, Exception> errors, CallbackInfo ci) { + REGISTRY_INFO.remove(); + } @Inject( method = "Lnet/minecraft/registry/RegistryLoader;parseAndAdd(Lnet/minecraft/registry/MutableRegistry;Lcom/mojang/serialization/Decoder;Lnet/minecraft/registry/RegistryOps;Lnet/minecraft/registry/RegistryKey;Lnet/minecraft/resource/Resource;Lnet/minecraft/registry/entry/RegistryEntryInfo;)V", @@ -77,10 +68,10 @@ public class RegistryLoaderMixin { ) throws IOException { // This method is called both on the server (when loading resources) and on the client (when syncing from the // server). We only want to apply resource conditions when loading via loadFromResource. - DynamicRegistryManager registries = REGISTRIES.get(); - if (registries == null) return; + RegistryOps.RegistryInfoGetter registryInfoGetter = REGISTRY_INFO.get(); + if (registryInfoGetter == null) return; - if (jsonElement.isJsonObject() && !ResourceConditionsImpl.applyResourceConditions(jsonElement.getAsJsonObject(), key.getRegistry().toString(), key.getValue(), registries)) { + if (jsonElement.isJsonObject() && !ResourceConditionsImpl.applyResourceConditions(jsonElement.getAsJsonObject(), key.getRegistry().toString(), key.getValue(), registryInfoGetter)) { reader.close(); ci.cancel(); } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/ReloadableRegistriesMixin.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/ReloadableRegistriesMixin.java index 76c600e7e..3d23438b3 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/ReloadableRegistriesMixin.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/ReloadableRegistriesMixin.java @@ -71,7 +71,7 @@ public class ReloadableRegistriesMixin { @Inject(method = "method_61239", at = @At("HEAD"), cancellable = true) private static void applyConditions(LootDataType lootDataType, RegistryOps ops, MutableRegistry mutableRegistry, Identifier id, JsonElement json, CallbackInfo ci) { - if (json.isJsonObject() && !ResourceConditionsImpl.applyResourceConditions(json.getAsJsonObject(), lootDataType.registryKey().getValue().getPath(), id, REGISTRY_LOOKUPS.get(ops))) { + if (json.isJsonObject() && !ResourceConditionsImpl.applyResourceConditions(json.getAsJsonObject(), lootDataType.registryKey().getValue().getPath(), id, new RegistryOps.CachedRegistryInfoGetter(REGISTRY_LOOKUPS.get(ops)))) { ci.cancel(); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/ServerAdvancementLoaderMixin.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/ServerAdvancementLoaderMixin.java index 84c0bfd91..5b13390f4 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/ServerAdvancementLoaderMixin.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/ServerAdvancementLoaderMixin.java @@ -16,6 +16,8 @@ package net.fabricmc.fabric.mixin.resource.conditions; +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -31,7 +33,7 @@ public class ServerAdvancementLoaderMixin extends SinglePreparationResourceReloa private RegistryWrapper.WrapperLookup registryLookup; @Override - protected @Nullable RegistryWrapper.WrapperLookup fabric_getRegistryLookup() { - return this.registryLookup; + protected @Nullable RegistryOps.RegistryInfoGetter fabric_getRegistryLookup() { + return new RegistryOps.CachedRegistryInfoGetter(this.registryLookup); } } diff --git a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/SinglePreparationResourceReloaderMixin.java b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/SinglePreparationResourceReloaderMixin.java index 4bb54a737..a95fbf3a3 100644 --- a/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/SinglePreparationResourceReloaderMixin.java +++ b/fabric-resource-conditions-api-v1/src/main/java/net/fabricmc/fabric/mixin/resource/conditions/SinglePreparationResourceReloaderMixin.java @@ -16,6 +16,8 @@ package net.fabricmc.fabric.mixin.resource.conditions; +import net.minecraft.registry.RegistryOps; + import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -39,11 +41,11 @@ public class SinglePreparationResourceReloaderMixin { fabric_applyResourceConditions(resourceManager, profiler, object, fabric_getRegistryLookup()); } - protected void fabric_applyResourceConditions(ResourceManager resourceManager, Profiler profiler, Object object, @Nullable RegistryWrapper.WrapperLookup registryLookup) { + protected void fabric_applyResourceConditions(ResourceManager resourceManager, Profiler profiler, Object object, @Nullable RegistryOps.RegistryInfoGetter registryLookup) { } @Nullable - protected RegistryWrapper.WrapperLookup fabric_getRegistryLookup() { + protected RegistryOps.RegistryInfoGetter fabric_getRegistryLookup() { return null; } } diff --git a/fabric-resource-conditions-api-v1/src/main/resources/fabric-resource-conditions-api-v1.accesswidener b/fabric-resource-conditions-api-v1/src/main/resources/fabric-resource-conditions-api-v1.accesswidener index d67b5f319..abbb50e08 100644 --- a/fabric-resource-conditions-api-v1/src/main/resources/fabric-resource-conditions-api-v1.accesswidener +++ b/fabric-resource-conditions-api-v1/src/main/resources/fabric-resource-conditions-api-v1.accesswidener @@ -1,3 +1,4 @@ accessWidener v2 named accessible class net/minecraft/registry/ReloadableRegistries$ReloadableWrapperLookup +accessible class net/minecraft/registry/RegistryOps$CachedRegistryInfoGetter diff --git a/fabric-resource-conditions-api-v1/src/testmod/java/net/fabricmc/fabric/test/resource/conditions/DefaultResourceConditionsTest.java b/fabric-resource-conditions-api-v1/src/testmod/java/net/fabricmc/fabric/test/resource/conditions/DefaultResourceConditionsTest.java index 3b7ef435b..611bb1f5a 100644 --- a/fabric-resource-conditions-api-v1/src/testmod/java/net/fabricmc/fabric/test/resource/conditions/DefaultResourceConditionsTest.java +++ b/fabric-resource-conditions-api-v1/src/testmod/java/net/fabricmc/fabric/test/resource/conditions/DefaultResourceConditionsTest.java @@ -27,6 +27,7 @@ import net.minecraft.registry.Registries; import net.minecraft.registry.Registry; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; +import net.minecraft.registry.RegistryOps; import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.tag.BiomeTags; import net.minecraft.registry.tag.BlockTags; @@ -52,7 +53,7 @@ public class DefaultResourceConditionsTest { private void expectCondition(TestContext context, String name, ResourceCondition condition, boolean expected) { RegistryWrapper.WrapperLookup registryLookup = context.getWorld().getRegistryManager(); - boolean actual = condition.test(registryLookup); + boolean actual = condition.test(new RegistryOps.CachedRegistryInfoGetter(registryLookup)); if (actual != expected) { throw new AssertionError("Test \"%s\" for condition %s failed; expected %s, got %s".formatted(name, condition.getType().id(), expected, actual)); diff --git a/fabric-resource-conditions-api-v1/src/testmod/resources/data/fabric-resource-conditions-api-v1-testmod/recipe/features_enabled.json b/fabric-resource-conditions-api-v1/src/testmod/resources/data/fabric-resource-conditions-api-v1-testmod/recipe/features_enabled.json index 3267fcdad..011e60d3e 100644 --- a/fabric-resource-conditions-api-v1/src/testmod/resources/data/fabric-resource-conditions-api-v1-testmod/recipe/features_enabled.json +++ b/fabric-resource-conditions-api-v1/src/testmod/resources/data/fabric-resource-conditions-api-v1-testmod/recipe/features_enabled.json @@ -1,9 +1,7 @@ { "type": "minecraft:crafting_shapeless", "ingredients": [ - { - "item": "minecraft:blue_dye" - } + "minecraft:blue_dye" ], "result": { "id": "minecraft:diamond"