mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-01 23:47:50 +00:00
Fix fractal trees
This commit is contained in:
commit
9ac098f1ca
@ -1,6 +1,6 @@
|
||||
import com.dfsek.terra.getGitHash
|
||||
|
||||
val versionObj = Version("2", "2", "0", true)
|
||||
val versionObj = Version("3", "0", "0", true)
|
||||
|
||||
allprojects {
|
||||
version = versionObj
|
||||
|
@ -704,7 +704,7 @@ public class FastNoiseLite {
|
||||
/*FNLdouble*/
|
||||
double xy = x + y;
|
||||
/*FNLdouble*/
|
||||
double s2 = xy * -(/*FNLdouble*/ double) 0.211324865405187;
|
||||
double s2 = xy * -0.211324865405187D;
|
||||
/*FNLdouble*/
|
||||
z *= 0.577350269189626;
|
||||
x += s2 - z;
|
||||
@ -717,7 +717,7 @@ public class FastNoiseLite {
|
||||
/*FNLdouble*/
|
||||
double xz = x + z;
|
||||
/*FNLdouble*/
|
||||
double s2 = xz * -(/*FNLdouble*/ double) 0.211324865405187;
|
||||
double s2 = xz * -0.211324865405187D;
|
||||
/*FNLdouble*/
|
||||
y *= 0.577350269189626;
|
||||
x += s2 - y;
|
||||
@ -1898,7 +1898,7 @@ public class FastNoiseLite {
|
||||
/*FNLdouble*/
|
||||
double xy = xs + ys;
|
||||
/*FNLdouble*/
|
||||
double s2 = xy * -(/*FNLdouble*/ double) 0.211324865405187;
|
||||
double s2 = xy * -0.211324865405187D;
|
||||
/*FNLdouble*/
|
||||
zs *= 0.577350269189626;
|
||||
xs += s2 - zs;
|
||||
@ -1911,7 +1911,7 @@ public class FastNoiseLite {
|
||||
/*FNLdouble*/
|
||||
double xz = xs + zs;
|
||||
/*FNLdouble*/
|
||||
double s2 = xz * -(/*FNLdouble*/ double) 0.211324865405187;
|
||||
double s2 = xz * -0.211324865405187D;
|
||||
/*FNLdouble*/
|
||||
ys *= 0.577350269189626;
|
||||
xs += s2 - ys;
|
||||
@ -1989,7 +1989,7 @@ public class FastNoiseLite {
|
||||
/*FNLdouble*/
|
||||
double xy = xs + ys;
|
||||
/*FNLdouble*/
|
||||
double s2 = xy * -(/*FNLdouble*/ double) 0.211324865405187;
|
||||
double s2 = xy * -0.211324865405187D;
|
||||
/*FNLdouble*/
|
||||
zs *= 0.577350269189626;
|
||||
xs += s2 - zs;
|
||||
@ -2002,7 +2002,7 @@ public class FastNoiseLite {
|
||||
/*FNLdouble*/
|
||||
double xz = xs + zs;
|
||||
/*FNLdouble*/
|
||||
double s2 = xz * -(/*FNLdouble*/ double) 0.211324865405187;
|
||||
double s2 = xz * -0.211324865405187D;
|
||||
/*FNLdouble*/
|
||||
ys *= 0.577350269189626;
|
||||
xs += s2 - ys;
|
||||
@ -2081,7 +2081,7 @@ public class FastNoiseLite {
|
||||
/*FNLdouble*/
|
||||
double xy = xs + ys;
|
||||
/*FNLdouble*/
|
||||
double s2 = xy * -(/*FNLdouble*/ double) 0.211324865405187;
|
||||
double s2 = xy * -0.211324865405187D;
|
||||
/*FNLdouble*/
|
||||
zs *= 0.577350269189626;
|
||||
xs += s2 - zs;
|
||||
@ -2094,7 +2094,7 @@ public class FastNoiseLite {
|
||||
/*FNLdouble*/
|
||||
double xz = xs + zs;
|
||||
/*FNLdouble*/
|
||||
double s2 = xz * -(/*FNLdouble*/ double) 0.211324865405187;
|
||||
double s2 = xz * -0.211324865405187D;
|
||||
/*FNLdouble*/
|
||||
ys *= 0.577350269189626;
|
||||
xs += s2 - ys;
|
||||
|
@ -1,70 +1,27 @@
|
||||
package com.dfsek.terra.api.gaea.tree.fractal;
|
||||
|
||||
import com.dfsek.terra.api.gaea.util.GlueList;
|
||||
import com.dfsek.terra.api.generic.Entity;
|
||||
import com.dfsek.terra.api.generic.TerraPlugin;
|
||||
import com.dfsek.terra.api.generic.world.block.BlockData;
|
||||
import com.dfsek.terra.api.generic.world.block.MaterialData;
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Random;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
public abstract class FractalTree {
|
||||
private final Map<Location, BlockData> treeAssembler = new HashMap<>();
|
||||
private final List<EntitySpawnHolder> entities = new GlueList<>();
|
||||
protected final Location origin;
|
||||
protected final Random random;
|
||||
protected final TerraPlugin main;
|
||||
|
||||
public abstract MaterialSet getSpawnable();
|
||||
|
||||
/**
|
||||
* Instantiates a TreeGrower at an origin location.
|
||||
*
|
||||
* @param origin - The origin location.
|
||||
* @param random - The random object to use whilst generating the tree.
|
||||
*/
|
||||
public FractalTree(Location origin, Random random, TerraPlugin plugin) {
|
||||
this.origin = origin.add(0, 1, 0);
|
||||
this.random = random;
|
||||
public FractalTree(TerraPlugin plugin) {
|
||||
this.main = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the raw tree map.
|
||||
*
|
||||
* @return HashMap<Location, BlockData> - The raw dictionary representation of the tree.
|
||||
*/
|
||||
public Map<Location, BlockData> getTree() {
|
||||
return treeAssembler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fetches the Random object used to generate the tree.
|
||||
*
|
||||
* @return Random - The Random object.
|
||||
*/
|
||||
public Random getRandom() {
|
||||
return random;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the origin location.
|
||||
*
|
||||
* @return Location - The origin location specified upon instantiation.
|
||||
*/
|
||||
public Location getOrigin() {
|
||||
return origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a block in the tree's storage map to a material.
|
||||
*
|
||||
@ -72,7 +29,7 @@ public abstract class FractalTree {
|
||||
* @param m - The material to which it will be set.
|
||||
*/
|
||||
public void setBlock(Location l, BlockData m) {
|
||||
treeAssembler.put(l, m);
|
||||
l.getBlock().setBlockData(m, false);
|
||||
}
|
||||
|
||||
public TerraPlugin getMain() {
|
||||
@ -82,34 +39,9 @@ public abstract class FractalTree {
|
||||
/**
|
||||
* Grows the tree in memory. Intended to be invoked from an async thread.
|
||||
*/
|
||||
public abstract void grow();
|
||||
public abstract void grow(Location origin, Random random);
|
||||
|
||||
/**
|
||||
* Pastes the tree in the world. Must be invoked from main thread.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void plant() {
|
||||
for(Map.Entry<Location, BlockData> entry : treeAssembler.entrySet()) {
|
||||
entry.getKey().getBlock().setBlockData(entry.getValue(), false);
|
||||
}
|
||||
for(EntitySpawnHolder e : entities) {
|
||||
Objects.requireNonNull(e.getLocation().getWorld()).spawn(e.getLocation(), e.getEntity(), e.getConsumer());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes, unchecked")
|
||||
public void spawnEntity(Location spawn, Class clazz, Consumer<Entity> consumer) {
|
||||
entities.add(new EntitySpawnHolder(spawn, clazz, consumer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the material at the specified block.
|
||||
* Returns air if no material has been set.
|
||||
*
|
||||
* @param l - The location at which to check.
|
||||
* @return Material - The material at the specified block.
|
||||
*/
|
||||
public MaterialData getMaterial(Location l) {
|
||||
return treeAssembler.getOrDefault(l, main.getWorldHandle().createBlockData("minecraft:air")).getMaterial();
|
||||
public void spawnEntity(Location spawn, Class<Entity> clazz, Consumer<Entity> consumer) {
|
||||
spawn.getWorld().spawn(spawn, clazz, consumer);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@ import com.dfsek.terra.api.generic.world.block.BlockData;
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
import com.dfsek.terra.api.generic.world.vector.Vector3;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class TreeGeometry {
|
||||
private final FractalTree tree;
|
||||
|
||||
@ -33,19 +35,19 @@ public class TreeGeometry {
|
||||
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 || tree.getMaterial(position.toLocation(l.getWorld())).isAir()))
|
||||
if(l.toVector().distance(position) <= radius + 0.5 && (overwrite || position.toLocation(l.getWorld()).getBlock().isEmpty()))
|
||||
tree.setBlock(position.toLocation(l.getWorld()), m.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void generateSponge(Location l, ProbabilityCollection<BlockData> m, int radius, boolean overwrite, int sponginess) {
|
||||
for(int x = - radius; x <= radius; x++) {
|
||||
for(int y = - radius; y <= radius; y++) {
|
||||
for(int z = - radius; z <= radius; z++) {
|
||||
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(tree.getRandom().nextInt(100) < sponginess && l.toVector().distance(position) <= radius + 0.5 && (overwrite || tree.getMaterial(position.toLocation(l.getWorld())).isAir()))
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -57,7 +59,7 @@ public class TreeGeometry {
|
||||
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 || tree.getMaterial(position.toLocation(l.getWorld())).isAir()))
|
||||
if(l.toVector().distance(position) <= radius + 0.5 && (overwrite || position.toLocation(l.getWorld()).getBlock().isEmpty()))
|
||||
tree.setBlock(position.toLocation(l.getWorld()), m.get());
|
||||
}
|
||||
}
|
||||
|
@ -18,21 +18,18 @@ public class Cactus extends FractalTree {
|
||||
|
||||
/**
|
||||
* Instantiates a TreeGrower at an origin location.
|
||||
*
|
||||
* @param origin - The origin location.
|
||||
* @param random - The random object to use whilst generating the tree.
|
||||
*/
|
||||
public Cactus(Location origin, Random random, TerraPlugin main) {
|
||||
super(origin, random, main);
|
||||
public Cactus(TerraPlugin main) {
|
||||
super(main);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grows the tree in memory. Intended to be invoked from an async thread.
|
||||
*/
|
||||
@Override
|
||||
public void grow() {
|
||||
public void grow(Location origin, Random random) {
|
||||
BlockData cactus = getMain().getWorldHandle().createBlockData("minecraft:cactus");
|
||||
int h = super.getRandom().nextInt(4) + 1;
|
||||
for(int i = 0; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 0), cactus);
|
||||
int h = random.nextInt(4) + 1;
|
||||
for(int i = 0; i < h; i++) setBlock(origin.clone().add(0, i, 0), cactus);
|
||||
}
|
||||
}
|
||||
|
@ -27,34 +27,31 @@ public class IceSpike extends FractalTree {
|
||||
|
||||
/**
|
||||
* Instantiates a TreeGrower at an origin location.
|
||||
*
|
||||
* @param origin - The origin location.
|
||||
* @param random - The random object to use whilst generating the tree.
|
||||
*/
|
||||
public IceSpike(Location origin, Random random, TerraPlugin main) {
|
||||
super(origin, random, main);
|
||||
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() {
|
||||
return (getRandom().nextDouble() - 0.5D);
|
||||
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() {
|
||||
Vector3 direction = new Vector3(getOffset(), 0, getOffset());
|
||||
Location l1 = super.getOrigin().clone();
|
||||
int h = super.getRandom().nextInt(16) + 8;
|
||||
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);
|
||||
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(super.getRandom()));
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,9 @@ public class OakTree extends FractalTree {
|
||||
|
||||
/**
|
||||
* Instantiates a TreeGrower at an origin location.
|
||||
*
|
||||
* @param origin - The origin location.
|
||||
* @param random - The random object to use whilst generating the tree.
|
||||
*/
|
||||
public OakTree(Location origin, Random random, TerraPlugin main) {
|
||||
super(origin, random, main);
|
||||
public OakTree(TerraPlugin main) {
|
||||
super(main);
|
||||
geo = new TreeGeometry(this);
|
||||
}
|
||||
|
||||
@ -36,15 +33,15 @@ public class OakTree extends FractalTree {
|
||||
* Grows the tree in memory. Intended to be invoked from an async thread.
|
||||
*/
|
||||
@Override
|
||||
public void grow() {
|
||||
growBranch(super.getOrigin().clone(), new Vector3(super.getRandom().nextInt(5) - 2, super.getRandom().nextInt(4) + 6, super.getRandom().nextInt(5) - 2), 2, 0);
|
||||
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) {
|
||||
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_leave");
|
||||
if(recursions > 1) {
|
||||
geo.generateSphere(l1, leaves, 1 + super.getRandom().nextInt(2) + (3 - recursions), false);
|
||||
geo.generateSphere(l1, leaves, 1 + r.nextInt(2) + (3 - recursions), false);
|
||||
if(recursions > 2) return;
|
||||
}
|
||||
if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI);
|
||||
@ -53,17 +50,17 @@ public class OakTree extends FractalTree {
|
||||
geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), wood, FastMath.max((int) d1, 0), true);
|
||||
}
|
||||
double runningAngle = (double) 45 / (recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundX(FastMath.toRadians(runningAngle + getNoise())).rotateAroundZ(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundX(FastMath.toRadians(- runningAngle + getNoise())).rotateAroundZ(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundZ(FastMath.toRadians(runningAngle + getNoise())).rotateAroundX(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.75).rotateAroundZ(FastMath.toRadians(- runningAngle + getNoise())).rotateAroundX(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, 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() {
|
||||
return super.getRandom().nextInt(60) - 30;
|
||||
private int getNoise(Random r) {
|
||||
return r.nextInt(60) - 30;
|
||||
}
|
||||
}
|
||||
|
@ -17,41 +17,40 @@ public class ShatteredPillar extends FractalTree {
|
||||
|
||||
/**
|
||||
* Instantiates a TreeGrower at an origin location.
|
||||
*
|
||||
* @param origin - The origin location.
|
||||
* @param random - The random object to use whilst generating the tree.
|
||||
*/
|
||||
public ShatteredPillar(Location origin, Random random, TerraPlugin main) {
|
||||
super(origin, random, main);
|
||||
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() {
|
||||
public void grow(Location origin, Random random) {
|
||||
BlockData obsidian = getMain().getWorldHandle().createBlockData("minecraft:obsidian");
|
||||
int h = super.getRandom().nextInt(5) + 8;
|
||||
int h = random.nextInt(5) + 8;
|
||||
int max = h;
|
||||
for(int i = - h; i < h; i++) setBlock(super.getOrigin().clone().add(0, i, 0), obsidian);
|
||||
h = h + (getRandom().nextBoolean() ? getRandom().nextInt(3) + 1 : - (getRandom().nextInt(3) + 1));
|
||||
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(super.getOrigin().clone().add(1, i, 0), obsidian);
|
||||
h = h + (getRandom().nextBoolean() ? getRandom().nextInt(3) + 1 : - (getRandom().nextInt(3) + 1));
|
||||
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(super.getOrigin().clone().add(0, i, 1), obsidian);
|
||||
h = h + (getRandom().nextBoolean() ? getRandom().nextInt(3) + 1 : - (getRandom().nextInt(3) + 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(super.getOrigin().clone().add(1, i, 1), obsidian);
|
||||
for(int i = -h; i < h; i++) setBlock(origin.clone().add(1, i, 1), obsidian);
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,9 @@ public class ShatteredTree extends FractalTree {
|
||||
|
||||
/**
|
||||
* Instantiates a TreeGrower at an origin location.
|
||||
*
|
||||
* @param origin - The origin location.
|
||||
* @param random - The random object to use whilst generating the tree.
|
||||
*/
|
||||
public ShatteredTree(Location origin, Random random, TerraPlugin main) {
|
||||
super(origin, random, main);
|
||||
public ShatteredTree(TerraPlugin main) {
|
||||
super(main);
|
||||
geo = new TreeGeometry(this);
|
||||
WorldHandle handle = main.getWorldHandle();
|
||||
|
||||
@ -46,14 +43,14 @@ public class ShatteredTree extends FractalTree {
|
||||
* Grows the tree in memory. Intended to be invoked from an async thread.
|
||||
*/
|
||||
@Override
|
||||
public void grow() {
|
||||
growBranch(super.getOrigin().clone(), new Vector3(super.getRandom().nextInt(5) - 2, super.getRandom().nextInt(4) + 6, super.getRandom().nextInt(5) - 2), 1, 0);
|
||||
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) {
|
||||
private void growBranch(Location l1, Vector3 diff, double d1, int recursions, Random r) {
|
||||
if(recursions > 2) {
|
||||
geo.generateSphere(l1, leaves, 1 + super.getRandom().nextInt(2), false);
|
||||
geo.generateSphere(l1, leaves, 1 + r.nextInt(2), false);
|
||||
return;
|
||||
}
|
||||
if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI);
|
||||
@ -62,17 +59,17 @@ public class ShatteredTree extends FractalTree {
|
||||
geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), bark, FastMath.max((int) d1, 0), true);
|
||||
}
|
||||
double runningAngle = (double) 45 / (recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.9).rotateAroundX(FastMath.toRadians(runningAngle + getNoise())).rotateAroundZ(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.9).rotateAroundX(FastMath.toRadians(- runningAngle + getNoise())).rotateAroundZ(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.9).rotateAroundZ(FastMath.toRadians(runningAngle + getNoise())).rotateAroundX(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.9).rotateAroundZ(FastMath.toRadians(- runningAngle + getNoise())).rotateAroundX(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, 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() {
|
||||
return super.getRandom().nextInt(90) - 45;
|
||||
private int getNoise(Random r) {
|
||||
return r.nextInt(90) - 45;
|
||||
}
|
||||
}
|
||||
|
@ -17,21 +17,20 @@ public class SmallShatteredPillar extends FractalTree {
|
||||
|
||||
/**
|
||||
* Instantiates a TreeGrower at an origin location.
|
||||
*
|
||||
* @param origin - The origin location.
|
||||
* @param random - The random object to use whilst generating the tree.
|
||||
*/
|
||||
public SmallShatteredPillar(Location origin, Random random, TerraPlugin main) {
|
||||
super(origin, random, main);
|
||||
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() {
|
||||
int h = super.getRandom().nextInt(5) + 5;
|
||||
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(super.getOrigin().clone().add(0, i, 0), obsidian);
|
||||
for(int i = -h; i < h; i++) setBlock(origin.clone().add(0, i, 0), obsidian);
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,9 @@ public class SmallShatteredTree extends FractalTree {
|
||||
|
||||
/**
|
||||
* Instantiates a TreeGrower at an origin location.
|
||||
*
|
||||
* @param origin - The origin location.
|
||||
* @param random - The random object to use whilst generating the tree.
|
||||
*/
|
||||
public SmallShatteredTree(Location origin, Random random, TerraPlugin main) {
|
||||
super(origin, random, main);
|
||||
public SmallShatteredTree(TerraPlugin main) {
|
||||
super(main);
|
||||
geo = new TreeGeometry(this);
|
||||
|
||||
WorldHandle handle = main.getWorldHandle();
|
||||
@ -46,14 +43,14 @@ public class SmallShatteredTree extends FractalTree {
|
||||
* Grows the tree in memory. Intended to be invoked from an async thread.
|
||||
*/
|
||||
@Override
|
||||
public void grow() {
|
||||
growBranch(super.getOrigin().clone(), new Vector3(super.getRandom().nextInt(5) - 2, super.getRandom().nextInt(3) + 4, super.getRandom().nextInt(5) - 2), 1.5, 0);
|
||||
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) {
|
||||
private void growBranch(Location l1, Vector3 diff, double d1, int recursions, Random r) {
|
||||
if(recursions > 2) {
|
||||
geo.generateSphere(l1, leaves, 1 + super.getRandom().nextInt(2) + (3 - recursions), false);
|
||||
geo.generateSphere(l1, leaves, 1 + r.nextInt(2) + (3 - recursions), false);
|
||||
return;
|
||||
}
|
||||
if(diff.getY() < 0) diff.rotateAroundAxis(TreeGeometry.getPerpendicular(diff.clone()).normalize(), FastMath.PI);
|
||||
@ -62,17 +59,17 @@ public class SmallShatteredTree extends FractalTree {
|
||||
geo.generateSphere(l1.clone().add(diff.clone().multiply((double) i / d)), bark, FastMath.max((int) d1, 0), true);
|
||||
}
|
||||
double runningAngle = (double) 45 / (recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.7).rotateAroundX(FastMath.toRadians(runningAngle + getNoise())).rotateAroundZ(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.7).rotateAroundX(FastMath.toRadians(- runningAngle + getNoise())).rotateAroundZ(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.7).rotateAroundZ(FastMath.toRadians(runningAngle + getNoise())).rotateAroundX(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, recursions + 1);
|
||||
growBranch(l1.clone().add(diff), diff.clone().multiply(0.7).rotateAroundZ(FastMath.toRadians(- runningAngle + getNoise())).rotateAroundX(FastMath.toRadians(getNoise())),
|
||||
d1 - 1, 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() {
|
||||
return super.getRandom().nextInt(90) - 45;
|
||||
private int getNoise(Random r) {
|
||||
return r.nextInt(90) - 45;
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,9 @@ public class SpruceTree extends FractalTree {
|
||||
|
||||
/**
|
||||
* Instantiates a TreeGrower at an origin location.
|
||||
*
|
||||
* @param origin - The origin location.
|
||||
* @param random - The random object to use whilst generating the tree.
|
||||
*/
|
||||
public SpruceTree(Location origin, Random random, TerraPlugin main) {
|
||||
super(origin, random, main);
|
||||
public SpruceTree(TerraPlugin main) {
|
||||
super(main);
|
||||
geo = new TreeGeometry(this);
|
||||
}
|
||||
|
||||
@ -35,8 +32,8 @@ public class SpruceTree extends FractalTree {
|
||||
* Grows the tree in memory. Intended to be invoked from an async thread.
|
||||
*/
|
||||
@Override
|
||||
public void grow() {
|
||||
growTrunk(super.getOrigin().clone(), new Vector3(0, 16 + super.getRandom().nextInt(5), 0));
|
||||
public void grow(Location origin, Random random) {
|
||||
growTrunk(origin.clone(), new Vector3(0, 16 + random.nextInt(5), 0));
|
||||
}
|
||||
|
||||
private void growTrunk(Location l1, Vector3 diff) {
|
||||
|
@ -11,10 +11,9 @@ import com.dfsek.terra.api.gaea.tree.fractal.trees.SmallShatteredPillar;
|
||||
import com.dfsek.terra.api.gaea.tree.fractal.trees.SmallShatteredTree;
|
||||
import com.dfsek.terra.api.gaea.tree.fractal.trees.SpruceTree;
|
||||
import com.dfsek.terra.api.generic.TerraPlugin;
|
||||
import com.dfsek.terra.api.generic.world.WorldHandle;
|
||||
import com.dfsek.terra.api.generic.world.block.BlockFace;
|
||||
import com.dfsek.terra.api.generic.world.block.MaterialData;
|
||||
import com.dfsek.terra.api.generic.world.vector.Location;
|
||||
import com.dfsek.terra.util.MaterialSet;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -69,32 +68,30 @@ public class TreeRegistry extends TerraRegistry<Tree> {
|
||||
}
|
||||
}
|
||||
|
||||
private final class FractalTreeHolder implements Tree { // TODO: this is jank and should be replaced later.
|
||||
private final Constructor<? extends FractalTree> constructor;
|
||||
private final MaterialSet set;
|
||||
private final class FractalTreeHolder implements Tree {
|
||||
private final FractalTree tree;
|
||||
|
||||
private FractalTreeHolder(Class<? extends FractalTree> clazz) throws NoSuchMethodException {
|
||||
constructor = clazz.getConstructor(Location.class, Random.class, TerraPlugin.class);
|
||||
WorldHandle h = main.getWorldHandle();
|
||||
set = MaterialSet.get(h.createMaterialData("minecraft:grass_block"), h.createMaterialData("minecraft:snow_block")); // TODO: actually implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plant(Location l, Random r) {
|
||||
Constructor<? extends FractalTree> constructor = clazz.getConstructor(TerraPlugin.class);
|
||||
try {
|
||||
FractalTree tree = constructor.newInstance(l, r, main);
|
||||
tree.grow();
|
||||
tree.plant();
|
||||
return true;
|
||||
tree = constructor.newInstance(main);
|
||||
} catch(InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
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 Set<MaterialData> getSpawnable() {
|
||||
return set;
|
||||
return tree.getSpawnable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user