Merge branch 'master' of https://github.com/Anuken/Mindustry into 7.0-features
Conflicts: core/src/mindustry/content/Blocks.java
This commit is contained in:
@@ -121,6 +121,11 @@ public class ContentParser{
|
||||
return sound;
|
||||
});
|
||||
put(Objectives.Objective.class, (type, data) -> {
|
||||
if(data.isString()){
|
||||
var cont = locateAny(data.asString());
|
||||
if(cont == null) throw new IllegalArgumentException("Unknown objective content: " + data.asString());
|
||||
return new Research((UnlockableContent)cont);
|
||||
}
|
||||
var oc = resolve(data.getString("type", ""), SectorComplete.class);
|
||||
data.remove("type");
|
||||
Objectives.Objective obj = make(oc);
|
||||
@@ -228,6 +233,7 @@ public class ContentParser{
|
||||
case "item" -> block.consumes.item(find(ContentType.item, child.asString()));
|
||||
case "items" -> block.consumes.add((Consume)parser.readValue(ConsumeItems.class, child));
|
||||
case "liquid" -> block.consumes.add((Consume)parser.readValue(ConsumeLiquid.class, child));
|
||||
case "coolant" -> block.consumes.add((Consume)parser.readValue(ConsumeCoolant.class, child));
|
||||
case "power" -> {
|
||||
if(child.isNumber()){
|
||||
block.consumes.power(child.asFloat());
|
||||
@@ -543,6 +549,16 @@ public class ContentParser{
|
||||
return first != null ? first : Vars.content.getByName(type, currentMod.name + "-" + name);
|
||||
}
|
||||
|
||||
private <T extends MappableContent> T locateAny(String name){
|
||||
for(ContentType t : ContentType.all){
|
||||
var out = locate(t, name);
|
||||
if(out != null){
|
||||
return (T)out;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
<T> T make(Class<T> type){
|
||||
try{
|
||||
Constructor<T> cons = type.getDeclaredConstructor();
|
||||
@@ -679,18 +695,26 @@ public class ContentParser{
|
||||
lastNode.remove();
|
||||
}
|
||||
|
||||
TechNode node = new TechNode(null, unlock, customRequirements == null ? unlock.researchRequirements() : customRequirements);
|
||||
TechNode node = new TechNode(null, unlock, customRequirements == null ? ItemStack.empty : customRequirements);
|
||||
LoadedMod cur = currentMod;
|
||||
|
||||
postreads.add(() -> {
|
||||
currentContent = unlock;
|
||||
currentMod = cur;
|
||||
|
||||
//add custom objectives
|
||||
if(research.has("objectives")){
|
||||
node.objectives.addAll(parser.readValue(Objective[].class, research.get("objectives")));
|
||||
}
|
||||
|
||||
//remove old node from parent
|
||||
if(node.parent != null){
|
||||
node.parent.children.remove(node);
|
||||
}
|
||||
|
||||
if(customRequirements == null){
|
||||
node.setupRequirements(unlock.researchRequirements());
|
||||
}
|
||||
|
||||
//find parent node.
|
||||
TechNode parent = TechTree.all.find(t -> t.content.name.equals(researchName) || t.content.name.equals(currentMod.name + "-" + researchName));
|
||||
|
||||
@@ -11,25 +11,23 @@ public class ModClassLoader extends ClassLoader{
|
||||
}
|
||||
|
||||
@Override
|
||||
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException{
|
||||
//always try the superclass first
|
||||
try{
|
||||
return super.loadClass(name, resolve);
|
||||
}catch(ClassNotFoundException error){
|
||||
//a child may try to delegate class loading to its parent, which is *this class loader* - do not let that happen
|
||||
if(inChild) throw error;
|
||||
int size = children.size;
|
||||
//if it doesn't exist in the main class loader, try all the children
|
||||
for(int i = 0; i < size; i++){
|
||||
try{
|
||||
inChild = true;
|
||||
var out = children.get(i).loadClass(name);
|
||||
inChild = false;
|
||||
return out;
|
||||
}catch(ClassNotFoundException ignored){
|
||||
}
|
||||
protected Class<?> findClass(String name) throws ClassNotFoundException{
|
||||
//a child may try to delegate class loading to its parent, which is *this class loader* - do not let that happen
|
||||
if(inChild) throw new ClassNotFoundException(name);
|
||||
|
||||
ClassNotFoundException last = null;
|
||||
int size = children.size;
|
||||
//if it doesn't exist in the main class loader, try all the children
|
||||
for(int i = 0; i < size; i++){
|
||||
try{
|
||||
inChild = true;
|
||||
var out = children.get(i).loadClass(name);
|
||||
inChild = false;
|
||||
return out;
|
||||
}catch(ClassNotFoundException e){
|
||||
last = e;
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
throw (last == null ? new ClassNotFoundException(name) : last);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public class Scripts implements Disposable{
|
||||
|
||||
public String runConsole(String text){
|
||||
try{
|
||||
Object o = context.evaluateString(scope, text, "console.js", 1, null);
|
||||
Object o = context.evaluateString(scope, text, "console.js", 1);
|
||||
if(o instanceof NativeJavaObject n) o = n.unwrap();
|
||||
if(o instanceof Undefined) o = "undefined";
|
||||
return String.valueOf(o);
|
||||
@@ -172,11 +172,11 @@ public class Scripts implements Disposable{
|
||||
try{
|
||||
if(currentMod != null){
|
||||
//inject script info into file
|
||||
context.evaluateString(scope, "modName = \"" + currentMod.name + "\"\nscriptName = \"" + file + "\"", "initscript.js", 1, null);
|
||||
context.evaluateString(scope, "modName = \"" + currentMod.name + "\"\nscriptName = \"" + file + "\"", "initscript.js", 1);
|
||||
}
|
||||
context.evaluateString(scope,
|
||||
wrap ? "(function(){'use strict';\n" + script + "\n})();" : script,
|
||||
file, 0, null);
|
||||
file, 0);
|
||||
return true;
|
||||
}catch(Throwable t){
|
||||
if(currentMod != null){
|
||||
@@ -224,7 +224,7 @@ public class Scripts implements Disposable{
|
||||
if(!module.exists() || module.isDirectory()) return null;
|
||||
return new ModuleSource(
|
||||
new InputStreamReader(new ByteArrayInputStream((module.readString()).getBytes())),
|
||||
null, new URI(moduleId), root.file().toURI(), validator);
|
||||
new URI(moduleId), root.file().toURI(), validator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user