Reformat & add .editorconfig

This commit is contained in:
dfsek
2020-11-06 15:21:42 -07:00
parent bfa55fdb5d
commit 4f40550465
33 changed files with 527 additions and 280 deletions

View File

@@ -30,6 +30,36 @@ import java.util.Random;
* Populates Flora and Trees
*/
public class FloraPopulator extends GaeaBlockPopulator {
private static boolean doTrees(@NotNull UserDefinedBiome biome, TerraWorld world, @NotNull Random random, @NotNull Chunk chunk, int x, int z) {
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
Tree tree = biome.getDecorator().getTrees().get(random);
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
if(! range.isInRange(block.getY())) continue;
try {
Location l = block.getLocation();
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
Bukkit.getPluginManager().callEvent(event);
if(! event.isCancelled()) tree.plant(l, random, Terra.getInstance());
} catch(NullPointerException ignore) {
}
}
return false;
}
private static int offset(Random r, int i) {
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
}
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
List<Block> blocks = new ArrayList<>();
for(int y : check) {
if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
blocks.add(chunk.getBlock(x, y + 1, z));
}
}
return blocks;
}
@Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
@@ -70,34 +100,4 @@ public class FloraPopulator extends GaeaBlockPopulator {
}
}
}
private static boolean doTrees(@NotNull UserDefinedBiome biome, TerraWorld world, @NotNull Random random, @NotNull Chunk chunk, int x, int z) {
for(Block block : getValidTreeSpawnsAt(chunk, x, z, new Range(0, 254))) {
Tree tree = biome.getDecorator().getTrees().get(random);
Range range = world.getConfig().getBiome(biome).getTreeRange(tree);
if(! range.isInRange(block.getY())) continue;
try {
Location l = block.getLocation();
TreeGenerateEvent event = new TreeGenerateEvent(world, l, tree);
Bukkit.getPluginManager().callEvent(event);
if(! event.isCancelled()) tree.plant(l, random, Terra.getInstance());
} catch(NullPointerException ignore) {
}
}
return false;
}
private static int offset(Random r, int i) {
return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15);
}
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
List<Block> blocks = new ArrayList<>();
for(int y : check) {
if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) {
blocks.add(chunk.getBlock(x, y + 1, z));
}
}
return blocks;
}
}