Captain-Chaos / WorldPainter

WorldPainter is an interactive graphical map generator for the indie game Minecraft.
http://www.worldpainter.net/
GNU General Public License v3.0
358 stars 58 forks source link

Can't instantiate JavaMinecraftWorld when used in own code. #294

Closed timbaas closed 1 year ago

timbaas commented 1 year ago

First of all, great project and thanks for open-sourcing!

I'm writing a script which I want to be able to generate worlds for Minecraft Java edition. I'm trying to use the JavaMinecraftWorld class to do some of the heavy lifting but I'm running into some problems.

First I got this error when instantiating JavaMinecraftWorld:

the return value of "org.pepsoft.worldpainter.plugins.WPPluginManager.getInstance()" is null

I did some digging and managed to solve this by extending the AbstractTool class and calling initialisePlatform in the constructor of my app.

The error that followed is:

java.lang.reflect.InvocationTargetException
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:116)
    at java.lang.reflect.Method.invoke (Method.java:578)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:1589)
Caused by: java.lang.NullPointerException: Cannot invoke "org.pepsoft.worldpainter.plugins.BlockBasedPlatformProvider.getChunkStore(org.pepsoft.worldpainter.Platform, java.io.File, int)" because the return value of "org.pepsoft.worldpainter.plugins.PlatformManager.getImplementation(Object)" is null
    at org.pepsoft.worldpainter.plugins.PlatformManager.getChunkStore (PlatformManager.java:47)
    at org.pepsoft.worldpainter.exporting.CachingMinecraftWorld.<init> (CachingMinecraftWorld.java:30)
    at org.pepsoft.worldpainter.exporting.JavaMinecraftWorld.<init> (JavaMinecraftWorld.java:18)
    at com.phg.worldgenerator.App.main (App.java:33)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:578)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:1589)

I saw that BiomeNameHarvester is also using the JavaMinecraftWorld class, so I tried BiomeNameHarvester.main(new String[]{ "--create" }) but this results in an ImageIO.read error in Minecraft1_17Biomes.java:289.

I'm using the following versions:

Minecraft 1.19.2 + 1.19.3
WorldPainter 2.15.18
Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
Java version: 19.0.2, vendor: Oracle Corporation
OS name: "windows 11", version: "10.0", arch: "amd64", family: "windows"

I don't have a lot of experience with Java, so I may be missing something simple here.

Any help is greatly appreciated!

Captain-Chaos commented 1 year ago

The tools which use AbstractTool call initialisePlatform() in their main method, not in the constructor; see if that makes a difference. Otherwise I'm not sure what is happening; this seems like something that should work? Is all of WorldPainter and its dependencies on the runtime classpath? Can you send me a project that demonstrates the problem?

Captain-Chaos commented 1 year ago

How is this going? Have you got it to work? Do you still need my help? Otherwise I'll close the ticket.

Captain-Chaos commented 1 year ago

Closing this since I haven't heard back; feel free to open a new issue if you are still having trouble.