[1.19.2 - Dev Env] Help with setting up SerializableDataTypes for Conditions/Actions / Feature Request
MerchantPug opened this issue ยท 3 comments
Calio 1.6.0.3
Apoli 2.3.4.4
Origins 1.5.0.6
I need some help with setting up SerializableDataTypes for Conditions/Actions (Origins Addon Multiloader Template uses FabricPowerConfiguration
based PowerFactory
, which uses the SerializableDataType system as opposed to the codec system brought by Origins Forge).
https://github.com/MerchantPug/Origins-Addon-Multiloader-Template/tree/1.19-broken
I've currently done:
public static final SerializableDataType<ConfiguredItemCondition<?, ?>> ITEM_CONDITION = new SerializableDataType<>(MultiloaderDataTypes.castClass(ConfiguredItemCondition.class), ConfiguredItemCondition.CODEC);
public static final SerializableDataType<ConfiguredEntityAction<?, ?>> ENTITY_ACTION = new SerializableDataType<>(MultiloaderDataTypes.castClass(ConfiguredEntityAction.class), ConfiguredEntityAction.CODEC);
Which results in the registry of the ItemCondition or EntityAction CODEC not being found.
Caused by: java.lang.NullPointerException: Cannot invoke "java.util.function.Supplier.get()" because "registry" is null
at io.github.edwinmindcraft.apoli.api.registry.ApoliRegistries.lambda$codec$0(ApoliRegistries.java:55) ~[apoli-forge-1.19.2-2.3.4.4_mapped_official_1.19.2.jar%23191!/:1.19.2-2.3.4.4] {re:classloading}
at io.github.edwinmindcraft.apoli.api.registry.ApoliRegistries$1.lambda$decode$2(ApoliRegistries.java:63) ~[apoli-forge-1.19.2-2.3.4.4_mapped_official_1.19.2.jar%23191!/:1.19.2-2.3.4.4] {re:classloading}
at com.mojang.serialization.DataResult.lambda$flatMap$10(DataResult.java:138) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.DataResult.flatMap(DataResult.java:136) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at io.github.edwinmindcraft.apoli.api.registry.ApoliRegistries$1.decode(ApoliRegistries.java:62) ~[apoli-forge-1.19.2-2.3.4.4_mapped_official_1.19.2.jar%23191!/:1.19.2-2.3.4.4] {re:classloading}
at com.mojang.serialization.codecs.KeyDispatchCodec.decode(KeyDispatchCodec.java:56) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.MapDecoder.lambda$compressedDecode$0(MapDecoder.java:52) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.DataResult.lambda$flatMap$10(DataResult.java:138) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.DataResult.flatMap(DataResult.java:136) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.MapDecoder.compressedDecode(MapDecoder.java:52) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.MapCodec$MapCodecCodec.decode(MapCodec.java:91) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at io.github.edwinmindcraft.calio.api.network.HolderCodec.decode(HolderCodec.java:33) ~[calio-forge-1.19.2-1.6.0.3_mapped_official_1.19.2.jar%23190!/:1.19.2-1.6.0.3] {re:classloading}
at com.mojang.serialization.Decoder.parse(Decoder.java:18) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at io.github.edwinmindcraft.calio.api.network.PropagatingDefaultedOptionalFieldCodec.decode(PropagatingDefaultedOptionalFieldCodec.java:33) ~[calio-forge-1.19.2-1.6.0.3_mapped_official_1.19.2.jar%23190!/:1.19.2-1.6.0.3] {re:classloading}
at com.mojang.serialization.codecs.RecordCodecBuilder$Instance$7.decode(RecordCodecBuilder.java:406) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.codecs.RecordCodecBuilder$2.decode(RecordCodecBuilder.java:107) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.codecs.RecordCodecBuilder$Instance$3.decode(RecordCodecBuilder.java:248) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.codecs.RecordCodecBuilder$2.decode(RecordCodecBuilder.java:107) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.codecs.RecordCodecBuilder$Instance$3.decode(RecordCodecBuilder.java:248) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.codecs.RecordCodecBuilder$2.decode(RecordCodecBuilder.java:107) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.codecs.KeyDispatchCodec.lambda$decode$1(KeyDispatchCodec.java:67) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.DataResult.lambda$flatMap$10(DataResult.java:138) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.DataResult.flatMap(DataResult.java:136) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.codecs.KeyDispatchCodec.lambda$decode$2(KeyDispatchCodec.java:58) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.DataResult.lambda$flatMap$10(DataResult.java:138) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.DataResult.flatMap(DataResult.java:136) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.codecs.KeyDispatchCodec.decode(KeyDispatchCodec.java:56) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.MapDecoder.lambda$compressedDecode$0(MapDecoder.java:52) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.DataResult.lambda$flatMap$10(DataResult.java:138) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.DataResult.flatMap(DataResult.java:136) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.MapDecoder.compressedDecode(MapDecoder.java:52) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at com.mojang.serialization.MapCodec$MapCodecCodec.decode(MapCodec.java:91) ~[datafixerupper-5.0.28.jar%23147!/:?] {}
at io.github.edwinmindcraft.apoli.common.data.PowerLoader.lambda$accept$3(PowerLoader.java:38) ~[apoli-forge-1.19.2-2.3.4.4_mapped_official_1.19.2.jar%23191!/:1.19.2-2.3.4.4] {re:classloading}
at java.util.stream.ReferencePipeline$7$1.accept(ReferencePipeline.java:273) ~[?:?] {}
at java.util.LinkedList$LLSpliterator.forEachRemaining(LinkedList.java:1242) ~[?:?] {}
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?] {}
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?] {}
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921) ~[?:?] {}
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?] {}
at java.util.stream.ReferencePipeline.reduce(ReferencePipeline.java:662) ~[?:?] {}
at java.util.stream.ReferencePipeline.max(ReferencePipeline.java:698) ~[?:?] {}
at io.github.edwinmindcraft.apoli.common.data.PowerLoader.accept(PowerLoader.java:49) ~[apoli-forge-1.19.2-2.3.4.4_mapped_official_1.19.2.jar%23191!/:1.19.2-2.3.4.4] {re:classloading}
at io.github.edwinmindcraft.apoli.common.data.PowerLoader.create(PowerLoader.java:59) ~[apoli-forge-1.19.2-2.3.4.4_mapped_official_1.19.2.jar%23191!/:1.19.2-2.3.4.4] {re:classloading}
at io.github.edwinmindcraft.calio.common.registry.CalioDynamicRegistryManager$ReloadFactory.lambda$reload$1(CalioDynamicRegistryManager.java:371) ~[calio-forge-1.19.2-1.6.0.3_mapped_official_1.19.2.jar%23190!/:1.19.2-1.6.0.3] {re:classloading}
at java.util.HashMap.forEach(HashMap.java:1421) ~[?:?] {re:mixin}
at io.github.edwinmindcraft.calio.common.registry.CalioDynamicRegistryManager$ReloadFactory.reload(CalioDynamicRegistryManager.java:371) ~[calio-forge-1.19.2-1.6.0.3_mapped_official_1.19.2.jar%23190!/:1.19.2-1.6.0.3] {re:classloading}
at io.github.edwinmindcraft.calio.common.registry.CalioDynamicRegistryManager.lambda$reload$8(CalioDynamicRegistryManager.java:118) ~[calio-forge-1.19.2-1.6.0.3_mapped_official_1.19.2.jar%23190!/:1.19.2-1.6.0.3] {re:classloading}
at java.util.concurrent.CompletableFuture$AsyncRun.run$$$capture(CompletableFuture.java:1804) ~[?:?] {}
at java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java) ~[?:?] {}
at net.minecraft.server.packs.resources.SimpleReloadInstance.lambda$new$3(SimpleReloadInstance.java:65) ~[forge-1.19.2-43.1.1_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading}
at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:143) ~[forge-1.19.2-43.1.1_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B}
at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:22) ~[forge-1.19.2-43.1.1_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:mixin,re:computing_frames,re:classloading}
at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:116) ~[forge-1.19.2-43.1.1_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B}
at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:126) ~[forge-1.19.2-43.1.1_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:mixin,pl:accesstransformer:B,re:computing_frames,pl:accesstransformer:B,re:classloading,pl:accesstransformer:B}
at net.minecraft.client.gui.screens.worldselection.WorldOpenFlows.loadWorldStem(WorldOpenFlows.java:130) ~[forge-1.19.2-43.1.1_mapped_official_1.19.2-recomp.jar%23183!/:?] {re:classloading,pl:runtimedistcleaner:A}
... 36 more
Ive also tried using the HOLDER codec too
I'd be more than happy to PR what we come up with if it works.
Alternatively I'm asking for the missing SerializableDataType
s to be added to Origins Forge's API sooner rather than later as it's rather vital for what's being done here.
Can confirm that I got this to work in my own environment.
Will PR in a bit, thanks.
I'll only be PRing this fix, I won't be PRing data types unfortunately because that's quite a bit more work.
Found it. Currently the code limits at what time you're able to initialize data types, which I'll agree isn't optimal (basically it currently shouldn't be done before the NewRegistry event).
Fixing it is a matter of changing the calls to ApoliRegistries.codec from ApoliRegistries.codec(WHATEVER_REGISTRY)
to ApoliRegistries.codec(() -> WHATEVER_REGISTRY.get())
. ( Tested it, it doesn't work.WHATEVER_REGISTRY::get
may work as I'm not familiar with the exact workings of lambda method referencing, but I think it'll suffer from the same issues as the current implementation)
Don't know if I can get to it in a correct amount of time, feel free to make a PR.
I kinda ran into this earlier when porting Origins: Classes, I was using @Mod.EventBusSubscriber
on PowerFactory
subclasses ;(
@Mod.EventBusSubscriber
will trigger class load and causing the static code in PowerFactory (containing initialization of Codec<PowerFactory<?>
) to run in an early stage, which is much like this use case.
I should have report this, but I didn't, because I thought it's not so important at that time ;(