Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Create and register item only if another mod is present


ninety
 Share

Recommended Posts

Posted (edited)

I'm currently writing an add-on for another mod, but also wish to add integration with yet another add-on within mine — more specifically, an AE2 add-on for larger tiers of storage cells with Applied Mekanistics integration to also offer higher-capacity chemical cells for use with Mekanism. As part of that integration, I am trying to create and register some new items only if the other add-on is also installed and attempting to make use of Object holders in order to retrieve registered instances of those items.

So far, I've been successful in adding these items and making them work when the other add-on is installed. However, attempting to run a game with my add-on installed but not the other optional one results in an IllegalStateException crash because of the Item holders not having a registry entry to inject from. I am not sure how to handle this case, so I would like to know how to go about only having these items in the presence of another mod.

Huge disclaimer: I am very new to a lot of the mod-making process in Forge and this is also my first time using some of the features in it, so my code will most definitely look like shit in a few places. I have a GitHub repo for my add-on here with the beginning of this integration attempt committed to it just now.

Full crash report:

Spoiler
---- Minecraft Crash Report ----
// I let you down. Sorry :(

Time: 13/05/2022, 18:51
Description: Rendering overlay

java.lang.IllegalStateException: Some intrusive holders were not added to registry: [Reference{null=MaterialItem[mega_chemical_cell_housing]}]
	at net.minecraftforge.registries.NamespacedHolderHelper.freeze(NamespacedHolderHelper.java:166) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading}
	at net.minecraftforge.registries.NamespacedDefaultedWrapper.m_203521_(NamespacedDefaultedWrapper.java:204) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading}
	at net.minecraftforge.registries.GameData.lambda$freezeData$7(GameData.java:283) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading}
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[?:?] {}
	at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179) ~[?:?] {}
	at java.util.Iterator.forEachRemaining(Iterator.java:133) ~[?:?] {}
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845) ~[?:?] {}
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?] {}
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?] {}
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?] {}
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?] {}
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?] {}
	at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[?:?] {}
	at net.minecraftforge.registries.GameData.freezeData(GameData.java:283) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading}
	at net.minecraftforge.common.ForgeStatesProvider.lambda$new$5(ForgeStatesProvider.java:33) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading}
	at net.minecraftforge.fml.ModLoader.lambda$dispatchAndHandleError$20(ModLoader.java:185) ~[fmlcore-1.18.2-40.1.19.jar%2356!/:?] {}
	at java.util.Optional.ifPresent(Optional.java:178) ~[?:?] {}
	at net.minecraftforge.fml.ModLoader.dispatchAndHandleError(ModLoader.java:185) ~[fmlcore-1.18.2-40.1.19.jar%2356!/:?] {}
	at net.minecraftforge.fml.ModLoader.lambda$finishMods$17(ModLoader.java:175) ~[fmlcore-1.18.2-40.1.19.jar%2356!/:?] {}
	at java.lang.Iterable.forEach(Iterable.java:75) ~[?:?] {re:mixin}
	at net.minecraftforge.fml.ModLoader.finishMods(ModLoader.java:175) ~[fmlcore-1.18.2-40.1.19.jar%2356!/:?] {}
	at net.minecraftforge.client.loading.ClientModLoader.lambda$finishModLoading$6(ClientModLoader.java:127) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraftforge.client.loading.ClientModLoader.lambda$createRunnableWithCatch$4(ClientModLoader.java:113) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraftforge.client.loading.ClientModLoader.finishModLoading(ClientModLoader.java:127) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraftforge.client.loading.ClientModLoader.lambda$onResourceReload$3(ClientModLoader.java:106) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading,pl:runtimedistcleaner:A}
	at java.util.concurrent.CompletableFuture$UniRun.tryFire(CompletableFuture.java:787) ~[?:?] {}
	at java.util.concurrent.CompletableFuture$Completion.exec(CompletableFuture.java:483) ~[?:?] {}
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) ~[?:?] {}
	at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) ~[?:?] {}
	at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) ~[?:?] {}
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) ~[?:?] {}
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165) ~[?:?] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Render thread
Stacktrace:
	at net.minecraftforge.registries.NamespacedHolderHelper.freeze(NamespacedHolderHelper.java:166) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading}
	at net.minecraftforge.registries.NamespacedDefaultedWrapper.m_203521_(NamespacedDefaultedWrapper.java:204) ~[forge-1.18.2-40.1.19-universal.jar%2359!/:?] {re:classloading}
-- Overlay render details --
Details:
	Overlay name: net.minecraft.client.gui.screens.LoadingOverlay
Stacktrace:
	at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:880) ~[client-1.18.2-20220404.173914-srg.jar%2355!/:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1044) ~[client-1.18.2-20220404.173914-srg.jar%2355!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:ae2.mixins.json:PickColorMixin,pl:mixin:A,pl:runtimedistcleaner:A}
	at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:663) ~[client-1.18.2-20220404.173914-srg.jar%2355!/:?] {re:mixin,pl:accesstransformer:B,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,pl:mixin:APP:ae2.mixins.json:PickColorMixin,pl:mixin:A,pl:runtimedistcleaner:A}
	at net.minecraft.client.main.Main.main(Main.java:205) ~[client-1.18.2-20220404.173914-srg.jar%2355!/:?] {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.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:31) ~[fmlloader-1.18.2-40.1.19.jar%2350!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.1.3.jar%2339!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.1.3.jar%2339!/:?] {}
	at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.1.3.jar%2339!/:?] {}
	at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.1.3.jar%2339!/:?] {}
	at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.1.3.jar%2339!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.1.3.jar%2339!/:?] {}
	at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.1.3.jar%2339!/:?] {}
	at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:149) [bootstraplauncher-1.0.0.jar:?] {}
	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 io.github.zekerzhayard.forgewrapper.installer.Main.main(Main.java:57) [ForgeWrapper-mmc2.jar:mmc2] {}
	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 org.multimc.onesix.OneSixLauncher.launchWithMainClass(OneSixLauncher.java:210) [NewLaunch.jar:?] {}
	at org.multimc.onesix.OneSixLauncher.launch(OneSixLauncher.java:245) [NewLaunch.jar:?] {}
	at org.multimc.EntryPoint.listen(EntryPoint.java:143) [NewLaunch.jar:?] {}
	at org.multimc.EntryPoint.main(EntryPoint.java:34) [NewLaunch.jar:?] {}

 

 

Edited by ninety
Link to comment
Share on other sites

Returning briefly back to this topic, would it be possible at least to do things like disabling crafting recipes outright for an item if some condition (in this case, the other mod being present) isn't met? While I'm content with the dummy item approach for now, I'd rather they remained as far away from view as possible if there's otherwise no reason for them to be used.

Link to comment
Share on other sites

Nice, the ConditionalRecipe looks like it might be just the thing I'd need. Thanks!

On second thought, I still don't exactly like the "dummy item" approach in general here. At my own risk, I've gone for the "all of nothing" approach in the end of conditionally registering the extra items from somewhat more generic Item-like definitions.

Edited by ninety
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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.