mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 11:17:11 +07:00
Mod loading fixes
This commit is contained in:
parent
01e3bd703e
commit
d973283039
@ -140,7 +140,7 @@ public class ContentParser{
|
||||
if(value.has("consumes")){
|
||||
for(JsonValue child : value.get("consumes")){
|
||||
if(child.name.equals("item")){
|
||||
block.consumes.item(Vars.content.getByName(ContentType.item, child.asString()));
|
||||
block.consumes.item(find(ContentType.item, child.asString()));
|
||||
}else if(child.name.equals("items")){
|
||||
block.consumes.add((Consume)parser.readValue(ConsumeItems.class, child));
|
||||
}else if(child.name.equals("liquid")){
|
||||
@ -164,7 +164,7 @@ public class ContentParser{
|
||||
|
||||
//add research tech node
|
||||
if(value.has("research")){
|
||||
TechTree.create(Vars.content.getByName(ContentType.block, value.get("research").asString()), block);
|
||||
TechTree.create(find(ContentType.block, value.get("research").asString()), block);
|
||||
}
|
||||
|
||||
//make block visible
|
||||
@ -191,6 +191,13 @@ public class ContentParser{
|
||||
ContentType.zone, parser(ContentType.zone, Zone::new)
|
||||
);
|
||||
|
||||
private <T extends Content> T find(ContentType type, String name){
|
||||
Content c = Vars.content.getByName(type, name);
|
||||
if(c == null) c = Vars.content.getByName(type, currentMod.name + "-" + name);
|
||||
if(c == null) throw new IllegalArgumentException("No " + type + " found with name '" + name + "'");
|
||||
return (T)c;
|
||||
}
|
||||
|
||||
private <T extends Content> TypeParser<T> parser(ContentType type, Function<String, T> constructor){
|
||||
return (mod, name, value) -> {
|
||||
T item;
|
||||
@ -418,6 +425,8 @@ public class ContentParser{
|
||||
|
||||
/** Tries to resolve a class from a list of potential class names. */
|
||||
private <T> Class<T> resolve(String base, String... potentials){
|
||||
if(!base.isEmpty() && Character.isLowerCase(base.charAt(0))) base = Strings.capitalize(base);
|
||||
|
||||
for(String type : potentials){
|
||||
try{
|
||||
return (Class<T>)Class.forName(type + '.' + base);
|
||||
|
@ -295,6 +295,7 @@ public class Mods implements Loadable{
|
||||
//this finishes parsing content fields
|
||||
parser.finishParsing();
|
||||
|
||||
//load content for code mods
|
||||
each(Mod::loadContent);
|
||||
}
|
||||
|
||||
@ -466,6 +467,15 @@ public class Mods implements Loadable{
|
||||
public boolean enabled(){
|
||||
return Core.settings.getBool(name + "-enabled", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "LoadedMod{" +
|
||||
"file=" + file +
|
||||
", root=" + root +
|
||||
", name='" + name + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
/** Plugin metadata information.*/
|
||||
|
Loading…
Reference in New Issue
Block a user