fix strata depth calculation (mistake introduced in 0.0.8)

This commit is contained in:
dags- 2020-03-22 11:18:40 +00:00
parent d63e14acaf
commit bb6263dfb8
4 changed files with 78 additions and 7 deletions

View File

@ -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());
});
}
}

View File

@ -56,7 +56,7 @@ public class Strata<T> {
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;

View File

@ -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);
}

View File

@ -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