remove legacy fractal trees (will be available in an addon)

This commit is contained in:
dfsek 2021-03-16 21:49:08 -07:00
parent cda2d4688c
commit 1b70766a17
25 changed files with 16 additions and 689 deletions

View File

@ -1,4 +1,4 @@
package com.dfsek.terra.api.world.tree;
package com.dfsek.terra.api.platform.world;
import com.dfsek.terra.api.math.vector.Location;

View File

@ -1,32 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.entity.Entity;
import java.util.function.Consumer;
public class EntitySpawnHolder {
private final Location l;
private final Class<? extends Entity> e;
private final Consumer<Entity> c;
public EntitySpawnHolder(Location l, Class<? extends Entity> e, Consumer<Entity> c) {
this.l = l;
this.e = e;
this.c = c;
}
@SuppressWarnings("rawtypes")
public Class getEntity() {
return e;
}
public Consumer<Entity> getConsumer() {
return c;
}
public Location getLocation() {
return l;
}
}

View File

@ -1,48 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.entity.Entity;
import com.dfsek.terra.api.platform.entity.EntityType;
import com.dfsek.terra.api.util.collections.MaterialSet;
import java.util.Random;
import java.util.function.Consumer;
public abstract class FractalTree {
protected final TerraPlugin main;
public abstract MaterialSet getSpawnable();
/**
* Instantiates a TreeGrower at an origin location.
*/
public FractalTree(TerraPlugin plugin) {
this.main = plugin;
}
/**
* Sets a block in the tree's storage map to a material.
*
* @param l - The location to set.
* @param m - The material to which it will be set.
*/
public void setBlock(Location l, BlockData m) {
l.getBlock().setBlockData(m, false);
}
public TerraPlugin getMain() {
return main;
}
/**
* Grows the tree in memory. Intended to be invoked from an async thread.
*/
public abstract void grow(Location origin, Random random);
public void spawnEntity(Location spawn, EntityType type, Consumer<Entity> consumer) {
consumer.accept(spawn.getWorld().spawnEntity(spawn, type));
}
}

View File

@ -1,68 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import java.util.Random;
public class TreeGeometry {
private final FractalTree tree;
public TreeGeometry(FractalTree tree) {
this.tree = tree;
}
public static Vector3 getPerpendicular(Vector3 v) {
return v.getZ() < v.getX() ? new Vector3(v.getY(), -v.getX(), 0) : new Vector3(0, -v.getZ(), v.getY());
}
public FractalTree getTree() {
return tree;
}
public void generateSphere(Location l, BlockData m, int radius, boolean overwrite, Random r) {
generateSphere(l, new ProbabilityCollection<BlockData>().add(m, 1), radius, overwrite, r);
}
public void generateCylinder(Location l, BlockData m, int radius, int height, boolean overwrite, Random r) {
generateCylinder(l, new ProbabilityCollection<BlockData>().add(m, 1), radius, height, overwrite, r);
}
public void generateSphere(Location l, ProbabilityCollection<BlockData> m, int radius, boolean overwrite, Random r) {
for(int x = -radius; x <= radius; x++) {
for(int y = -radius; y <= radius; y++) {
for(int z = -radius; z <= radius; z++) {
Vector3 position = l.toVector().clone().add(new Vector3(x, y, z));
if(l.toVector().distance(position) <= radius + 0.5 && (overwrite || position.toLocation(l.getWorld()).getBlock().isEmpty()))
tree.setBlock(position.toLocation(l.getWorld()), m.get(r));
}
}
}
}
public void generateSponge(Location l, ProbabilityCollection<BlockData> m, int radius, boolean overwrite, int sponginess, Random r) {
for(int x = -radius; x <= radius; x++) {
for(int y = -radius; y <= radius; y++) {
for(int z = -radius; z <= radius; z++) {
Vector3 position = l.toVector().clone().add(new Vector3(x, y, z));
if(r.nextInt(100) < sponginess && l.toVector().distance(position) <= radius + 0.5 && (overwrite || position.toLocation(l.getWorld()).getBlock().isEmpty()))
tree.setBlock(position.toLocation(l.getWorld()), m.get(r));
}
}
}
}
public void generateCylinder(Location l, ProbabilityCollection<BlockData> m, int radius, int height, boolean overwrite, Random r) {
for(int x = -radius; x <= radius; x++) {
for(int y = 0; y <= height; y++) {
for(int z = -radius; z <= radius; z++) {
Vector3 position = l.toVector().clone().add(new Vector3(x, 0, z));
if(l.toVector().distance(position) <= radius + 0.5 && (overwrite || position.toLocation(l.getWorld()).getBlock().isEmpty()))
tree.setBlock(position.toLocation(l.getWorld()), m.get(r));
}
}
}
}
}

View File

@ -1,35 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal.trees;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import java.util.Random;
public class Cactus extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:sand"),
main.getWorldHandle().createBlockData("minecraft:red_sand"));
}
/**
* Instantiates a TreeGrower at an origin location.
*/
public Cactus(TerraPlugin main) {
super(main);
}
/**
* Grows the tree in memory. Intended to be invoked from an async thread.
*/
@Override
public void grow(Location origin, Random random) {
BlockData cactus = getMain().getWorldHandle().createBlockData("minecraft:cactus");
int h = random.nextInt(4) + 1;
for(int i = 0; i < h; i++) setBlock(origin.clone().add(0, i, 0), cactus);
}
}

View File

@ -1,57 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal.trees;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import com.dfsek.terra.api.world.tree.fractal.TreeGeometry;
import java.util.Random;
public class IceSpike extends FractalTree {
private final TreeGeometry geo;
private final ProbabilityCollection<BlockData> ice;
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:stone"),
main.getWorldHandle().createBlockData("minecraft:gravel"),
main.getWorldHandle().createBlockData("minecraft:snow_block"),
main.getWorldHandle().createBlockData("minecraft:grass_block"));
}
/**
* Instantiates a TreeGrower at an origin location.
*/
public IceSpike(TerraPlugin main) {
super(main);
geo = new TreeGeometry(this);
WorldHandle handle = main.getWorldHandle();
ice = new ProbabilityCollection<BlockData>().add(handle.createBlockData("minecraft:packed_ice"), 95).add(handle.createBlockData("minecraft:blue_ice"), 5);
}
private double getOffset(Random r) {
return (r.nextDouble() - 0.5D);
}
/**
* Grows the tree in memory. Intended to be invoked from an async thread.
*/
@Override
public void grow(Location origin, Random random) {
Vector3 direction = new Vector3(getOffset(random), 0, getOffset(random));
Location l1 = origin.clone();
int h = random.nextInt(16) + 8;
for(int i = 0; i < h; i++) {
geo.generateSponge(l1.clone().add(0, i, 0).add(direction.clone().multiply(i)), ice, (int) ((1 - ((double) i / h)) * 2 + 1), true, 80, random);
}
for(int i = 0; i < h / 3; i++) {
setBlock(l1.clone().add(0, h + i, 0).add(direction.clone().multiply(h + i)), ice.get(random));
}
}
}

View File

@ -1,66 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal.trees;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import com.dfsek.terra.api.world.tree.fractal.TreeGeometry;
import net.jafama.FastMath;
import java.util.Random;
public class OakTree extends FractalTree {
private final TreeGeometry geo;
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:podzol"),
main.getWorldHandle().createBlockData("minecraft:grass_block"));
}
/**
* Instantiates a TreeGrower at an origin location.
*/
public OakTree(TerraPlugin main) {
super(main);
geo = new TreeGeometry(this);
}
/**
* Grows the tree in memory. Intended to be invoked from an async thread.
*/
@Override
public void grow(Location origin, Random random) {
growBranch(origin.clone(), new Vector3(random.nextInt(5) - 2, random.nextInt(4) + 6, random.nextInt(5) - 2), 2, 0, random);
}
private void growBranch(Location l1, Vector3 diff, double d1, int recursions, Random r) {
BlockData wood = getMain().getWorldHandle().createBlockData("minecraft:oak_wood");
BlockData leaves = getMain().getWorldHandle().createBlockData("minecraft:oak_leaves");
if(recursions > 1) {
geo.generateSphere(l1, leaves, 1 + r.nextInt(2) + (3 - recursions), false, r);
if(recursions > 2) return;
}
if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI);
int d = (int) diff.length();
for(int i = 0; i < d; i++) {
geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), wood, FastMath.max((int) d1, 0), true, r);
}
double runningAngle = (double) 45 / (recursions + 1);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundX(FastMath.toRadians(runningAngle + getNoise(r))).rotateAroundZ(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundX(FastMath.toRadians(-runningAngle + getNoise(r))).rotateAroundZ(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundZ(FastMath.toRadians(runningAngle + getNoise(r))).rotateAroundX(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundZ(FastMath.toRadians(-runningAngle + getNoise(r))).rotateAroundX(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
}
private int getNoise(Random r) {
return r.nextInt(60) - 30;
}
}

View File

@ -1,56 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal.trees;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import java.util.Random;
public class ShatteredPillar extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone"));
}
/**
* Instantiates a TreeGrower at an origin location.
*/
public ShatteredPillar(TerraPlugin main) {
super(main);
}
/**
* Grows the tree in memory. Intended to be invoked from an async thread.
* @param origin
* @param random
*/
@Override
public void grow(Location origin, Random random) {
BlockData obsidian = getMain().getWorldHandle().createBlockData("minecraft:obsidian");
int h = random.nextInt(5) + 8;
int max = h;
for(int i = -h; i < h; i++) setBlock(origin.clone().add(0, i, 0), obsidian);
h = h + (random.nextBoolean() ? random.nextInt(3) + 1 : -(random.nextInt(3) + 1));
int[] crystalLoc = new int[] {0, 0};
if(h > max) {
max = h;
crystalLoc = new int[] {1, 0};
}
for(int i = -h; i < h; i++) setBlock(origin.clone().add(1, i, 0), obsidian);
h = h + (random.nextBoolean() ? random.nextInt(3) + 1 : -(random.nextInt(3) + 1));
if(h > max) {
max = h;
crystalLoc = new int[] {0, 1};
}
for(int i = -h; i < h; i++) setBlock(origin.clone().add(0, i, 1), obsidian);
h = h + (random.nextBoolean() ? random.nextInt(3) + 1 : -(random.nextInt(3) + 1));
if(h > max) {
max = h;
crystalLoc = new int[] {1, 1};
}
for(int i = -h; i < h; i++) setBlock(origin.clone().add(1, i, 1), obsidian);
}
}

View File

@ -1,75 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal.trees;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import com.dfsek.terra.api.world.tree.fractal.TreeGeometry;
import net.jafama.FastMath;
import java.util.Random;
public class ShatteredTree extends FractalTree {
private final TreeGeometry geo;
private final ProbabilityCollection<BlockData> bark;
private final ProbabilityCollection<BlockData> leaves;
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone"));
}
/**
* Instantiates a TreeGrower at an origin location.
*/
public ShatteredTree(TerraPlugin main) {
super(main);
geo = new TreeGeometry(this);
WorldHandle handle = main.getWorldHandle();
bark = new ProbabilityCollection<BlockData>()
.add(handle.createBlockData("minecraft:obsidian"), 1)
.add(handle.createBlockData("minecraft:black_concrete"), 1);
leaves = new ProbabilityCollection<BlockData>()
.add(handle.createBlockData("minecraft:purple_stained_glass"), 1)
.add(handle.createBlockData("minecraft:magenta_stained_glass"), 1);
}
/**
* Grows the tree in memory. Intended to be invoked from an async thread.
*/
@Override
public void grow(Location origin, Random random) {
growBranch(origin.clone(), new Vector3(random.nextInt(5) - 2, random.nextInt(4) + 6, random.nextInt(5) - 2), 1, 0, random);
}
private void growBranch(Location l1, Vector3 diff, double d1, int recursions, Random r) {
if(recursions > 2) {
geo.generateSphere(l1, leaves, 1 + r.nextInt(2), false, r);
return;
}
if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI);
int d = (int) diff.length();
for(int i = 0; i < d; i++) {
geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), bark, FastMath.max((int) d1, 0), true, r);
}
double runningAngle = (double) 45 / (recursions + 1);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.9).rotateAroundX(FastMath.toRadians(runningAngle + getNoise(r))).rotateAroundZ(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.9).rotateAroundX(FastMath.toRadians(-runningAngle + getNoise(r))).rotateAroundZ(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.9).rotateAroundZ(FastMath.toRadians(runningAngle + getNoise(r))).rotateAroundX(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.9).rotateAroundZ(FastMath.toRadians(-runningAngle + getNoise(r))).rotateAroundX(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
}
private int getNoise(Random r) {
return r.nextInt(90) - 45;
}
}

View File

@ -1,36 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal.trees;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import java.util.Random;
public class SmallShatteredPillar extends FractalTree {
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone"));
}
/**
* Instantiates a TreeGrower at an origin location.
*/
public SmallShatteredPillar(TerraPlugin main) {
super(main);
}
/**
* Grows the tree in memory. Intended to be invoked from an async thread.
* @param origin
* @param random
*/
@Override
public void grow(Location origin, Random random) {
int h = random.nextInt(5) + 5;
BlockData obsidian = getMain().getWorldHandle().createBlockData("minecraft:obsidian");
for(int i = -h; i < h; i++) setBlock(origin.clone().add(0, i, 0), obsidian);
}
}

View File

@ -1,75 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal.trees;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import com.dfsek.terra.api.world.tree.fractal.TreeGeometry;
import net.jafama.FastMath;
import java.util.Random;
public class SmallShatteredTree extends FractalTree {
private final TreeGeometry geo;
private final ProbabilityCollection<BlockData> bark;
private final ProbabilityCollection<BlockData> leaves;
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:end_stone"));
}
/**
* Instantiates a TreeGrower at an origin location.
*/
public SmallShatteredTree(TerraPlugin main) {
super(main);
geo = new TreeGeometry(this);
WorldHandle handle = main.getWorldHandle();
bark = new ProbabilityCollection<BlockData>()
.add(handle.createBlockData("minecraft:obsidian"), 1)
.add(handle.createBlockData("minecraft:black_concrete"), 1);
leaves = new ProbabilityCollection<BlockData>()
.add(handle.createBlockData("minecraft:purple_stained_glass"), 1)
.add(handle.createBlockData("minecraft:magenta_stained_glass"), 1);
}
/**
* Grows the tree in memory. Intended to be invoked from an async thread.
*/
@Override
public void grow(Location origin, Random random) {
growBranch(origin.clone(), new Vector3(random.nextInt(5) - 2, random.nextInt(3) + 4, random.nextInt(5) - 2), 1.5, 0, random);
}
private void growBranch(Location l1, Vector3 diff, double d1, int recursions, Random r) {
if(recursions > 2) {
geo.generateSphere(l1, leaves, 1 + r.nextInt(2) + (3 - recursions), false, r);
return;
}
if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI);
int d = (int) diff.length();
for(int i = 0; i < d; i++) {
geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), bark, FastMath.max((int) d1, 0), true, r);
}
double runningAngle = (double) 45 / (recursions + 1);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.7).rotateAroundX(FastMath.toRadians(runningAngle + getNoise(r))).rotateAroundZ(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.7).rotateAroundX(FastMath.toRadians(-runningAngle + getNoise(r))).rotateAroundZ(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.7).rotateAroundZ(FastMath.toRadians(runningAngle + getNoise(r))).rotateAroundX(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
growBranch(l1.clone().add(diff), diff.clone().multiply(0.7).rotateAroundZ(FastMath.toRadians(-runningAngle + getNoise(r))).rotateAroundX(FastMath.toRadians(getNoise(r))),
d1 - 1, recursions + 1, r);
}
private int getNoise(Random r) {
return r.nextInt(90) - 45;
}
}

View File

@ -1,53 +0,0 @@
package com.dfsek.terra.api.world.tree.fractal.trees;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.math.vector.Vector3;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import com.dfsek.terra.api.world.tree.fractal.TreeGeometry;
import net.jafama.FastMath;
import java.util.Random;
public class SpruceTree extends FractalTree {
private final TreeGeometry geo;
@Override
public MaterialSet getSpawnable() {
return MaterialSet.get(main.getWorldHandle().createBlockData("minecraft:podzol"),
main.getWorldHandle().createBlockData("minecraft:grass_block"));
}
/**
* Instantiates a TreeGrower at an origin location.
*/
public SpruceTree(TerraPlugin main) {
super(main);
geo = new TreeGeometry(this);
}
/**
* Grows the tree in memory. Intended to be invoked from an async thread.
*/
@Override
public void grow(Location origin, Random random) {
growTrunk(origin.clone(), new Vector3(0, 16 + random.nextInt(5), 0), random);
}
private void growTrunk(Location l1, Vector3 diff, Random r) {
if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI);
int d = (int) diff.length();
int rad = 7;
BlockData wood = getMain().getWorldHandle().createBlockData("minecraft:spruce_wood");
BlockData leaves = getMain().getWorldHandle().createBlockData("minecraft:spruce_leave");
for(int i = 0; i < d; i++) {
geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), wood, (int) ((i > d * 0.65) ? 0.5 : 1.5), true, r);
if(i > 3)
geo.generateCylinder(l1.clone().add(diff.clone().multiply((double) i / d)), leaves, (int) (((6 - (i % 4))) * (1.25 - ((double) i / d))), 1, false, r);
}
setBlock(l1.clone().add(diff), leaves);
setBlock(l1.clone().add(diff).add(0, 1, 0), leaves);
}
}

View File

@ -1,7 +1,7 @@
package com.dfsek.terra.config.factories;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.config.templates.TreeTemplate;
import com.dfsek.terra.world.population.items.tree.TerraTree;

View File

@ -1,11 +1,11 @@
package com.dfsek.terra.config.loaders;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.tree.Tree;
import java.lang.reflect.Type;
import java.util.Map;

View File

@ -5,9 +5,9 @@ import com.dfsek.tectonic.loading.ConfigLoader;
import com.dfsek.tectonic.loading.TypeLoader;
import com.dfsek.terra.api.math.Range;
import com.dfsek.terra.api.math.noise.samplers.noise.random.WhiteNoiseSampler;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.config.loaders.Types;
import com.dfsek.terra.world.population.items.tree.TreeLayer;

View File

@ -12,6 +12,7 @@ import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.event.events.config.ConfigPackPostLoadEvent;
import com.dfsek.terra.api.event.events.config.ConfigPackPreLoadEvent;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.structures.loot.LootTable;
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
@ -20,7 +21,6 @@ import com.dfsek.terra.api.util.seeded.NoiseSeeded;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.config.builder.BiomeBuilder;
import com.dfsek.terra.config.dummy.DummyWorld;
@ -120,7 +120,7 @@ public class ConfigPack implements LoaderRegistrar {
long l = System.nanoTime();
floraRegistry = new FloraRegistry(main);
paletteRegistry = new PaletteRegistry(main);
treeRegistry = new TreeRegistry(main);
treeRegistry = new TreeRegistry();
register(abstractConfigLoader);
register(selfLoader);
@ -156,7 +156,7 @@ public class ConfigPack implements LoaderRegistrar {
long l = System.nanoTime();
floraRegistry = new FloraRegistry(main);
paletteRegistry = new PaletteRegistry(main);
treeRegistry = new TreeRegistry(main);
treeRegistry = new TreeRegistry();
register(abstractConfigLoader);
register(selfLoader);

View File

@ -1,19 +1,15 @@
package com.dfsek.terra.config.pack;
import com.dfsek.tectonic.loading.object.ObjectTemplate;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.registry.LockedRegistry;
import com.dfsek.terra.api.structures.loot.LootTable;
import com.dfsek.terra.api.structures.parser.lang.functions.FunctionBuilder;
import com.dfsek.terra.api.structures.script.StructureScript;
import com.dfsek.terra.api.util.seeded.NoiseSeeded;
import com.dfsek.terra.api.world.biome.TerraBiome;
import com.dfsek.terra.api.world.biome.provider.BiomeProvider;
import com.dfsek.terra.api.world.flora.Flora;
import com.dfsek.terra.api.world.palette.Palette;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.carving.UserDefinedCarver;
import com.dfsek.terra.registry.OpenRegistry;
import com.dfsek.terra.world.TerraWorld;
@ -22,7 +18,6 @@ import com.dfsek.terra.world.population.items.TerraStructure;
import com.dfsek.terra.world.population.items.ores.Ore;
import java.util.Set;
import java.util.function.Supplier;
public class WorldConfig {
private final LockedRegistry<StructureScript> scriptRegistry;

View File

@ -1,77 +1,11 @@
package com.dfsek.terra.registry.config;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.block.BlockFace;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.api.world.tree.fractal.FractalTree;
import com.dfsek.terra.api.world.tree.fractal.trees.Cactus;
import com.dfsek.terra.api.world.tree.fractal.trees.IceSpike;
import com.dfsek.terra.api.world.tree.fractal.trees.OakTree;
import com.dfsek.terra.api.world.tree.fractal.trees.ShatteredPillar;
import com.dfsek.terra.api.world.tree.fractal.trees.ShatteredTree;
import com.dfsek.terra.api.world.tree.fractal.trees.SmallShatteredPillar;
import com.dfsek.terra.api.world.tree.fractal.trees.SmallShatteredTree;
import com.dfsek.terra.api.world.tree.fractal.trees.SpruceTree;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.registry.OpenRegistry;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Random;
public class TreeRegistry extends OpenRegistry<Tree> {
private final TerraPlugin main;
public TreeRegistry(TerraPlugin main) {
this.main = main;
tryAdd("CACTUS", Cactus.class);
tryAdd("GIANT_OAK", OakTree.class);
tryAdd("GIANT_SPRUCE", SpruceTree.class);
tryAdd("LARGE_SHATTERED_PILLAR", ShatteredPillar.class);
tryAdd("SHATTERED_LARGE", ShatteredTree.class);
tryAdd("SHATTERED_SMALL", SmallShatteredTree.class);
tryAdd("SMALL_SHATTERED_PILLAR", SmallShatteredPillar.class);
tryAdd("ICE_SPIKE", IceSpike.class);
}
private void tryAdd(String id, Class<? extends FractalTree> value) {
try {
add(id, new FractalTreeHolder(value));
} catch(Exception e) {
main.logger().warning("Unable to load tree " + id + ": " + e.getMessage());
}
}
@Override
public boolean add(String identifier, Tree value) {
return super.add(identifier, value);
}
private final class FractalTreeHolder implements Tree {
private final FractalTree tree;
private FractalTreeHolder(Class<? extends FractalTree> clazz) throws NoSuchMethodException {
Constructor<? extends FractalTree> constructor = clazz.getConstructor(TerraPlugin.class);
try {
tree = constructor.newInstance(main);
} catch(InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
throw new IllegalArgumentException("Unable to load tree: " + clazz);
}
}
@Override
public boolean plant(Location l, Random r) {
if(!getSpawnable().contains(l.getBlock().getType())) return false;
if(!l.getBlock().getRelative(BlockFace.UP).isEmpty()) return false;
tree.grow(l.add(0, 1, 0), r);
return true;
}
@Override
public MaterialSet getSpawnable() {
return tree.getSpawnable();
}
}
}

View File

@ -1,11 +1,11 @@
package com.dfsek.terra.world.population.items.tree;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.structures.script.StructureScript;
import com.dfsek.terra.api.structures.structure.Rotation;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.world.tree.Tree;
import java.util.Random;

View File

@ -6,9 +6,9 @@ import com.dfsek.terra.api.math.vector.Vector2;
import com.dfsek.terra.api.platform.block.Block;
import com.dfsek.terra.api.platform.block.BlockFace;
import com.dfsek.terra.api.platform.world.Chunk;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.util.collections.ProbabilityCollection;
import com.dfsek.terra.api.util.world.PopulationUtil;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.world.population.items.PlaceableLayer;
public class TreeLayer extends PlaceableLayer<Tree> {

View File

@ -2,13 +2,12 @@ package com.dfsek.terra.bukkit.listeners;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.transform.MapTransform;
import com.dfsek.terra.api.transform.Transformer;
import com.dfsek.terra.api.util.FastRandom;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.bukkit.world.BukkitAdapter;
import com.dfsek.terra.config.pack.ConfigPack;
import com.dfsek.terra.config.pack.WorldConfig;
import com.dfsek.terra.world.TerraWorld;
import org.bukkit.Material;

View File

@ -3,8 +3,8 @@ package com.dfsek.terra.bukkit.world;
import com.dfsek.terra.api.TerraPlugin;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.Tree;
import org.bukkit.TreeType;
import java.util.Random;

View File

@ -20,6 +20,7 @@ import com.dfsek.terra.api.platform.CommandSender;
import com.dfsek.terra.api.platform.block.BlockData;
import com.dfsek.terra.api.platform.handle.ItemHandle;
import com.dfsek.terra.api.platform.handle.WorldHandle;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.platform.world.World;
import com.dfsek.terra.api.registry.CheckedRegistry;
import com.dfsek.terra.api.registry.LockedRegistry;
@ -27,7 +28,6 @@ import com.dfsek.terra.api.transform.NotNullValidator;
import com.dfsek.terra.api.transform.Transformer;
import com.dfsek.terra.api.util.logging.DebugLogger;
import com.dfsek.terra.api.util.logging.Logger;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.commands.CommandUtil;
import com.dfsek.terra.config.GenericLoaders;
import com.dfsek.terra.config.PluginConfig;

View File

@ -1,8 +1,8 @@
package com.dfsek.terra.fabric.world;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.Tree;
import com.dfsek.terra.fabric.TerraFabricPlugin;
import com.dfsek.terra.fabric.world.generator.FabricChunkGenerator;
import com.dfsek.terra.fabric.world.handles.world.FabricWorldAccess;

View File

@ -1,8 +1,8 @@
package com.dfsek.terra.platform;
import com.dfsek.terra.api.math.vector.Location;
import com.dfsek.terra.api.platform.world.Tree;
import com.dfsek.terra.api.util.collections.MaterialSet;
import com.dfsek.terra.api.world.tree.Tree;
import java.util.Random;