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

[Solved] [1.16.5] How to make Curios support optional?


Recommended Posts

Posted (edited)

I haven't made a working mod since 1.12, but I'm starting a new one for 1.16.5 and I'd like it to support the Curios API. I've gotten that working, but I realized that in order to register a Curios slot, I need to reference the Curios API SlotTypeMessage class. I was hoping I could make Curios support optional, i.e. register the slot if the Curios mod is installed, or just gracefully ignore it if not, but if I'm referencing SlotTypeMessage and someone installs my mod without including Curios, won't that just crash? Is there something special I need to do to make the support optional? Or am I totally misunderstanding how dependencies are handled and worrying about crashes that won't happen after all?

Edited by IceMetalPunk
Solved

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to post
Share on other sites
  • IceMetalPunk changed the title to [1.16.5] How to make Curios support optional?

You have to confine classes that interact with the dependency to one part of your mod which must not directly be accessed from anywhere else in your mod. The way you then interact with it is that you have an interface (say CuriosCompat) which is implemented twice. Once for when Curios is not present and once for when it is (this 2nd one can reference Curios classes). Then at startup check if Curios is loaded (the ModList class tells you whether a mod is loaded). If it isn't, instantiate the first implementation. If it is, get the 2nd implementat class using reflection (Class.forName) and create an isntance of it (newInstance()). You cannot reference it directly as otherwise the JVM will try and load this class even though the code is never executed.

  • Like 1
Link to post
Share on other sites
Posted (edited)
15 hours ago, diesieben07 said:

You have to confine classes that interact with the dependency to one part of your mod which must not directly be accessed from anywhere else in your mod. The way you then interact with it is that you have an interface (say CuriosCompat) which is implemented twice. Once for when Curios is not present and once for when it is (this 2nd one can reference Curios classes). Then at startup check if Curios is loaded (the ModList class tells you whether a mod is loaded). If it isn't, instantiate the first implementation. If it is, get the 2nd implementat class using reflection (Class.forName) and create an isntance of it (newInstance()). You cannot reference it directly as otherwise the JVM will try and load this class even though the code is never executed.

Ah! Using reflection to prevent crashing is the trick I needed to know! Thank you, I'll work on implementing it when I get a chance; hopefully it should go smoothly, if not, I'll ask more here with more details.

EDIT Worked perfectly the first try ūüėĀ Thank you for your help!

Edited by IceMetalPunk
Update

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to post
Share on other sites
  • IceMetalPunk changed the title to [Solved] [1.16.5] How to make Curios support optional?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • HI! I installed a map with a modpack 5 minutes ago, i put all the files in the right position, but when i open the game it crash and give me the shutdown report. ---- Minecraft Crash Report ---- // Surprise! Haha. Well, this is awkward. Time: 22/06/21 19.54 Description: There was a severe problem during mod loading that has caused the game to fail cpw.mods.fml.common.LoaderException: java.lang.NoClassDefFoundError: net/minecraftforge/fml/common/network/simpleimpl/IMessage ¬†¬† ¬†at cpw.mods.fml.common.LoadController.transition(LoadController.java:163) ¬†¬† ¬†at cpw.mods.fml.common.Loader.loadMods(Loader.java:544) ¬†¬† ¬†at cpw.mods.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:208) ¬†¬† ¬†at net.minecraft.client.Minecraft.func_71384_a(Minecraft.java:480) ¬†¬† ¬†at net.minecraft.client.Minecraft.func_99999_d(Minecraft.java:878) ¬†¬† ¬†at net.minecraft.client.main.Main.main(SourceFile:148) ¬†¬† ¬†at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ¬†¬† ¬†at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ¬†¬† ¬†at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ¬†¬† ¬†at java.lang.reflect.Method.invoke(Method.java:497) ¬†¬† ¬†at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) ¬†¬† ¬†at net.minecraft.launchwrapper.Launch.main(Launch.java:28) Caused by: java.lang.NoClassDefFoundError: net/minecraftforge/fml/common/network/simpleimpl/IMessage ¬†¬† ¬†at java.lang.Class.forName0(Native Method) ¬†¬† ¬†at java.lang.Class.forName(Class.java:348) ¬†¬† ¬†at cpw.mods.fml.common.FMLModContainer.constructMod(FMLModContainer.java:440) ¬†¬† ¬†at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ¬†¬† ¬†at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ¬†¬† ¬†at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ¬†¬† ¬†at java.lang.reflect.Method.invoke(Method.java:497) ¬†¬† ¬†at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ¬†¬† ¬†at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ¬†¬† ¬†at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ¬†¬† ¬†at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ¬†¬† ¬†at com.google.common.eventbus.EventBus.post(EventBus.java:275) ¬†¬† ¬†at cpw.mods.fml.common.LoadController.sendEventToModContainer(LoadController.java:212) ¬†¬† ¬†at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:190) ¬†¬† ¬†at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ¬†¬† ¬†at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ¬†¬† ¬†at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ¬†¬† ¬†at java.lang.reflect.Method.invoke(Method.java:497) ¬†¬† ¬†at com.google.common.eventbus.EventSubscriber.handleEvent(EventSubscriber.java:74) ¬†¬† ¬†at com.google.common.eventbus.SynchronizedEventSubscriber.handleEvent(SynchronizedEventSubscriber.java:47) ¬†¬† ¬†at com.google.common.eventbus.EventBus.dispatch(EventBus.java:322) ¬†¬† ¬†at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:304) ¬†¬† ¬†at com.google.common.eventbus.EventBus.post(EventBus.java:275) ¬†¬† ¬†at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:119) ¬†¬† ¬†at cpw.mods.fml.common.Loader.loadMods(Loader.java:513) ¬†¬† ¬†... 10 more Caused by: java.lang.ClassNotFoundException: net.minecraftforge.fml.common.network.simpleimpl.IMessage ¬†¬† ¬†at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:191) ¬†¬† ¬†at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ¬†¬† ¬†at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ¬†¬† ¬†... 35 more Caused by: java.lang.NullPointerException ¬†¬† ¬†at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:182) ¬†¬† ¬†... 37 more A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- System Details -- Details: ¬†¬† ¬†Minecraft Version: 1.7.10 ¬†¬† ¬†Operating System: Windows 10 (amd64) version 10.0 ¬†¬† ¬†Java Version: 1.8.0_51, Oracle Corporation ¬†¬† ¬†Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation ¬†¬† ¬†Memory: 215593488 bytes (205 MB) / 536870912 bytes (512 MB) up to 8589934592 bytes (8192 MB) ¬†¬† ¬†JVM Flags: 8 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump -Xmx8G -XX:+UnlockExperimentalVMOptions -XX:+UseG1GC -XX:G1NewSizePercent=20 -XX:G1ReservePercent=20 -XX:MaxGCPauseMillis=50 -XX:G1HeapRegionSize=32M ¬†¬† ¬†AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used ¬†¬† ¬†IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0 ¬†¬† ¬†FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 53 mods loaded, 53 mods active ¬†¬† ¬†States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored ¬†¬† ¬†UC¬†¬† ¬†mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†FML{7.10.99.99} [Forge Mod Loader] (forge-1.7.10-10.13.4.1614-1.7.10.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†Forge{10.13.4.1614} [Minecraft Forge] (forge-1.7.10-10.13.4.1614-1.7.10.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†battlegear2{1.7.10} [Mine & Blade Battlegear 2 - Bullseye] (1.7.10-MB_Battlegear2-Bullseye-1.0.8.3.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†bspkrsCore{6.16} [bspkrsCore] ([1.7.10]bspkrsCore-universal-6.16.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†StatusEffectHUD{1.27} [StatusEffectHUD] ([1.7.10]StatusEffectHUD-client-1.27.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†cfm{3.4.8} [¬ß9MrCrayfish's Furniture Mod] ([Minecraft-INSIDE.com] mrcrayfishfurnituremodv3.4.81.7.10.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†ArchimedesShips{1.7.10 v1.7.1} [Archimedes' Ships] (ArchimedesShips-1.7.1.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†Backpack{2.0.1} [Backpack] (backpack-2.0.1-1.7.x.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†BiblioCraft{1.11.4} [BiblioCraft] (BiblioCraft[v1.11.4][MC1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†BiomesOPlenty{2.1.0} [Biomes O' Plenty] (BiomesOPlenty-1.7.10-2.1.0.1889-universal.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†CarpentersBlocks{3.3.5} [Carpenter's Blocks] (Carpenter's Blocks v3.3.5 - MC 1.7.10.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†OblisgrMod{1.2.1} [OblisgrMod] (clothing.zip)¬† ¬†¬† ¬†UC¬†¬† ¬†CustomSpawner{3.3.0} [DrZhark's CustomSpawner] (CustomMobSpawner 3)¬† ¬†¬† ¬†UC¬†¬† ¬†customnpcs{1.7.10d} [CustomNpcs] (CustomNPCs_1.7.10d(21feb16).jar)¬† ¬†¬† ¬†UC¬†¬† ¬†DamageIndicatorsMod{3.2.0} [Damage Indicators] (Damage-Indicators-Mod-1.7.10.jar)¬† ¬†¬† ¬†UE¬†¬† ¬†PTRModelLib{1.0.0} [PTRModelLib] (Decocraft-2.4.2_1.7.10.jar)¬† ¬†¬† ¬†UE¬†¬† ¬†props{2.4.2} [Decocraft] (Decocraft-2.4.2_1.7.10.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†MoCreatures{6.3.1} [DrZhark's Mo'Creatures Mod] (DrZharks MoCreatures Mod v6)¬† ¬†¬† ¬†UC¬†¬† ¬†eplus{3.0.2-d} [Enchanting Plus] (EnchantingPlus-1.7.10-3.0.2-d.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†exoticbirds{1.0} [Exotic Birds] (Exotic Birds 1.7.10 - 1.0.3b.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†flansmod{4.10.0} [Flan's Mod] (Flans Mod-1.7.10-4.10.0.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†fossil{1.7.10 Build 7.2.1} [Fossils and Archeology Revival] (Fossils_Archeology_Revival-1.7.10_Build-7.2.1.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†journeymap{5.1.4p2} [JourneyMap] (journeymap-1.7.10-5.1.4p2-unlimited.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†lycanitesmobs{1.13.0.5 - MC 1.7.10} [Lycanites Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†arcticmobs{1.13.0.5 - MC 1.7.10} [Lycanites Arctic Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†demonmobs{1.13.0.5 - MC 1.7.10} [Lycanites Demon Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†desertmobs{1.13.0.5 - MC 1.7.10} [Lycanites Desert Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†forestmobs{1.13.0.5 - MC 1.7.10} [Lycanites Forest Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†freshwatermobs{1.13.0.5 - MC 1.7.10} [Lycanites Freshwater Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†infernomobs{1.13.0.5 - MC 1.7.10} [Lycanites Inferno Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†junglemobs{1.13.0.5 - MC 1.7.10} [Lycanites Jungle Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†mountainmobs{1.13.0.5 - MC 1.7.10} [Lycanites Mountain Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†plainsmobs{1.13.0.5 - MC 1.7.10} [Lycanites Plains Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†saltwatermobs{1.13.0.5 - MC 1.7.10} [Lycanites Saltwater Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†shadowmobs{1.13.0.5 - MC 1.7.10} [Lycanites Shadow Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†swampmobs{1.13.0.5 - MC 1.7.10} [Lycanites Swamp Mobs] (LycanitesMobsComplete 1.13.0.5 [1.7.10].jar)¬† ¬†¬† ¬†UC¬†¬† ¬†MapWriter{2.1.8} [MapWriter] (MapWriter-1.7.10-2.1.10.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†RadixCore{2.1.1} [RadixCore] (RadixCore-1.7.10-2.1.1-universal.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†MCA{1.7.10-5.1.2} [Minecraft Comes Alive] (MCA-1.7.10-5.1.2-universal.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†mcheli{1.0.3} [MC Helicopter] (mcheli)¬† ¬†¬† ¬†UC¬†¬† ¬†MiniBosses{1.2a} [Mini-Bosses] (MiniBosses-1.2a.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†modularpots{1.7.10.14} [Modular Flower Pots] (ModularPots-1.7.10.14-2.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†mw{1.11.7.7} [Modern Warfare] (mw-1.11.7.7_mc1.7.10.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†plantmegapack{4.33} [Plant Mega Pack] (plantmegapack-4.33-1.7.10-1492.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†potioncore{@VERSION@} [Potion Core] (PotionCore-1.2_beta_for_1.7.10.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†roadstuff{1.0.3-final} [Road Stuff] (RoadStuff-mc1.7.10-1.0.2-final.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†row{1.7.10-15.01.18-2} [Rails of War] (RoW-1.7.10-15.01.18-2.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†soundfilters{0.8_for_1.7.X} [Sound Filters] (SoundFilters-0.8_for_1.7.X.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†Waila{1.5.10} [Waila] (Waila-1.5.10_1.7.10.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†weaponmod{v1.14.3} [Balkon's WeaponMod] (weaponmod-1.14.3.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†witchery{0.24.1} [Witchery] (witchery-1.7.10-0.24.1.jar)¬† ¬†¬† ¬†UC¬†¬† ¬†worldedit{6.1.1} [WorldEdit] (worldedit-forge-mc1.7.10-6.1.1-dist.jar)¬† ¬†¬† ¬†GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.6.0 NVIDIA 457.51' Renderer: 'GeForce RTX 3070/PCIe/SSE2'
    • so i tried to join my friends minecraft server and i got this message:¬†Internal Exception: java.lang.InexOutOfBoundsException: readerindex(42) + length(1) exceeds writerIndex(42):PooledUnsafeDirectByteBuf(ridx: 42, widx: 42, cap: 42) debug.log here:¬†https://gist.github.com/odasety/385dd969b2677f42b726d12b7d3bc78f please help
    • No, that's strange, but it has only one state. Moreover, even if I wanted to compare block (not blockstate), i don't know how to do it, because this function require BlockState
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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