Revert "use getUngeneratedBlock for trees"

This reverts commit ca8cc8bc
This commit is contained in:
dfsek 2021-01-13 20:03:01 -07:00
parent ca8cc8bc66
commit 56a0d5d15b
10 changed files with 26 additions and 64 deletions

View File

@ -45,11 +45,11 @@ public class GenericLoaders implements LoaderRegistrar {
.registerLoader(GridSpawn.class, new GridSpawnLoader()) .registerLoader(GridSpawn.class, new GridSpawnLoader())
.registerLoader(PaletteHolder.class, new PaletteHolderLoader()) .registerLoader(PaletteHolder.class, new PaletteHolderLoader())
.registerLoader(PaletteLayer.class, new PaletteLayerLoader()) .registerLoader(PaletteLayer.class, new PaletteLayerLoader())
.registerLoader(FloraLayer.class, new FloraLayerLoader(main)) .registerLoader(FloraLayer.class, new FloraLayerLoader())
.registerLoader(Ore.Type.class, (t, o, l) -> Ore.Type.valueOf(o.toString())) .registerLoader(Ore.Type.class, (t, o, l) -> Ore.Type.valueOf(o.toString()))
.registerLoader(OreConfig.class, new OreConfigLoader()) .registerLoader(OreConfig.class, new OreConfigLoader())
.registerLoader(NoiseBuilder.class, new NoiseBuilderLoader()) .registerLoader(NoiseBuilder.class, new NoiseBuilderLoader())
.registerLoader(TreeLayer.class, new TreeLayerLoader(main)) .registerLoader(TreeLayer.class, new TreeLayerLoader())
.registerLoader(MaterialSet.class, new MaterialSetLoader()) .registerLoader(MaterialSet.class, new MaterialSetLoader())
.registerLoader(OreHolder.class, new OreHolderLoader()) .registerLoader(OreHolder.class, new OreHolderLoader())
.registerLoader(TerraFlora.Search.class, (t, o, l) -> TerraFlora.Search.valueOf(o.toString())) .registerLoader(TerraFlora.Search.class, (t, o, l) -> TerraFlora.Search.valueOf(o.toString()))

View File

@ -186,10 +186,6 @@ public class Vector2 implements Cloneable {
return FastMath.floorToInt(z); return FastMath.floorToInt(z);
} }
public Vector3 toVector3(double y) {
return new Vector3(x, y, z);
}
@Override @Override
public String toString() { public String toString() {
return "(" + x + ", " + z + ")"; return "(" + x + ", " + z + ")";

View File

@ -68,7 +68,7 @@ public class StructureScript {
.registerFunction("loot", new LootFunctionBuilder(main, lootRegistry)) .registerFunction("loot", new LootFunctionBuilder(main, lootRegistry))
.registerFunction("entity", new EntityFunctionBuilder(main)) .registerFunction("entity", new EntityFunctionBuilder(main))
.registerFunction("getBiome", new BiomeFunctionBuilder(main)) .registerFunction("getBiome", new BiomeFunctionBuilder(main))
.registerFunction("getBlock", new CheckBlockFunctionBuilder(main)) .registerFunction("getBlock", new CheckBlockFunctionBuilder())
.registerFunction("state", new StateFunctionBuilder(main)) .registerFunction("state", new StateFunctionBuilder(main))
.registerFunction("originX", new ZeroArgFunctionBuilder<Number>(arguments -> arguments.getBuffer().getOrigin().getX(), Returnable.ReturnType.NUMBER)) .registerFunction("originX", new ZeroArgFunctionBuilder<Number>(arguments -> arguments.getBuffer().getOrigin().getX(), Returnable.ReturnType.NUMBER))
.registerFunction("originY", new ZeroArgFunctionBuilder<Number>(arguments -> arguments.getBuffer().getOrigin().getY(), Returnable.ReturnType.NUMBER)) .registerFunction("originY", new ZeroArgFunctionBuilder<Number>(arguments -> arguments.getBuffer().getOrigin().getY(), Returnable.ReturnType.NUMBER))

View File

@ -1,6 +1,5 @@
package com.dfsek.terra.api.structures.script.builders; package com.dfsek.terra.api.structures.script.builders;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.Returnable;
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder; import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
import com.dfsek.terra.api.structures.script.functions.CheckBlockFunction; import com.dfsek.terra.api.structures.script.functions.CheckBlockFunction;
@ -9,16 +8,10 @@ import com.dfsek.terra.api.structures.tokenizer.Position;
import java.util.List; import java.util.List;
public class CheckBlockFunctionBuilder implements FunctionBuilder<CheckBlockFunction> { public class CheckBlockFunctionBuilder implements FunctionBuilder<CheckBlockFunction> {
private final TerraPlugin main;
public CheckBlockFunctionBuilder(TerraPlugin main) {
this.main = main;
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public CheckBlockFunction build(List<Returnable<?>> argumentList, Position position) { public CheckBlockFunction build(List<Returnable<?>> argumentList, Position position) {
return new CheckBlockFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(2), position, main); return new CheckBlockFunction((Returnable<Number>) argumentList.get(0), (Returnable<Number>) argumentList.get(1), (Returnable<Number>) argumentList.get(2), position);
} }
@Override @Override

View File

@ -1,10 +1,7 @@
package com.dfsek.terra.api.structures.script.functions; package com.dfsek.terra.api.structures.script.functions;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector2;
import com.dfsek.terra.api.math.vector.Vector3; import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments; import com.dfsek.terra.api.structures.parser.lang.ImplementationArguments;
import com.dfsek.terra.api.structures.parser.lang.Returnable; import com.dfsek.terra.api.structures.parser.lang.Returnable;
import com.dfsek.terra.api.structures.parser.lang.functions.Function; import com.dfsek.terra.api.structures.parser.lang.functions.Function;
@ -16,14 +13,12 @@ import net.jafama.FastMath;
public class CheckBlockFunction implements Function<String> { public class CheckBlockFunction implements Function<String> {
private final Returnable<Number> x, y, z; private final Returnable<Number> x, y, z;
private final Position position; private final Position position;
private final TerraPlugin main;
public CheckBlockFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Position position, TerraPlugin main) { public CheckBlockFunction(Returnable<Number> x, Returnable<Number> y, Returnable<Number> z, Position position) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
this.position = position; this.position = position;
this.main = main;
} }
@ -35,11 +30,7 @@ public class CheckBlockFunction implements Function<String> {
RotationUtil.rotateVector(xz, arguments.getRotation()); RotationUtil.rotateVector(xz, arguments.getRotation());
TerraWorld world = main.getWorld(arguments.getBuffer().getOrigin().getWorld()); String data = arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).doubleValue(), FastMath.roundToInt(xz.getZ()))).getBlock().getBlockData().getAsString();
BlockData blockData = world.getUngeneratedBlock(arguments.getBuffer().getOrigin().clone().add(new Vector3(FastMath.roundToInt(xz.getX()), y.apply(implementationArguments).doubleValue(), FastMath.roundToInt(xz.getZ()))));
String data = blockData.getAsString();
if(data.contains("[")) return data.substring(0, data.indexOf('[')); // Strip properties if(data.contains("[")) return data.substring(0, data.indexOf('[')); // Strip properties
else return data; else return data;
} }

View File

@ -7,7 +7,6 @@ import com.dfsek.tectonic.loading.TypeLoader;
import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.ProbabilityCollection;
import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite; import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.config.loaders.Types; import com.dfsek.terra.config.loaders.Types;
import com.dfsek.terra.generation.config.NoiseBuilder; import com.dfsek.terra.generation.config.NoiseBuilder;
@ -18,12 +17,6 @@ import java.util.Map;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class FloraLayerLoader implements TypeLoader<FloraLayer> { public class FloraLayerLoader implements TypeLoader<FloraLayer> {
private final TerraPlugin main;
public FloraLayerLoader(TerraPlugin main) {
this.main = main;
}
@Override @Override
public FloraLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException { public FloraLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
Map<String, Object> map = (Map<String, Object>) o; Map<String, Object> map = (Map<String, Object>) o;
@ -39,12 +32,12 @@ public class FloraLayerLoader implements TypeLoader<FloraLayer> {
} catch(ConfigException e) { } catch(ConfigException e) {
throw new LoadException("Unable to load noise", e); throw new LoadException("Unable to load noise", e);
} }
return new FloraLayer(density, range, items, sampler.build(2403), main); return new FloraLayer(density, range, items, sampler.build(2403));
} }
sampler = new NoiseBuilder(); sampler = new NoiseBuilder();
sampler.setType(FastNoiseLite.NoiseType.WhiteNoise); sampler.setType(FastNoiseLite.NoiseType.WhiteNoise);
sampler.setDimensions(3); sampler.setDimensions(3);
return new FloraLayer(density, range, items, sampler.build(2403), main); return new FloraLayer(density, range, items, sampler.build(2403));
} }
} }

View File

@ -8,7 +8,6 @@ import com.dfsek.tectonic.loading.TypeLoader;
import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.ProbabilityCollection;
import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite; import com.dfsek.terra.api.math.noise.samplers.FastNoiseLite;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.config.loaders.Types; import com.dfsek.terra.config.loaders.Types;
import com.dfsek.terra.generation.config.NoiseBuilder; import com.dfsek.terra.generation.config.NoiseBuilder;
@ -19,12 +18,6 @@ import java.util.Map;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class TreeLayerLoader implements TypeLoader<TreeLayer> { public class TreeLayerLoader implements TypeLoader<TreeLayer> {
private final TerraPlugin main;
public TreeLayerLoader(TerraPlugin main) {
this.main = main;
}
@Override @Override
public TreeLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException { public TreeLayer load(Type type, Object o, ConfigLoader configLoader) throws LoadException {
Map<String, Object> map = (Map<String, Object>) o; Map<String, Object> map = (Map<String, Object>) o;
@ -40,12 +33,12 @@ public class TreeLayerLoader implements TypeLoader<TreeLayer> {
} catch(ConfigException e) { } catch(ConfigException e) {
throw new LoadException("Unable to load noise", e); throw new LoadException("Unable to load noise", e);
} }
return new TreeLayer(density, range, items, sampler.build(2403), main); return new TreeLayer(density, range, items, sampler.build(2403));
} }
sampler.setType(FastNoiseLite.NoiseType.WhiteNoise); sampler.setType(FastNoiseLite.NoiseType.WhiteNoise);
sampler.setDimensions(3); sampler.setDimensions(3);
return new TreeLayer(density, range, items, sampler.build(2403), main); return new TreeLayer(density, range, items, sampler.build(2403));
} }
} }

View File

@ -4,24 +4,25 @@ import com.dfsek.terra.api.math.ProbabilityCollection;
import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler; import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector2;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.Chunk;
public abstract class PlaceableLayer<T> { public abstract class PlaceableLayer<T> {
protected final double density; protected final double density;
protected final Range level; protected final Range level;
protected final ProbabilityCollection<T> layer; protected final ProbabilityCollection<T> layer;
protected final TerraPlugin main;
protected final NoiseSampler noise; protected final NoiseSampler noise;
public PlaceableLayer(double density, Range level, ProbabilityCollection<T> layer, NoiseSampler noise, TerraPlugin main) { public PlaceableLayer(double density, Range level, ProbabilityCollection<T> layer, NoiseSampler noise) {
this.density = density; this.density = density;
this.level = level; this.level = level;
this.layer = layer; this.layer = layer;
this.main = main;
this.noise = noise; this.noise = noise;
} }
public NoiseSampler getNoise() {
return noise;
}
public double getDensity() { public double getDensity() {
return density; return density;
} }

View File

@ -4,15 +4,14 @@ import com.dfsek.terra.api.math.ProbabilityCollection;
import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler; import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector2;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.world.flora.Flora; import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.population.items.PlaceableLayer; import com.dfsek.terra.population.items.PlaceableLayer;
public class FloraLayer extends PlaceableLayer<Flora> { public class FloraLayer extends PlaceableLayer<Flora> {
public FloraLayer(double density, Range level, ProbabilityCollection<Flora> layer, NoiseSampler noise, TerraPlugin main) { public FloraLayer(double density, Range level, ProbabilityCollection<Flora> layer, NoiseSampler noise) {
super(density, level, layer, noise, main); super(density, level, layer, noise);
} }
public double getDensity() { public double getDensity() {

View File

@ -1,12 +1,11 @@
package com.dfsek.terra.population.items.tree; package com.dfsek.terra.population.items.tree;
import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.math.ProbabilityCollection; import com.dfsek.terra.api.math.ProbabilityCollection;
import com.dfsek.terra.api.math.Range; import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.noise.samplers.NoiseSampler; import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
import com.dfsek.terra.api.math.vector.Vector2; import com.dfsek.terra.api.math.vector.Vector2;
import com.dfsek.terra.api.platform.TerraPlugin; import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockData; import com.dfsek.terra.api.platform.block.BlockFace;
import com.dfsek.terra.api.platform.world.Chunk; import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.world.tree.Tree; import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.population.items.PlaceableLayer; import com.dfsek.terra.population.items.PlaceableLayer;
@ -14,21 +13,18 @@ import com.dfsek.terra.util.PopulationUtil;
public class TreeLayer extends PlaceableLayer<Tree> { public class TreeLayer extends PlaceableLayer<Tree> {
public TreeLayer(double density, Range level, ProbabilityCollection<Tree> layer, NoiseSampler noise, TerraPlugin main) { public TreeLayer(double density, Range level, ProbabilityCollection<Tree> layer, NoiseSampler noise) {
super(density, level, layer, noise, main); super(density, level, layer, noise);
} }
@Override @Override
public void place(Chunk chunk, Vector2 coords) { public void place(Chunk chunk, Vector2 coords) {
Tree item = layer.get(noise, coords.getX(), coords.getZ()); Tree item = layer.get(noise, coords.getX(), coords.getZ());
TerraWorld terraWorld = main.getWorld(chunk.getWorld()); Block current = chunk.getBlock((int) coords.getX(), level.getMax(), (int) coords.getZ());
int cx = chunk.getX() << 4; for(int ignored : level) {
int cz = chunk.getZ() << 4; current = current.getRelative(BlockFace.DOWN);
BlockData current; if(item.getSpawnable().contains(current.getType())) {
for(int y : level) { item.plant(current.getLocation().add(0, 1, 0), PopulationUtil.getRandom(chunk));
current = terraWorld.getUngeneratedBlock(coords.getBlockX() + cx, y, coords.getBlockZ() + cz);
if(item.getSpawnable().contains(current.getMaterial())) {
item.plant(coords.toVector3(y).add(cx, 1, cz).toLocation(chunk.getWorld()), PopulationUtil.getRandom(chunk));
} }
} }
} }