Block tech tree mods

This commit is contained in:
Anuken
2019-10-01 21:47:02 -04:00
parent 5b8c237a1e
commit d9b8335e0e
3 changed files with 20 additions and 8 deletions

View File

@@ -31,7 +31,7 @@ import static io.anuke.arc.Core.*;
public class Vars implements Loadable{ public class Vars implements Loadable{
/** Whether to load locales.*/ /** Whether to load locales.*/
public static boolean loadLocales = true; public static boolean loadLocales = true;
/** Maximum number of broken blocks.*/ /** Maximum number of broken blocks. TODO implement or remove.*/
public static final int maxBrokenBlocks = 256; public static final int maxBrokenBlocks = 256;
/** IO buffer size. */ /** IO buffer size. */
public static final int bufferSize = 8192; public static final int bufferSize = 8192;

View File

@@ -13,6 +13,7 @@ public class TechTree implements ContentList{
@Override @Override
public void load(){ public void load(){
TechNode.context = null;
all = new Array<>(); all = new Array<>();
root = node(coreShard, () -> { root = node(coreShard, () -> {
@@ -302,7 +303,7 @@ public class TechTree implements ContentList{
}); });
} }
private TechNode node(Block block, Runnable children){ private static TechNode node(Block block, Runnable children){
ItemStack[] requirements = new ItemStack[block.requirements.length]; ItemStack[] requirements = new ItemStack[block.requirements.length];
for(int i = 0; i < requirements.length; i++){ for(int i = 0; i < requirements.length; i++){
requirements[i] = new ItemStack(block.requirements[i].item, 30 + block.requirements[i].amount * 6); requirements[i] = new ItemStack(block.requirements[i].item, 30 + block.requirements[i].amount * 6);
@@ -311,10 +312,15 @@ public class TechTree implements ContentList{
return new TechNode(block, requirements, children); return new TechNode(block, requirements, children);
} }
private TechNode node(Block block){ private static TechNode node(Block block){
return node(block, () -> {}); return node(block, () -> {});
} }
public static void create(Block parent, Block block){
TechNode.context = all.find(t -> t.block == parent);
node(block, () -> {});
}
public static class TechNode{ public static class TechNode{
static TechNode context; static TechNode context;
@@ -322,19 +328,22 @@ public class TechTree implements ContentList{
public final ItemStack[] requirements; public final ItemStack[] requirements;
public final Array<TechNode> children = new Array<>(); public final Array<TechNode> children = new Array<>();
TechNode(Block block, ItemStack[] requirements, Runnable children){ TechNode(TechNode ccontext, Block block, ItemStack[] requirements, Runnable children){
if(context != null){ if(ccontext != null){
context.children.add(this); ccontext.children.add(this);
} }
this.block = block; this.block = block;
this.requirements = requirements; this.requirements = requirements;
TechNode last = context;
context = this; context = this;
children.run(); children.run();
context = last; context = ccontext;
all.add(this); all.add(this);
} }
TechNode(Block block, ItemStack[] requirements, Runnable children){
this(context, block, requirements, children);
}
} }
} }

View File

@@ -70,6 +70,9 @@ public class ContentParser{
Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name); Block block = type.getDeclaredConstructor(String.class).newInstance(mod + "-" + name);
read(() -> { read(() -> {
readFields(block, value, true); readFields(block, value, true);
if(value.has("research")){
TechTree.create(Vars.content.getByName(ContentType.block, value.get("research").asString()), block);
}
//make block visible //make block visible
if(block.requirements != null){ if(block.requirements != null){