mirror of
https://github.com/Anuken/Mindustry.git
synced 2026-10-02 11:10:50 +03:00
Backported patch loading in mods from v9 for future compatibility
This commit is contained in:
@@ -183,7 +183,10 @@ public abstract class ClientLauncher extends ApplicationCore implements Platform
|
||||
|
||||
assets.load(schematics);
|
||||
|
||||
assets.loadRun("contentinit", ContentLoader.class, () -> content.init(), () -> content.load());
|
||||
assets.loadRun("contentinit", ContentLoader.class, () -> content.init(), () -> {
|
||||
content.load();
|
||||
mods.loadModPatches();
|
||||
});
|
||||
assets.loadRun("baseparts", BaseRegistry.class, () -> {}, () -> bases.load());
|
||||
|
||||
Core.assets.load("sprites/schematic-background.png", Texture.class).loaded = t -> t.setWrap(TextureWrap.repeat);
|
||||
|
||||
@@ -22,6 +22,7 @@ import mindustry.gen.*;
|
||||
import mindustry.graphics.*;
|
||||
import mindustry.graphics.MultiPacker.*;
|
||||
import mindustry.mod.ContentParser.*;
|
||||
import mindustry.mod.data.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.*;
|
||||
|
||||
@@ -936,6 +937,24 @@ public class Mods implements Loadable{
|
||||
Events.fire(new ModContentLoadEvent());
|
||||
}
|
||||
|
||||
public void loadModPatches(){
|
||||
for(LoadedMod mod : orderedMods()){
|
||||
if(mod.root.child("patches").exists()){
|
||||
try{
|
||||
Seq<Fi> patches = mod.root.child("patches").findAll(f -> f.extEquals("json") || f.extEquals("hjson"));
|
||||
if(patches.size > 0){
|
||||
//create a new patcher per mod so the fields don't get reset
|
||||
DataPatcher patcher = new DataPatcher();
|
||||
patches.sort();
|
||||
patcher.apply(patches.map(f -> new PatchAsset(f.readString())), new Seq<>());
|
||||
}
|
||||
}catch(Exception e){
|
||||
Log.err("Failed to apply patches from mod " + mod.meta.name, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void handleContentError(Content content, Throwable error){
|
||||
parser.markError(content, error);
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class ServerLauncher implements ApplicationListener{
|
||||
mods.loadScripts();
|
||||
content.createModContent();
|
||||
content.init();
|
||||
mods.loadModPatches();
|
||||
|
||||
if(mods.hasContentErrors()){
|
||||
err("Error occurred loading mod content:");
|
||||
|
||||
Reference in New Issue
Block a user