Jump to content

[1.20.2] RecipeSerializer Codec requirement


Corgam

Recommended Posts

Hi,
I am just updating my mod from 1.20.1 to 1.20.2 and I saw a big change for the custom RecipeSerializers, they now require Codec<?> serialization instead of a simple fromJson() function.
Unfortunately, I am struggling with setting up the Codec for a few of the serialization features:

- Using the Forge "mod_loaded" condition (the file should not be loaded when a mod is missing)

- Loading an Ingredient field 

Current Codec Code:

Spoiler
    public static final Codec<EnvironmentData> CODEC = RecordCodecBuilder.create((builder) -> builder
            .group(
                Ingredient.CODEC_NONEMPTY.fieldOf("input").forGetter(EnvironmentData::getInputItem),
                BlockState.CODEC.fieldOf("render").forGetter(EnvironmentData::getRenderState),
                Codec.FLOAT.fieldOf("growModifier").forGetter(EnvironmentData::getGrowModifier),
                Codec.list(Codec.STRING).fieldOf("categories").forGetter(EnvironmentData::getCategories)
            ).apply(builder, EnvironmentData::new));

For the first problem, previously the "mod_loaded" condition was automatically taken into account, but I suppose that now it changed and has to be taken care of in the codec?
For the second problem, I am trying to read the Ingredient with the CODEC_NONEMPTY from the Ingredient class, but I get the following error:

[17:35:14] [Render thread/ERROR] [minecraft/RecipeManager]: Parsing error loading recipe cagedmobs:environments/red_mushroom_block
com.google.gson.JsonParseException: Not a JSON object: "minecraft:red_mushroom_block"
	at net.minecraft.Util.getOrThrow(Util.java:820) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading}
	at net.minecraft.world.item.crafting.RecipeManager.fromJson(RecipeManager.java:171) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading}
	at net.minecraft.world.item.crafting.RecipeManager.apply(RecipeManager.java:76) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading}
	at net.minecraft.world.item.crafting.RecipeManager.apply(RecipeManager.java:37) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading}
	at net.minecraft.server.packs.resources.SimplePreparableReloadListener.lambda$reload$1(SimplePreparableReloadListener.java:12) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading}
	at java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718) ~[?:?] {}
	at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:482) ~[?:?] {}
	at net.minecraft.server.packs.resources.SimpleReloadInstance.lambda$new$3(SimpleReloadInstance.java:65) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading}
	at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:166) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:22) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading}
	at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:132) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:145) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.gui.screens.worldselection.CreateWorldScreen.openFresh(CreateWorldScreen.java:132) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.worldselection.WorldSelectionList.loadLevels(WorldSelectionList.java:189) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.worldselection.WorldSelectionList.<init>(WorldSelectionList.java:100) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.worldselection.SelectWorldScreen.init(SelectWorldScreen.java:37) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.Screen.init(Screen.java:338) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.setScreen(Minecraft.java:1090) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.TitleScreen.lambda$createNormalMenuOptions$7(TitleScreen.java:171) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.components.Button.onPress(Button.java:38) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.components.AbstractButton.onClick(AbstractButton.java:41) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.components.AbstractWidget.mouseClicked(AbstractWidget.java:179) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.components.events.ContainerEventHandler.mouseClicked(ContainerEventHandler.java:53) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.TitleScreen.mouseClicked(TitleScreen.java:329) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHandler.lambda$onPress$0(MouseHandler.java:98) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.gui.screens.Screen.wrapScreenError(Screen.java:461) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHandler.onPress(MouseHandler.java:95) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.MouseHandler.lambda$setup$4(MouseHandler.java:207) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.util.thread.BlockableEventLoop.execute(BlockableEventLoop.java:106) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.client.MouseHandler.lambda$setup$5(MouseHandler.java:206) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at org.lwjgl.glfw.GLFWMouseButtonCallbackI.callback(GLFWMouseButtonCallbackI.java:43) ~[lwjgl-glfw-3.3.2.jar:build 13] {}
	at org.lwjgl.system.JNI.invokeV(Native Method) ~[lwjgl-3.3.2.jar:build 13] {}
	at org.lwjgl.glfw.GLFW.glfwWaitEventsTimeout(GLFW.java:3509) ~[lwjgl-glfw-3.3.2.jar:build 13] {}
	at com.mojang.blaze3d.systems.RenderSystem.limitDisplayFPS(RenderSystem.java:207) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.runTick(Minecraft.java:1261) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.run(Minecraft.java:783) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:221) ~[forge-1.20.2-48.0.33_mapped_parchment_2023.10.22-1.20.2-recomp.jar:?] {re:classloading,pl:runtimedistcleaner:A}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}
	at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?] {}
	at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}
	at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?] {}
	at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.runTarget(CommonLaunchHandler.java:98) ~[fmlloader-1.20.2-48.0.33.jar:?] {}
	at net.minecraftforge.fml.loading.targets.CommonLaunchHandler.lambda$makeService$0(CommonLaunchHandler.java:82) ~[fmlloader-1.20.2-48.0.33.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:17) ~[modlauncher-10.1.1.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:40) ~[modlauncher-10.1.1.jar:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:58) ~[modlauncher-10.1.1.jar:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:96) ~[modlauncher-10.1.1.jar:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) ~[modlauncher-10.1.1.jar:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:13) ~[modlauncher-10.1.1.jar:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:10) ~[modlauncher-10.1.1.jar:?] {}
	at net.minecraftforge.bootstrap.BootstrapLauncher.main(BootstrapLauncher.java:126) ~[bootstrap-1.2.0.jar:?] {}

 

The "cagedmobs:environments/red_mushroom_block" JSON recipe:

Spoiler
{
	"type": "cagedmobs:environment_data",
	"conditions": [
		{
			"type": "forge:mod_loaded",
			"modid": "cagedmobs"
		}
	],
	"input": {
		"item": "minecraft:red_mushroom_block"
	},
	"render": "minecraft:red_mushroom_block",
	"growModifier": 1.0,
	"categories": ["mycelium"]
}

As seen here, the Ingredient input item is in the form of a nested JSON:

"input": {
		"item": "minecraft:red_mushroom_block"
}

 

 

Edited by Corgam
Link to comment
Share on other sites

The problem is not the 'input' field its' the 'render' field.
You expect there a BlockState but 'minecraft:red_mushroom_block' is a Block.

If you need no BlockState you can use ForgeRegistries.BLOCKS.getCodec() instead of BlockState.CODEC.
If you need explicit a BlockState take a look at the Codec which fields are required.

Edited by Luis_ST
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.