Jump to content

[Solved] Access to other mods (requirements?) (1.12.1)


Pixtar

Recommended Posts

Hi dev community,

 

I'm currently try to access the functions / variables of another mod. I know there are still threads about it, but they didn't helped me at all.

 

Let us imagine a mod called "FooBar"

It's modid is "foo_bar"

It has a class declared as:

static class FooAPI

with a function declared as:

public static boolean getBar(){ return true; }

 

Now I have the jar and the source of the mod.

 

I've modified the build.gradle of my mod like this:

dependencies { provided fileTree(dir: 'libs', includes: ['*.jar']) }

 

The folder "libs" is placed at the root of gradlew and contains "FooBar.jar"

 

Now I'm importing all classes with:

import FooBar.*;

I'm checking for the existence of the mod and calling the needed function:

boolean x = false;
if( Loader.isModLoaded("foo_bar") )
  x = FooAPI.getBar()

 

Gradle is saying:

error: cannot find symbol: FooAPI

 

I appreciate any help to get the above example working. Maybe I'm missing something simple or maybe MC / Forge are not designed to work as the above example. I would even use other methods to get the above example to work,

 

Kiind regards,

Pixtar

 

EDIT: I'm currently using forge-1.12.1-14.22.0.2467-mdk

Edited by Pixtar
Link to comment
Share on other sites

Well, for one, you have to wrap your API getter in a separate class. If FooAPI isn't available at runtime, Minecraft will crash when it instanciates your main class because FooAPI can't be found.

 

That said, you need to do this in the dependencies section of your build.gradle file:


    compile files('lib/FooBar.jar')

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

30 minutes ago, Pixtar said:

Thanks for the reply Draco18s. I want to have the mod "included" as optional mod.

You still need to put any access to FooAPI into another class. The JVM doesn't know at the time that it reads your main mod file from disk that FooAPI will never be accessed, so it goes to check to see if it knows where FooAPI is, won't find it, and will crash.

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/farming/FarmingBase.java#L196-L198

 

I don't know why you're getting the error you are when compiling, though.

Did you add FooAPI to your build path in Eclipse?

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Hi Dracos18s,

 

I know about the fact, that if I want to use another mod that this one needs to be loaded before the access.

But I thought that this would be handled by the useage of the following line in build.gradle or am I wrong?

dependencies { compile files('lib/FooBar.jar') }

 

Currently I'm only using Eclipse as editor not as compiler interface or something like that.

You've mentioned the "build path"; I think this can also be handled via build.gradle but how?!

 

Kind regards,

Pixtar

Link to comment
Share on other sites

Right click anywhere in the Package Explorer window. Build Path -> Configure Build Path. Libraries tab. Add External Jars.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Hi Draco18s,

 

I've found the option and I've added the JAR but executing "gradlew build" via cmd still bitches, that it cannot find symbol FooApi.

 

Anyway I'm asking myself, what the external JAR is good for in Eclipse, when I'm calling gradlew not via Eclipse?!

 

Pixtar

Link to comment
Share on other sites

1 minute ago, Pixtar said:

Anyway I'm asking myself, what the external JAR is good for in Eclipse

Oh, probably for doing things like code hinting, error checking, and development/debug builds. Nothing special.

 

As for gradle, that's what the dependencies { ... } block is for. If it's bitching, show the error.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

22 minutes ago, Draco18s said:

Oh, probably for doing things like code hinting, error checking, and development/debug builds. Nothing special.

I've heard that sarcasm. ;-P

 

.. and now I put myself in a corner to feel ashamed of myself. *facepalm*

 

I've found my mistake - because of your hint. Now eclipse was moaning that it knows that the FooApi is comming from FooBar.jar, but if I want to use it I should include the defined path to the interface/function/whatever.

 

So I changed

import FooBar.*;

to

import FooBar.FooApi;

and gradlew is compiling without any errors.

 

.. but I stumbled right in the failure you've described above .. the mod is maybe loaded after mine, because

if( Loader.isModLoaded("foo_bar") )

is false.

 

Pixtar

Edited by Pixtar
Link to comment
Share on other sites

@Mod annotation. Add dependencies="after:foo_bar"

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Hi Draco18s,

okay, I've added the property to my @Mod annotation which now looks like the following:

@Mod( modid = ExampleMod.MODID, version = ExampleMod.VERSION, useMetadata = true,
	  serverSideOnly = true, acceptableRemoteVersions="*", dependencies="after:foo_bar" )
public class ExampleMod
{
    public static final String MODID = "examplemod";
    public static final String VERSION = "1.0";
	....

and I've also edited mcmod.info from the resources and added:

  "dependencies": ["foo_bar"],
  "useDependencyInformation": true

.. and .. *drum roll* .. oh miracle .. it's working .. fabulous!

 

Thanks you very much Draco18s for your help and your patience. Hopefully other users may have a little walkthrough/manual by reading this thread.

 

Have a nice day,

Pixtar

Link to comment
Share on other sites

For reference, the mcmod.info files has no bearing on whether or not it works. It's just a easy-to-read text format of the details of your mod so that services like Curse can display that information without having to decompile the entire jar.

 

Good practice to change it, but doesn't actually do anything.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.