mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-06 07:46:13 +00:00
Reimplement structure trees with TerraScripts
This commit is contained in:
@@ -21,7 +21,7 @@ public class Block implements Item<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnLevel apply(Location location, Rotation rotation, int recursions) {
|
||||
public synchronized ReturnLevel apply(Location location, Rotation rotation, int recursions) {
|
||||
for(Item<?> item : items) {
|
||||
Object result = item.apply(location, rotation, recursions);
|
||||
if(result instanceof ReturnLevel) {
|
||||
@@ -33,7 +33,7 @@ public class Block implements Item<Block.ReturnLevel> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnLevel apply(Location location, Chunk chunk, Rotation rotation, int recursions) {
|
||||
public synchronized ReturnLevel apply(Location location, Chunk chunk, Rotation rotation, int recursions) {
|
||||
for(Item<?> item : items) {
|
||||
Object result = item.apply(location, chunk, rotation, recursions);
|
||||
if(result instanceof ReturnLevel) {
|
||||
|
||||
@@ -19,14 +19,14 @@ public class Assignment<T> implements Item<T> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public T apply(Location location, Rotation rotation, int recursions) {
|
||||
public synchronized T apply(Location location, Rotation rotation, int recursions) {
|
||||
T val = value.apply(location, rotation, recursions);
|
||||
delegate.setValue(val);
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T apply(Location location, Chunk chunk, Rotation rotation, int recursions) {
|
||||
public synchronized T apply(Location location, Chunk chunk, Rotation rotation, int recursions) {
|
||||
T val = value.apply(location, chunk, rotation, recursions);
|
||||
delegate.setValue(val);
|
||||
return val;
|
||||
|
||||
@@ -19,12 +19,12 @@ public class Getter implements Returnable<Object> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(Location location, Rotation rotation, int recursions) {
|
||||
public synchronized Object apply(Location location, Rotation rotation, int recursions) {
|
||||
return delegate.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object apply(Location location, Chunk chunk, Rotation rotation, int recursions) {
|
||||
public synchronized Object apply(Location location, Chunk chunk, Rotation rotation, int recursions) {
|
||||
return delegate.getValue();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.dfsek.terra.config.factories.FloraFactory;
|
||||
import com.dfsek.terra.config.factories.OreFactory;
|
||||
import com.dfsek.terra.config.factories.PaletteFactory;
|
||||
import com.dfsek.terra.config.factories.TerraFactory;
|
||||
import com.dfsek.terra.config.factories.TreeFactory;
|
||||
import com.dfsek.terra.config.files.FolderLoader;
|
||||
import com.dfsek.terra.config.files.Loader;
|
||||
import com.dfsek.terra.config.files.ZIPLoader;
|
||||
@@ -37,6 +38,7 @@ import com.dfsek.terra.config.templates.CarverTemplate;
|
||||
import com.dfsek.terra.config.templates.FloraTemplate;
|
||||
import com.dfsek.terra.config.templates.OreTemplate;
|
||||
import com.dfsek.terra.config.templates.PaletteTemplate;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.generation.items.TerraStructure;
|
||||
import com.dfsek.terra.generation.items.ores.Ore;
|
||||
import com.dfsek.terra.registry.BiomeGridRegistry;
|
||||
@@ -143,20 +145,22 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
}
|
||||
abstractConfigLoader
|
||||
.registerLoader(LootTable.class, new LootTableLoader(loader, main)); // These loaders need access to the Loader instance to get files.
|
||||
loader
|
||||
.open("palettes", ".yml").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new), main)).close()
|
||||
.open("ores", ".yml").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new), main)).close()
|
||||
.open("flora", ".yml").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new), main)).close()
|
||||
.open("carving", ".yml").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this, main)), main)).close()
|
||||
.open("grids", ".yml").then(streams -> buildAll(new BiomeGridFactory(), biomeGridRegistry, abstractConfigLoader.load(streams, BiomeGridTemplate::new), main)).close();
|
||||
|
||||
|
||||
loader.open("structures/data", ".tesf").then(streams -> streams.forEach(stream -> {
|
||||
StructureScript structureScript = new StructureScript(stream, main, scriptRegistry);
|
||||
scriptRegistry.add(structureScript.getId(), structureScript);
|
||||
})).close();
|
||||
|
||||
loader
|
||||
.open("palettes", ".yml").then(streams -> buildAll(new PaletteFactory(), paletteRegistry, abstractConfigLoader.load(streams, PaletteTemplate::new), main)).close()
|
||||
.open("ores", ".yml").then(streams -> buildAll(new OreFactory(), oreRegistry, abstractConfigLoader.load(streams, OreTemplate::new), main)).close()
|
||||
.open("structures/trees", ".yml").then(streams -> buildAll(new TreeFactory(), treeRegistry, abstractConfigLoader.load(streams, TreeTemplate::new), main)).close()
|
||||
.open("flora", ".yml").then(streams -> buildAll(new FloraFactory(), floraRegistry, abstractConfigLoader.load(streams, FloraTemplate::new), main)).close()
|
||||
.open("carving", ".yml").then(streams -> buildAll(new CarverFactory(this), carverRegistry, abstractConfigLoader.load(streams, CarverTemplate::new), main)).close()
|
||||
.open("biomes", ".yml").then(streams -> buildAll(new BiomeFactory(this), biomeRegistry, abstractConfigLoader.load(streams, () -> new BiomeTemplate(this, main)), main)).close()
|
||||
.open("grids", ".yml").then(streams -> buildAll(new BiomeGridFactory(), biomeGridRegistry, abstractConfigLoader.load(streams, BiomeGridTemplate::new), main)).close();
|
||||
|
||||
|
||||
for(UserDefinedBiome b : biomeRegistry.entries()) {
|
||||
try {
|
||||
Objects.requireNonNull(b.getErode()); // Throws NPE if it cannot load erosion biomes.
|
||||
@@ -237,7 +241,8 @@ public class ConfigPack implements LoaderRegistrar {
|
||||
.registerLoader(UserDefinedCarver.class, carverRegistry)
|
||||
.registerLoader(Flora.class, floraRegistry)
|
||||
.registerLoader(Ore.class, oreRegistry)
|
||||
.registerLoader(Tree.class, treeRegistry);
|
||||
.registerLoader(Tree.class, treeRegistry)
|
||||
.registerLoader(StructureScript.class, scriptRegistry);
|
||||
}
|
||||
|
||||
public ScriptRegistry getScriptRegistry() {
|
||||
|
||||
@@ -3,14 +3,14 @@ package com.dfsek.terra.config.templates;
|
||||
import com.dfsek.tectonic.annotations.Abstractable;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class TreeTemplate extends AbstractableTemplate {
|
||||
@Value("files")
|
||||
@Value("script")
|
||||
@Abstractable
|
||||
private ProbabilityCollection<Void> structures;
|
||||
private StructureScript structure;
|
||||
|
||||
@Value("id")
|
||||
private String id;
|
||||
@@ -24,8 +24,8 @@ public class TreeTemplate extends AbstractableTemplate {
|
||||
@Abstractable
|
||||
private MaterialSet spawnable;
|
||||
|
||||
public ProbabilityCollection<Void> getStructures() {
|
||||
return structures;
|
||||
public StructureScript getStructures() {
|
||||
return structure;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.dfsek.terra.generation.items.tree;
|
||||
|
||||
import com.dfsek.terra.api.math.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.math.vector.Location;
|
||||
import com.dfsek.terra.api.platform.TerraPlugin;
|
||||
import com.dfsek.terra.api.structures.script.StructureScript;
|
||||
import com.dfsek.terra.api.structures.structure.Rotation;
|
||||
import com.dfsek.terra.api.world.tree.Tree;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
|
||||
@@ -11,26 +11,18 @@ import java.util.Random;
|
||||
public class TerraTree implements Tree {
|
||||
private final MaterialSet spawnable;
|
||||
private final int yOffset;
|
||||
private final ProbabilityCollection<Void> structure;
|
||||
private final StructureScript structure;
|
||||
|
||||
public TerraTree(MaterialSet spawnable, int yOffset, ProbabilityCollection<Void> structure) {
|
||||
public TerraTree(MaterialSet spawnable, int yOffset, StructureScript structure) {
|
||||
this.spawnable = spawnable;
|
||||
this.yOffset = yOffset;
|
||||
this.structure = structure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plant(Location location, Random random) {
|
||||
/*
|
||||
Location mut = location.clone().subtract(0, yOffset, 0);
|
||||
if(!spawnable.contains(location.getBlock().getType())) return false;
|
||||
Structure struc = structure.get(random);
|
||||
Rotation rotation = Rotation.fromDegrees(random.nextInt(4) * 90);
|
||||
if(!struc.checkSpawns(mut, rotation, null)) return false;
|
||||
struc.paste(mut, rotation, null);*/
|
||||
public synchronized boolean plant(Location location, Random random) {
|
||||
structure.execute(location.clone().add(0, yOffset, 0), Rotation.fromDegrees(90 * random.nextInt(4)), 0);
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,29 +30,4 @@ public class TerraTree implements Tree {
|
||||
return spawnable;
|
||||
}
|
||||
|
||||
public boolean plantBlockCheck(Location location, Random random, TerraPlugin main) {
|
||||
/*
|
||||
Location mut = location.clone().subtract(0, yOffset, 0);
|
||||
if(!spawnable.contains(location.getBlock().getType())) return false;
|
||||
Structure struc = structure.get(random);
|
||||
Rotation rotation = Rotation.fromDegrees(random.nextInt(4) * 90);
|
||||
StructureInfo info = struc.getStructureInfo();
|
||||
for(StructureContainedBlock spawn : struc.getSpawns()) {
|
||||
Vector2 rot = RotationUtil.rotateVector(new Vector2(spawn.getX() - info.getCenterX(), spawn.getZ() - info.getCenterZ()), rotation);
|
||||
int x = (int) rot.getX();
|
||||
int z = (int) rot.getZ();
|
||||
switch(spawn.getRequirement()) {
|
||||
case AIR:
|
||||
if(!mut.clone().add(x, spawn.getY() - 1, z).getBlock().isPassable()) return false;
|
||||
break;
|
||||
case LAND:
|
||||
if(!mut.clone().add(x, spawn.getY() - 1, z).getBlock().getType().isSolid()) return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
struc.paste(mut, rotation, main);
|
||||
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,12 @@ public class TreeRegistry extends TerraRegistry<Tree> {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(String name, Tree value) {
|
||||
System.out.println("Added " + name);
|
||||
return super.add(name, value);
|
||||
}
|
||||
|
||||
private final class FractalTreeHolder implements Tree {
|
||||
private final FractalTree tree;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user