diff --git a/src/main/java/com/dfsek/terra/TerraWorld.java b/src/main/java/com/dfsek/terra/TerraWorld.java index dbc0bd9f4..ea25f2f8d 100644 --- a/src/main/java/com/dfsek/terra/TerraWorld.java +++ b/src/main/java/com/dfsek/terra/TerraWorld.java @@ -24,14 +24,6 @@ public class TerraWorld { private final WorldConfig worldConfig; private boolean safe; - public static void loadWorld(WorldConfig w) { - loaded.put(w.getWorldID(), w); - } - - public static synchronized TerraWorld getWorld(World w) { - return map.computeIfAbsent(w, TerraWorld::new); - } - private TerraWorld(World w) { safe = true; worldConfig = loaded.get(w.getName()); @@ -87,6 +79,14 @@ public class TerraWorld { grid = new TerraBiomeGrid(w, config.freq1, config.freq2, zone, config, erosion); } + public static void loadWorld(WorldConfig w) { + loaded.put(w.getWorldID(), w); + } + + public static synchronized TerraWorld getWorld(World w) { + return map.computeIfAbsent(w, TerraWorld::new); + } + public static synchronized void invalidate() { map.clear(); for(WorldConfig config : loaded.values()) { @@ -98,6 +98,10 @@ public class TerraWorld { return map.size(); } + public static boolean isTerraWorld(World w) { + return w.getGenerator() instanceof TerraChunkGenerator; + } + public TerraBiomeGrid getGrid() { return grid; } @@ -117,8 +121,4 @@ public class TerraWorld { public boolean isSafe() { return safe; } - - public static boolean isTerraWorld(World w) { - return w.getGenerator() instanceof TerraChunkGenerator; - } } diff --git a/src/main/java/com/dfsek/terra/carving/SimplexCarver.java b/src/main/java/com/dfsek/terra/carving/SimplexCarver.java index 42a951f80..e88984a5c 100644 --- a/src/main/java/com/dfsek/terra/carving/SimplexCarver.java +++ b/src/main/java/com/dfsek/terra/carving/SimplexCarver.java @@ -40,6 +40,10 @@ public class SimplexCarver extends Carver { hasCaves.setFrequency(0.005f); } + private static double acot(double x) { + return Math.PI / 2 - Math.atan(x); + } + @Override public CarvingData carve(int chunkX, int chunkZ, World w) { CarvingData c = new CarvingData(chunkX, chunkZ); @@ -68,10 +72,6 @@ public class SimplexCarver extends Carver { return c; } - private static double acot(double x) { - return Math.PI / 2 - Math.atan(x); - } - @Override public Worm getWorm(long l, Vector vector) { return null; diff --git a/src/main/java/com/dfsek/terra/command/structure/load/LoadCommand.java b/src/main/java/com/dfsek/terra/command/structure/load/LoadCommand.java index 7a7eaa441..b3a962887 100644 --- a/src/main/java/com/dfsek/terra/command/structure/load/LoadCommand.java +++ b/src/main/java/com/dfsek/terra/command/structure/load/LoadCommand.java @@ -21,16 +21,6 @@ public class LoadCommand extends PlayerCommand implements DebugCommand { super(parent); } - @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { - return true; - } - - @Override - public String getName() { - return "load"; - } - public static List getStructureNames() { List names = new ArrayList<>(); File structureDir = new File(Terra.getInstance().getDataFolder() + File.separator + "export" + File.separator + "structures"); @@ -45,6 +35,16 @@ public class LoadCommand extends PlayerCommand implements DebugCommand { return names; } + @Override + public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { + return true; + } + + @Override + public String getName() { + return "load"; + } + @Override public List getSubCommands() { return Arrays.asList(new LoadRawCommand(this), new LoadFullCommand(this, true), new LoadFullCommand(this, false)); diff --git a/src/main/java/com/dfsek/terra/config/base/ConfigPack.java b/src/main/java/com/dfsek/terra/config/base/ConfigPack.java index 01fa2b265..17932fcf5 100644 --- a/src/main/java/com/dfsek/terra/config/base/ConfigPack.java +++ b/src/main/java/com/dfsek/terra/config/base/ConfigPack.java @@ -194,30 +194,6 @@ public class ConfigPack extends YamlConfiguration { LangUtil.log("config-pack.loaded", Level.INFO, getID(), String.valueOf((System.nanoTime() - l) / 1000000D)); } - public String getID() { - return id; - } - - public Map getDefinedVariables() { - return definedVariables; - } - - public Map getBiomes() { - return biomes; - } - - public StructureConfig getStructure(String id) { - return structures.get(id); - } - - public BiomeGridConfig getBiomeGrid(String id) { - return grids.get(id); - } - - public Map getNoiseBuilders() { - return noiseBuilders; - } - public static synchronized void loadAll(JavaPlugin main) { configs.clear(); File file = new File(main.getDataFolder(), "packs"); @@ -252,6 +228,30 @@ public class ConfigPack extends YamlConfiguration { return configs.get(id); } + public String getID() { + return id; + } + + public Map getDefinedVariables() { + return definedVariables; + } + + public Map getBiomes() { + return biomes; + } + + public StructureConfig getStructure(String id) { + return structures.get(id); + } + + public BiomeGridConfig getBiomeGrid(String id) { + return grids.get(id); + } + + public Map getNoiseBuilders() { + return noiseBuilders; + } + public Map getLocatable() { return locatable; } diff --git a/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java b/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java index a54de9a05..3801f1fbf 100644 --- a/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java +++ b/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java @@ -77,12 +77,6 @@ public class TerraChunkGenerator extends GaeaChunkGenerator { popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld()); } - @Override - public void attachProfiler(WorldProfiler p) { - super.attachProfiler(p); - popMan.attachProfiler(p); - } - private static Palette getPalette(int x, int y, int z, BiomeConfig c, ChunkInterpolator interpolator, ElevationInterpolator elevationInterpolator) { Palette slant = ((WorldGenerator) c.getBiome().getGenerator()).getSlantPalette(y); if(slant != null) { @@ -138,6 +132,12 @@ public class TerraChunkGenerator extends GaeaChunkGenerator { } } + @Override + public void attachProfiler(WorldProfiler p) { + super.attachProfiler(p); + popMan.attachProfiler(p); + } + @Override @SuppressWarnings("try") public ChunkData generateBase(@NotNull World world, @NotNull Random random, int chunkX, int chunkZ, ChunkInterpolator interpolator) { diff --git a/src/main/java/com/dfsek/terra/generation/config/NoiseBuilder.java b/src/main/java/com/dfsek/terra/generation/config/NoiseBuilder.java index 927162922..051dc3403 100644 --- a/src/main/java/com/dfsek/terra/generation/config/NoiseBuilder.java +++ b/src/main/java/com/dfsek/terra/generation/config/NoiseBuilder.java @@ -49,41 +49,6 @@ public class NoiseBuilder { return noise; } - public NoiseBuilder setFrequency(double frequency) { - this.frequency = frequency; - return this; - } - - public NoiseBuilder setFractalGain(double fractalGain) { - this.fractalGain = fractalGain; - return this; - } - - public NoiseBuilder setFractalLacunarity(double fractalLacunarity) { - this.fractalLacunarity = fractalLacunarity; - return this; - } - - public NoiseBuilder setFractalType(FastNoiseLite.FractalType fractalType) { - this.fractalType = fractalType; - return this; - } - - public NoiseBuilder setOctaves(int octaves) { - this.octaves = octaves; - return this; - } - - public NoiseBuilder setPingPong(double pingPong) { - this.pingPong = pingPong; - return this; - } - - public NoiseBuilder setWeightedStrength(double weightedStrength) { - this.weightedStrength = weightedStrength; - return this; - } - public FastNoiseLite.NoiseType getType() { return type; } @@ -93,21 +58,6 @@ public class NoiseBuilder { return this; } - public NoiseBuilder setCellularDistanceFunction(FastNoiseLite.CellularDistanceFunction cellularDistanceFunction) { - this.cellularDistanceFunction = cellularDistanceFunction; - return this; - } - - public NoiseBuilder setCellularReturnType(FastNoiseLite.CellularReturnType cellularReturnType) { - this.cellularReturnType = cellularReturnType; - return this; - } - - public NoiseBuilder setCellularJitter(double cellularJitter) { - this.cellularJitter = cellularJitter; - return this; - } - public int getSeedOffset() { return seedOffset; } @@ -116,71 +66,121 @@ public class NoiseBuilder { this.seedOffset = seedOffset; } - public NoiseBuilder setDomainWarpAmp(double domainWarpAmp) { - this.domainWarpAmp = domainWarpAmp; + public FastNoiseLite.CellularDistanceFunction getCellularDistanceFunction() { + return cellularDistanceFunction; + } + + public NoiseBuilder setCellularDistanceFunction(FastNoiseLite.CellularDistanceFunction cellularDistanceFunction) { + this.cellularDistanceFunction = cellularDistanceFunction; return this; } + public FastNoiseLite.CellularReturnType getCellularReturnType() { + return cellularReturnType; + } + + public NoiseBuilder setCellularReturnType(FastNoiseLite.CellularReturnType cellularReturnType) { + this.cellularReturnType = cellularReturnType; + return this; + } + + public FastNoiseLite.DomainWarpType getDomainWarpType() { + return domainWarpType; + } + public NoiseBuilder setDomainWarpType(FastNoiseLite.DomainWarpType domainWarpType) { this.domainWarpType = domainWarpType; return this; } - public NoiseBuilder setRotationType3D(FastNoiseLite.RotationType3D rotationType3D) { - this.rotationType3D = rotationType3D; - return this; - } - - public FastNoiseLite.CellularDistanceFunction getCellularDistanceFunction() { - return cellularDistanceFunction; - } - - public FastNoiseLite.CellularReturnType getCellularReturnType() { - return cellularReturnType; - } - - public FastNoiseLite.DomainWarpType getDomainWarpType() { - return domainWarpType; - } - public double getCellularJitter() { return cellularJitter; } + public NoiseBuilder setCellularJitter(double cellularJitter) { + this.cellularJitter = cellularJitter; + return this; + } + public double getDomainWarpAmp() { return domainWarpAmp; } + public NoiseBuilder setDomainWarpAmp(double domainWarpAmp) { + this.domainWarpAmp = domainWarpAmp; + return this; + } + public double getFractalGain() { return fractalGain; } + public NoiseBuilder setFractalGain(double fractalGain) { + this.fractalGain = fractalGain; + return this; + } + public double getFractalLacunarity() { return fractalLacunarity; } + public NoiseBuilder setFractalLacunarity(double fractalLacunarity) { + this.fractalLacunarity = fractalLacunarity; + return this; + } + public double getFrequency() { return frequency; } + public NoiseBuilder setFrequency(double frequency) { + this.frequency = frequency; + return this; + } + public double getPingPong() { return pingPong; } + public NoiseBuilder setPingPong(double pingPong) { + this.pingPong = pingPong; + return this; + } + public double getWeightedStrength() { return weightedStrength; } + public NoiseBuilder setWeightedStrength(double weightedStrength) { + this.weightedStrength = weightedStrength; + return this; + } + public int getOctaves() { return octaves; } + public NoiseBuilder setOctaves(int octaves) { + this.octaves = octaves; + return this; + } + public FastNoiseLite.FractalType getFractalType() { return fractalType; } + public NoiseBuilder setFractalType(FastNoiseLite.FractalType fractalType) { + this.fractalType = fractalType; + return this; + } + public FastNoiseLite.RotationType3D getRotationType3D() { return rotationType3D; } + + public NoiseBuilder setRotationType3D(FastNoiseLite.RotationType3D rotationType3D) { + this.rotationType3D = rotationType3D; + return this; + } } diff --git a/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java b/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java index e93e9ab9e..c2d1ee9f1 100644 --- a/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java +++ b/src/main/java/com/dfsek/terra/generation/config/WorldGenerator.java @@ -28,14 +28,12 @@ public class WorldGenerator extends Generator { private final Palette[] slantPalettes; private final boolean preventSmooth; - - private boolean elevationInterpolation = true; - private final Expression noiseExp; private final Scope s = new Scope(); private final Variable xVar = s.getVariable("x"); private final Variable yVar = s.getVariable("y"); private final Variable zVar = s.getVariable("z"); + private boolean elevationInterpolation = true; @SuppressWarnings({"rawtypes", "unchecked"}) public WorldGenerator(long seed, String equation, String elevateEquation, Map userVariables, Map noiseBuilders, Palette[] palettes, Palette[] slantPalettes, boolean preventSmooth) { diff --git a/src/main/java/com/dfsek/terra/population/FloraPopulator.java b/src/main/java/com/dfsek/terra/population/FloraPopulator.java index 23b7827bf..bc9b37c71 100644 --- a/src/main/java/com/dfsek/terra/population/FloraPopulator.java +++ b/src/main/java/com/dfsek/terra/population/FloraPopulator.java @@ -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; + } + + public static List getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) { + List 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; + } + + private static int offset(Random r, int i) { + return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15); + } + @SuppressWarnings("try") @Override public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { @@ -71,34 +101,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; - } - - public static List getValidTreeSpawnsAt(Chunk chunk, int x, int z, Range check) { - List 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; - } - - private static int offset(Random r, int i) { - return Math.min(Math.max(i + r.nextInt(3) - 1, 0), 15); - } } diff --git a/src/main/java/com/dfsek/terra/structure/Structure.java b/src/main/java/com/dfsek/terra/structure/Structure.java index 306658f81..acdd5348d 100644 --- a/src/main/java/com/dfsek/terra/structure/Structure.java +++ b/src/main/java/com/dfsek/terra/structure/Structure.java @@ -144,6 +144,12 @@ public class Structure implements Serializable { return (Structure) o; } + private static void toFile(@NotNull Serializable o, @NotNull File f) throws IOException { + ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f)); + oos.writeObject(o); + oos.close(); + } + public StructureContainedBlock[][][] getRawStructure() { return structure; } @@ -328,12 +334,6 @@ public class Structure implements Serializable { toFile(this, f); } - private static void toFile(@NotNull Serializable o, @NotNull File f) throws IOException { - ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(f)); - oos.writeObject(o); - oos.close(); - } - @NotNull public String getId() { return id; diff --git a/src/main/java/com/dfsek/terra/structure/features/EntityFeature.java b/src/main/java/com/dfsek/terra/structure/features/EntityFeature.java index 818257058..5b1e726d2 100644 --- a/src/main/java/com/dfsek/terra/structure/features/EntityFeature.java +++ b/src/main/java/com/dfsek/terra/structure/features/EntityFeature.java @@ -12,6 +12,7 @@ import org.bukkit.entity.EntityType; import org.polydev.gaea.math.MathUtil; import org.polydev.gaea.math.Range; +import java.util.Objects; import java.util.Random; import java.util.Set; @@ -32,6 +33,10 @@ public class EntityFeature implements Feature { this.inSize = inSize; } + private static boolean isInChunk(Chunk c, Location l) { + return Math.floorDiv(l.getBlockX(), 16) == c.getX() && Math.floorDiv(l.getBlockZ(), 16) == c.getZ(); + } + @Override public void apply(Structure structure, Location l, Chunk chunk) { Random random = new Random(MathUtil.getCarverChunkSeed(chunk.getX(), chunk.getZ(), chunk.getWorld().getSeed())); @@ -75,10 +80,6 @@ public class EntityFeature implements Feature { } } - private static boolean isInChunk(Chunk c, Location l) { - return Math.floorDiv(l.getBlockX(), 16) == c.getX() && Math.floorDiv(l.getBlockZ(), 16) == c.getZ(); - } - @Override public void apply(Structure structure, Location l, Random random) { int amountSpawn = amount.get(random); @@ -114,7 +115,7 @@ public class EntityFeature implements Feature { } if(canSpawn) { Debug.info("Spawning entity at " + attempt); - l.getWorld().spawnEntity(attempt.add(0.5, 1, 0.5), type); // Add 0.5 to X & Z so entity spawns in center of block. + Objects.requireNonNull(l.getWorld()).spawnEntity(attempt.add(0.5, 1, 0.5), type); // Add 0.5 to X & Z so entity spawns in center of block. } } }