From bb6263dfb804da5e9af27fe4f90076a7ce12788e Mon Sep 17 00:00:00 2001 From: dags- Date: Sun, 22 Mar 2020 11:18:40 +0000 Subject: [PATCH] fix strata depth calculation (mistake introduced in 0.0.8) --- .../terraforged/core/util/points/Poisson.java | 76 +++++++++++++++++++ .../core/world/geology/Strata.java | 2 +- .../mod/feature/TerrainHelper.java | 5 -- gradle.properties | 2 +- 4 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 TerraForgedCore/src/main/java/com/terraforged/core/util/points/Poisson.java diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/util/points/Poisson.java b/TerraForgedCore/src/main/java/com/terraforged/core/util/points/Poisson.java new file mode 100644 index 0000000..cb277e6 --- /dev/null +++ b/TerraForgedCore/src/main/java/com/terraforged/core/util/points/Poisson.java @@ -0,0 +1,76 @@ +package com.terraforged.core.util.points; + +import com.terraforged.core.cell.Cell; +import com.terraforged.core.region.Region; +import me.dags.noise.Module; +import me.dags.noise.Source; +import me.dags.noise.util.Vec2i; + +import javax.swing.*; +import java.awt.*; +import java.awt.image.BufferedImage; + +public class Poisson { + + public static void main(String[] args) { + Region region = new Region(0, 0, 5, 2); + BufferedImage image = new BufferedImage(region.getBlockSize().size, region.getBlockSize().size, BufferedImage.TYPE_INT_RGB); + points(region, 123,8, 20F, 0.8F); + render(region, image); + + JFrame frame = new JFrame(); + frame.add(new JLabel(new ImageIcon(image))); + frame.pack(); + frame.setVisible(true); + frame.setResizable(false); + frame.setLocationRelativeTo(null); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + + private static void points(Region region, int seed, int scale, float radius, float threshold) { + region.generate(chunk -> chunk.generate((cell, dx, dz) -> {})); + + Module noise = Source.simplex(seed, scale, 1); + + int gridSize = (int) Math.ceil(region.getBlockSize().size / radius); + Vec2i[][] grid = new Vec2i[gridSize][gridSize]; + + for (int dz = 0; dz < region.getBlockSize().size; dz++) { + for (int dx = 0; dx < region.getBlockSize().size; dx++) { + int x = region.getBlockX() + dx; + int z = region.getBlockZ() + dz; + float value = noise.getValue(x, z); + region.getCell(dx, dz).value = value; + if (true) continue; + + if (value > threshold) { + continue; + } + + int gridX = (int) (dx / radius); + int gridZ = (int) (dz / radius); + Vec2i point = grid[gridZ][gridX]; + + if (point != null) { + Cell current = region.getCell(point.x, point.y); + if (current.value > value) { + continue; + } + } + + region.getCell(dx, dz).value = value; + grid[gridZ][gridX] = new Vec2i(dx, dz); + } + } + } + + private static void render(Region region, BufferedImage image) { + region.iterate((cell, dx, dz) -> { + if (cell.value == 0) { + return; + } + int w = (int) (cell.value * 255); + image.setRGB(dx, dz, new Color(w, w, w).getRGB()); + }); + } +} diff --git a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Strata.java b/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Strata.java index 436d3f8..1ba7be4 100644 --- a/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Strata.java +++ b/TerraForgedCore/src/main/java/com/terraforged/core/world/geology/Strata.java @@ -56,7 +56,7 @@ public class Strata { int py = y; T last = null; for (int i = 0; i < strata.size(); i++) { - float depth = buffer.get(i); + float depth = buffer.getDepth(i); int height = NoiseUtil.round(depth * y); T value = strata.get(i).getValue(); last = value; diff --git a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/TerrainHelper.java b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/TerrainHelper.java index fecbaba..e1bb5dc 100644 --- a/TerraForgedMod/src/main/java/com/terraforged/mod/feature/TerrainHelper.java +++ b/TerraForgedMod/src/main/java/com/terraforged/mod/feature/TerrainHelper.java @@ -26,7 +26,6 @@ package com.terraforged.mod.feature; import com.terraforged.api.material.state.States; -import com.terraforged.core.cell.Cell; import com.terraforged.core.region.chunk.ChunkReader; import it.unimi.dsi.fastutil.longs.LongIterator; import it.unimi.dsi.fastutil.objects.ObjectArrayList; @@ -140,10 +139,6 @@ public class TerrainHelper { private void flatten(IChunk chunk, ChunkReader reader, MutableBoundingBox bounds, BlockPos.Mutable pos, int dx, int dz, int level, int surface, int borderRadius) { if (pos.getX() >= bounds.minX && pos.getX() <= bounds.maxX && pos.getZ() >= bounds.minZ && pos.getZ() <= bounds.maxZ) { - Cell cell = reader.getCell(dx, dz); - cell.steepness = 0F; - cell.sediment = 0F; - cell.erosion = 0F; for (int dy = level + 1; dy <= surface; dy++) { chunk.setBlockState(pos.setPos(dx, dy, dz), Blocks.AIR.getDefaultState(), false); } diff --git a/gradle.properties b/gradle.properties index 8a91541..f6586bd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -mod_version=0.0.8 +mod_version=0.0.9 mc_version=1.15.2 forge_version=31.1.1 mcp_channel=snapshot