From 375e8342a4498e5d19d0c03ad07a1abff31318c4 Mon Sep 17 00:00:00 2001 From: Minecraftschurli Date: Tue, 23 Jul 2024 09:00:46 +0200 Subject: [PATCH] Fix missing registries --- .../java/vazkii/patchouli/api/IVariable.java | 33 ++++++++++++++++--- .../api/IVariablesAvailableCallback.java | 15 +++++---- .../client/book/BookContentsBuilder.java | 2 ++ .../book/template/TemplateComponent.java | 11 ++++--- .../book/template/TemplateInclusion.java | 8 ++--- .../book/template/VariableAssigner.java | 18 +++++----- .../template/component/ComponentCustom.java | 7 ++-- .../template/component/ComponentEntity.java | 5 +-- .../template/component/ComponentHeader.java | 5 +-- .../template/component/ComponentImage.java | 7 ++-- .../component/ComponentItemStack.java | 5 +-- .../template/component/ComponentText.java | 5 +-- .../template/component/ComponentTooltip.java | 5 +-- .../template/test/ComponentCustomTest.java | 5 +-- .../template/test/EntityTestProcessor.java | 2 +- .../template/test/RecipeTestProcessor.java | 6 ++-- .../patchouli/common/util/ItemStackUtil.java | 5 ++- .../common/util/SerializationUtil.java | 3 +- 18 files changed, 95 insertions(+), 52 deletions(-) diff --git a/Xplat/src/main/java/vazkii/patchouli/api/IVariable.java b/Xplat/src/main/java/vazkii/patchouli/api/IVariable.java index b8f4f9de9..aca29b9d9 100644 --- a/Xplat/src/main/java/vazkii/patchouli/api/IVariable.java +++ b/Xplat/src/main/java/vazkii/patchouli/api/IVariable.java @@ -142,16 +142,31 @@ static IVariable wrapList(Iterable elems, HolderLookup.Provider regis return wrap(arr, registries); } + @Deprecated // Use HolderLookup.Provider version static IVariable wrap(@Nullable Number n) { - return n != null ? wrap(new JsonPrimitive(n), RegistryAccess.EMPTY) : empty(); + return wrap(n, RegistryAccess.EMPTY); } + static IVariable wrap(@Nullable Number n, HolderLookup.Provider registries) { + return n != null ? wrap(new JsonPrimitive(n), registries) : empty(); + } + + @Deprecated // Use HolderLookup.Provider version static IVariable wrap(@Nullable Boolean b) { - return b != null ? wrap(new JsonPrimitive(b), RegistryAccess.EMPTY) : empty(); + return wrap(b, RegistryAccess.EMPTY); } + static IVariable wrap(@Nullable Boolean b, HolderLookup.Provider registries) { + return b != null ? wrap(new JsonPrimitive(b), registries) : empty(); + } + + @Deprecated // Use HolderLookup.Provider version static IVariable wrap(@Nullable String s) { - return s != null ? wrap(new JsonPrimitive(s), RegistryAccess.EMPTY) : empty(); + return wrap(s, RegistryAccess.EMPTY); + } + + static IVariable wrap(@Nullable String s, HolderLookup.Provider registries) { + return s != null ? wrap(new JsonPrimitive(s), registries) : empty(); } static IVariable empty() { @@ -159,9 +174,19 @@ static IVariable empty() { } class Serializer implements JsonDeserializer { + + private HolderLookup.Provider registryCache; + @Override public IVariable deserialize(JsonElement elem, Type t, JsonDeserializationContext c) { - return IVariable.wrap(elem, RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)); + if (registryCache == null || registryCache.listRegistries().findFirst().isEmpty()) { + registryCache = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY); + } + return IVariable.wrap(elem, registryCache); + } + + public void setRegistries(HolderLookup.Provider registries) { + this.registryCache = registries; } } } diff --git a/Xplat/src/main/java/vazkii/patchouli/api/IVariablesAvailableCallback.java b/Xplat/src/main/java/vazkii/patchouli/api/IVariablesAvailableCallback.java index 77bf5583e..659fa95bf 100644 --- a/Xplat/src/main/java/vazkii/patchouli/api/IVariablesAvailableCallback.java +++ b/Xplat/src/main/java/vazkii/patchouli/api/IVariablesAvailableCallback.java @@ -1,17 +1,20 @@ package vazkii.patchouli.api; +import net.minecraft.core.HolderLookup; + import java.util.function.UnaryOperator; public interface IVariablesAvailableCallback { /** * Called when variables are available, before the template component is built * - * @param lookup Call with arbitrary text, and it will be expanded: - * first expanding all inline variables, - * then attempting to apply "->" derivations if possible, otherwise looking up the string as a - * plain variable from the template environment
- * Gracefully handles nulls given as input, but will never return null itself. + * @param lookup Call with arbitrary text, and it will be expanded: + * first expanding all inline variables, + * then attempting to apply "->" derivations if possible, otherwise looking up the string as a + * plain variable from the template environment
+ * Gracefully handles nulls given as input, but will never return null itself. + * @param registries Provider for accessing registries in IVariable#wrap operations. */ - void onVariablesAvailable(UnaryOperator lookup); + void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries); } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/BookContentsBuilder.java b/Xplat/src/main/java/vazkii/patchouli/client/book/BookContentsBuilder.java index 203829b0e..a9072457f 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/BookContentsBuilder.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/BookContentsBuilder.java @@ -11,6 +11,7 @@ import vazkii.patchouli.common.book.Book; import vazkii.patchouli.common.book.BookRegistry; import vazkii.patchouli.common.util.ItemStackUtil; +import vazkii.patchouli.common.util.SerializationUtil; import org.jetbrains.annotations.Nullable; @@ -69,6 +70,7 @@ public void addRecipeMapping(ItemStackUtil.StackWrapper stack, BookEntry entry, public static BookContents loadAndBuildFor(Level level, Book book, boolean singleBookReload) { BookContentsBuilder builder = new BookContentsBuilder(book, singleBookReload); + SerializationUtil.VARIABLE_SERIALIZER.setRegistries(level.registryAccess()); builder.loadFiles(); return builder.build(level); } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/TemplateComponent.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/TemplateComponent.java index f0c6b373d..c22170154 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/TemplateComponent.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/TemplateComponent.java @@ -4,6 +4,7 @@ import com.google.gson.annotations.SerializedName; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderLookup; import net.minecraft.world.level.Level; import vazkii.patchouli.api.IComponentProcessor; @@ -90,11 +91,11 @@ public boolean mouseClicked(BookPage page, double mouseX, double mouseY, int mou } @Override - public void onVariablesAvailable(UnaryOperator lookup) { + public void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries) { // TODO fix this up to use IVariable more intelligently - group = lookup.apply(IVariable.wrap(group)).asString(); - flag = lookup.apply(IVariable.wrap(flag)).asString(); - advancement = lookup.apply(IVariable.wrap(advancement)).asString(); - guardPass = (guard == null || lookup.apply(IVariable.wrap(guard)).asBoolean()); + group = lookup.apply(IVariable.wrap(group, registries)).asString(); + flag = lookup.apply(IVariable.wrap(flag, registries)).asString(); + advancement = lookup.apply(IVariable.wrap(advancement, registries)).asString(); + guardPass = (guard == null || lookup.apply(IVariable.wrap(guard, registries)).asBoolean()); } } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/TemplateInclusion.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/TemplateInclusion.java index 9939b5248..855c43bc8 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/TemplateInclusion.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/TemplateInclusion.java @@ -101,11 +101,11 @@ public String qualifyName(String name) { /** * Attempt to look up a variable in local scope. */ - public IVariable attemptVariableLookup(String key) { + public IVariable attemptVariableLookup(String key, HolderLookup.Provider registries) { if (key.startsWith("#")) { key = key.substring(1); } - IVariable result = IVariable.wrap(localBindings.get(key), RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)); + IVariable result = IVariable.wrap(localBindings.get(key), registries); return result.asString().isEmpty() || isUpreference(result) ? null : result; } @@ -120,12 +120,12 @@ public IVariableProvider wrapProvider(IVariableProvider provider) { return new IVariableProvider() { @Override public boolean has(String key) { - return attemptVariableLookup(key) != null || provider.has(qualifyName(key)); + return attemptVariableLookup(key, RegistryAccess.EMPTY) != null || provider.has(qualifyName(key)); } @Override public IVariable get(String key, HolderLookup.Provider registries) { - IVariable vari = attemptVariableLookup(key); + IVariable vari = attemptVariableLookup(key, registries); return vari == null ? provider.get(qualifyName(key), registries) : vari; } }; diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/VariableAssigner.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/VariableAssigner.java index 409853d8f..cd7199719 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/VariableAssigner.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/VariableAssigner.java @@ -58,7 +58,7 @@ public static void assignVariableHolders(Level level, IVariablesAvailableCallbac } } return input; - }); + }, level.registryAccess()); } private static IVariable resolveString(Level level, @Nullable String curr, Context c) { @@ -118,7 +118,7 @@ private static IVariable resolveStringVar(Level level, String original, Context if (curr.startsWith("#")) { if (c.encapsulation != null) { - val = c.encapsulation.attemptVariableLookup(curr); + val = c.encapsulation.attemptVariableLookup(curr, level.registryAccess()); if (val != null) { return val; } else { @@ -139,34 +139,34 @@ private static IVariable resolveStringVar(Level level, String original, Context return val == null ? IVariable.empty() : val; } - return IVariable.wrap(curr); + return IVariable.wrap(curr, level.registryAccess()); } private static BiFunction wrapStringFunc(Function inner) { - return (x, r) -> IVariable.wrap(inner.apply(x.asString())); + return (x, r) -> IVariable.wrap(inner.apply(x.asString()), r); } private static IVariable iname(IVariable arg, HolderLookup.Provider registries) { ItemStack stack = arg.as(ItemStack.class); - return IVariable.wrap(stack.getHoverName().getString()); + return IVariable.wrap(stack.getHoverName().getString(), registries); } private static IVariable icount(IVariable arg, HolderLookup.Provider registries) { ItemStack stack = arg.as(ItemStack.class); - return IVariable.wrap(stack.getCount()); + return IVariable.wrap(stack.getCount(), registries); } private static IVariable exists(IVariable arg, HolderLookup.Provider registries) { - return IVariable.wrap(!arg.unwrap().isJsonNull()); + return IVariable.wrap(!arg.unwrap().isJsonNull(), registries); } private static IVariable iexists(IVariable arg, HolderLookup.Provider registries) { ItemStack stack = arg.as(ItemStack.class); - return IVariable.wrap(stack != null && !stack.isEmpty()); + return IVariable.wrap(stack != null && !stack.isEmpty(), registries); } private static IVariable inv(IVariable arg, HolderLookup.Provider registries) { - return IVariable.wrap(!arg.unwrap().getAsBoolean()); + return IVariable.wrap(!arg.unwrap().getAsBoolean(), registries); } private static IVariable stacks(IVariable arg, HolderLookup.Provider registries) { diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentCustom.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentCustom.java index ea00f248c..926ecf0cc 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentCustom.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentCustom.java @@ -3,6 +3,7 @@ import com.google.gson.annotations.SerializedName; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderLookup; import vazkii.patchouli.api.ICustomComponent; import vazkii.patchouli.api.IVariable; @@ -22,12 +23,12 @@ public class ComponentCustom extends TemplateComponent { private transient ICustomComponent callbacks; @Override - public void onVariablesAvailable(UnaryOperator lookup) { - super.onVariablesAvailable(lookup); + public void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries) { + super.onVariablesAvailable(lookup, registries); try { Class classObj = Class.forName(clazz); callbacks = (ICustomComponent) SerializationUtil.RAW_GSON.fromJson(sourceObject, classObj); - callbacks.onVariablesAvailable(lookup); + callbacks.onVariablesAvailable(lookup, registries); } catch (Exception e) { throw new RuntimeException("Failed to create custom component " + clazz, e); } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentEntity.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentEntity.java index 5ed5fa95b..6a99b6c40 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentEntity.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentEntity.java @@ -3,6 +3,7 @@ import com.google.gson.annotations.SerializedName; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderLookup; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; @@ -58,8 +59,8 @@ public void render(GuiGraphics graphics, BookPage page, int mouseX, int mouseY, } @Override - public void onVariablesAvailable(UnaryOperator lookup) { - super.onVariablesAvailable(lookup); + public void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries) { + super.onVariablesAvailable(lookup, registries); entityId = lookup.apply(entityId); } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentHeader.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentHeader.java index 56b1fbab9..9e203fe8a 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentHeader.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentHeader.java @@ -3,6 +3,7 @@ import com.google.gson.annotations.SerializedName; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderLookup; import net.minecraft.network.chat.Component; import vazkii.patchouli.api.IVariable; @@ -57,8 +58,8 @@ public void render(GuiGraphics graphics, BookPage page, int mouseX, int mouseY, } @Override - public void onVariablesAvailable(UnaryOperator lookup) { - super.onVariablesAvailable(lookup); + public void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries) { + super.onVariablesAvailable(lookup, registries); actualText = lookup.apply(text).as(Component.class); colorStr = lookup.apply(colorStr); } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentImage.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentImage.java index 934d676fd..6b29489ff 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentImage.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentImage.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderLookup; import net.minecraft.resources.ResourceLocation; import vazkii.patchouli.api.IVariable; @@ -33,9 +34,9 @@ public void build(BookContentsBuilder builder, BookPage page, BookEntry entry, i } @Override - public void onVariablesAvailable(UnaryOperator lookup) { - super.onVariablesAvailable(lookup); - image = lookup.apply(IVariable.wrap(image)).asString(); + public void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries) { + super.onVariablesAvailable(lookup, registries); + image = lookup.apply(IVariable.wrap(image, registries)).asString(); } @Override diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentItemStack.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentItemStack.java index 855fd1fac..c317f22af 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentItemStack.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentItemStack.java @@ -4,6 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderLookup; import net.minecraft.world.item.ItemStack; import vazkii.patchouli.api.IVariable; @@ -33,8 +34,8 @@ public void build(BookContentsBuilder builder, BookPage page, BookEntry entry, i } @Override - public void onVariablesAvailable(UnaryOperator lookup) { - super.onVariablesAvailable(lookup); + public void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries) { + super.onVariablesAvailable(lookup, registries); items = lookup.apply(item).as(ItemStack[].class); } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentText.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentText.java index 900553d3a..b321d3c0b 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentText.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentText.java @@ -3,6 +3,7 @@ import com.google.gson.annotations.SerializedName; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderLookup; import net.minecraft.network.chat.Component; import vazkii.patchouli.api.IVariable; @@ -39,8 +40,8 @@ public void build(BookContentsBuilder builder, BookPage page, BookEntry entry, i } @Override - public void onVariablesAvailable(UnaryOperator lookup) { - super.onVariablesAvailable(lookup); + public void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries) { + super.onVariablesAvailable(lookup, registries); actualText = lookup.apply(text).as(Component.class); colorStr = lookup.apply(colorStr); } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentTooltip.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentTooltip.java index ed32544d0..0fed8b333 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentTooltip.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/component/ComponentTooltip.java @@ -3,6 +3,7 @@ import com.google.gson.annotations.SerializedName; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderLookup; import net.minecraft.network.chat.Component; import vazkii.patchouli.api.IVariable; @@ -23,8 +24,8 @@ public class ComponentTooltip extends TemplateComponent { transient List tooltip; @Override - public void onVariablesAvailable(UnaryOperator lookup) { - super.onVariablesAvailable(lookup); + public void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries) { + super.onVariablesAvailable(lookup, registries); for (int i = 0; i < tooltipRaw.length; i++) { tooltipRaw[i] = lookup.apply(tooltipRaw[i]); } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/ComponentCustomTest.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/ComponentCustomTest.java index 5c00110b5..25d404efe 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/ComponentCustomTest.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/ComponentCustomTest.java @@ -2,6 +2,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.HolderLookup; import net.minecraft.network.chat.Component; import vazkii.patchouli.api.IComponentRenderContext; @@ -35,7 +36,7 @@ public boolean mouseClicked(IComponentRenderContext context, double mouseX, doub } @Override - public void onVariablesAvailable(UnaryOperator lookup) { - text = lookup.apply(IVariable.wrap("First we eat #spaghet#, then we drink #pop#")).asString(); + public void onVariablesAvailable(UnaryOperator lookup, HolderLookup.Provider registries) { + text = lookup.apply(IVariable.wrap("First we eat #spaghet#, then we drink #pop#", registries)).asString(); } } diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/EntityTestProcessor.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/EntityTestProcessor.java index 63403dfb0..07a851622 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/EntityTestProcessor.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/EntityTestProcessor.java @@ -30,7 +30,7 @@ public void setup(Level level, IVariableProvider variables) { @Override public IVariable process(Level level, String key) { if (key.equals("name")) { - return IVariable.wrap(entityName); + return IVariable.wrap(entityName, level.registryAccess()); } return null; diff --git a/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/RecipeTestProcessor.java b/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/RecipeTestProcessor.java index 7474a2027..5843ffa79 100644 --- a/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/RecipeTestProcessor.java +++ b/Xplat/src/main/java/vazkii/patchouli/client/book/template/test/RecipeTestProcessor.java @@ -34,11 +34,11 @@ public IVariable process(Level level, String key) { return IVariable.from(stack, level.registryAccess()); } else if (key.equals("text")) { ItemStack out = recipe.getResultItem(level.registryAccess()); - return IVariable.wrap(out.getCount() + "x$(br)" + out.getHoverName()); + return IVariable.wrap(out.getCount() + "x$(br)" + out.getHoverName(), level.registryAccess()); } else if (key.equals("icount")) { - return IVariable.wrap(recipe.getResultItem(level.registryAccess()).getCount()); + return IVariable.wrap(recipe.getResultItem(level.registryAccess()).getCount(), level.registryAccess()); } else if (key.equals("iname")) { - return IVariable.wrap(recipe.getResultItem(level.registryAccess()).getHoverName().getString()); + return IVariable.wrap(recipe.getResultItem(level.registryAccess()).getHoverName().getString(), level.registryAccess()); } return null; diff --git a/Xplat/src/main/java/vazkii/patchouli/common/util/ItemStackUtil.java b/Xplat/src/main/java/vazkii/patchouli/common/util/ItemStackUtil.java index d3011276e..6a020f234 100644 --- a/Xplat/src/main/java/vazkii/patchouli/common/util/ItemStackUtil.java +++ b/Xplat/src/main/java/vazkii/patchouli/common/util/ItemStackUtil.java @@ -8,6 +8,7 @@ import net.minecraft.commands.arguments.item.ItemParser; import net.minecraft.core.Holder; import net.minecraft.core.HolderLookup; +import net.minecraft.core.HolderSet; import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.registries.BuiltInRegistries; @@ -78,9 +79,11 @@ public static List loadStackListFromString(String ingredientString, H String[] stacksSerialized = splitStacksFromSerializedIngredient(ingredientString); List stacks = new ArrayList<>(); for (String s : stacksSerialized) { + if (s.isEmpty()) + continue; if (s.startsWith("tag:")) { var key = TagKey.create(Registries.ITEM, ResourceLocation.tryParse(s.substring(4))); - BuiltInRegistries.ITEM.getTag(key).ifPresent(tag -> tag.stream().forEach(item -> stacks.add(new ItemStack(item)))); + registries.lookupOrThrow(Registries.ITEM).get(key).stream().flatMap(HolderSet::stream).forEach(item -> stacks.add(new ItemStack(item))); } else { stacks.add(loadStackFromString(s, registries)); } diff --git a/Xplat/src/main/java/vazkii/patchouli/common/util/SerializationUtil.java b/Xplat/src/main/java/vazkii/patchouli/common/util/SerializationUtil.java index 602c4613a..42222b4a5 100644 --- a/Xplat/src/main/java/vazkii/patchouli/common/util/SerializationUtil.java +++ b/Xplat/src/main/java/vazkii/patchouli/common/util/SerializationUtil.java @@ -15,9 +15,10 @@ public final class SerializationUtil { + public static final IVariable.Serializer VARIABLE_SERIALIZER = new IVariable.Serializer(); public static final Gson RAW_GSON = new GsonBuilder() .registerTypeAdapter(ResourceLocation.class, new ResourceLocation.Serializer()) - .registerTypeAdapter(IVariable.class, new IVariable.Serializer()) + .registerTypeAdapter(IVariable.class, VARIABLE_SERIALIZER) .create(); public static final Gson PRETTY_GSON = new GsonBuilder().setPrettyPrinting().create();