This post will give you an overview on how a plugin for worldpainter can be developed and what you need to get started.

A worldpainter plugin is like a mod for worldpainter. It is written in java, compiled into a .jar, placed into worldpainter/plugins folder and loaded automatically by worldpainter when the program starts.
It is much faster than the worldpainter scripts and allows to add to worldpainters functionality. This includes (but is not limited to):

  1. add new operations
  2. add new layers
  3. add new custom layers
  4. add new layer editors (GUI)
  5. add new exporters
  6. add new custom object providers

a showcase on whats possible with plugins: MacroMachine in 100 seconds

Prerequisites to plugin development

  1. You must be able to write, compile and run java code
  2. Java IDE (recommended Intellij Community or Ultimate)
  3. Maven installation
  4. Worldpainter installation
  5. Git installation

This github repository contains an example plugin set up by CaptainChaos (the worldpainter dev). It showcases whats already possible with the worldpainter plugin API. Clone it locally and you can extend it to your needs:
DemoWpPlugin

Clone the worldpainter repository, so you can search in it how the code works:
Worldpainter Repository

Worldpainter uses Java Swing for its GUI, if you want to make a complex plugin with custom GUIs/Editors, you might want to learn how Swing works:
Java Swing

The community has only recently started to publish plugins. As of now, only the first 4 have releases (that i know of):

  1. Custom Garden Layer
  2. Expand Layer
  3. MacroMachine
  4. CubicChunks
  5. MineTest Exporter
  6. WorleyCaves
  7. WurmUnlimited Exporter
  8. Slabify

Setup

See this README file for the necessary steps to set up the required maven dependencies:
README

Worldpainter uses JIDE Dock, an external framework in its GUI. The problem is, that you cant just download JIDE from maven, because the source code is closed-source. The offical worldpainter guide suggests to contact JIDE, get an open source license and the dependency jars from there. I tried that, their forum looks dead and they never activated my account or contacted me back.
Instead, you can use the .jar files that come with your worldpainter installation. For compiling you need the files for windows AND linux (but worldpainter only installs the required ones), so i provide the .jars in this repository, you need to download all 3 jide .jars:
repository

After downloading, you need to install the jide jars with maven, so that maven can find them when looking for dependencies (see README file tutorial above)

If you have no experience with maven, get some basic tutorials in on how to use it. AI is really good now writing POM.xml

Developement

After you have made your changes to the code, you can use maven to start a worldpainter that has your current plugin loaded, to test it inside worldpainter.
Use maven test with the testWithWorldpainter profile.
The release profile is the one used for compiling release artifacts.

The most relevant classes to do things inside worldpainter is Dimension.java
It represents the currently loaded project and you can read/write terrain, height, water, layers etc in it.

Warning: The worldpainter plugin API is not perfect. Some things are wierd and you have to go to great lengths to make simple things work. Often times things are set private that you need access to.
You can contact CaptainChaos and ask if there is a better solution, he is willing to adapt the API to make things easier.
The current core idea (as i understand it) is that your plugin and classes implement certain interfaces (like CustomLayerProvider or BrushOperation), which worldpainter will use to integrate your new functionality into the existing framework, like offering a new brush operation.

Releases

Worldpainter has a signing mechanism for plugins. It will refuse to load any plugins in the worldpainter/plugins folder, that are not virtually signed by the worldpainter build server. The official reason for this mechanism is to prevent malware being loaded in by unsuspecting users. So far CaptainChaos has not expressed interest in removing this obstacle.

In order to get your plugin signed, you need to contact CaptainChaos (use reddit or discord). You need to set up a way for the build server to push the build-artifact to your github repository. I use a fine grained access token, which grants the buildserver write access to my repo (which is a security risk, but whatever).

The build server will detect any pushes to a specific branch you chose, and then build a release for that push every time.
I use a separate release branch, that i only push to whenever i want to make a release.
Once the build server is done, it creates a release in your repository that has the signed .jar artifact attached. Users can then download the jar file and use it in their worldpainter.

A workaround to load unsigned jar files, is to add your jar file to the worldpainters class path. Usually you dont need that because you can start wp + plugin form your IDE. In case you need it: get the command line arguments used to start wp with testInWorldpainter, add you own jar file to the class path, combine the command line so it can be run in powershell or whatever you use. Then start the normal worldpainter.exe using this command line. Worldpainter will accept any plugin that is part of its classpath, unsigned or not.

Relevant technologies

This section is targeted at less experienced java developers.

  1. If you dont understand something (including steps in this tutorial) let AI explain it to you.
  2. Learn Java Swing if you want to make custom GUIs.
  3. Set up JUnit tests in your repository, dont test manually by hand but automate it instead
  4. Learn how to use the debugger, stepper and breakpoints (with conditions) in Intellij
  5. Use hot reload
  6. Use the VisualVM sampler to performance-profile your plugin to figure out what bottlenecks limits the performance. Dont guess where bottlenecks are.
  7. You can attach to worldpainter with your intellij debugger to debug worldpainter itself. For that WP must have been started with a cli parameter that allows debuggers to attach to it:
    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005
    using the testWithWorldpainter profile does that.
  8. After making a release, download the jar and test in normal worldpainter a last time before publishing. Sometimes it behaves different than when started from the IDE, f.e. regarding writing files that live in the jar to HDD

Leave a Reply

Your email address will not be published. Required fields are marked *