Noise fix

This commit is contained in:
Dan Macbook 2020-08-13 02:49:35 -04:00
parent 1f63b47500
commit b1663c040f
8 changed files with 339 additions and 446 deletions

View File

@ -31,8 +31,7 @@ import lombok.EqualsAndHashCode;
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public abstract class TerrainChunkGenerator extends ParallelChunkGenerator public abstract class TerrainChunkGenerator extends ParallelChunkGenerator {
{
private long lastUpdateRequest = M.ms(); private long lastUpdateRequest = M.ms();
private long lastChunkLoad = M.ms(); private long lastChunkLoad = M.ms();
private GenLayerCave glCave; private GenLayerCave glCave;
@ -42,8 +41,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
private BiomeResult[] cacheTrueBiome; private BiomeResult[] cacheTrueBiome;
private IrisLock cacheLock; private IrisLock cacheLock;
public TerrainChunkGenerator(String dimensionName, int threads) public TerrainChunkGenerator(String dimensionName, int threads) {
{
super(dimensionName, threads); super(dimensionName, threads);
cacheHeightMap = new int[256]; cacheHeightMap = new int[256];
cacheTrueBiome = new BiomeResult[256]; cacheTrueBiome = new BiomeResult[256];
@ -51,29 +49,25 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
cacheLock = new IrisLock("TerrainCacheLock"); cacheLock = new IrisLock("TerrainCacheLock");
} }
public void onInit(World world, RNG rng) public void onInit(World world, RNG rng) {
{
super.onInit(world, rng); super.onInit(world, rng);
rockRandom = getMasterRandom().nextParallelRNG(2858678); rockRandom = getMasterRandom().nextParallelRNG(2858678);
glCave = new GenLayerCave(this, rng.nextParallelRNG(238948)); glCave = new GenLayerCave(this, rng.nextParallelRNG(238948));
glCarve = new GenLayerCarve(this, rng.nextParallelRNG(968346576)); glCarve = new GenLayerCarve(this, rng.nextParallelRNG(968346576));
} }
public KList<CaveResult> getCaves(int x, int z) public KList<CaveResult> getCaves(int x, int z) {
{
return glCave.genCaves(x, z, x & 15, z & 15, null); return glCave.genCaves(x, z, x & 15, z & 15, null);
} }
@Override @Override
protected void onGenerateColumn(int cx, int cz, int rx, int rz, int x, int z, AtomicSliver sliver, BiomeMap biomeMap, boolean sampled) protected void onGenerateColumn(int cx, int cz, int rx, int rz, int x, int z, AtomicSliver sliver,
{ BiomeMap biomeMap, boolean sampled) {
if(x > 15 || x < 0 || z > 15 || z < 0) if (x > 15 || x < 0 || z > 15 || z < 0) {
{
throw new RuntimeException("Invalid OnGenerate call: x:" + x + " z:" + z); throw new RuntimeException("Invalid OnGenerate call: x:" + x + " z:" + z);
} }
try try {
{
int highestPlaced = 0; int highestPlaced = 0;
BlockData block; BlockData block;
int fluidHeight = getDimension().getFluidHeight(); int fluidHeight = getDimension().getFluidHeight();
@ -89,29 +83,27 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
BiomeResult biomeResult = sampleTrueBiome(rx, rz, noise); BiomeResult biomeResult = sampleTrueBiome(rx, rz, noise);
IrisBiome biome = biomeResult.getBiome(); IrisBiome biome = biomeResult.getBiome();
if(biome == null) if (biome == null) {
{
throw new RuntimeException("Null Biome!"); throw new RuntimeException("Null Biome!");
} }
cacheBiome(cachingAllowed && !sampled, x, z, biomeResult, height); cacheBiome(cachingAllowed && !sampled, x, z, biomeResult, height);
cacheInternalBiome(cachingAllowed && !sampled, x, z, biome); cacheInternalBiome(cachingAllowed && !sampled, x, z, biome);
KList<BlockData> layers = biome.generateLayers(wx, wz, masterRandom, height, height - getFluidHeight()); KList<BlockData> layers = biome.generateLayers(rx, rz, masterRandom, height, height - getFluidHeight());
KList<BlockData> seaLayers = biome.isSea() ? biome.generateSeaLayers(wx, wz, masterRandom, fluidHeight - height) : new KList<>(); KList<BlockData> seaLayers = biome.isSea()
? biome.generateSeaLayers(rx, rz, masterRandom, fluidHeight - height)
: new KList<>();
boolean caverning = false; boolean caverning = false;
KList<Integer> cavernHeights = new KList<>(); KList<Integer> cavernHeights = new KList<>();
int lastCavernHeight = -1; int lastCavernHeight = -1;
// From Height to Bedrock // From Height to Bedrock
for(int k = Math.max(height, fluidHeight); k >= 0; k--) for (int k = Math.max(height, fluidHeight); k >= 0; k--) {
{
boolean cavernSurface = false; boolean cavernSurface = false;
// Bedrock // Bedrock
if(k == 0) if (k == 0) {
{ if (biomeMap != null) {
if(biomeMap != null)
{
sliver.set(k, biome.getDerivative()); sliver.set(k, biome.getDerivative());
biomeMap.setBiome(x, z, biome); biomeMap.setBiome(x, z, biome);
} }
@ -121,10 +113,8 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
} }
// Carving // Carving
if(carvable && glCarve.isCarved(rx, k, rz)) if (carvable && glCarve.isCarved(rx, k, rz)) {
{ if (biomeMap != null) {
if(biomeMap != null)
{
sliver.set(k, biome.getDerivative()); sliver.set(k, biome.getDerivative());
biomeMap.setBiome(x, z, biome); biomeMap.setBiome(x, z, biome);
} }
@ -134,8 +124,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
continue; continue;
} }
else if(carvable && caverning) else if (carvable && caverning) {
{
lastCavernHeight = k; lastCavernHeight = k;
cavernSurface = true; cavernSurface = true;
cavernHeights.add(k); cavernHeights.add(k);
@ -145,27 +134,24 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
boolean underwater = k > height && k <= fluidHeight; boolean underwater = k > height && k <= fluidHeight;
// Set Biome // Set Biome
if(biomeMap != null) if (biomeMap != null) {
{
sliver.set(k, biome.getGroundBiome(masterRandom, rz, k, rx)); sliver.set(k, biome.getGroundBiome(masterRandom, rz, k, rx));
biomeMap.setBiome(x, z, biome); biomeMap.setBiome(x, z, biome);
} }
// Set Sea Material (water/lava) // Set Sea Material (water/lava)
if(underwater) if (underwater) {
{ block = seaLayers.hasIndex(fluidHeight - k) ? layers.get(depth)
block = seaLayers.hasIndex(fluidHeight - k) ? layers.get(depth) : getDimension().getFluid(rockRandom, wx, k, wz); : getDimension().getFluid(rockRandom, wx, k, wz);
} }
// Set Surface Material for cavern layer surfaces // Set Surface Material for cavern layer surfaces
else if(layers.hasIndex(lastCavernHeight - k)) else if (layers.hasIndex(lastCavernHeight - k)) {
{
block = layers.get(lastCavernHeight - k); block = layers.get(lastCavernHeight - k);
} }
// Set Surface Material for true surface // Set Surface Material for true surface
else else {
{
block = layers.hasIndex(depth) ? layers.get(depth) : getDimension().getRock(rockRandom, wx, k, wz); block = layers.hasIndex(depth) ? layers.get(depth) : getDimension().getRock(rockRandom, wx, k, wz);
depth++; depth++;
} }
@ -175,14 +161,13 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
highestPlaced = Math.max(highestPlaced, k); highestPlaced = Math.max(highestPlaced, k);
// Decorate underwater surface // Decorate underwater surface
if(!cavernSurface && (k == height && block.getMaterial().isSolid() && k < fluidHeight)) if (!cavernSurface && (k == height && block.getMaterial().isSolid() && k < fluidHeight)) {
{
decorateUnderwater(biome, sliver, wx, k, wz, rx, rz, block); decorateUnderwater(biome, sliver, wx, k, wz, rx, rz, block);
} }
// Decorate Cavern surfaces, but not the true surface // Decorate Cavern surfaces, but not the true surface
if((carvable && cavernSurface) && !(k == Math.max(height, fluidHeight) && block.getMaterial().isSolid() && k < 255 && k >= fluidHeight)) if ((carvable && cavernSurface) && !(k == Math.max(height, fluidHeight) && block.getMaterial().isSolid()
{ && k < 255 && k >= fluidHeight)) {
decorateLand(biome, sliver, wx, k, wz, rx, rz, block); decorateLand(biome, sliver, wx, k, wz, rx, rz, block);
} }
} }
@ -192,36 +177,31 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
IrisBiome caveBiome = glBiome.generateData(InferredType.CAVE, wx, wz, rx, rz, region).getBiome(); IrisBiome caveBiome = glBiome.generateData(InferredType.CAVE, wx, wz, rx, rz, region).getBiome();
// Decorate Cave Biome Height Sections // Decorate Cave Biome Height Sections
if(caveBiome != null) if (caveBiome != null) {
{ for (CaveResult i : caveResults) {
for(CaveResult i : caveResults) for (int j = i.getFloor(); j <= i.getCeiling(); j++) {
{
for(int j = i.getFloor(); j <= i.getCeiling(); j++)
{
sliver.set(j, caveBiome); sliver.set(j, caveBiome);
sliver.set(j, caveBiome.getGroundBiome(masterRandom, rz, j, rx)); sliver.set(j, caveBiome.getGroundBiome(masterRandom, rz, j, rx));
} }
KList<BlockData> floor = caveBiome.generateLayers(wx, wz, rockRandom, i.getFloor() - 2, i.getFloor() - 2); KList<BlockData> floor = caveBiome.generateLayers(wx, wz, rockRandom, i.getFloor() - 2,
KList<BlockData> ceiling = caveBiome.generateLayers(wx + 256, wz + 256, rockRandom, height - i.getCeiling() - 2, height - i.getCeiling() - 2); i.getFloor() - 2);
KList<BlockData> ceiling = caveBiome.generateLayers(wx + 256, wz + 256, rockRandom,
height - i.getCeiling() - 2, height - i.getCeiling() - 2);
BlockData blockc = null; BlockData blockc = null;
for(int j = 0; j < floor.size(); j++) for (int j = 0; j < floor.size(); j++) {
{ if (j == 0) {
if(j == 0)
{
blockc = floor.get(j); blockc = floor.get(j);
} }
sliver.set(i.getFloor() - j, floor.get(j)); sliver.set(i.getFloor() - j, floor.get(j));
} }
for(int j = ceiling.size() - 1; j > 0; j--) for (int j = ceiling.size() - 1; j > 0; j--) {
{
sliver.set(i.getCeiling() + j, ceiling.get(j)); sliver.set(i.getCeiling() + j, ceiling.get(j));
} }
if(blockc != null && !sliver.isSolid(i.getFloor() + 1)) if (blockc != null && !sliver.isSolid(i.getFloor() + 1)) {
{
decorateCave(caveBiome, sliver, wx, i.getFloor(), wz, rx, rz, blockc); decorateCave(caveBiome, sliver, wx, i.getFloor(), wz, rx, rz, blockc);
} }
} }
@ -230,122 +210,100 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
block = sliver.get(Math.max(height, fluidHeight)); block = sliver.get(Math.max(height, fluidHeight));
// Decorate True Surface // Decorate True Surface
if(block.getMaterial().isSolid()) if (block.getMaterial().isSolid()) {
{
decorateLand(biome, sliver, wx, Math.max(height, fluidHeight), wz, rx, rz, block); decorateLand(biome, sliver, wx, Math.max(height, fluidHeight), wz, rx, rz, block);
} }
// Update Height Map // Update Height Map
if(!sampled && cachingAllowed && highestPlaced < height) if (!sampled && cachingAllowed && highestPlaced < height) {
{
cacheHeightMap[(z << 4) | x] = highestPlaced; cacheHeightMap[(z << 4) | x] = highestPlaced;
} }
} }
catch(Throwable e) catch (Throwable e) {
{
fail(e); fail(e);
} }
} }
protected void cacheInternalBiome(boolean b, int x, int z, IrisBiome bv) protected void cacheInternalBiome(boolean b, int x, int z, IrisBiome bv) {
{ if (b) {
if(b)
{
cacheInternalBiome(x, z, bv); cacheInternalBiome(x, z, bv);
} }
} }
private void cacheBiome(boolean b, int x, int z, BiomeResult biomeResult, int height) private void cacheBiome(boolean b, int x, int z, BiomeResult biomeResult, int height) {
{ if (b) {
if(b) try {
{
try
{
cacheTrueBiome[(z << 4) | x] = biomeResult; cacheTrueBiome[(z << 4) | x] = biomeResult;
cacheHeightMap[(z << 4) | x] = height; cacheHeightMap[(z << 4) | x] = height;
} }
catch(Throwable e) catch (Throwable e) {
{
Iris.error("Failed to write cache at " + x + " " + z); Iris.error("Failed to write cache at " + x + " " + z);
} }
} }
} }
@Override @Override
protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) protected void onGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid) {
{
super.onGenerate(random, x, z, data, grid); super.onGenerate(random, x, z, data, grid);
RNG ro = random.nextParallelRNG((x * x * x) - z); RNG ro = random.nextParallelRNG((x * x * x) - z);
IrisRegion region = sampleRegion((x * 16) + 7, (z * 16) + 7); IrisRegion region = sampleRegion((x * 16) + 7, (z * 16) + 7);
IrisBiome biome = sampleTrueBiome((x * 16) + 7, (z * 16) + 7).getBiome(); IrisBiome biome = sampleTrueBiome((x * 16) + 7, (z * 16) + 7).getBiome();
for(IrisDepositGenerator k : getDimension().getDeposits()) for (IrisDepositGenerator k : getDimension().getDeposits()) {
{
k.generate(data, ro, this); k.generate(data, ro, this);
} }
for(IrisDepositGenerator k : region.getDeposits()) for (IrisDepositGenerator k : region.getDeposits()) {
{ for (int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate(data, ro, this); k.generate(data, ro, this);
} }
} }
for(IrisDepositGenerator k : biome.getDeposits()) for (IrisDepositGenerator k : biome.getDeposits()) {
{ for (int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++) {
for(int l = 0; l < ro.i(k.getMinPerChunk(), k.getMaxPerChunk()); l++)
{
k.generate(data, ro, this); k.generate(data, ro, this);
} }
} }
} }
private void decorateLand(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz, BlockData block) private void decorateLand(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz,
{ BlockData block) {
if(!getDimension().isDecorate()) if (!getDimension().isDecorate()) {
{
return; return;
} }
int j = 0; int j = 0;
for(IrisBiomeDecorator i : biome.getDecorators()) for (IrisBiomeDecorator i : biome.getDecorators()) {
{ if (i.getPartOf().equals(DecorationPart.SHORE_LINE) && (!touchesSea(rx, rz) || k != getFluidHeight())) {
if(i.getPartOf().equals(DecorationPart.SHORE_LINE) && (!touchesSea(rx, rz) || k != getFluidHeight()))
{
continue; continue;
} }
BlockData d = i.getBlockData(getMasterRandom().nextParallelRNG((int) (38888 + biome.getRarity() + biome.getName().length() + j++)), wx, wz); BlockData d = i.getBlockData(getMasterRandom()
.nextParallelRNG((int) (38888 + biome.getRarity() + biome.getName().length() + j++)), rx, rz);
if(d != null) if (d != null) {
{ if (!B.canPlaceOnto(d.getMaterial(), block.getMaterial())) {
if(!B.canPlaceOnto(d.getMaterial(), block.getMaterial()))
{
continue; continue;
} }
if(d.getMaterial().equals(Material.CACTUS)) if (d.getMaterial().equals(Material.CACTUS)) {
{ if (!block.getMaterial().equals(Material.SAND) && !block.getMaterial().equals(Material.RED_SAND)) {
if(!block.getMaterial().equals(Material.SAND) && !block.getMaterial().equals(Material.RED_SAND))
{
sliver.set(k, B.getBlockData("RED_SAND")); sliver.set(k, B.getBlockData("RED_SAND"));
} }
} }
if(d.getMaterial().equals(Material.WHEAT) || d.getMaterial().equals(Material.CARROTS) || d.getMaterial().equals(Material.POTATOES) || d.getMaterial().equals(Material.MELON_STEM) || d.getMaterial().equals(Material.PUMPKIN_STEM)) if (d.getMaterial().equals(Material.WHEAT) || d.getMaterial().equals(Material.CARROTS)
{ || d.getMaterial().equals(Material.POTATOES) || d.getMaterial().equals(Material.MELON_STEM)
if(!block.getMaterial().equals(Material.FARMLAND)) || d.getMaterial().equals(Material.PUMPKIN_STEM)) {
{ if (!block.getMaterial().equals(Material.FARMLAND)) {
sliver.set(k, B.getBlockData("FARMLAND")); sliver.set(k, B.getBlockData("FARMLAND"));
} }
} }
if(d instanceof Bisected && k < 254) if (d instanceof Bisected && k < 254) {
{
Bisected t = ((Bisected) d.clone()); Bisected t = ((Bisected) d.clone());
t.setHalf(Half.TOP); t.setHalf(Half.TOP);
Bisected b = ((Bisected) d.clone()); Bisected b = ((Bisected) d.clone());
@ -354,19 +312,17 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
sliver.set(k + 2, t); sliver.set(k + 2, t);
} }
else else {
{ int stack = i.getHeight(getMasterRandom().nextParallelRNG(
int stack = i.getHeight(getMasterRandom().nextParallelRNG((int) (39456 + (10000 * i.getChance()) + i.getStackMax() + i.getStackMin() + i.getZoom())), wx, wz); (int) (39456 + (10000 * i.getChance()) + i.getStackMax() + i.getStackMin() + i.getZoom())),
rx, rz);
if(stack == 1) if (stack == 1) {
{
sliver.set(k + 1, d); sliver.set(k + 1, d);
} }
else if(k < 255 - stack) else if (k < 255 - stack) {
{ for (int l = 0; l < stack; l++) {
for(int l = 0; l < stack; l++)
{
sliver.set(k + l + 1, d); sliver.set(k + l + 1, d);
} }
} }
@ -377,36 +333,31 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
} }
} }
private void decorateCave(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz, BlockData block) private void decorateCave(IrisBiome biome, AtomicSliver sliver, double wx, int k, double wz, int rx, int rz,
{ BlockData block) {
if(!getDimension().isDecorate()) if (!getDimension().isDecorate()) {
{
return; return;
} }
int j = 0; int j = 0;
for(IrisBiomeDecorator i : biome.getDecorators()) for (IrisBiomeDecorator i : biome.getDecorators()) {
{ BlockData d = i.getBlockData(
BlockData d = i.getBlockData(getMasterRandom().nextParallelRNG(2333877 + biome.getRarity() + biome.getName().length() + +j++), wx, wz); getMasterRandom().nextParallelRNG(2333877 + biome.getRarity() + biome.getName().length() + +j++),
rx, rz);
if(d != null) if (d != null) {
{ if (!B.canPlaceOnto(d.getMaterial(), block.getMaterial())) {
if(!B.canPlaceOnto(d.getMaterial(), block.getMaterial()))
{
continue; continue;
} }
if(d.getMaterial().equals(Material.CACTUS)) if (d.getMaterial().equals(Material.CACTUS)) {
{ if (!block.getMaterial().equals(Material.SAND) && !block.getMaterial().equals(Material.RED_SAND)) {
if(!block.getMaterial().equals(Material.SAND) && !block.getMaterial().equals(Material.RED_SAND))
{
sliver.set(k, B.getBlockData("SAND")); sliver.set(k, B.getBlockData("SAND"));
} }
} }
if(d instanceof Bisected && k < 254) if (d instanceof Bisected && k < 254) {
{
Bisected t = ((Bisected) d.clone()); Bisected t = ((Bisected) d.clone());
t.setHalf(Half.TOP); t.setHalf(Half.TOP);
Bisected b = ((Bisected) d.clone()); Bisected b = ((Bisected) d.clone());
@ -415,21 +366,17 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
sliver.set(k + 2, t); sliver.set(k + 2, t);
} }
else else {
{ int stack = i.getHeight(getMasterRandom()
int stack = i.getHeight(getMasterRandom().nextParallelRNG((int) (39456 + (1000 * i.getChance()) + i.getZoom() * 10)), wx, wz); .nextParallelRNG((int) (39456 + (1000 * i.getChance()) + i.getZoom() * 10)), rx, rz);
if(stack == 1) if (stack == 1) {
{
sliver.set(k + 1, d); sliver.set(k + 1, d);
} }
else if(k < 255 - stack) else if (k < 255 - stack) {
{ for (int l = 0; l < stack; l++) {
for(int l = 0; l < stack; l++) if (sliver.isSolid(k + l + 1)) {
{
if(sliver.isSolid(k + l + 1))
{
break; break;
} }
@ -443,38 +390,35 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
} }
} }
private void decorateUnderwater(IrisBiome biome, AtomicSliver sliver, double wx, int y, double wz, int rx, int rz, BlockData block) private void decorateUnderwater(IrisBiome biome, AtomicSliver sliver, double wx, int y, double wz, int rx, int rz,
{ BlockData block) {
if(!getDimension().isDecorate()) if (!getDimension().isDecorate()) {
{
return; return;
} }
int j = 0; int j = 0;
for(IrisBiomeDecorator i : biome.getDecorators()) for (IrisBiomeDecorator i : biome.getDecorators()) {
{ if (biome.getInferredType().equals(InferredType.SHORE)) {
if(biome.getInferredType().equals(InferredType.SHORE))
{
continue; continue;
} }
BlockData d = i.getBlockData(getMasterRandom().nextParallelRNG(2555 + biome.getRarity() + biome.getName().length() + j++), wx, wz); BlockData d = i.getBlockData(
getMasterRandom().nextParallelRNG(2555 + biome.getRarity() + biome.getName().length() + j++), rx,
rz);
if(d != null) if (d != null) {
{ int stack = i.getHeight(getMasterRandom().nextParallelRNG((int) (239456 + i.getStackMax()
int stack = i.getHeight(getMasterRandom().nextParallelRNG((int) (239456 + i.getStackMax() + i.getStackMin() + i.getVerticalZoom() + i.getZoom() + i.getBlockData().size() + j)), wx, wz); + i.getStackMin() + i.getVerticalZoom() + i.getZoom() + i.getBlockData().size() + j)), rx, rz);
if(stack == 1) if (stack == 1) {
{
sliver.set(i.getPartOf().equals(DecorationPart.SEA_SURFACE) ? (getFluidHeight() + 1) : (y + 1), d); sliver.set(i.getPartOf().equals(DecorationPart.SEA_SURFACE) ? (getFluidHeight() + 1) : (y + 1), d);
} }
else if(y < getFluidHeight() - stack) else if (y < getFluidHeight() - stack) {
{ for (int l = 0; l < stack; l++) {
for(int l = 0; l < stack; l++) sliver.set(i.getPartOf().equals(DecorationPart.SEA_SURFACE) ? (getFluidHeight() + 1 + l)
{ : (y + l + 1), d);
sliver.set(i.getPartOf().equals(DecorationPart.SEA_SURFACE) ? (getFluidHeight() + 1 + l) : (y + l + 1), d);
} }
} }
@ -484,33 +428,30 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
} }
@Override @Override
protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap) protected void onPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height,
{ BiomeMap biomeMap) {
onPreParallaxPostGenerate(random, x, z, data, grid, height, biomeMap); onPreParallaxPostGenerate(random, x, z, data, grid, height, biomeMap);
} }
protected void onPreParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap) protected void onPreParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height,
{ BiomeMap biomeMap) {
} }
protected void onPostParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid, HeightMap height, BiomeMap biomeMap) protected void onPostParallaxPostGenerate(RNG random, int x, int z, ChunkData data, BiomeGrid grid,
{ HeightMap height, BiomeMap biomeMap) {
} }
protected double getNoiseHeight(int rx, int rz) protected double getNoiseHeight(int rx, int rz) {
{
double wx = getZoomed(rx); double wx = getZoomed(rx);
double wz = getZoomed(rz); double wz = getZoomed(rz);
return getBiomeHeight(wx, wz, rx, rz); return getBiomeHeight(wx, wz, rx, rz);
} }
public BiomeResult sampleTrueBiomeBase(int x, int z, int height) public BiomeResult sampleTrueBiomeBase(int x, int z, int height) {
{ if (!getDimension().getFocus().equals("")) {
if(!getDimension().getFocus().equals(""))
{
return focus(); return focus();
} }
@ -520,51 +461,42 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
double sh = region.getShoreHeight(wx, wz); double sh = region.getShoreHeight(wx, wz);
IrisBiome current = sampleBiome(x, z).getBiome(); IrisBiome current = sampleBiome(x, z).getBiome();
if(current.isShore() && height > sh) if (current.isShore() && height > sh) {
{
return glBiome.generateData(InferredType.LAND, wx, wz, x, z, region); return glBiome.generateData(InferredType.LAND, wx, wz, x, z, region);
} }
if(current.isShore() || current.isLand() && height <= getDimension().getFluidHeight()) if (current.isShore() || current.isLand() && height <= getDimension().getFluidHeight()) {
{
return glBiome.generateData(InferredType.SEA, wx, wz, x, z, region); return glBiome.generateData(InferredType.SEA, wx, wz, x, z, region);
} }
if(current.isSea() && height > getDimension().getFluidHeight()) if (current.isSea() && height > getDimension().getFluidHeight()) {
{
return glBiome.generateData(InferredType.LAND, wx, wz, x, z, region); return glBiome.generateData(InferredType.LAND, wx, wz, x, z, region);
} }
if(height <= getDimension().getFluidHeight()) if (height <= getDimension().getFluidHeight()) {
{
return glBiome.generateData(InferredType.SEA, wx, wz, x, z, region); return glBiome.generateData(InferredType.SEA, wx, wz, x, z, region);
} }
if(height <= getDimension().getFluidHeight() + sh) if (height <= getDimension().getFluidHeight() + sh) {
{
return glBiome.generateData(InferredType.SHORE, wx, wz, x, z, region); return glBiome.generateData(InferredType.SHORE, wx, wz, x, z, region);
} }
return glBiome.generateRegionData(wx, wz, x, z, region); return glBiome.generateRegionData(wx, wz, x, z, region);
} }
public BiomeResult sampleCaveBiome(int x, int z) public BiomeResult sampleCaveBiome(int x, int z) {
{
double wx = getModifiedX(x, z); double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z); double wz = getModifiedZ(x, z);
return glBiome.generateData(InferredType.CAVE, wx, wz, x, z, sampleRegion(x, z)); return glBiome.generateData(InferredType.CAVE, wx, wz, x, z, sampleRegion(x, z));
} }
public BiomeResult sampleTrueBiome(int x, int y, int z) public BiomeResult sampleTrueBiome(int x, int y, int z) {
{ if (y < getTerrainHeight(x, z)) {
if(y < getTerrainHeight(x, z))
{
double wx = getModifiedX(x, z); double wx = getModifiedX(x, z);
double wz = getModifiedZ(x, z); double wz = getModifiedZ(x, z);
BiomeResult r = glBiome.generateData(InferredType.CAVE, wx, wz, x, z, sampleRegion(x, z)); BiomeResult r = glBiome.generateData(InferredType.CAVE, wx, wz, x, z, sampleRegion(x, z));
if(r.getBiome() != null) if (r.getBiome() != null) {
{
return r; return r;
} }
} }
@ -572,20 +504,16 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
return sampleTrueBiome(x, z); return sampleTrueBiome(x, z);
} }
public BiomeResult sampleTrueBiome(int x, int z) public BiomeResult sampleTrueBiome(int x, int z) {
{
return sampleTrueBiome(x, z, getTerrainHeight(x, z)); return sampleTrueBiome(x, z, getTerrainHeight(x, z));
} }
public BiomeResult sampleTrueBiome(int x, int z, double noise) public BiomeResult sampleTrueBiome(int x, int z, double noise) {
{ if (!getDimension().getFocus().equals("")) {
if(!getDimension().getFocus().equals(""))
{
return focus(); return focus();
} }
if(isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ) if (isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ) {
{
return cacheTrueBiome[((z & 15) << 4) | (x & 15)]; return cacheTrueBiome[((z & 15) << 4) | (x & 15)];
} }
@ -597,8 +525,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
BiomeResult res = sampleTrueBiomeBase(x, z, height); BiomeResult res = sampleTrueBiomeBase(x, z, height);
IrisBiome current = res.getBiome(); IrisBiome current = res.getBiome();
if(current.isSea() && height > getDimension().getFluidHeight() - sh) if (current.isSea() && height > getDimension().getFluidHeight() - sh) {
{
return glBiome.generateData(InferredType.SHORE, wx, wz, x, z, region); return glBiome.generateData(InferredType.SHORE, wx, wz, x, z, region);
} }
@ -606,46 +533,39 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
} }
@Override @Override
protected int onSampleColumnHeight(int cx, int cz, int rx, int rz, int x, int z) protected int onSampleColumnHeight(int cx, int cz, int rx, int rz, int x, int z) {
{
int fluidHeight = getDimension().getFluidHeight(); int fluidHeight = getDimension().getFluidHeight();
double noise = getNoiseHeight(rx, rz); double noise = getNoiseHeight(rx, rz);
return (int) Math.round(noise) + fluidHeight; return (int) Math.round(noise) + fluidHeight;
} }
private boolean touchesSea(int rx, int rz) private boolean touchesSea(int rx, int rz) {
{ return isFluidAtHeight(rx + 1, rz) || isFluidAtHeight(rx - 1, rz) || isFluidAtHeight(rx, rz - 1)
return isFluidAtHeight(rx + 1, rz) || isFluidAtHeight(rx - 1, rz) || isFluidAtHeight(rx, rz - 1) || isFluidAtHeight(rx, rz + 1); || isFluidAtHeight(rx, rz + 1);
} }
public boolean isUnderwater(int x, int z) public boolean isUnderwater(int x, int z) {
{
return isFluidAtHeight(x, z); return isFluidAtHeight(x, z);
} }
public boolean isFluidAtHeight(int x, int z) public boolean isFluidAtHeight(int x, int z) {
{
return Math.round(getTerrainHeight(x, z)) < getFluidHeight(); return Math.round(getTerrainHeight(x, z)) < getFluidHeight();
} }
public int getFluidHeight() public int getFluidHeight() {
{
return getDimension().getFluidHeight(); return getDimension().getFluidHeight();
} }
public double getTerrainHeight(int x, int z) public double getTerrainHeight(int x, int z) {
{ if (isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ) {
if(isSafe() && x >> 4 == cacheX && z >> 4 == cacheZ)
{
return cacheHeightMap[((z & 15) << 4) | (x & 15)]; return cacheHeightMap[((z & 15) << 4) | (x & 15)];
} }
return getNoiseHeight(x, z) + getFluidHeight(); return getNoiseHeight(x, z) + getFluidHeight();
} }
public double getTerrainWaterHeight(int x, int z) public double getTerrainWaterHeight(int x, int z) {
{
return Math.max(getTerrainHeight(x, z), getFluidHeight()); return Math.max(getTerrainHeight(x, z), getFluidHeight());
} }
} }

View File

@ -13,7 +13,7 @@ public class CellHeightNoise implements NoiseGenerator {
} }
private double filter(double noise) { private double filter(double noise) {
return M.clip((noise / 2D) + 0.5D, 0D, 1D); return M.clip(1D - ((noise / 2D) + 0.5D), 0D, 1D);
} }
@Override @Override

View File

@ -0,0 +1,29 @@
package com.volmit.iris.noise;
import com.volmit.iris.object.NoiseStyle;
import com.volmit.iris.util.RNG;
public class Research {
public static void main(String[] args) {
CNG cng = NoiseStyle.VIGOCTAVE_SIMPLEX.create(new RNG(RNG.r.nextLong()));
double max = -1;
double min = 2;
for (int i = 0; i < 999999; i++) {
double n = cng.noise(i, i * 2, i * 4);
if (n < min) {
min = n;
}
if (n > max) {
max = n;
}
}
System.out.println(min + " - " + max);
}
}

View File

@ -3,11 +3,11 @@ package com.volmit.iris.noise;
import com.volmit.iris.util.RNG; import com.volmit.iris.util.RNG;
public class SimplexNoise implements NoiseGenerator, OctaveNoise { public class SimplexNoise implements NoiseGenerator, OctaveNoise {
private final SNG n; private final FastNoise n;
private int octaves; private int octaves;
public SimplexNoise(long seed) { public SimplexNoise(long seed) {
this.n = new SNG(new RNG(seed)); this.n = new FastNoise(new RNG(seed).imax());
octaves = 1; octaves = 1;
} }
@ -18,26 +18,55 @@ public class SimplexNoise implements NoiseGenerator, OctaveNoise {
@Override @Override
public double noise(double x) { public double noise(double x) {
if (octaves <= 1) { if (octaves <= 1) {
return f(n.noise(x)); return f(n.GetNoise((float) x, 0f));
} }
return f(n.noise(x, octaves, 1D, 1D, false)); double f = 1;
double m = 0;
double v = 0;
for (int i = 0; i < octaves; i++) {
v += n.GetNoise((float) (x * (f == 1 ? f++ : (f *= 2))), 0f) * f;
m += f;
}
return f(v / m);
} }
@Override @Override
public double noise(double x, double z) { public double noise(double x, double z) {
if (octaves <= 1) { if (octaves <= 1) {
return f(n.noise(x, z)); return f(n.GetNoise((float) x, (float) z));
} }
return f(n.noise(x, z, octaves, 1D, 1D, true)); double f = 1;
double m = 0;
double v = 0;
for (int i = 0; i < octaves; i++) {
f = f == 1 ? f + 1 : f * 2;
v += n.GetNoise((float) (x * f), (float) (z * f)) * f;
m += f;
}
return f(v / m);
} }
@Override @Override
public double noise(double x, double y, double z) { public double noise(double x, double y, double z) {
if (octaves <= 1) { if (octaves <= 1) {
return f(n.noise(x, y, z)); return f(n.GetNoise((float) x, (float) y, (float) z));
} }
return f(n.noise(x, y, z, octaves, 1D, 1D, true)); double f = 1;
double m = 0;
double v = 0;
for (int i = 0; i < octaves; i++) {
f = f == 1 ? f + 1 : f * 2;
v += n.GetNoise((float) (x * f), (float) (y * f), (float) (z * f)) * f;
m += f;
}
return f(v / m);
} }
@Override @Override

View File

@ -13,7 +13,7 @@ public class VascularNoise implements NoiseGenerator {
} }
private double filter(double noise) { private double filter(double noise) {
return M.clip(1D - ((noise / 2D) + 0.5D), 0D, 1D); return M.clip((noise / 2D) + 0.5D, 0D, 1D);
} }
@Override @Override

View File

@ -26,8 +26,7 @@ import lombok.EqualsAndHashCode;
@Desc("Represents a biome in iris. Biomes are placed inside of regions and hold objects.") @Desc("Represents a biome in iris. Biomes are placed inside of regions and hold objects.")
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
public class IrisBiome extends IrisRegistrant implements IRare public class IrisBiome extends IrisRegistrant implements IRare {
{
@MinNumber(2) @MinNumber(2)
@Required @Required
@DontObfuscate @DontObfuscate
@ -115,7 +114,8 @@ public class IrisBiome extends IrisRegistrant implements IRare
@ArrayType(min = 1, type = IrisBiomeGeneratorLink.class) @ArrayType(min = 1, type = IrisBiomeGeneratorLink.class)
@DontObfuscate @DontObfuscate
@Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.") @Desc("Generators for this biome. Multiple generators with different interpolation sizes will mix with other biomes how you would expect. This defines your biome height relative to the fluid height. Use negative for oceans.")
private KList<IrisBiomeGeneratorLink> generators = new KList<IrisBiomeGeneratorLink>().qadd(new IrisBiomeGeneratorLink()); private KList<IrisBiomeGeneratorLink> generators = new KList<IrisBiomeGeneratorLink>()
.qadd(new IrisBiomeGeneratorLink());
@ArrayType(min = 1, type = IrisStructurePlacement.class) @ArrayType(min = 1, type = IrisStructurePlacement.class)
@DontObfuscate @DontObfuscate
@ -135,85 +135,71 @@ public class IrisBiome extends IrisRegistrant implements IRare
private transient AtomicCache<KList<CNG>> layerHeightGenerators = new AtomicCache<>(); private transient AtomicCache<KList<CNG>> layerHeightGenerators = new AtomicCache<>();
private transient AtomicCache<KList<CNG>> layerSeaHeightGenerators = new AtomicCache<>(); private transient AtomicCache<KList<CNG>> layerSeaHeightGenerators = new AtomicCache<>();
public IrisBiome() public IrisBiome() {
{
} }
public double getHeight(ContextualChunkGenerator xg, double x, double z, long seed) public double getHeight(ContextualChunkGenerator xg, double x, double z, long seed) {
{
double height = 0; double height = 0;
for(IrisBiomeGeneratorLink i : generators) for (IrisBiomeGeneratorLink i : generators) {
{
height += i.getHeight(xg, x, z, seed); height += i.getHeight(xg, x, z, seed);
} }
return Math.max(0, Math.min(height, 255)); return Math.max(0, Math.min(height, 255));
} }
public CNG getBiomeGenerator(RNG random) public CNG getBiomeGenerator(RNG random) {
{ return biomeGenerator.aquire(() -> {
return biomeGenerator.aquire(() ->
{
return biomeStyle.create(random.nextParallelRNG(213949 + 228888 + getRarity() + getName().length())); return biomeStyle.create(random.nextParallelRNG(213949 + 228888 + getRarity() + getName().length()));
}); });
} }
public RarityCellGenerator<IrisBiome> getChildrenGenerator(RNG random, int sig, double scale) public RarityCellGenerator<IrisBiome> getChildrenGenerator(RNG random, int sig, double scale) {
{ return childrenCell.aquire(() -> {
return childrenCell.aquire(() -> RarityCellGenerator<IrisBiome> childrenCell = new RarityCellGenerator<IrisBiome>(
{ random.nextParallelRNG(sig * 2137));
RarityCellGenerator<IrisBiome> childrenCell = new RarityCellGenerator<IrisBiome>(random.nextParallelRNG(sig * 2137));
childrenCell.setCellScale(scale); childrenCell.setCellScale(scale);
return childrenCell; return childrenCell;
}); });
} }
public KList<BlockData> generateLayers(double wx, double wz, RNG random, int maxDepth, int height) public KList<BlockData> generateLayers(double wx, double wz, RNG random, int maxDepth, int height) {
{ if (isLockLayers()) {
if(isLockLayers())
{
return generateLockedLayers(wx, wz, random, maxDepth, height); return generateLockedLayers(wx, wz, random, maxDepth, height);
} }
KList<BlockData> data = new KList<>(); KList<BlockData> data = new KList<>();
if(maxDepth <= 0) if (maxDepth <= 0) {
{
return data; return data;
} }
for(int i = 0; i < layers.size(); i++) for (int i = 0; i < layers.size(); i++) {
{
CNG hgen = getLayerHeightGenerators(random).get(i); CNG hgen = getLayerHeightGenerators(random).get(i);
int d = hgen.fit(layers.get(i).getMinHeight(), layers.get(i).getMaxHeight(), wx / layers.get(i).getZoom(), wz / layers.get(i).getZoom()); int d = hgen.fit(layers.get(i).getMinHeight(), layers.get(i).getMaxHeight(), wx / layers.get(i).getZoom(),
wz / layers.get(i).getZoom());
if(d < 0) if (d < 0) {
{
continue; continue;
} }
for(int j = 0; j < d; j++) for (int j = 0; j < d; j++) {
{ if (data.size() >= maxDepth) {
if(data.size() >= maxDepth)
{
break; break;
} }
try try {
{ data.add(getLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / layers.get(i).getZoom(),
data.add(getLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / layers.get(i).getZoom(), j, (wz - j) / layers.get(i).getZoom())); j, (wz - j) / layers.get(i).getZoom()));
} }
catch(Throwable e) catch (Throwable e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
if(data.size() >= maxDepth) if (data.size() >= maxDepth) {
{
break; break;
} }
} }
@ -221,47 +207,40 @@ public class IrisBiome extends IrisRegistrant implements IRare
return data; return data;
} }
public KList<BlockData> generateLockedLayers(double wx, double wz, RNG random, int maxDepth, int height) public KList<BlockData> generateLockedLayers(double wx, double wz, RNG random, int maxDepth, int height) {
{
KList<BlockData> data = new KList<>(); KList<BlockData> data = new KList<>();
KList<BlockData> real = new KList<>(); KList<BlockData> real = new KList<>();
if(maxDepth <= 0) if (maxDepth <= 0) {
{
return data; return data;
} }
for(int i = 0; i < layers.size(); i++) for (int i = 0; i < layers.size(); i++) {
{
CNG hgen = getLayerHeightGenerators(random).get(i); CNG hgen = getLayerHeightGenerators(random).get(i);
int d = hgen.fit(layers.get(i).getMinHeight(), layers.get(i).getMaxHeight(), wx / layers.get(i).getZoom(), wz / layers.get(i).getZoom()); int d = hgen.fit(layers.get(i).getMinHeight(), layers.get(i).getMaxHeight(), wx / layers.get(i).getZoom(),
wz / layers.get(i).getZoom());
if(d < 0) if (d < 0) {
{
continue; continue;
} }
for(int j = 0; j < d; j++) for (int j = 0; j < d; j++) {
{ try {
try data.add(getLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / layers.get(i).getZoom(),
{ j, (wz - j) / layers.get(i).getZoom()));
data.add(getLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / layers.get(i).getZoom(), j, (wz - j) / layers.get(i).getZoom()));
} }
catch(Throwable e) catch (Throwable e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
if(data.isEmpty()) if (data.isEmpty()) {
{
return real; return real;
} }
for(int i = 0; i < maxDepth; i++) for (int i = 0; i < maxDepth; i++) {
{
int offset = (getMaxHeight() - height) - i; int offset = (getMaxHeight() - height) - i;
int index = offset % data.size(); int index = offset % data.size();
real.add(data.get(index < 0 ? 0 : index)); real.add(data.get(index < 0 ? 0 : index));
@ -270,14 +249,11 @@ public class IrisBiome extends IrisRegistrant implements IRare
return real; return real;
} }
private int getMaxHeight() private int getMaxHeight() {
{ return maxHeight.aquire(() -> {
return maxHeight.aquire(() ->
{
int maxHeight = 0; int maxHeight = 0;
for(IrisBiomeGeneratorLink i : getGenerators()) for (IrisBiomeGeneratorLink i : getGenerators()) {
{
maxHeight += i.getMax(); maxHeight += i.getMax();
} }
@ -285,46 +261,39 @@ public class IrisBiome extends IrisRegistrant implements IRare
}); });
} }
public IrisBiome infer(InferredType t, InferredType type) public IrisBiome infer(InferredType t, InferredType type) {
{
setInferredType(t.equals(InferredType.DEFER) ? type : t); setInferredType(t.equals(InferredType.DEFER) ? type : t);
return this; return this;
} }
public KList<BlockData> generateSeaLayers(double wx, double wz, RNG random, int maxDepth) public KList<BlockData> generateSeaLayers(double wx, double wz, RNG random, int maxDepth) {
{
KList<BlockData> data = new KList<>(); KList<BlockData> data = new KList<>();
for(int i = 0; i < seaLayers.size(); i++) for (int i = 0; i < seaLayers.size(); i++) {
{
CNG hgen = getLayerSeaHeightGenerators(random).get(i); CNG hgen = getLayerSeaHeightGenerators(random).get(i);
int d = hgen.fit(seaLayers.get(i).getMinHeight(), seaLayers.get(i).getMaxHeight(), wx / seaLayers.get(i).getZoom(), wz / seaLayers.get(i).getZoom()); int d = hgen.fit(seaLayers.get(i).getMinHeight(), seaLayers.get(i).getMaxHeight(),
wx / seaLayers.get(i).getZoom(), wz / seaLayers.get(i).getZoom());
if(d < 0) if (d < 0) {
{
continue; continue;
} }
for(int j = 0; j < d; j++) for (int j = 0; j < d; j++) {
{ if (data.size() >= maxDepth) {
if(data.size() >= maxDepth)
{
break; break;
} }
try try {
{ data.add(getSeaLayers().get(i).get(random.nextParallelRNG(i + j),
data.add(getSeaLayers().get(i).get(random.nextParallelRNG(i + j), (wx + j) / seaLayers.get(i).getZoom(), j, (wz - j) / seaLayers.get(i).getZoom())); (wx + j) / seaLayers.get(i).getZoom(), j, (wz - j) / seaLayers.get(i).getZoom()));
} }
catch(Throwable e) catch (Throwable e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
if(data.size() >= maxDepth) if (data.size() >= maxDepth) {
{
break; break;
} }
} }
@ -332,16 +301,13 @@ public class IrisBiome extends IrisRegistrant implements IRare
return data; return data;
} }
public KList<CNG> getLayerHeightGenerators(RNG rng) public KList<CNG> getLayerHeightGenerators(RNG rng) {
{ return layerHeightGenerators.aquire(() -> {
return layerHeightGenerators.aquire(() ->
{
KList<CNG> layerHeightGenerators = new KList<>(); KList<CNG> layerHeightGenerators = new KList<>();
int m = 7235; int m = 7235;
for(IrisBiomePaletteLayer i : getLayers()) for (IrisBiomePaletteLayer i : getLayers()) {
{
layerHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m))); layerHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m)));
} }
@ -349,16 +315,13 @@ public class IrisBiome extends IrisRegistrant implements IRare
}); });
} }
public KList<CNG> getLayerSeaHeightGenerators(RNG rng) public KList<CNG> getLayerSeaHeightGenerators(RNG rng) {
{ return layerSeaHeightGenerators.aquire(() -> {
return layerSeaHeightGenerators.aquire(() ->
{
KList<CNG> layerSeaHeightGenerators = new KList<>(); KList<CNG> layerSeaHeightGenerators = new KList<>();
int m = 7735; int m = 7735;
for(IrisBiomePaletteLayer i : getSeaLayers()) for (IrisBiomePaletteLayer i : getSeaLayers()) {
{
layerSeaHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m))); layerSeaHeightGenerators.add(i.getHeightGenerator(rng.nextParallelRNG((m++) * m * m * m)));
} }
@ -366,57 +329,45 @@ public class IrisBiome extends IrisRegistrant implements IRare
}); });
} }
public boolean isLand() public boolean isLand() {
{ if (inferredType == null) {
if(inferredType == null)
{
return true; return true;
} }
return inferredType.equals(InferredType.LAND); return inferredType.equals(InferredType.LAND);
} }
public boolean isSea() public boolean isSea() {
{ if (inferredType == null) {
if(inferredType == null)
{
return false; return false;
} }
return inferredType.equals(InferredType.SEA); return inferredType.equals(InferredType.SEA);
} }
public boolean isShore() public boolean isShore() {
{ if (inferredType == null) {
if(inferredType == null)
{
return false; return false;
} }
return inferredType.equals(InferredType.SHORE); return inferredType.equals(InferredType.SHORE);
} }
public Biome getSkyBiome(RNG rng, double x, double y, double z) public Biome getSkyBiome(RNG rng, double x, double y, double z) {
{ if (biomeSkyScatter.size() == 1) {
if(biomeSkyScatter.size() == 1)
{
return biomeSkyScatter.get(0); return biomeSkyScatter.get(0);
} }
if(biomeSkyScatter.isEmpty()) if (biomeSkyScatter.isEmpty()) {
{
return getGroundBiome(rng, x, y, z); return getGroundBiome(rng, x, y, z);
} }
return biomeSkyScatter.get(getBiomeGenerator(rng).fit(0, biomeSkyScatter.size() - 1, x, y, z)); return biomeSkyScatter.get(getBiomeGenerator(rng).fit(0, biomeSkyScatter.size() - 1, x, y, z));
} }
public KList<IrisBiome> getRealChildren(ContextualChunkGenerator g) public KList<IrisBiome> getRealChildren(ContextualChunkGenerator g) {
{ return realChildren.aquire(() -> {
return realChildren.aquire(() ->
{
KList<IrisBiome> realChildren = new KList<>(); KList<IrisBiome> realChildren = new KList<>();
for(String i : getChildren()) for (String i : getChildren()) {
{
realChildren.add(g != null ? g.loadBiome(i) : Iris.globaldata.getBiomeLoader().load(i)); realChildren.add(g != null ? g.loadBiome(i) : Iris.globaldata.getBiomeLoader().load(i));
} }
@ -424,16 +375,13 @@ public class IrisBiome extends IrisRegistrant implements IRare
}); });
} }
public KList<String> getAllChildren(ContextualChunkGenerator g, int limit) public KList<String> getAllChildren(ContextualChunkGenerator g, int limit) {
{
KSet<String> m = new KSet<>(); KSet<String> m = new KSet<>();
m.addAll(getChildren()); m.addAll(getChildren());
limit--; limit--;
if(limit > 0) if (limit > 0) {
{ for (String i : getChildren()) {
for(String i : getChildren())
{
IrisBiome b = g != null ? g.loadBiome(i) : Iris.globaldata.getBiomeLoader().load(i); IrisBiome b = g != null ? g.loadBiome(i) : Iris.globaldata.getBiomeLoader().load(i);
int l = limit; int l = limit;
m.addAll(b.getAllChildren(g, l)); m.addAll(b.getAllChildren(g, l));
@ -443,18 +391,15 @@ public class IrisBiome extends IrisRegistrant implements IRare
return new KList<String>(m); return new KList<String>(m);
} }
public Biome getGroundBiome(RNG rng, double x, double y, double z) public Biome getGroundBiome(RNG rng, double x, double y, double z) {
{ if (biomeSkyScatter.isEmpty()) {
if(biomeSkyScatter.isEmpty())
{
return getDerivative(); return getDerivative();
} }
if(biomeScatter.size() == 1) if (biomeScatter.size() == 1) {
{
return biomeScatter.get(0); return biomeScatter.get(0);
} }
return biomeScatter.get(getBiomeGenerator(rng).fit(0, biomeScatter.size() - 1, x, y, z)); return getBiomeGenerator(rng).fit(biomeScatter, x, y, z);
} }
} }

View File

@ -28,43 +28,43 @@ public enum NoiseStyle {
@Desc("Basic, Smooth & Fast Simplex noise.") @Desc("Basic, Smooth & Fast Simplex noise.")
@DontObfuscate @DontObfuscate
SIMPLEX(rng -> new CNG(rng, 1D, 1)), SIMPLEX(rng -> new CNG(rng, 1D, 1).scale(0.04)),
@Desc("Basic, Smooth & Fast Simplex noise. Uses 2 octaves") @Desc("Basic, Smooth & Fast Simplex noise. Uses 2 octaves")
@DontObfuscate @DontObfuscate
BIOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 2)), BIOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 2).scale(0.04)),
@Desc("Basic, Smooth & Fast Simplex noise. Uses 3 octaves") @Desc("Basic, Smooth & Fast Simplex noise. Uses 3 octaves")
@DontObfuscate @DontObfuscate
TRIOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 3)), TRIOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 3).scale(0.04)),
@Desc("Basic, Smooth & Fast Simplex noise. Uses 4 octaves") @Desc("Basic, Smooth & Fast Simplex noise. Uses 4 octaves")
@DontObfuscate @DontObfuscate
QUADOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 4)), QUADOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 4).scale(0.04)),
@Desc("Basic, Smooth & Fast Simplex noise. Uses 5 octaves") @Desc("Basic, Smooth & Fast Simplex noise. Uses 5 octaves")
@DontObfuscate @DontObfuscate
QUINTOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 5)), QUINTOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 5).scale(0.04)),
@Desc("Basic, Smooth & Fast Simplex noise. Uses 6 octaves") @Desc("Basic, Smooth & Fast Simplex noise. Uses 6 octaves")
@DontObfuscate @DontObfuscate
SEXOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 6)), SEXOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 6).scale(0.04)),
@Desc("Basic, Smooth & Fast Simplex noise. Uses 7 octaves") @Desc("Basic, Smooth & Fast Simplex noise. Uses 7 octaves")
@DontObfuscate @DontObfuscate
SEPTOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 7)), SEPTOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 7).scale(0.04)),
@Desc("Basic, Smooth & Fast Simplex noise. Uses 8 octaves") @Desc("Basic, Smooth & Fast Simplex noise. Uses 8 octaves")
@DontObfuscate @DontObfuscate
OCTOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 8)), OCTOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 8).scale(0.04)),
@Desc("Basic, Smooth & Fast Simplex noise. Uses 9 octaves") @Desc("Basic, Smooth & Fast Simplex noise. Uses 9 octaves")
@DontObfuscate @DontObfuscate
NONOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 9)), NONOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 9).scale(0.04)),
@Desc("Basic, Smooth & Fast Simplex noise. Uses 10 octaves") @Desc("Basic, Smooth & Fast Simplex noise. Uses 10 octaves")
@DontObfuscate @DontObfuscate
VIGOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 10)), VIGOCTAVE_SIMPLEX(rng -> new CNG(rng, 1D, 10).scale(0.04)),
@Desc("Cellular noise creates the same noise level for cells, changes noise level on cell borders.") @Desc("Cellular noise creates the same noise level for cells, changes noise level on cell borders.")
@DontObfuscate @DontObfuscate

View File

@ -9,8 +9,7 @@ import com.volmit.iris.object.IrisRegistrant;
import lombok.Data; import lombok.Data;
@Data @Data
public class ResourceLoader<T extends IrisRegistrant> public class ResourceLoader<T extends IrisRegistrant> {
{
protected File root; protected File root;
protected String folderName; protected String folderName;
protected String resourceTypeName; protected String resourceTypeName;
@ -22,8 +21,7 @@ public class ResourceLoader<T extends IrisRegistrant>
protected IrisLock lock; protected IrisLock lock;
protected String preferredFolder = null; protected String preferredFolder = null;
public ResourceLoader(File root, String folderName, String resourceTypeName, Class<? extends T> objectClass) public ResourceLoader(File root, String folderName, String resourceTypeName, Class<? extends T> objectClass) {
{
lock = new IrisLock("Res"); lock = new IrisLock("Res");
folderMapCache = new KMap<>(); folderMapCache = new KMap<>();
this.objectClass = objectClass; this.objectClass = objectClass;
@ -34,15 +32,12 @@ public class ResourceLoader<T extends IrisRegistrant>
loadCache = new KMap<>(); loadCache = new KMap<>();
} }
public long count() public long count() {
{
return loadCache.size(); return loadCache.size();
} }
protected T loadFile(File j, String key, String name) protected T loadFile(File j, String key, String name) {
{ try {
try
{
T t = new Gson().fromJson(IO.readAll(j), objectClass); T t = new Gson().fromJson(IO.readAll(j), objectClass);
loadCache.put(key, t); loadCache.put(key, t);
Iris.hotloader.track(j); Iris.hotloader.track(j);
@ -53,39 +48,32 @@ public class ResourceLoader<T extends IrisRegistrant>
return t; return t;
} }
catch(Throwable e) catch (Throwable e) {
{
lock.unlock(); lock.unlock();
Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage()); Iris.warn("Couldn't read " + resourceTypeName + " file: " + j.getPath() + ": " + e.getMessage());
return null; return null;
} }
} }
public T load(String name) public T load(String name) {
{
String key = name + "-" + cname; String key = name + "-" + cname;
if(loadCache.containsKey(key)) if (loadCache.containsKey(key)) {
{
T t = loadCache.get(key); T t = loadCache.get(key);
return t; return t;
} }
lock.lock(); lock.lock();
for(File i : getFolders(name)) for (File i : getFolders(name)) {
{ for (File j : i.listFiles()) {
for(File j : i.listFiles()) if (j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(name)) {
{
if(j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(name))
{
return loadFile(j, key, name); return loadFile(j, key, name);
} }
} }
File file = new File(i, name + ".json"); File file = new File(i, name + ".json");
if(file.exists()) if (file.exists()) {
{
return loadFile(file, key, name); return loadFile(file, key, name);
} }
} }
@ -96,20 +84,15 @@ public class ResourceLoader<T extends IrisRegistrant>
return null; return null;
} }
public KList<File> getFolders() public KList<File> getFolders() {
{ lock.lock();
if(folderCache == null) if (folderCache == null) {
{
folderCache = new KList<>(); folderCache = new KList<>();
for(File i : root.listFiles()) for (File i : root.listFiles()) {
{ if (i.isDirectory()) {
if(i.isDirectory()) for (File j : i.listFiles()) {
{ if (j.isDirectory() && j.getName().equals(folderName)) {
for(File j : i.listFiles())
{
if(j.isDirectory() && j.getName().equals(folderName))
{
folderCache.add(j); folderCache.add(j);
break; break;
} }
@ -117,32 +100,26 @@ public class ResourceLoader<T extends IrisRegistrant>
} }
} }
if(preferredFolder != null) if (preferredFolder != null) {
{ for (File i : folderCache.copy()) {
for(File i : folderCache.copy()) if (i.getParentFile().getName().equals(preferredFolder)) {
{
if(i.getParentFile().getName().equals(preferredFolder))
{
folderCache.remove(i); folderCache.remove(i);
folderCache.add(0, i); folderCache.add(0, i);
} }
} }
} }
} }
lock.unlock();
return folderCache; return folderCache;
} }
public KList<File> getFolders(String rc) public KList<File> getFolders(String rc) {
{
KList<File> folders = getFolders().copy(); KList<File> folders = getFolders().copy();
if(rc.contains(":")) if (rc.contains(":")) {
{ for (File i : folders.copy()) {
for(File i : folders.copy()) if (!rc.startsWith(i.getName() + ":")) {
{
if(!rc.startsWith(i.getName() + ":"))
{
folders.remove(i); folders.remove(i);
} }
} }
@ -151,28 +128,23 @@ public class ResourceLoader<T extends IrisRegistrant>
return folders; return folders;
} }
public void clearCache() public void clearCache() {
{
loadCache.clear(); loadCache.clear();
folderCache = null; folderCache = null;
} }
public File fileFor(T b) public File fileFor(T b) {
{ for (File i : getFolders()) {
for(File i : getFolders()) for (File j : i.listFiles()) {
{ if (j.isFile() && j.getName().endsWith(".json")
for(File j : i.listFiles()) && j.getName().split("\\Q.\\E")[0].equals(b.getLoadKey())) {
{
if(j.isFile() && j.getName().endsWith(".json") && j.getName().split("\\Q.\\E")[0].equals(b.getLoadKey()))
{
return j; return j;
} }
} }
File file = new File(i, b.getLoadKey() + ".json"); File file = new File(i, b.getLoadKey() + ".json");
if(file.exists()) if (file.exists()) {
{
return file; return file;
} }
} }
@ -180,13 +152,11 @@ public class ResourceLoader<T extends IrisRegistrant>
return null; return null;
} }
public boolean isLoaded(String next) public boolean isLoaded(String next) {
{
return loadCache.containsKey(next); return loadCache.containsKey(next);
} }
public void preferFolder(String name) public void preferFolder(String name) {
{
preferredFolder = name; preferredFolder = name;
} }
} }