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,22 +107,33 @@ 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);
//TODO generate dynamically instead of doing.. this Block block;
Class<? extends Block> type = resolve(value.getString("type"),
"io.anuke.mindustry.world", if(Vars.content.getByName(ContentType.block, name) != null){
"io.anuke.mindustry.world.blocks", block = Vars.content.getByName(ContentType.block, name);
"io.anuke.mindustry.world.blocks.defense",
"io.anuke.mindustry.world.blocks.defense.turrets", if(value.has("type")){
"io.anuke.mindustry.world.blocks.distribution", throw new IllegalArgumentException("When overwriting an existing block, you may not declared its type. The original type will be used. Block: " + name);
"io.anuke.mindustry.world.blocks.logic", }
"io.anuke.mindustry.world.blocks.power", }else{
"io.anuke.mindustry.world.blocks.production", //TODO generate dynamically instead of doing.. this
"io.anuke.mindustry.world.blocks.sandbox", Class<? extends Block> type = resolve(value.getString("type"),
"io.anuke.mindustry.world.blocks.storage", "io.anuke.mindustry.world",
"io.anuke.mindustry.world.blocks.units" "io.anuke.mindustry.world.blocks",
); "io.anuke.mindustry.world.blocks.defense",
"io.anuke.mindustry.world.blocks.defense.turrets",
"io.anuke.mindustry.world.blocks.distribution",
"io.anuke.mindustry.world.blocks.logic",
"io.anuke.mindustry.world.blocks.power",
"io.anuke.mindustry.world.blocks.production",
"io.anuke.mindustry.world.blocks.sandbox",
"io.anuke.mindustry.world.blocks.storage",
"io.anuke.mindustry.world.blocks.units"
);
block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name);
}
Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name);
currentContent = block; currentContent = block;
read(() -> { read(() -> {
if(value.has("consumes")){ if(value.has("consumes")){