Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

Have you already tried to surround everything that has a reference to the mod with try()?

Another solution would be to use the oreregistry.

Here could be your advertisement!

  • 5 weeks later...
  • Author

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

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.

 

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

 

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.

  • Author

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

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.