mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-04-09 17:26:07 +00:00
refactor trees
This commit is contained in:
@@ -48,7 +48,7 @@ import com.dfsek.terra.addons.flora.flora.FloraLayer;
|
||||
import com.dfsek.terra.addons.flora.flora.TerraFlora;
|
||||
import com.dfsek.terra.addons.ore.ores.OreConfig;
|
||||
import com.dfsek.terra.addons.ore.ores.OreHolder;
|
||||
import com.dfsek.terra.world.population.items.tree.TreeLayer;
|
||||
import com.dfsek.terra.addons.tree.tree.TreeLayer;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.dfsek.terra.config.factories;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.config.templates.TreeTemplate;
|
||||
import com.dfsek.terra.world.population.items.tree.TerraTree;
|
||||
|
||||
public class TreeFactory implements ConfigFactory<TreeTemplate, Tree> {
|
||||
@Override
|
||||
public Tree build(TreeTemplate config, TerraPlugin main) {
|
||||
return new TerraTree(config.getSpawnable(), config.getyOffset(), config.getStructures());
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import com.dfsek.terra.api.util.seeded.NoiseSeeded;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.config.loaders.Types;
|
||||
import com.dfsek.terra.noise.samplers.noise.random.WhiteNoiseSampler;
|
||||
import com.dfsek.terra.world.population.items.tree.TreeLayer;
|
||||
import com.dfsek.terra.addons.tree.tree.TreeLayer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
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.config.AbstractableTemplate;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class TreeTemplate implements AbstractableTemplate {
|
||||
@Value("scripts")
|
||||
@Abstractable
|
||||
private ProbabilityCollection<Structure> structure;
|
||||
|
||||
@Value("id")
|
||||
private String id;
|
||||
|
||||
@Value("y-offset")
|
||||
@Abstractable
|
||||
@Default
|
||||
private int yOffset = 0;
|
||||
|
||||
@Value("spawnable")
|
||||
@Abstractable
|
||||
private MaterialSet spawnable;
|
||||
|
||||
public ProbabilityCollection<Structure> getStructures() {
|
||||
return structure;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getyOffset() {
|
||||
return yOffset;
|
||||
}
|
||||
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package com.dfsek.terra.world.population;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.profiler.ProfileFrame;
|
||||
import com.dfsek.terra.api.util.PopulationUtil;
|
||||
import com.dfsek.terra.api.vector.Vector2;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.TerraWorld;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import com.dfsek.terra.api.world.biome.UserDefinedBiome;
|
||||
import com.dfsek.terra.api.world.biome.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.TerraBlockPopulator;
|
||||
import com.dfsek.terra.world.population.items.tree.TreeLayer;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class TreePopulator implements TerraBlockPopulator {
|
||||
private final TerraPlugin main;
|
||||
|
||||
public TreePopulator(TerraPlugin main) {
|
||||
this.main = main;
|
||||
}
|
||||
|
||||
private static int offset(Random r, int i) {
|
||||
return FastMath.min(FastMath.max(i + r.nextInt(3) - 1, 0), 15);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("try")
|
||||
public void populate(@NotNull World world, @NotNull Chunk chunk) {
|
||||
TerraWorld tw = main.getWorld(world);
|
||||
try(ProfileFrame ignore = main.getProfiler().profile("tree")) {
|
||||
if(tw.getConfig().disableTrees()) return;
|
||||
|
||||
if(!tw.isSafe()) return;
|
||||
BiomeProvider provider = tw.getBiomeProvider();
|
||||
Random random = PopulationUtil.getRandom(chunk);
|
||||
for(int x = 0; x < 16; x += 2) {
|
||||
for(int z = 0; z < 16; z += 2) {
|
||||
UserDefinedBiome biome = (UserDefinedBiome) provider.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z);
|
||||
for(TreeLayer layer : biome.getConfig().getTrees()) {
|
||||
if(layer.getDensity() >= random.nextDouble() * 100) {
|
||||
layer.place(chunk, new Vector2(offset(random, x), offset(random, z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package com.dfsek.terra.world.population.items.tree;
|
||||
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||
import com.dfsek.terra.api.util.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.collections.MaterialSet;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class TerraTree implements Tree {
|
||||
private final MaterialSet spawnable;
|
||||
private final int yOffset;
|
||||
private final ProbabilityCollection<Structure> structure;
|
||||
|
||||
public TerraTree(MaterialSet spawnable, int yOffset, ProbabilityCollection<Structure> structure) {
|
||||
this.spawnable = spawnable;
|
||||
this.yOffset = yOffset;
|
||||
this.structure = structure;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized boolean plant(Vector3 location, World world, Random random) {
|
||||
return structure.get(random).generateDirect(location.clone().add(0, yOffset, 0), world, random, Rotation.fromDegrees(90 * random.nextInt(4)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package com.dfsek.terra.world.population.items.tree;
|
||||
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.PopulationUtil;
|
||||
import com.dfsek.terra.api.util.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.vector.Vector2;
|
||||
import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
import com.dfsek.terra.world.population.items.PlaceableLayer;
|
||||
|
||||
public class TreeLayer extends PlaceableLayer<Tree> {
|
||||
|
||||
public TreeLayer(double density, Range level, ProbabilityCollection<Tree> layer, NoiseSampler noise) {
|
||||
super(density, level, layer, noise);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void place(Chunk chunk, Vector2 coords) {
|
||||
int cx = chunk.getX() << 4;
|
||||
int cz = chunk.getZ() << 4;
|
||||
Tree item = layer.get(noise, coords.getX() + cx, coords.getZ() + cz);
|
||||
Vector3 running = coords.extrude(level.getMax());
|
||||
for(int ignored : level) {
|
||||
running.subtract(0, 1, 0);
|
||||
if(item.getSpawnable().contains(chunk.getBlock(running.getBlockX(), running.getBlockY(), running.getBlockZ()).getBlockType())) {
|
||||
item.plant(running.clone().add(cx, 1, cz), chunk.getWorld(), PopulationUtil.getRandom(chunk, coords.hashCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user