Mod loading fixes
This commit is contained in:
@@ -140,7 +140,7 @@ public class ContentParser{
|
|||||||
if(value.has("consumes")){
|
if(value.has("consumes")){
|
||||||
for(JsonValue child : value.get("consumes")){
|
for(JsonValue child : value.get("consumes")){
|
||||||
if(child.name.equals("item")){
|
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")){
|
}else if(child.name.equals("items")){
|
||||||
block.consumes.add((Consume)parser.readValue(ConsumeItems.class, child));
|
block.consumes.add((Consume)parser.readValue(ConsumeItems.class, child));
|
||||||
}else if(child.name.equals("liquid")){
|
}else if(child.name.equals("liquid")){
|
||||||
@@ -164,7 +164,7 @@ public class ContentParser{
|
|||||||
|
|
||||||
//add research tech node
|
//add research tech node
|
||||||
if(value.has("research")){
|
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
|
//make block visible
|
||||||
@@ -191,6 +191,13 @@ public class ContentParser{
|
|||||||
ContentType.zone, parser(ContentType.zone, Zone::new)
|
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){
|
private <T extends Content> TypeParser<T> parser(ContentType type, Function<String, T> constructor){
|
||||||
return (mod, name, value) -> {
|
return (mod, name, value) -> {
|
||||||
T item;
|
T item;
|
||||||
@@ -418,6 +425,8 @@ public class ContentParser{
|
|||||||
|
|
||||||
/** Tries to resolve a class from a list of potential class names. */
|
/** Tries to resolve a class from a list of potential class names. */
|
||||||
private <T> Class<T> resolve(String base, String... potentials){
|
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){
|
for(String type : potentials){
|
||||||
try{
|
try{
|
||||||
return (Class<T>)Class.forName(type + '.' + base);
|
return (Class<T>)Class.forName(type + '.' + base);
|
||||||
|
|||||||
@@ -295,6 +295,7 @@ public class Mods implements Loadable{
|
|||||||
//this finishes parsing content fields
|
//this finishes parsing content fields
|
||||||
parser.finishParsing();
|
parser.finishParsing();
|
||||||
|
|
||||||
|
//load content for code mods
|
||||||
each(Mod::loadContent);
|
each(Mod::loadContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -466,6 +467,15 @@ public class Mods implements Loadable{
|
|||||||
public boolean enabled(){
|
public boolean enabled(){
|
||||||
return Core.settings.getBool(name + "-enabled", true);
|
return Core.settings.getBool(name + "-enabled", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "LoadedMod{" +
|
||||||
|
"file=" + file +
|
||||||
|
", root=" + root +
|
||||||
|
", name='" + name + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Plugin metadata information.*/
|
/** Plugin metadata information.*/
|
||||||
|
|||||||
Reference in New Issue
Block a user