mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-14 12:51:20 +00:00
noise function flora and tree dist
This commit is contained in:
@@ -55,7 +55,7 @@ public class FloraPopulator implements TerraBlockPopulator {
|
||||
if(entry.getValue().size() <= iter) continue;
|
||||
finished = false;
|
||||
FloraLayer layer = entry.getValue().get(iter);
|
||||
if(layer.getDensity() >= random.nextDouble() * 100D) layer.place(chunk, entry.getKey(), random);
|
||||
if(layer.getDensity() >= random.nextDouble() * 100D) layer.place(chunk, entry.getKey());
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TreePopulator implements TerraBlockPopulator {
|
||||
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE);
|
||||
for(TreeLayer layer : biome.getConfig().getTrees()) {
|
||||
if(layer.getDensity() >= random.nextDouble() * 100)
|
||||
layer.place(chunk, new Vector2(offset(random, x), offset(random, z)), random);
|
||||
layer.place(chunk, new Vector2(offset(random, x), offset(random, z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@ import com.dfsek.terra.api.math.noise.samplers.NoiseSampler;
|
||||
import com.dfsek.terra.api.math.vector.Vector2;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public abstract class PlaceableLayer<T> {
|
||||
protected final double density;
|
||||
protected final Range level;
|
||||
@@ -37,5 +35,5 @@ public abstract class PlaceableLayer<T> {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public abstract void place(Chunk chunk, Vector2 coords, Random random);
|
||||
public abstract void place(Chunk chunk, Vector2 coords);
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.world.flora.Flora;
|
||||
import com.dfsek.terra.population.items.PlaceableLayer;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class FloraLayer extends PlaceableLayer<Flora> {
|
||||
|
||||
public FloraLayer(double density, Range level, ProbabilityCollection<Flora> layer, NoiseSampler noise) {
|
||||
@@ -21,8 +19,8 @@ public class FloraLayer extends PlaceableLayer<Flora> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(Chunk chunk, Vector2 coords, Random random) {
|
||||
Flora item = noise == null ? layer.get(random) : layer.get(noise, (chunk.getX() << 4) + coords.getX(), (chunk.getZ() << 4) + coords.getZ());
|
||||
public void place(Chunk chunk, Vector2 coords) {
|
||||
Flora item = layer.get(noise, (chunk.getX() << 4) + coords.getX(), (chunk.getZ() << 4) + coords.getZ());
|
||||
item.getValidSpawnsAt(chunk, (int) coords.getX(), (int) coords.getZ(), level).forEach(block -> item.plant(block.getLocation()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ import com.dfsek.terra.api.platform.block.BlockFace;
|
||||
import com.dfsek.terra.api.platform.world.Chunk;
|
||||
import com.dfsek.terra.api.world.tree.Tree;
|
||||
import com.dfsek.terra.population.items.PlaceableLayer;
|
||||
|
||||
import java.util.Random;
|
||||
import com.dfsek.terra.util.PopulationUtil;
|
||||
|
||||
public class TreeLayer extends PlaceableLayer<Tree> {
|
||||
|
||||
@@ -19,13 +18,13 @@ public class TreeLayer extends PlaceableLayer<Tree> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(Chunk chunk, Vector2 coords, Random random) {
|
||||
Tree item = layer.get(random);
|
||||
public void place(Chunk chunk, Vector2 coords) {
|
||||
Tree item = layer.get(noise, coords.getX(), coords.getZ());
|
||||
Block current = chunk.getBlock((int) coords.getX(), level.getMax(), (int) coords.getZ());
|
||||
for(int ignored : level) {
|
||||
current = current.getRelative(BlockFace.DOWN);
|
||||
if(item.getSpawnable().contains(current.getType())) {
|
||||
item.plant(current.getLocation().add(0, 1, 0), random);
|
||||
item.plant(current.getLocation().add(0, 1, 0), PopulationUtil.getRandom(chunk));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user