This commit is contained in:
Daniel Mills
2020-07-30 02:58:08 -04:00
parent 773dd2fd1a
commit aec5486144
14 changed files with 241 additions and 13 deletions

View File

@@ -183,7 +183,7 @@ public abstract class ContextualChunkGenerator extends ChunkGenerator implements
}
}
protected void close()
public void close()
{
HandlerList.unregisterAll(this);
Bukkit.getScheduler().cancelTask(getTask());

View File

@@ -19,6 +19,7 @@ public abstract class DimensionChunkGenerator extends ContextualChunkGenerator
{
protected final String dimensionName;
protected static final BlockData AIR = Material.AIR.createBlockData();
protected static final BlockData CAVE_AIR = Material.CAVE_AIR.createBlockData();
protected static final BlockData BEDROCK = Material.BEDROCK.createBlockData();
public DimensionChunkGenerator(String dimensionName)

View File

@@ -1,9 +1,11 @@
package com.volmit.iris.generator;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.volmit.iris.Iris;
@@ -40,6 +42,19 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon
lock.unlock();
}
public void onInit(World world, RNG rng)
{
try
{
super.onInit(world, rng);
}
catch(Throwable e)
{
fail(e);
}
}
@Override
public BiomeResult getBiome(int x, int z)
{
@@ -68,6 +83,29 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon
protected void onClose()
{
super.onClose();
try
{
parallaxMap.saveAll();
ceilingParallaxMap.saveAll();
parallaxMap.getLoadedChunks().clear();
parallaxMap.getLoadedRegions().clear();
ceilingParallaxMap.getLoadedChunks().clear();
ceilingParallaxMap.getLoadedRegions().clear();
}
catch(IOException e)
{
e.printStackTrace();
}
setBiomeCache(null);
setAvailableFilters(null);
setBiomeHitCache(null);
setCacheTrueBiome(null);
setCacheHeightMap(null);
setCeilingSliverCache(null);
setSliverCache(null);
Iris.info("Closing Iris Dimension " + getWorld().getName());
}

View File

@@ -89,7 +89,19 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
@Override
public int getHighest(int x, int z, boolean ignoreFluid)
{
return (int) Math.round(ignoreFluid ? getTerrainHeight(x, z) : getTerrainWaterHeight(x, z));
int h = (int) Math.round(ignoreFluid ? getTerrainHeight(x, z) : getTerrainWaterHeight(x, z));
if(getDimension().isCarving() && h >= getDimension().getCarvingMin())
{
while(getGlCarve().isCarved(x, h, z))
{
h--;
}
return h;
}
return h;
}
@Override

View File

@@ -9,6 +9,7 @@ import org.bukkit.block.data.Bisected.Half;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.Iris;
import com.volmit.iris.layer.GenLayerCarve;
import com.volmit.iris.layer.GenLayerCave;
import com.volmit.iris.object.DecorationPart;
import com.volmit.iris.object.InferredType;
@@ -35,6 +36,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
private long lastUpdateRequest = M.ms();
private long lastChunkLoad = M.ms();
private GenLayerCave glCave;
private GenLayerCarve glCarve;
private RNG rockRandom;
private int[] cacheHeightMap;
private IrisBiome[] cacheTrueBiome;
@@ -55,6 +57,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
super.onInit(world, rng);
rockRandom = getMasterRandom().nextParallelRNG(2858678);
glCave = new GenLayerCave(this, rng.nextParallelRNG(238948));
glCarve = new GenLayerCarve(this, rng.nextParallelRNG(968346576));
}
public KList<CaveResult> getCaves(int x, int z)
@@ -78,6 +81,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
try
{
int highestPlaced = 0;
BlockData block;
int fluidHeight = getDimension().getFluidHeight();
double ox = getModifiedX(rx, rz);
@@ -87,6 +91,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
int depth = 0;
double noise = getNoiseHeight(rx, rz);
int height = (int) Math.round(noise) + fluidHeight;
boolean carvable = getDimension().isCarving() && height > getDimension().getCarvingMin();
IrisRegion region = sampleRegion(rx, rz);
IrisBiome biome = sampleTrueBiome(rx, rz).getBiome();
@@ -107,14 +112,15 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
{
Iris.error("Failed to write cache at " + x + " " + z + " in chunk " + cx + " " + cz);
}
}
KList<BlockData> layers = biome.generateLayers(wx, wz, masterRandom, height, height - getFluidHeight());
KList<BlockData> seaLayers = biome.isSea() ? biome.generateSeaLayers(wx, wz, masterRandom, fluidHeight - height) : new KList<>();
cacheInternalBiome(x, z, biome);
boolean caverning = false;
KList<Integer> cavernHeights = new KList<>();
int lastCavernHeight = -1;
// Set ground biome (color) to HEIGHT - HEIGHT+3
for(int k = Math.max(height, fluidHeight); k < Math.max(height, fluidHeight) + 3; k++)
{
if(k < Math.max(height, fluidHeight) + 3)
@@ -128,12 +134,41 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
for(int k = Math.max(height, fluidHeight); k >= 0; k--)
{
boolean cavernSurface = false;
if(k == 0)
{
if(biomeMap != null)
{
sliver.set(k, biome.getDerivative());
biomeMap.setBiome(x, z, biome);
}
sliver.set(k, BEDROCK);
continue;
}
if(carvable && glCarve.isCarved(rx, k, rz))
{
if(biomeMap != null)
{
sliver.set(k, biome.getDerivative());
biomeMap.setBiome(x, z, biome);
}
sliver.set(k, CAVE_AIR);
caverning = true;
continue;
}
else if(carvable && caverning)
{
lastCavernHeight = k;
cavernSurface = true;
cavernHeights.add(k);
caverning = false;
}
boolean underwater = k > height && k <= fluidHeight;
if(biomeMap != null)
@@ -147,6 +182,11 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
block = seaLayers.hasIndex(fluidHeight - k) ? layers.get(depth) : getDimension().getFluid(rockRandom, wx, k, wz);
}
else if(layers.hasIndex(lastCavernHeight - k))
{
block = layers.get(lastCavernHeight - k);
}
else
{
block = layers.hasIndex(depth) ? layers.get(depth) : getDimension().getRock(rockRandom, wx, k, wz);
@@ -154,15 +194,14 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
}
sliver.set(k, block);
highestPlaced = Math.max(highestPlaced, k);
// Decorate underwater
if(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);
}
// Decorate land
if(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);
}
@@ -205,6 +244,11 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
}
}
}
if(caching && highestPlaced < height)
{
cacheHeightMap[(z << 4) | x] = highestPlaced;
}
}
catch(Throwable e)