mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-06-19 07:11:14 +00:00
Reformat all code
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
This commit is contained in:
+9
-8
@@ -11,22 +11,23 @@ import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent;
|
||||
import com.dfsek.terra.api.event.functional.FunctionalEventHandler;
|
||||
import com.dfsek.terra.api.injection.annotations.Inject;
|
||||
|
||||
|
||||
@Addon("config-flora")
|
||||
@Author("Terra")
|
||||
@Version("0.1.0")
|
||||
public class FloraAddon extends TerraAddon {
|
||||
@Inject
|
||||
private TerraPlugin main;
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
main.getEventManager()
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().registerConfigType(new FloraConfigType(), "FLORA", 2);
|
||||
event.getPack().applyLoader(BlockLayer.class, BlockLayerTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
.getHandler(FunctionalEventHandler.class)
|
||||
.register(this, ConfigPackPreLoadEvent.class)
|
||||
.then(event -> {
|
||||
event.getPack().registerConfigType(new FloraConfigType(), "FLORA", 2);
|
||||
event.getPack().applyLoader(BlockLayer.class, BlockLayerTemplate::new);
|
||||
})
|
||||
.failThrough();
|
||||
}
|
||||
}
|
||||
|
||||
+20
-19
@@ -1,5 +1,7 @@
|
||||
package com.dfsek.terra.addons.flora;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.config.ConfigPack;
|
||||
@@ -8,30 +10,29 @@ import com.dfsek.terra.api.registry.OpenRegistry;
|
||||
import com.dfsek.terra.api.util.reflection.TypeKey;
|
||||
import com.dfsek.terra.api.world.Flora;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class FloraConfigType implements ConfigType<FloraTemplate, Flora> {
|
||||
public static final TypeKey<Flora> FLORA_TYPE_TOKEN = new TypeKey<>() {
|
||||
};
|
||||
private final FloraFactory factory = new FloraFactory();
|
||||
|
||||
public static final TypeKey<Flora> FLORA_TYPE_TOKEN = new TypeKey<>(){};
|
||||
|
||||
@Override
|
||||
public FloraTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new FloraTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<FloraTemplate, Flora> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Flora> getTypeKey() {
|
||||
return FLORA_TYPE_TOKEN;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Supplier<OpenRegistry<Flora>> registrySupplier(ConfigPack pack) {
|
||||
return pack.getRegistryFactory()::create;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FloraTemplate getTemplate(ConfigPack pack, TerraPlugin main) {
|
||||
return new FloraTemplate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigFactory<FloraTemplate, Flora> getFactory() {
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKey<Flora> getTypeKey() {
|
||||
return FLORA_TYPE_TOKEN;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -5,9 +5,12 @@ import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.config.ConfigFactory;
|
||||
import com.dfsek.terra.api.world.Flora;
|
||||
|
||||
|
||||
public class FloraFactory implements ConfigFactory<FloraTemplate, Flora> {
|
||||
@Override
|
||||
public TerraFlora build(FloraTemplate config, TerraPlugin main) {
|
||||
return new TerraFlora(config.getLayers(), config.doPhysics(), config.isCeiling(), config.getIrrigable(), config.getSpawnable(), config.getReplaceable(), config.getRotatable(), config.getMaxPlacements(), config.getSearch(), config.isSpawnBlacklist(), config.getIrrigableOffset(), main, config.getNoiseDistribution());
|
||||
return new TerraFlora(config.getLayers(), config.doPhysics(), config.isCeiling(), config.getIrrigable(), config.getSpawnable(),
|
||||
config.getReplaceable(), config.getRotatable(), config.getMaxPlacements(), config.getSearch(),
|
||||
config.isSpawnBlacklist(), config.getIrrigableOffset(), main, config.getNoiseDistribution());
|
||||
}
|
||||
}
|
||||
|
||||
+58
-56
@@ -3,6 +3,9 @@ package com.dfsek.terra.addons.flora;
|
||||
import com.dfsek.tectonic.annotations.Default;
|
||||
import com.dfsek.tectonic.annotations.Final;
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.dfsek.terra.addons.flora.flora.gen.BlockLayer;
|
||||
import com.dfsek.terra.addons.flora.flora.gen.TerraFlora;
|
||||
import com.dfsek.terra.api.config.AbstractableTemplate;
|
||||
@@ -10,108 +13,107 @@ import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.noise.NoiseSampler;
|
||||
import com.dfsek.terra.api.util.collection.MaterialSet;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings({"FieldMayBeFinal", "unused"})
|
||||
@SuppressWarnings({ "FieldMayBeFinal", "unused" })
|
||||
public class FloraTemplate implements AbstractableTemplate {
|
||||
@Value("id")
|
||||
@Final
|
||||
private String id;
|
||||
|
||||
|
||||
@Value("spawnable")
|
||||
private @Meta MaterialSet spawnable;
|
||||
|
||||
|
||||
@Value("spawn-blacklist")
|
||||
@Default
|
||||
private @Meta boolean spawnBlacklist = false;
|
||||
|
||||
|
||||
|
||||
|
||||
@Value("replaceable")
|
||||
@Default
|
||||
private @Meta MaterialSet replaceable = MaterialSet.empty();
|
||||
|
||||
|
||||
@Value("irrigable")
|
||||
@Default
|
||||
private @Meta MaterialSet irrigable = null;
|
||||
|
||||
private @Meta MaterialSet irrigable;
|
||||
|
||||
@Value("rotatable")
|
||||
@Default
|
||||
private @Meta MaterialSet rotatable = MaterialSet.empty();
|
||||
|
||||
|
||||
@Value("physics")
|
||||
@Default
|
||||
private @Meta boolean doPhysics = false;
|
||||
|
||||
|
||||
@Value("ceiling")
|
||||
@Default
|
||||
private @Meta boolean ceiling = false;
|
||||
|
||||
|
||||
@Value("search")
|
||||
@Default
|
||||
private TerraFlora.@Meta Search search = TerraFlora.Search.UP;
|
||||
|
||||
|
||||
@Value("max-placements")
|
||||
@Default
|
||||
private @Meta int maxPlacements = -1;
|
||||
|
||||
|
||||
@Value("irrigable-offset")
|
||||
@Default
|
||||
private @Meta int irrigableOffset;
|
||||
|
||||
|
||||
@Value("layers")
|
||||
private @Meta List<@Meta BlockLayer> layers;
|
||||
|
||||
|
||||
@Value("layer-distribution")
|
||||
private @Meta NoiseSampler noiseDistribution;
|
||||
|
||||
public NoiseSampler getNoiseDistribution() {
|
||||
return noiseDistribution;
|
||||
}
|
||||
|
||||
public List<BlockLayer> getLayers() {
|
||||
return layers;
|
||||
}
|
||||
|
||||
public int getIrrigableOffset() {
|
||||
return irrigableOffset;
|
||||
}
|
||||
|
||||
public TerraFlora.Search getSearch() {
|
||||
return search;
|
||||
}
|
||||
|
||||
public int getMaxPlacements() {
|
||||
return maxPlacements;
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
|
||||
public MaterialSet getIrrigable() {
|
||||
return irrigable;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
public boolean doPhysics() {
|
||||
return doPhysics;
|
||||
}
|
||||
|
||||
|
||||
public NoiseSampler getNoiseDistribution() {
|
||||
return noiseDistribution;
|
||||
}
|
||||
|
||||
public List<BlockLayer> getLayers() {
|
||||
return layers;
|
||||
}
|
||||
|
||||
public int getIrrigableOffset() {
|
||||
return irrigableOffset;
|
||||
}
|
||||
|
||||
public TerraFlora.Search getSearch() {
|
||||
return search;
|
||||
}
|
||||
|
||||
public int getMaxPlacements() {
|
||||
return maxPlacements;
|
||||
}
|
||||
|
||||
public MaterialSet getReplaceable() {
|
||||
return replaceable;
|
||||
}
|
||||
|
||||
public MaterialSet getSpawnable() {
|
||||
return spawnable;
|
||||
}
|
||||
|
||||
public MaterialSet getIrrigable() {
|
||||
return irrigable;
|
||||
}
|
||||
|
||||
public String getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isCeiling() {
|
||||
return ceiling;
|
||||
}
|
||||
|
||||
|
||||
public boolean isSpawnBlacklist() {
|
||||
return spawnBlacklist;
|
||||
}
|
||||
|
||||
|
||||
public MaterialSet getRotatable() {
|
||||
return rotatable;
|
||||
}
|
||||
|
||||
+4
-2
@@ -2,18 +2,20 @@ package com.dfsek.terra.addons.flora.config;
|
||||
|
||||
import com.dfsek.tectonic.annotations.Value;
|
||||
import com.dfsek.tectonic.loading.object.ObjectTemplate;
|
||||
|
||||
import com.dfsek.terra.addons.flora.flora.gen.BlockLayer;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.config.meta.Meta;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
public class BlockLayerTemplate implements ObjectTemplate<BlockLayer> {
|
||||
@Value("layers")
|
||||
private @Meta int layers;
|
||||
|
||||
|
||||
@Value("materials")
|
||||
private @Meta ProbabilityCollection<BlockState> data;
|
||||
|
||||
|
||||
@Override
|
||||
public BlockLayer get() {
|
||||
return new BlockLayer(layers, data);
|
||||
|
||||
+4
-3
@@ -3,19 +3,20 @@ package com.dfsek.terra.addons.flora.flora.gen;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.util.collection.ProbabilityCollection;
|
||||
|
||||
|
||||
public class BlockLayer {
|
||||
private final int layers;
|
||||
private final ProbabilityCollection<BlockState> blocks;
|
||||
|
||||
|
||||
public BlockLayer(int layers, ProbabilityCollection<BlockState> blocks) {
|
||||
this.layers = layers;
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
|
||||
public int getLayers() {
|
||||
return layers;
|
||||
}
|
||||
|
||||
|
||||
public ProbabilityCollection<BlockState> getBlocks() {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
+69
-60
@@ -1,6 +1,12 @@
|
||||
package com.dfsek.terra.addons.flora.flora.gen;
|
||||
|
||||
import com.dfsek.terra.addons.flora.flora.gen.BlockLayer;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.dfsek.terra.api.TerraPlugin;
|
||||
import com.dfsek.terra.api.block.state.BlockState;
|
||||
import com.dfsek.terra.api.block.state.properties.base.Properties;
|
||||
@@ -13,38 +19,35 @@ import com.dfsek.terra.api.vector.Vector3;
|
||||
import com.dfsek.terra.api.world.Chunk;
|
||||
import com.dfsek.terra.api.world.Flora;
|
||||
import com.dfsek.terra.api.world.World;
|
||||
import net.jafama.FastMath;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class TerraFlora implements Flora {
|
||||
private final List<ProbabilityCollection<BlockState>> layers;
|
||||
private final boolean physics;
|
||||
private final boolean ceiling;
|
||||
|
||||
|
||||
private final MaterialSet irrigable;
|
||||
|
||||
|
||||
private final MaterialSet spawnable;
|
||||
private final MaterialSet replaceable;
|
||||
|
||||
|
||||
private final MaterialSet testRotation;
|
||||
|
||||
|
||||
private final int maxPlacements;
|
||||
|
||||
|
||||
private final Search search;
|
||||
|
||||
|
||||
private final boolean spawnBlacklist;
|
||||
|
||||
|
||||
private final int irrigableOffset;
|
||||
|
||||
|
||||
private final TerraPlugin main;
|
||||
|
||||
|
||||
private final NoiseSampler distribution;
|
||||
|
||||
public TerraFlora(List<BlockLayer> layers, boolean physics, boolean ceiling, MaterialSet irrigable, MaterialSet spawnable, MaterialSet replaceable, MaterialSet testRotation, int maxPlacements, Search search, boolean spawnBlacklist, int irrigableOffset, TerraPlugin main, NoiseSampler distribution) {
|
||||
|
||||
public TerraFlora(List<BlockLayer> layers, boolean physics, boolean ceiling, MaterialSet irrigable, MaterialSet spawnable,
|
||||
MaterialSet replaceable, MaterialSet testRotation, int maxPlacements, Search search, boolean spawnBlacklist,
|
||||
int irrigableOffset, TerraPlugin main, NoiseSampler distribution) {
|
||||
this.physics = physics;
|
||||
this.testRotation = testRotation;
|
||||
this.spawnBlacklist = spawnBlacklist;
|
||||
@@ -57,7 +60,7 @@ public class TerraFlora implements Flora {
|
||||
this.irrigableOffset = irrigableOffset;
|
||||
this.main = main;
|
||||
this.distribution = distribution;
|
||||
|
||||
|
||||
this.layers = new ArrayList<>();
|
||||
layers.forEach(layer -> {
|
||||
for(int i = 0; i < layer.getLayers(); i++) {
|
||||
@@ -65,7 +68,35 @@ public class TerraFlora implements Flora {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean plant(Vector3 location, World world) {
|
||||
boolean doRotation = testRotation.size() > 0;
|
||||
int size = layers.size();
|
||||
int c = ceiling ? -1 : 1;
|
||||
|
||||
EnumSet<Direction> faces = doRotation ? getFaces(location.clone().add(0, c, 0), world) : EnumSet.noneOf(Direction.class);
|
||||
if(doRotation && faces.size() == 0) return false; // Don't plant if no faces are valid.
|
||||
|
||||
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||
int lvl = (FastMath.abs(i));
|
||||
BlockState data = getStateCollection((ceiling ? lvl : size - lvl - 1)).get(distribution, location.getX(), location.getY(),
|
||||
location.getZ(), world.getSeed()).clone();
|
||||
if(doRotation) {
|
||||
Direction oneFace = new ArrayList<>(faces).get(
|
||||
new Random(location.getBlockX() ^ location.getBlockZ()).nextInt(faces.size())); // Get random face.
|
||||
|
||||
data.setIfPresent(Properties.DIRECTION, oneFace.opposite())
|
||||
.setIfPresent(Properties.NORTH, faces.contains(Direction.NORTH))
|
||||
.setIfPresent(Properties.SOUTH, faces.contains(Direction.SOUTH))
|
||||
.setIfPresent(Properties.EAST, faces.contains(Direction.EAST))
|
||||
.setIfPresent(Properties.WEST, faces.contains(Direction.WEST));
|
||||
}
|
||||
world.setBlockData(location.clone().add(0, i + c, 0), data, physics);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Vector3> getValidSpawnsAt(Chunk chunk, int x, int z, Range range) {
|
||||
int size = layers.size();
|
||||
@@ -76,14 +107,17 @@ public class TerraFlora implements Flora {
|
||||
for(int y : range) {
|
||||
if(y > 255 || y < 0) continue;
|
||||
current = current.add(0, search.equals(Search.UP) ? 1 : -1, 0);
|
||||
if((spawnBlacklist != spawnable.contains(chunk.getBlock(current.getBlockX(), current.getBlockY(), current.getBlockZ()).getBlockType())) && isIrrigated(current.clone().add(cx, irrigableOffset, cz), chunk.getWorld()) && valid(size, current.clone().add(cx, 0, cz), chunk.getWorld())) {
|
||||
if((spawnBlacklist != spawnable.contains(
|
||||
chunk.getBlock(current.getBlockX(), current.getBlockY(), current.getBlockZ()).getBlockType())) && isIrrigated(
|
||||
current.clone().add(cx, irrigableOffset, cz), chunk.getWorld()) && valid(size, current.clone().add(cx, 0, cz),
|
||||
chunk.getWorld())) {
|
||||
blocks.add(current.clone());
|
||||
if(maxPlacements > 0 && blocks.size() >= maxPlacements) break;
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
|
||||
private boolean valid(int size, Vector3 block, World world) {
|
||||
for(int i = 0; i < size; i++) { // Down if ceiling, up if floor
|
||||
if(block.getY() + 1 > 255 || block.getY() < 0) return false;
|
||||
@@ -92,45 +126,25 @@ public class TerraFlora implements Flora {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void test(EnumSet<Direction> faces, Direction f, Vector3 b, World world) {
|
||||
if(testRotation.contains(
|
||||
world.getBlockData(b.getBlockX() + f.getModX(), b.getBlockY() + f.getModY(), b.getBlockZ() + f.getModZ()).getBlockType()))
|
||||
faces.add(f);
|
||||
}
|
||||
|
||||
private boolean isIrrigated(Vector3 b, World world) {
|
||||
if(irrigable == null) return true;
|
||||
return irrigable.contains(world.getBlockData(b.getBlockX() + 1, b.getBlockY(), b.getBlockZ()).getBlockType())
|
||||
|| irrigable.contains(world.getBlockData(b.getBlockX() - 1, b.getBlockY(), b.getBlockZ()).getBlockType())
|
||||
|| irrigable.contains(world.getBlockData(b.getBlockX(), b.getBlockY(), b.getBlockZ() + 1).getBlockType())
|
||||
|| irrigable.contains(world.getBlockData(b.getBlockX(), b.getBlockY(), b.getBlockZ() - 1).getBlockType());
|
||||
|| irrigable.contains(world.getBlockData(b.getBlockX() - 1, b.getBlockY(), b.getBlockZ()).getBlockType())
|
||||
|| irrigable.contains(world.getBlockData(b.getBlockX(), b.getBlockY(), b.getBlockZ() + 1).getBlockType())
|
||||
|| irrigable.contains(world.getBlockData(b.getBlockX(), b.getBlockY(), b.getBlockZ() - 1).getBlockType());
|
||||
}
|
||||
|
||||
|
||||
private ProbabilityCollection<BlockState> getStateCollection(int layer) {
|
||||
return layers.get(FastMath.max(FastMath.min(layer, layers.size()-1), 0));
|
||||
return layers.get(FastMath.max(FastMath.min(layer, layers.size() - 1), 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plant(Vector3 location, World world) {
|
||||
boolean doRotation = testRotation.size() > 0;
|
||||
int size = layers.size();
|
||||
int c = ceiling ? -1 : 1;
|
||||
|
||||
EnumSet<Direction> faces = doRotation ? getFaces(location.clone().add(0, c, 0), world) : EnumSet.noneOf(Direction.class);
|
||||
if(doRotation && faces.size() == 0) return false; // Don't plant if no faces are valid.
|
||||
|
||||
for(int i = 0; FastMath.abs(i) < size; i += c) { // Down if ceiling, up if floor
|
||||
int lvl = (FastMath.abs(i));
|
||||
BlockState data = getStateCollection((ceiling ? lvl : size - lvl - 1)).get(distribution, location.getX(), location.getY(), location.getZ(), world.getSeed()).clone();
|
||||
if(doRotation) {
|
||||
Direction oneFace = new ArrayList<>(faces).get(new Random(location.getBlockX() ^ location.getBlockZ()).nextInt(faces.size())); // Get random face.
|
||||
|
||||
data.setIfPresent(Properties.DIRECTION, oneFace.opposite())
|
||||
.setIfPresent(Properties.NORTH, faces.contains(Direction.NORTH))
|
||||
.setIfPresent(Properties.SOUTH, faces.contains(Direction.SOUTH))
|
||||
.setIfPresent(Properties.EAST, faces.contains(Direction.EAST))
|
||||
.setIfPresent(Properties.WEST, faces.contains(Direction.WEST));
|
||||
}
|
||||
world.setBlockData(location.clone().add(0, i + c, 0), data, physics);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private EnumSet<Direction> getFaces(Vector3 b, World world) {
|
||||
EnumSet<Direction> faces = EnumSet.noneOf(Direction.class);
|
||||
test(faces, Direction.NORTH, b, world);
|
||||
@@ -139,12 +153,7 @@ public class TerraFlora implements Flora {
|
||||
test(faces, Direction.WEST, b, world);
|
||||
return faces;
|
||||
}
|
||||
|
||||
private void test(EnumSet<Direction> faces, Direction f, Vector3 b, World world) {
|
||||
if(testRotation.contains(world.getBlockData(b.getBlockX() + f.getModX(), b.getBlockY() + f.getModY(), b.getBlockZ() + f.getModZ()).getBlockType()))
|
||||
faces.add(f);
|
||||
}
|
||||
|
||||
|
||||
public enum Search {
|
||||
UP,
|
||||
DOWN
|
||||
|
||||
Reference in New Issue
Block a user