Jump to content

[1.7.10]How do I implement soft-dependency recipes?


The_Fireplace

Recommended Posts

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:

 

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.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

  • 5 weeks later...

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.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

"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.

Link to comment
Share on other sites

I'm pretty sure that wasn't intended... I laughed a lot on this :D :D :D :D

return naruto1310.extendedWorkbench.crafting.ExtendedCraftingManager.assRecipe(stack, input);

Same here.

I thank you'd the wrong post, meaning to thank the one above it.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

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).

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.