Insane96MCP Posted April 1, 2018 Share Posted April 1, 2018 E.g. I want to add compatibility with BetterWithMods (exactly need to call this: https://github.com/BetterWithMods/BetterWithMods/blob/1.12/src/main/java/betterwithmods/module/hardcore/world/HCStumping.java#L71). How I can do this without the need of begin a dependency? Quote Link to comment Share on other sites More sharing options...
Insane96MCP Posted April 3, 2018 Author Share Posted April 3, 2018 (edited) So, here: ActiveModInteropProxy i need to use reflection to get the other mod's method and call it? And here: your.package.ActiveModInteropProxy the mod I'm trying to call? Edited April 3, 2018 by Insane96MCP Quote Link to comment Share on other sites More sharing options...
Insane96MCP Posted April 3, 2018 Author Share Posted April 3, 2018 1 minute ago, diesieben07 said: Wat? "betterwithmods.module.hardcore.world.HCStumping" in my case? I mean. The mod's package I'm trying to add compatibility for? Quote Link to comment Share on other sites More sharing options...
Insane96MCP Posted April 12, 2018 Author Share Posted April 12, 2018 What if there's a method that returns an object of other mod's class type? Quote Link to comment Share on other sites More sharing options...
jabelar Posted April 13, 2018 Share Posted April 13, 2018 (edited) 9 hours ago, Insane96MCP said: What if there's a method that returns an object of other mod's class type? I don't think you're really thinking this through. You're trying to avoid a dependency but then want to do things that depend on the other mod. But if you insiste, what you need to do is to encapsulate the proxy interface such that the method prototypes work even when the other mod isn't loaded. That means the methods cannot return a value that is specifically of the other mod's type, and cannot take parameters that are specifically of the other mod's type. However, the other mod's classes should have parents that may be common. Like if they have an EntityVampire that extends EntityMob, then you can just type the return value as EntityMob. But note that if you want to further act on it as an EntityVampire then you'll need proxied methods for that too like have a method called setVampireCoffin(EntityMob mobIn, BlockPos posIn) and then in your proxy you'd check if it is an instanceof EntityVampire and act accordingly. In other words, you'll need to encapsulate everything you want to do with the other mods stuff with generic method prototypes that re-cast back to specific types according to whether the other mod is loaded. Edited April 13, 2018 by jabelar Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Insane96MCP Posted April 27, 2018 Author Share Posted April 27, 2018 On 13/4/2018 at 7:15 AM, jabelar said: You're trying to avoid a dependency but then want to do things that depend on the other mod. And how I can add compatbility then? Quote Link to comment Share on other sites More sharing options...
jabelar Posted April 27, 2018 Share Posted April 27, 2018 (edited) Here's an example of what would work and would not work. Assume that the optional mod has an EntityVampire and in your mod if the other mod is loaded you want to spawn vampires, but if the other mod is not loaded then you want to spawn EntityWitch. Proper Encapsulation Example For proper encapsulation, the interface is designed so that the dummy implementation doesn't see any classes it won't have. For example, in your proxy interface you could have a method called spawnEvilEntity() that is prototyped like this: void spawnEvilEntity(World worldIn, BlockPos posIn); Then in your dummy proxy implementation class you implement the method as: public void spawnEvilEntity(World worldIn, BlockPos posIn) { EntityWitch entity = new EntityWitch(worldIn); entity.setLocationAndAngles(posIn); worldIn.spawnEntity(entity); } And in your active mod proxy implementation class you implement the method as: public void spawnEvilEntity(World worldIn, BlockPos posIn) { EntityVampire entity = new EntityVampire(worldIn); entity.setLocationAndAngles(posIn); worldIn.spawnEntity(entity); } Then you could use this in your main mod code whenever you want to spawn one of these you just call: proxy.spawnEvilEntity(theWorld, thePos); Wrong Way If you expose any classes from the optional mod to the interface it will cause trouble. For example, if instead of actually spawning the mob, if you made a method called createVampire() in your proxy interface like: EntityVampire createVampire(World worldIn, BlockPos posIn); And in your dummy proxy you had: public EntityVampire createVampire(World worldIn, BlockPos posIn) { return null; } And in your active mod proxy you had: public EntityVampire createVampire(World worldIn, BlockPos posIn) { EntityVampire entity = new EntityVampire(worldIn); entity.setLocationAndAngles(posIn); return entity; } In which case you might try to use it this way in your main mod: EntityVampire vampire = proxy.createVampire(theWorld, thePos); if (vampire != null) { theWorld.spawn(vampire); } else { EntityWitch witch = new EntityWitch(worldIn); witch.setLocationAndAngles(posIn); theWorld.spawn(witch); } This will fail because you have your main mod trying to access EntityVampire which may not be available. Not sure if my example is clear but the point is that you need to organize your proxy code so that all the code that depends on the classes from the optional mod are ONLY accessed within the active mod proxy implementation. You cannot expose those classes to the dummy proxy or the rest of your mod. If you get more specific on what you're trying to do, we can give more specific examples. Edited April 27, 2018 by jabelar 1 Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Mango106 Posted April 27, 2018 Share Posted April 27, 2018 You can also make recipes between mods compatible with craft tweaker. Its a mod that allows you to write scripts and create and delete recipes. Its useful for recipes, and changing item names, but nothing else. 1 Quote Link to comment Share on other sites More sharing options...
loordgek Posted April 28, 2018 Share Posted April 28, 2018 21 hours ago, Mango106 said: You can also make recipes between mods compatible with craft tweaker. it is better to use json Quote Link to comment Share on other sites More sharing options...
jabelar Posted April 28, 2018 Share Posted April 28, 2018 1 hour ago, loordgek said: it is better to use json You guys aren't answering the topic the original poster asked about. He actually changed his original post a bit, but basically he wants to call a method from a mod but doesn't want to force the other mod as a dependency. That means the code cannot be sure to be available, so diesieben07 has provided a very clever approach to make it optional. It has nothing to do with recipes, and also both of your suggestions don't help with case where he wants to optionally access code from another mod from his mod. Quote Check out my tutorials here: http://jabelarminecraft.blogspot.com/ Link to comment Share on other sites More sharing options...
Interplay Posted January 13, 2019 Share Posted January 13, 2019 On 4/27/2018 at 4:29 PM, jabelar said: Here's an example of what would work and would not work. Assume that the optional mod has an EntityVampire and in your mod if the other mod is loaded you want to spawn vampires, but if the other mod is not loaded then you want to spawn EntityWitch. I want to do something really similar to this. Can I? I want that my mod only use it's Ore Generation only when there is no other mods that do this present. (Obviously I already have created all the Ores, in case this happens.) And I want it to have some other materials - like rubber, or sludge and some others - that are only present if certain mods are present (in some cases), or if its not present (in other cases). This kind of thing will enable/disable some recipes and fetures from my mod. Can you send me to a tutorial about this? Or there isn't any out there? Quote Link to comment Share on other sites More sharing options...
Cadiboo Posted January 20, 2019 Share Posted January 20, 2019 The actual implementation depends on the mod you are being compatible with, for example in one of my mods I only register a special event subscriber if I am able to detect that BetterFoliage is installed. This topic provides a pretty comprehensive overview Quote About Me Spoiler My Discord - Cadiboo#8887 My Website - Cadiboo.github.io My Mods - Cadiboo.github.io/projects My Tutorials - Cadiboo.github.io/tutorials Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support. When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible. Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme) Link to comment Share on other sites More sharing options...
Keheck Posted April 8, 2019 Share Posted April 8, 2019 On 4/27/2018 at 9:29 PM, jabelar said: public void spawnEvilEntity(World worldIn, BlockPos posIn) { EntityVampire entity = new EntityVampire(worldIn); entity.setLocationAndAngles(posIn); worldIn.spawnEntity(entity); } Wouldn't the compiler throw out an error because the class doesn't exist? Quote Link to comment Share on other sites More sharing options...
Keheck Posted April 8, 2019 Share Posted April 8, 2019 Just now, diesieben07 said: You need to include the dependency-mod in your compilation process of course. And when I build the mod and run it on forge with the code that I wrote while having the dependency is not going to cause problems? Quote Link to comment Share on other sites More sharing options...
Keheck Posted April 8, 2019 Share Posted April 8, 2019 Lol I'm stoopid Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.