Fixed some modding bugs

This commit is contained in:
Anuken
2019-10-30 13:53:00 -04:00
parent ee5d229f51
commit 8616a82efc
2 changed files with 45 additions and 19 deletions

View File

@@ -321,31 +321,56 @@ public class Mods implements Loadable{
/** Creates all the content found in mod files. */
public void loadContent(){
class LoadRun implements Comparable<LoadRun>{
final ContentType type;
final FileHandle file;
final LoadedMod mod;
public LoadRun(ContentType type, FileHandle file, LoadedMod mod){
this.type = type;
this.file = file;
this.mod = mod;
}
@Override
public int compareTo(LoadRun l){
int mod = this.mod.name.compareTo(l.mod.name);
if(mod != 0) return mod;
return this.file.name().compareTo(l.file.name());
}
}
Array<LoadRun> runs = new Array<>();
for(LoadedMod mod : orderedMods()){
safeRun(mod, () -> {
if(mod.root.child("content").exists()){
FileHandle contentRoot = mod.root.child("content");
for(ContentType type : ContentType.all){
FileHandle folder = contentRoot.child(type.name().toLowerCase() + "s");
if(folder.exists()){
for(FileHandle file : folder.list()){
if(file.extension().equals("json")){
try{
//this binds the content but does not load it entirely
Content loaded = parser.parse(mod, file.nameWithoutExtension(), file.readString("UTF-8"), file, type);
Log.debug("[{0}] Loaded '{1}'.", mod.meta.name,
(loaded instanceof UnlockableContent ? ((UnlockableContent)loaded).localizedName : loaded));
}catch(Exception e){
throw new RuntimeException("Failed to parse content file '" + file + "' for mod '" + mod.meta.name + "'.", e);
}
}
if(mod.root.child("content").exists()){
FileHandle contentRoot = mod.root.child("content");
for(ContentType type : ContentType.all){
FileHandle folder = contentRoot.child(type.name().toLowerCase() + "s");
if(folder.exists()){
for(FileHandle file : folder.list()){
if(file.extension().equals("json")){
runs.add(new LoadRun(type, file, mod));
}
}
}
}
});
}
}
//make sure mod content is in proper order
runs.sort();
runs.each(l -> safeRun(l.mod, () -> {
try{
//this binds the content but does not load it entirely
Content loaded = parser.parse(l.mod, l.file.nameWithoutExtension(), l.file.readString("UTF-8"), l.file, l.type);
Log.debug("[{0}] Loaded '{1}'.", l.mod.meta.name,
(loaded instanceof UnlockableContent ? ((UnlockableContent)loaded).localizedName : loaded));
}catch(Exception e){
throw new RuntimeException("Failed to parse content file '" + l.file + "' for mod '" + l.mod.meta.name + "'.", e);
}
}));
//this finishes parsing content fields
parser.finishParsing();

View File

@@ -1,12 +1,13 @@
package io.anuke.mindustry.world.blocks.defense.turrets;
import io.anuke.arc.util.ArcAnnotate.*;
import io.anuke.mindustry.entities.bullet.BulletType;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockStat;
import io.anuke.mindustry.world.meta.StatUnit;
public abstract class PowerTurret extends CooledTurret{
protected BulletType shootType;
protected @NonNull BulletType shootType;
protected float powerUse = 1f;
public PowerTurret(String name){