Sign in to follow this  
ThisIsRaffeh

[WIP] WU Server Modding Support

Recommended Posts

It would be awesome to see some mod support in the Server code, so individual mods can co-exist, and not every mod needs to compile it's own version of the server.jar, it would also give CCAB more control over what they expose to modding and what not. 


 


Since i'm quite an apt coder myself, i took the liberty of writing an implementation for it based on the released server.jar for WU.


 


The way i currently set it up, allows there to be a "/mods/" folder in your WU Server folder and it will check folders in there for a file called "mod.info" which is a file that describes the mod info in a token=value format. 


 


First, here is the ModHandler or ModManager class, the LoadMods method would ideally be called early in the server startup, before any functionality mods could hook into. 



package com.wurmonline.server;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ModHandler {

private static Logger logger = Logger.getLogger(ModHandler.class.getName());
protected static List<Mod> availableMods;
protected static List<Mod> activeMods;

public static void LoadMods(String modDir) {
availableMods = new ArrayList<Mod>();
File modFolder = new File(modDir);
File[] files;
int numMods = 1;
for (File file : files = modFolder.listFiles()) {
if(file.isDirectory()) {
String[] modFiles;
for(String modFile : modFiles = file.list()) {
if (modFile.equalsIgnoreCase("mod.info")) {
Properties properties = new Properties();
FileInputStream stream;
try {
stream = new FileInputStream(modFile);
properties.load(stream);
} catch (FileNotFoundException ex) {
logger.log(Level.SEVERE, "Could not open mod.info file in folder " + file.toString());
} catch (IOException ex) {
logger.log(Level.SEVERE, "Could not read mod.info file in folder " + file.toString());
}
Mod info = new Mod(properties.getProperty("name", "Wurm Unlimted Mod " + String.valueOf(numMods)), file.toString(), properties.getProperty("enabled", "False"));
numMods++;
availableMods.add(info);

//Should probably have a method of enabling/disabling mods in the GUI
if(info.isEnabled()) {
activeMods.add(info);
}
}
}
}
}
}

public static void initialiseItemTemplates() {
for(Mod mod : activeMods) {
mod.initialiseITemTemplates();
}
}

public static void createSpells() {
for(Mod mod : activeMods) {
mod.createSpells();
}
}

public static void createCreatureTemplates() {
for(Mod mod : activeMods) {
mod.createCreatureTemplates();
}
}

}

Secondly, the Mod class, which will contain information about the mod, and run the actual modifications the mod made: 



package com.wurmonline.server;

class Mod {
public String modName;
public boolean enabled = false;
public String folder;

Mod(String name, String folder, String enabled) {
this.modName = name;
this.folder = folder;
this.enabled = Boolean.parseBoolean(enabled);
}

public String getModName() {
return modName;
}

public boolean isEnabled() {
return enabled;
}

public String getFolder() {
return folder;
}

void initialiseITemTemplates() {
throw new UnsupportedOperationException("Not supported yet.");
}

void createSpells() {
throw new UnsupportedOperationException("Not supported yet.");
}

void createCreatureTemplates() {
throw new UnsupportedOperationException("Not supported yet.");
}
}

Lastly, in server.startRunning, we call the modHandler equivalent for functionality we want to expose to modding, after we executed the standard WU functionality like such: 



ItemTemplateCreator.initialiseItemTemplates();
ModHandler.initialiseItemTemplates();

SpellGenerator.createSpells();
ModHandler.createSpells();

CreatureTemplateCreator.createCreatureTemplates();
ModHandler.createCreatureTemplates();

I'm looking for feedback, suggestions and if there is any chance of this getting implemented in the code. 


If there is enough support for this, i can start writing documentation/ work this out further.


Edited by ThisIsRaffeh
  • Like 4

Share this post


Link to post
Share on other sites

Something like this is exactly what WU needs to thrive.


 


+1 for taking the first steps!


  • Like 1

Share this post


Link to post
Share on other sites

 it would also give CCAB more control over what they expose to modding and what not.

NO. I do want a way to load mods that's supper easy to use and prevents mod conflicts. Although, I don't want CC starting to judge what should or shouldn't be modded. A major selling point of WU is they stated they didn't care how we modded WU. It should stay that way.

 

 

I'm confused about something. You don't need to compile server.jar for every mod. You use the server.jar as a library and either modify a copied extent class or make a new class. You then compile the newly created classes. Finally, drop the compiled classes into the client or server.jar file so your modifications override or extend the original code.

 

Although, I guess there would be a problem if two mods altered the same CC original class. They might actually be changing different parts of the class but my way would make it hard for them to co-exist.

  • Like 1

Share this post


Link to post
Share on other sites

NO. I do want a way to load mods that's supper easy to use and prevents mod conflicts. Although, I don't want CC starting to judge what should or shouldn't be modded. A major selling point of WU is they stated they didn't care how we modded WU. It should stay that way.

Edited by Lycanthropic

Share this post


Link to post
Share on other sites

Writing such a thing for wurm will be big

Share this post


Link to post
Share on other sites

Dont worry, I dont think Rolf will put any limits on modding in WU, its his cash-cow atm, and should he ever forbid certain mods here on the Wurm forums, then why not make a "WurmNexusMods" page ;)

so for example, I thought you can only mod Skyrim in ways that creation kit has outlets to do so. I've never modded Skyrim so I don't know all the details but I'm pretty sure there are some things you can't change because the means to do so aren't in the creation kit. The creation kit is made available by Bethesda. Folks that host mods for Skyrim on Nexus are still using the creation kit.

 

It's not about what's blocked. It's about what the devs decide to allow or what they have time to allow. We also add another pressure on the devs from modders asking for expansions on the built in modding support tool.

 

 

Writing such a thing for wurm will be big

Hard coded math, and variables. Strange organization of things...the farming yield stuff is in the behaviour/terraforming.class.  I imagine it would take a lot of effort for Wurm devs to do what the OP is asking.

 

 

Something does need to happen.

There is definitely going to be a problem. I went through the behaviour/terraforming.class in order to add Alexgopen's idea about automatically dropping dirt as a pile. Well, as I went through it I found a lot of other things I preferred different (pack and pave tiles underwater, buff farming yield by 2 across the board, directly cultivate grass, vastly increase dredge depth, a few others....).

Are we going to have a massive count of difference compiled version of behaviour/terraforming.class to account for the many combination of modification folks may want done with that class? This would be so folks can just drop the modified class into the jar file to override CC's base unmodded classes.

I just realized that in Minecraft, for as much as I can remember, mods just extend features. They don't change the way vanilla works. With all my mods the vanilla game isn't gone. The thing about WU is I know a lot of people will want to change the base game as much as they may want to extend. 

  • Like 1

Share this post


Link to post
Share on other sites

The main problem is that this code was never meant ot be mod-friendly.


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this