Jump to content

[1.9.4][Solved] Java inheritance across multiple mods not working correctly


Sinhika

Recommended Posts

I'm probably missing something that more experienced modders already know full well, but Google hasn't helped me on this. Hopefully someone here can point me in the right direction.

 

Problem Description:

 

-  Child Class B in Mod Bb extends Parent Class A in mod Aa.

- obfuscated jar file of Mod Aa is in Bb's ./libs directory.

- Method A1() is implemented in Class A.

- Class C in Mod Bb calls B.A1().

- Eclipse thinks everything is hunky-dory, builds okay.

- ./gradlew build of Mod Bb fails with "Cannot find symbol" error for method A1().

 

Troubleshooting:

 

- move parent Class A into Mod Bb.

- Child class B, class C, etc as before.

- Eclipse build still happy.

- ./gradlew build of Mod Bb works fine.

 

Just to be confusing:

 

- class Z in Mod Aa.

- Mod Bb instantiates Z (NOT extends). (e.g. "Z z1 = new Z();")

- everything builds just fine.

 

What am I doing wrong?  How do I fix it so parental class for lib/core/api-type mod can be properly inherited and its methods invoked by a child class in another mod.

Link to comment
Share on other sites

Is late for me, so I may be less than coherent, but I'll leave these links up for you to ponder when you get the chance:

 

I am working on the 1.9.4 port of "Fusion" for Alexndr's Simple Ores 2 collection of mods. Source here.

 

Originally, I had blocks/SimpleFurnace.java and tiles/TileEntitySimpleFurnace.java in the SimpleCore API mod, which serves as a common library for all the Simple Ores2 mods, because I thought I might want a common base class for later use with the improved furnaces in the Simple Ores2 Machines mod.

 

blocks/BlockFusionFurnace extends SimpleFurnace, and tiles/TileEntityFusionFurnace extends TileEntitySimpleFurnace. The problem I had was that where inventory/ContainerFusionFurnace's (the container class for the Fusion Furnace) detectAndSendChanges() and updateProgressBar() methods called TileEntityFusionFurnace methods getField() and setField(), that are actually inherited from TileEntitySimpleFurnace, they weren't found by the gradle compile. That is, "cannot find symbol" error.  They weren't the only such errors; I believe stuff in SimpleFurnace wasn't found, either.

 

When built within Eclipse, there were no compile errors.

When I moved both parent classes into the Fusion mod, gradle build compiled okay.  That is the current state you see at the source tree linked above.

 

Link to comment
Share on other sites

Yes, those sound like obfuscation errors... Are you sure you have an unobfuscated version of the library?

 

I am sure that I do NOT.  I take it I am supposed to use the unobfuscated version to build against?  See, this is an example of "missing something that more experienced modders already know full well", but I've never actually been clear as to what unobfuscated jars were for, beside "to run client inside Eclipse".

 

So why is it building okay when I instantiate a class from an obfuscated library?

 

Link to comment
Share on other sites

Yes, that's it. Also, someone needs to fix the Forge Gradle Cookbook: the Gradle snippet for creating a deobfuscated file is wrong. I had to go browsing various mod sources on GitHub to find the correct snippet. What's in the Cookbook creates a jar file filled with source code, which doesn't work very well as an external lib.

 

This snippet (from my build.gradle) works:

 

task deobfJar(type: Jar) {
    from sourceSets.main.output
    classifier "deobf"
}

artifacts {
    archives deobfJar
}

 

Note the difference in the 'from' line.

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.