mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2025-07-03 00:15:35 +00:00
commit
12540f3a2c
@ -2,6 +2,9 @@ package com.dfsek.terra.addons.feature.distributor;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.config.NoiseDistributorTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.config.PointSetDistributorTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.util.Point;
|
||||
import com.dfsek.terra.addons.feature.distributor.util.PointTemplate;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
@ -33,5 +36,9 @@ public class DistributorAddon extends TerraAddon implements EventListener {
|
||||
public void packPreLoad(ConfigPackPreLoadEvent event) {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<Distributor>>> distributorRegistry = event.getPack().getOrCreateRegistry(DISTRIBUTOR_TOKEN);
|
||||
distributorRegistry.register("NOISE", NoiseDistributorTemplate::new);
|
||||
distributorRegistry.register("POINTS", PointSetDistributorTemplate::new);
|
||||
|
||||
event.getPack()
|
||||
.applyLoader(Point.class, PointTemplate::new);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.addons.feature.distributor.distributors.PointSetDistributor;
|
||||
import com.dfsek.terra.addons.feature.distributor.util.Point;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class PointSetDistributorTemplate implements ObjectTemplate<Distributor> {
|
||||
@Value("points")
|
||||
private Set<Point> points;
|
||||
|
||||
@Override
|
||||
public Distributor get() {
|
||||
return new PointSetDistributor(points);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.distributors;
|
||||
|
||||
import com.dfsek.terra.addons.feature.distributor.util.Point;
|
||||
import com.dfsek.terra.api.structure.feature.Distributor;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class PointSetDistributor implements Distributor {
|
||||
private final Set<Point> points;
|
||||
|
||||
public PointSetDistributor(Set<Point> points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(int x, int z, long seed) {
|
||||
return points.contains(new Point(x, z));
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.util;
|
||||
|
||||
public class Point {
|
||||
private final int x;
|
||||
private final int z;
|
||||
|
||||
private final int hash;
|
||||
|
||||
public Point(int x, int z) {
|
||||
this.x = x;
|
||||
this.z = z;
|
||||
this.hash = 31 * x + z;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if(!(obj instanceof Point)) return false;
|
||||
Point that = (Point) obj;
|
||||
return this.x == that.x && this.z == that.z;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.dfsek.terra.addons.feature.distributor.util;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
public class PointTemplate implements ObjectTemplate<Point> {
|
||||
@Value("x")
|
||||
private int x;
|
||||
|
||||
@Value("z")
|
||||
private int z;
|
||||
|
||||
@Override
|
||||
public Point get() {
|
||||
return new Point(x, z);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.dfsek.terra.addons.feature.locator;
|
||||
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.addons.feature.locator.config.RandomLocatorTemplate;
|
||||
import com.dfsek.terra.addons.feature.locator.config.SurfaceLocatorTemplate;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
@ -33,5 +34,6 @@ public class LocatorAddon extends TerraAddon implements EventListener {
|
||||
public void onPackLoad(ConfigPackPreLoadEvent event) {
|
||||
CheckedRegistry<Supplier<ObjectTemplate<Locator>>> locatorRegistry = event.getPack().getOrCreateRegistry(LOCATOR_TOKEN);
|
||||
locatorRegistry.register("SURFACE", () -> new SurfaceLocatorTemplate(main));
|
||||
locatorRegistry.register("RANDOM", RandomLocatorTemplate::new);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.dfsek.terra.addons.feature.locator.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.addons.feature.locator.locators.RandomLocator;
|
||||
import com.dfsek.terra.addons.feature.locator.locators.SurfaceLocator;
|
||||
import com.dfsek.terra.api.structure.feature.Locator;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
|
||||
public class RandomLocatorTemplate implements ObjectTemplate<Locator> {
|
||||
@Value("height")
|
||||
private Range height;
|
||||
|
||||
@Value("amount")
|
||||
private Range amount;
|
||||
|
||||
@Override
|
||||
public Locator get() {
|
||||
return new RandomLocator(height, amount);
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.dfsek.terra.addons.feature.locator.locators;
|
||||
|
||||
import com.dfsek.terra.api.structure.feature.Locator;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.world.Column;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class RandomLocator implements Locator {
|
||||
private final Range height;
|
||||
|
||||
private final Range points;
|
||||
|
||||
public RandomLocator(Range height, Range points) {
|
||||
this.height = height;
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getSuitableCoordinates(Column column) {
|
||||
long seed = column.getWorld().getSeed();
|
||||
seed = 31 * seed + column.getX();
|
||||
seed = 31 * seed + column.getZ();
|
||||
|
||||
Random r = new Random(seed);
|
||||
|
||||
int size = points.get(r);
|
||||
|
||||
List<Integer> results = new ArrayList<>(size);
|
||||
for(int i = 0; i < size; i++) {
|
||||
results.set(i, height.get(r));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
# config-tree
|
||||
|
||||
Registers the default configuration for Terra Trees, `TREE`.
|
@ -1,45 +0,0 @@
|
||||
import com.dfsek.terra.configureCompilation
|
||||
import com.dfsek.terra.configureDependencies
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
idea
|
||||
}
|
||||
|
||||
configureCompilation()
|
||||
configureDependencies()
|
||||
|
||||
group = "com.dfsek.terra.common"
|
||||
|
||||
dependencies {
|
||||
"shadedApi"(project(":common:api"))
|
||||
"compileOnly"("com.google.guava:guava:30.0-jre")
|
||||
|
||||
"testImplementation"("com.google.guava:guava:30.0-jre")
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
artifact(tasks["sourcesJar"])
|
||||
artifact(tasks["jar"])
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
val mavenUrl = "https://repo.codemc.io/repository/maven-releases/"
|
||||
val mavenSnapshotUrl = "https://repo.codemc.io/repository/maven-snapshots/"
|
||||
|
||||
maven(mavenUrl) {
|
||||
val mavenUsername: String? by project
|
||||
val mavenPassword: String? by project
|
||||
if (mavenUsername != null && mavenPassword != null) {
|
||||
credentials {
|
||||
username = mavenUsername
|
||||
password = mavenPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.dfsek.terra.addons.tree;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
import com.dfsek.terra.api.addon.annotations.Author;
|
||||
import com.dfsek.terra.api.addon.annotations.Version;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
|
||||
@Addon("config-tree")
|
||||
@Author("Terra")
|
||||
@Version("1.0.0")
|
||||
public class TreeAddon extends TerraAddon implements EventListener {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager().registerListener(this, this);
|
||||
}
|
||||
|
||||
public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException {
|
||||
event.getPack().registerConfigType(new TreeConfigType(), "TREE", 2);
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.dfsek.terra.addons.tree;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
import com.dfsek.terra.api.config.ConfigType;
|
||||
import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class TreeConfigType implements ConfigType<TreeTemplate, Tree> {
|
||||
private final TreeFactory factory = new TreeFactory();
|
||||
|
||||
public static final TypeKey<Tree> TREE_TYPE_TOKEN = new TypeKey<>(){};
|
||||
|
||||
@Override
|
||||
public TreeTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new TreeTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<TreeTemplate, Tree> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Tree> getTypeClass() {
|
||||
return TREE_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<Tree>> registrySupplier(ConfigPack pack) {
|
||||
return pack.getRegistryFactory()::create;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
package com.dfsek.terra.addons.tree;
|
||||
|
||||
import com.dfsek.terra.addons.tree.tree.TerraTree;
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
|
||||
public class TreeFactory implements ConfigFactory<TreeTemplate, Tree> {
|
||||
@Override
|
||||
public Tree build(TreeTemplate config, TerraPlugin main) {
|
||||
return new TerraTree(config.getSpawnable(), config.getyOffset(), config.getStructures());
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.dfsek.terra.addons.tree;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Final;
|
||||
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.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
@SuppressWarnings({"unused", "FieldMayBeFinal"})
|
||||
public class TreeTemplate implements AbstractableTemplate {
|
||||
@Value("scripts")
|
||||
private ProbabilityCollection<Structure> structure;
|
||||
|
||||
@Value("id")
|
||||
@Final
|
||||
private String id;
|
||||
|
||||
@Value("y-offset")
|
||||
@Default
|
||||
private int yOffset = 0;
|
||||
|
||||
@Value("spawnable")
|
||||
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,33 +0,0 @@
|
||||
package com.dfsek.terra.addons.tree.tree;
|
||||
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.structure.rotation.Rotation;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
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,45 +0,0 @@
|
||||
import com.dfsek.terra.configureCompilation
|
||||
import com.dfsek.terra.configureDependencies
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
idea
|
||||
}
|
||||
|
||||
configureCompilation()
|
||||
configureDependencies()
|
||||
|
||||
group = "com.dfsek.terra.common"
|
||||
|
||||
dependencies {
|
||||
"shadedApi"(project(":common:api"))
|
||||
"compileOnly"("com.google.guava:guava:30.0-jre")
|
||||
|
||||
"testImplementation"("com.google.guava:guava:30.0-jre")
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("mavenJava") {
|
||||
artifact(tasks["sourcesJar"])
|
||||
artifact(tasks["jar"])
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
val mavenUrl = "https://repo.codemc.io/repository/maven-releases/"
|
||||
val mavenSnapshotUrl = "https://repo.codemc.io/repository/maven-snapshots/"
|
||||
|
||||
maven(mavenUrl) {
|
||||
val mavenUsername: String? by project
|
||||
val mavenPassword: String? by project
|
||||
if (mavenUsername != null && mavenPassword != null) {
|
||||
credentials {
|
||||
username = mavenUsername
|
||||
password = mavenPassword
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
package com.dfsek.terra.addons.generation.tree;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BiomeTreeTemplate implements ObjectTemplate<BiomeTrees> {
|
||||
@Value("trees")
|
||||
@Default
|
||||
private List<TreeLayer> trees = Collections.emptyList();
|
||||
|
||||
@Override
|
||||
public BiomeTrees get() {
|
||||
return new BiomeTrees(trees);
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.dfsek.terra.addons.generation.tree;
|
||||
|
||||
import com.dfsek.terra.api.properties.Properties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BiomeTrees implements Properties {
|
||||
private final List<TreeLayer> trees;
|
||||
|
||||
public BiomeTrees(List<TreeLayer> trees) {
|
||||
this.trees = trees;
|
||||
}
|
||||
|
||||
public List<TreeLayer> getTrees() {
|
||||
return trees;
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package com.dfsek.terra.addons.generation.tree;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.addon.TerraAddon;
|
||||
import com.dfsek.terra.api.addon.annotations.Addon;
|
||||
import com.dfsek.terra.api.addon.annotations.Author;
|
||||
import com.dfsek.terra.api.addon.annotations.Version;
|
||||
import com.dfsek.terra.api.event.EventListener;
|
||||
import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent;
|
||||
import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
import com.dfsek.terra.api.registry.exception.DuplicateEntryException;
|
||||
import com.dfsek.terra.api.world.biome.TerraBiome;
|
||||
import com.dfsek.terra.api.world.generator.GenerationStageProvider;
|
||||
|
||||
@Addon("generation-stage-tree")
|
||||
@Version("1.0.0")
|
||||
@Author("Tree")
|
||||
public class TreeGenerationAddon extends TerraAddon implements EventListener {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager().registerListener(this, this);
|
||||
}
|
||||
|
||||
public void onPackLoad(ConfigPackPreLoadEvent event) throws DuplicateEntryException {
|
||||
event.getPack().getOrCreateRegistry(GenerationStageProvider.class).register("TREE", pack -> new TreePopulator(main));
|
||||
event.getPack().applyLoader(TreeLayer.class, TreeLayerTemplate::new);
|
||||
}
|
||||
|
||||
public void onBiomeLoad(ConfigurationLoadEvent event) {
|
||||
if(event.is(TerraBiome.class)) {
|
||||
event.getLoadedObject(TerraBiome.class).getContext().put(event.load(new BiomeTreeTemplate()).get());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package com.dfsek.terra.addons.generation.tree;
|
||||
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.PopulationUtil;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
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;
|
||||
|
||||
public class TreeLayer {
|
||||
protected final double density;
|
||||
protected final Range level;
|
||||
protected final ProbabilityCollection<Tree> layer;
|
||||
protected final NoiseSampler noise;
|
||||
|
||||
public TreeLayer(double density, Range level, ProbabilityCollection<Tree> layer, NoiseSampler noise) {
|
||||
this.density = density;
|
||||
this.level = level;
|
||||
this.layer = layer;
|
||||
this.noise = noise;
|
||||
}
|
||||
|
||||
public NoiseSampler getNoise() {
|
||||
return noise;
|
||||
}
|
||||
|
||||
public double getDensity() {
|
||||
return density;
|
||||
}
|
||||
|
||||
public Range getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public ProbabilityCollection<Tree> getLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public void place(Chunk chunk, Vector2 coords) {
|
||||
Tree item = layer.get(noise, coords.getX(), coords.getZ(), chunk.getWorld().getSeed());
|
||||
BlockState current;
|
||||
int cx = (chunk.getX()) << 4;
|
||||
int cz = (chunk.getZ()) << 4;
|
||||
for(int y : level) {
|
||||
current = chunk.getBlock((int) coords.getX(), y, (int) coords.getZ());
|
||||
if(item.getSpawnable().contains(current.getBlockType())) {
|
||||
item.plant(new Vector3((int) coords.getX() + cx, y+1, (int) coords.getZ() + cz), chunk.getWorld(), PopulationUtil.getRandom(chunk, coords.hashCode()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.dfsek.terra.addons.generation.tree;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.Range;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
import com.dfsek.terra.api.world.Tree;
|
||||
|
||||
public class TreeLayerTemplate implements ObjectTemplate<TreeLayer> {
|
||||
@Value("density")
|
||||
private double density;
|
||||
|
||||
@Value("y")
|
||||
private Range y;
|
||||
|
||||
@Value("items")
|
||||
private ProbabilityCollection<Tree> items;
|
||||
|
||||
@Value("distribution")
|
||||
private NoiseSampler distribution;
|
||||
|
||||
@Override
|
||||
public TreeLayer get() {
|
||||
return new TreeLayer(density, y, items, distribution);
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.dfsek.terra.addons.generation.tree;
|
||||
|
||||
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.generation.BiomeProvider;
|
||||
import com.dfsek.terra.api.world.generator.TerraGenerationStage;
|
||||
import net.jafama.FastMath;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class TreePopulator implements TerraGenerationStage {
|
||||
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;
|
||||
|
||||
BiomeProvider provider = tw.getBiomeProvider();
|
||||
Random random = PopulationUtil.getRandom(chunk);
|
||||
long seed = world.getSeed();
|
||||
for(int x = 0; x < 16; x += 2) {
|
||||
for(int z = 0; z < 16; z += 2) {
|
||||
for(TreeLayer layer : provider.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, seed).getContext().get(BiomeTrees.class).getTrees()) {
|
||||
if(layer.getDensity() >= random.nextDouble() * 100) {
|
||||
layer.place(chunk, new Vector2(offset(random, x), offset(random, z)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -320,32 +320,6 @@ public class TerraFabricPlugin implements TerraPlugin, ModInitializer {
|
||||
|
||||
}
|
||||
|
||||
@Priority(Priority.HIGHEST)
|
||||
@Global
|
||||
public void injectTrees(ConfigTypePostLoadEvent event) {
|
||||
if(!event.is(Tree.class)) return;
|
||||
CheckedRegistry<Tree> treeRegistry = event.getPack().getOrCreateRegistry(Tree.class);
|
||||
injectTree(treeRegistry, "BROWN_MUSHROOM", ConfiguredFeatures.HUGE_BROWN_MUSHROOM);
|
||||
injectTree(treeRegistry, "RED_MUSHROOM", ConfiguredFeatures.HUGE_RED_MUSHROOM);
|
||||
injectTree(treeRegistry, "JUNGLE", ConfiguredFeatures.MEGA_JUNGLE_TREE);
|
||||
injectTree(treeRegistry, "JUNGLE_COCOA", ConfiguredFeatures.JUNGLE_TREE);
|
||||
injectTree(treeRegistry, "LARGE_OAK", ConfiguredFeatures.FANCY_OAK);
|
||||
injectTree(treeRegistry, "LARGE_SPRUCE", ConfiguredFeatures.PINE);
|
||||
injectTree(treeRegistry, "SMALL_JUNGLE", ConfiguredFeatures.JUNGLE_TREE);
|
||||
injectTree(treeRegistry, "SWAMP_OAK", ConfiguredFeatures.SWAMP_OAK);
|
||||
injectTree(treeRegistry, "TALL_BIRCH", ConfiguredFeatures.BIRCH_TALL);
|
||||
injectTree(treeRegistry, "ACACIA", ConfiguredFeatures.ACACIA);
|
||||
injectTree(treeRegistry, "BIRCH", ConfiguredFeatures.BIRCH);
|
||||
injectTree(treeRegistry, "DARK_OAK", ConfiguredFeatures.DARK_OAK);
|
||||
injectTree(treeRegistry, "OAK", ConfiguredFeatures.OAK);
|
||||
injectTree(treeRegistry, "CHORUS_PLANT", ConfiguredFeatures.CHORUS_PLANT);
|
||||
injectTree(treeRegistry, "SPRUCE", ConfiguredFeatures.SPRUCE);
|
||||
injectTree(treeRegistry, "JUNGLE_BUSH", ConfiguredFeatures.JUNGLE_BUSH);
|
||||
injectTree(treeRegistry, "MEGA_SPRUCE", ConfiguredFeatures.MEGA_SPRUCE);
|
||||
injectTree(treeRegistry, "CRIMSON_FUNGUS", ConfiguredFeatures.CRIMSON_FUNGI);
|
||||
injectTree(treeRegistry, "WARPED_FUNGUS", ConfiguredFeatures.WARPED_FUNGI);
|
||||
}
|
||||
|
||||
@Priority(Priority.HIGHEST)
|
||||
@Global
|
||||
public void createInjectionOptions(ConfigPackPostLoadEvent event) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user