Block mod overwrite

This commit is contained in:
Anuken
2019-10-09 18:39:12 -04:00
parent 16eb069717
commit 534f770314
2 changed files with 26 additions and 17 deletions
@@ -4,14 +4,12 @@ import io.anuke.arc.*;
import io.anuke.arc.assets.loaders.*; import io.anuke.arc.assets.loaders.*;
import io.anuke.arc.collection.*; import io.anuke.arc.collection.*;
import io.anuke.arc.files.*; import io.anuke.arc.files.*;
import io.anuke.arc.util.*;
/** Handles files in a modded context. */ /** Handles files in a modded context. */
public class FileTree implements FileHandleResolver{ public class FileTree implements FileHandleResolver{
private ObjectMap<String, FileHandle> files = new ObjectMap<>(); private ObjectMap<String, FileHandle> files = new ObjectMap<>();
public void addFile(String path, FileHandle f){ public void addFile(String path, FileHandle f){
Log.info("Add " + path);
files.put(path, f); files.put(path, f);
} }
@@ -107,6 +107,15 @@ public class ContentParser{
ContentType.block, (TypeParser<Block>)(mod, name, value) -> { ContentType.block, (TypeParser<Block>)(mod, name, value) -> {
readBundle(ContentType.block, name, value); readBundle(ContentType.block, name, value);
Block block;
if(Vars.content.getByName(ContentType.block, name) != null){
block = Vars.content.getByName(ContentType.block, name);
if(value.has("type")){
throw new IllegalArgumentException("When overwriting an existing block, you may not declared its type. The original type will be used. Block: " + name);
}
}else{
//TODO generate dynamically instead of doing.. this //TODO generate dynamically instead of doing.. this
Class<? extends Block> type = resolve(value.getString("type"), Class<? extends Block> type = resolve(value.getString("type"),
"io.anuke.mindustry.world", "io.anuke.mindustry.world",
@@ -122,7 +131,9 @@ public class ContentParser{
"io.anuke.mindustry.world.blocks.units" "io.anuke.mindustry.world.blocks.units"
); );
Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name); block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name);
}
currentContent = block; currentContent = block;
read(() -> { read(() -> {
if(value.has("consumes")){ if(value.has("consumes")){