Use FastRandom in populators, fix issues with flora/tree pop

This commit is contained in:
dfsek 2020-11-22 20:20:26 -07:00
parent 2b5fd16e4a
commit 7509c03cbd
9 changed files with 28 additions and 17 deletions

View File

@ -41,7 +41,7 @@ public final class ConfigUtil {
dataSave = Duration.parse(Objects.requireNonNull(config.getString("data-save", "PT6M"))).toMillis() / 20L; dataSave = Duration.parse(Objects.requireNonNull(config.getString("data-save", "PT6M"))).toMillis() / 20L;
masterDisableCaves = config.getBoolean("master-disable.caves", false); masterDisableCaves = config.getBoolean("master-disable.caves", false);
biomeSearchRes = config.getInt("biome-search-resolution", 4); biomeSearchRes = config.getInt("biome-search-resolution", 4);
cacheSize = config.getInt("cache-size", 256); cacheSize = config.getInt("cache-size", 384);
if(config.getBoolean("dump-default", true)) { if(config.getBoolean("dump-default", true)) {
try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) { try(JarFile jar = new JarFile(new File(Terra.class.getProtectionDomain().getCodeSource().getLocation().toURI()))) {

View File

@ -58,7 +58,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
super(ChunkInterpolator.InterpolationType.TRILINEAR); super(ChunkInterpolator.InterpolationType.TRILINEAR);
this.configPack = c; this.configPack = c;
popMan.attach(new TreePopulator()); popMan.attach(new TreePopulator());
popMan.attach(new FloraPopulator());
popMan.attach(new SnowPopulator()); popMan.attach(new SnowPopulator());
} }
@ -227,7 +226,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator {
@Override @Override
public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) { public @NotNull List<BlockPopulator> getDefaultPopulators(@NotNull World world) {
return Arrays.asList(new CavePopulator(), new StructurePopulator(), new OrePopulator(), popMan); return Arrays.asList(new CavePopulator(), new StructurePopulator(), new OrePopulator(), new FloraPopulator(), popMan);
} }
@Override @Override

View File

@ -5,6 +5,7 @@ import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.config.base.ConfigPack; import com.dfsek.terra.config.base.ConfigPack;
import com.dfsek.terra.config.base.ConfigUtil; import com.dfsek.terra.config.base.ConfigUtil;
import com.dfsek.terra.config.genconfig.CarverConfig; import com.dfsek.terra.config.genconfig.CarverConfig;
import com.dfsek.terra.util.PopulationUtil;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -30,9 +31,10 @@ public class CavePopulator extends BlockPopulator {
@SuppressWarnings("try") @SuppressWarnings("try")
@Override @Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
if(ConfigUtil.masterDisableCaves) return; if(ConfigUtil.masterDisableCaves) return;
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("CaveTime")) { try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("CaveTime")) {
Random random = PopulationUtil.getRandom(chunk);
TerraWorld tw = TerraWorld.getWorld(world); TerraWorld tw = TerraWorld.getWorld(world);
if(!tw.isSafe()) return; if(!tw.isSafe()) return;
ConfigPack config = tw.getConfig(); ConfigPack config = tw.getConfig();

View File

@ -6,12 +6,13 @@ import com.dfsek.terra.biome.UserDefinedBiome;
import com.dfsek.terra.biome.grid.TerraBiomeGrid; import com.dfsek.terra.biome.grid.TerraBiomeGrid;
import com.dfsek.terra.config.genconfig.biome.BiomeConfig; import com.dfsek.terra.config.genconfig.biome.BiomeConfig;
import com.dfsek.terra.config.genconfig.biome.BiomeFloraConfig; import com.dfsek.terra.config.genconfig.biome.BiomeFloraConfig;
import com.dfsek.terra.util.PopulationUtil;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.generator.BlockPopulator;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.generation.GenerationPhase; import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.population.GaeaBlockPopulator;
import org.polydev.gaea.profiler.ProfileFuture; import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.world.Flora; import org.polydev.gaea.world.Flora;
@ -20,13 +21,12 @@ import java.util.Random;
/** /**
* Populates Flora and Trees * Populates Flora and Trees
*/ */
public class FloraPopulator extends GaeaBlockPopulator { public class FloraPopulator extends BlockPopulator {
@SuppressWarnings("try") @SuppressWarnings("try")
@Override @Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) { try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) {
Random random = PopulationUtil.getRandom(chunk);
TerraWorld tw = TerraWorld.getWorld(world); TerraWorld tw = TerraWorld.getWorld(world);
if(!tw.isSafe()) return; if(!tw.isSafe()) return;
int originX = chunk.getX() << 4; int originX = chunk.getX() << 4;

View File

@ -12,6 +12,7 @@ import com.dfsek.terra.structure.Rotation;
import com.dfsek.terra.structure.Structure; import com.dfsek.terra.structure.Structure;
import com.dfsek.terra.structure.StructureContainedInventory; import com.dfsek.terra.structure.StructureContainedInventory;
import com.dfsek.terra.structure.features.Feature; import com.dfsek.terra.structure.features.Feature;
import com.dfsek.terra.util.PopulationUtil;
import com.dfsek.terra.util.structure.RotationUtil; import com.dfsek.terra.util.structure.RotationUtil;
import net.jafama.FastMath; import net.jafama.FastMath;
import org.bukkit.Chunk; import org.bukkit.Chunk;
@ -30,8 +31,9 @@ public class StructurePopulator extends BlockPopulator {
@SuppressWarnings("try") @SuppressWarnings("try")
@Override @Override
public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) { try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) {
Random random = PopulationUtil.getRandom(chunk);
int cx = (chunk.getX() << 4); int cx = (chunk.getX() << 4);
int cz = (chunk.getZ() << 4); int cz = (chunk.getZ() << 4);
TerraWorld tw = TerraWorld.getWorld(world); TerraWorld tw = TerraWorld.getWorld(world);

View File

@ -14,12 +14,10 @@ import org.bukkit.World;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.polydev.gaea.generation.GenerationPhase; import org.polydev.gaea.generation.GenerationPhase;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.math.Range; import org.polydev.gaea.math.Range;
import org.polydev.gaea.population.GaeaBlockPopulator; import org.polydev.gaea.population.GaeaBlockPopulator;
import org.polydev.gaea.profiler.ProfileFuture; import org.polydev.gaea.profiler.ProfileFuture;
import org.polydev.gaea.tree.Tree; import org.polydev.gaea.tree.Tree;
import org.polydev.gaea.util.FastRandom;
import org.polydev.gaea.util.GlueList; import org.polydev.gaea.util.GlueList;
import java.util.List; import java.util.List;
@ -45,7 +43,7 @@ public class TreePopulator extends GaeaBlockPopulator {
public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) { public static List<Block> getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) {
List<Block> blocks = new GlueList<>(); List<Block> blocks = new GlueList<>();
for(int y : check) { for(int y : check) {
if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).getType().isAir()) { if(chunk.getBlock(x, y, z).getType().isSolid() && chunk.getBlock(x, y + 1, z).isPassable()) {
blocks.add(chunk.getBlock(x, y + 1, z)); blocks.add(chunk.getBlock(x, y + 1, z));
} }
} }
@ -58,12 +56,11 @@ public class TreePopulator extends GaeaBlockPopulator {
@Override @Override
@SuppressWarnings("try") @SuppressWarnings("try")
public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) { public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) {
try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("TreeTime")) { try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("TreeTime")) {
TerraWorld tw = TerraWorld.getWorld(world); TerraWorld tw = TerraWorld.getWorld(world);
if(!tw.isSafe()) return; if(!tw.isSafe()) return;
TerraBiomeGrid grid = tw.getGrid(); TerraBiomeGrid grid = tw.getGrid();
FastRandom random = new FastRandom(MathUtil.getCarverChunkSeed(chunk.getX(), chunk.getZ(), world.getSeed()));
for(int x = 0; x < 16; x += 2) { for(int x = 0; x < 16; x += 2) {
for(int z = 0; z < 16; z += 2) { for(int z = 0; z < 16; z += 2) {
UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE); UserDefinedBiome biome = (UserDefinedBiome) grid.getBiome((chunk.getX() << 4) + x, (chunk.getZ() << 4) + z, GenerationPhase.POPULATE);

View File

@ -0,0 +1,11 @@
package com.dfsek.terra.util;
import org.bukkit.Chunk;
import org.polydev.gaea.math.MathUtil;
import org.polydev.gaea.util.FastRandom;
public final class PopulationUtil {
public static FastRandom getRandom(Chunk c) {
return new FastRandom(MathUtil.getCarverChunkSeed(c.getX(), c.getZ(), c.getWorld().getSeed()));
}
}

View File

@ -15,7 +15,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class TagUtil { public final class TagUtil {
private static final Map<String, Set<Material>> tagMap; private static final Map<String, Set<Material>> tagMap;
static { static {

View File

@ -4,6 +4,6 @@ language: "en_us"
fail-type: SHUTDOWN fail-type: SHUTDOWN
dump-default: true dump-default: true
biome-search-resolution: 4 biome-search-resolution: 4
cache-size: 256 cache-size: 384
master-disable: master-disable:
caves: false caves: false