The_Fireplace Posted August 4, 2014 Posted August 4, 2014 Sorry for the title, if it is unclear, and anything else in this post that is. Basically, I want to know how to set up a code that will allow me to add recipes in one mod using a class from the dependency that has an API to get items, blocks, and/or itemstacks from the soft-dependency. I did a search, the closest thing I could find was this: http://www.minecraftforge.net/forum/index.php?topic=10515.0 Anyways, I have a class here that lets me add recipes here for another mod's recipe type(Extended Workbench Mod is the mod) If I am confusing right now, sorry. My setup here is basically [Other mod](soft dependency of)[Fireplace Core](dependency of)[My dependant mods]. Fireplace Core is the one that has this class, and doing it that way allows me to use the code without copying this class to multiple of my mods. Anyways, this is the class: Reveal hidden contents public class EWAPI { private static final Class ecm = getECM(); private static Class getECM() { try { return Class.forName("naruto1310.extendedWorkbench.crafting.ExtendedCraftingManager"); } catch(ClassNotFoundException e) { return null; } } private static void addRecipe(ItemStack stack, Object[] input, boolean shapeless) { try { ecm.getMethod("add" + (shapeless ? "Shapeless" : "") + "Recipe", new Class[] {ItemStack.class, Object[].class}).invoke(null, stack, input); } catch(Exception e) { e.printStackTrace(); } } public static boolean getEWInstalled() { return ecm != null; } public static void addRecipe(ItemStack stack, Object[] input) { addRecipe(stack, input, false); } public static void addShaplessRecipe(ItemStack stack, Object[] input) { addRecipe(stack, input, true); } public static List<IRecipe> getRecipeList() { try { return (List<IRecipe>)ecm.getMethod("getRecipeList").invoke(null); } catch(Exception e) { e.printStackTrace(); return null; } } } And my question is this: How would I have to set up something similar to this to make it so in my other(dependent on Fireplace Core) mods, I could use blocks/items from other mods in my recipes without making the other mod a full dependency of any of them? If you have any questions, please, ask. Quote If I helped please press the Thank You button. Check out my mods at http://www.curse.com/users/The_Fireplace/projects
Jacky2611 Posted August 4, 2014 Posted August 4, 2014 Have you already tried to surround everything that has a reference to the mod with try()? Another solution would be to use the oreregistry. Quote Here could be your advertisement!
The_Fireplace Posted September 3, 2014 Author Posted September 3, 2014 OK, I've tried several times, and still can't get it. Can someone provide a code example of this? Quote If I helped please press the Thank You button. Check out my mods at http://www.curse.com/users/The_Fireplace/projects
Eternaldoom Posted September 3, 2014 Posted September 3, 2014 Post what you tried Quote Check out my mod, Realms of Chaos, here. If I helped you, be sure to press the "Thank You" button!
The_Fireplace Posted September 4, 2014 Author Posted September 4, 2014 On 9/3/2014 at 8:45 PM, Eternaldoom said: Post what you tried Allow me to rephrase that... I have made the two classes, then gotten confused as to what the interface is supposed to do that diesieben07 said to add. The several tries were attempts to interact through the interface, which I later deleted. Sorry for the confusion. Quote If I helped please press the Thank You button. Check out my mods at http://www.curse.com/users/The_Fireplace/projects
sequituri Posted September 4, 2014 Posted September 4, 2014 Use an plain old interface that defines the methods you want to call on the external mods class. Thusly: public interface IFirePlaceCore { public void addRecipe(ItemStack stack, Object[] input, boolean shapeless); ... } Then define two classes. One (DummyFirePlaceCore) where each method has an empty body or returns null, false, 0 depending. Another where the actual code is found. Thusly: public class RealFirePlaceCore implements IFirePlaceCore { // everything same as interface but overridden liek so: @Override public void addRecipe(ItemStack stack, Object input ...) { return naruto1310.extendedWorkbench.crafting.ExtendedCraftingManager.addRecipe(stack, input); } ... } Now, in the initialization event, if mod is loaded assign the second object to the interface property: public static IFireplaceCore fpc; onInit( .... ) { (if loader.isModLoaded("your dependency mod here") fpc = new RealFirePlaceCore(); else fpc = new DummyIFirePlaceCore(); Now just call fpc.addRecipe(yadda yadda); NOTE: Some detail left out for brevity. Quote -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
imadnsn Posted September 4, 2014 Posted September 4, 2014 I'm pretty sure that wasn't intended... I laughed a lot on this :D :D On 9/4/2014 at 9:02 AM, sequituri said: return naruto1310.extendedWorkbench.crafting.ExtendedCraftingManager.assRecipe(stack, input); Quote
Scribblon Posted September 4, 2014 Posted September 4, 2014 I remembered some post a while back... Let me look: http://minalien.com/minecraft-forge-feature-spotlight-api-annotation/ http://minalien.com/minecraft-forge-feature-spotlight-optional-annotation/ I think this is what you are looking for, if I am wrong apologies... I think you need the @Optional annotation over the @API one. As @API is meant to be package wide. But you can define it as a soft dependency on your mod to prevent it being unloadable whenever Fireplace Core isn't there... Then again, I am not sure myself when re-reading your problem. This really requires the Fireplace Core to have an API you want to implement. You will be calling a method in your own mod, and not some external mod expecting you to have some functionality implemented... Still, sorry if it doesn't really fit your problem. Quote "I guess as this is pretty much WIP, I can just 'borrow' the sounds from that game without problem. They are just 'placeholders' anyway." -Me, while extracting the Tear sounds of Bioshock Infinite.
The_Fireplace Posted September 4, 2014 Author Posted September 4, 2014 On 9/4/2014 at 9:44 AM, imadnsn said: I'm pretty sure that wasn't intended... I laughed a lot on this :D :D Quote return naruto1310.extendedWorkbench.crafting.ExtendedCraftingManager.assRecipe(stack, input); Same here. I thank you'd the wrong post, meaning to thank the one above it. Quote If I helped please press the Thank You button. Check out my mods at http://www.curse.com/users/The_Fireplace/projects
sequituri Posted September 5, 2014 Posted September 5, 2014 Yeah, typos can kill!!! Fixed it. On the other point. @API(owner = "API-owner", provides = "fireplace-core", apiVersion = "1.0.0") is good for the creator of the API to declare in the API java file he provides to other devs. @Optional.Interface(iface = "net.goodboy.badmod.IHammer", modid = "badtools" [, striprefs = false]) would go on a class that optionally implements an outside mods interface, it cannot go on the interface itself. @Optional.Method(modid = "badtools") would go on the specific method in your class that would be removed (if said mod was not installed). Quote -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
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.