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

@ -226,6 +226,14 @@ public class Iris extends JavaPlugin implements BoardProvider
i.close(); i.close();
} }
for(World i : Bukkit.getWorlds())
{
if(i.getGenerator() instanceof IrisChunkGenerator)
{
((IrisChunkGenerator) i).close();
}
}
executors.clear(); executors.clear();
manager.onDisable(); manager.onDisable();
Bukkit.getScheduler().cancelTasks(this); Bukkit.getScheduler().cancelTasks(this);

View File

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

View File

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

View File

@ -1,9 +1,11 @@
package com.volmit.iris.generator; package com.volmit.iris.generator;
import java.io.IOException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
@ -40,6 +42,19 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon
lock.unlock(); lock.unlock();
} }
public void onInit(World world, RNG rng)
{
try
{
super.onInit(world, rng);
}
catch(Throwable e)
{
fail(e);
}
}
@Override @Override
public BiomeResult getBiome(int x, int z) public BiomeResult getBiome(int x, int z)
{ {
@ -68,6 +83,29 @@ public class IrisChunkGenerator extends CeilingChunkGenerator implements IrisCon
protected void onClose() protected void onClose()
{ {
super.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()); Iris.info("Closing Iris Dimension " + getWorld().getName());
} }

View File

@ -89,7 +89,19 @@ public abstract class ParallaxChunkGenerator extends TerrainChunkGenerator imple
@Override @Override
public int getHighest(int x, int z, boolean ignoreFluid) 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 @Override

View File

@ -9,6 +9,7 @@ import org.bukkit.block.data.Bisected.Half;
import org.bukkit.block.data.BlockData; import org.bukkit.block.data.BlockData;
import com.volmit.iris.Iris; import com.volmit.iris.Iris;
import com.volmit.iris.layer.GenLayerCarve;
import com.volmit.iris.layer.GenLayerCave; import com.volmit.iris.layer.GenLayerCave;
import com.volmit.iris.object.DecorationPart; import com.volmit.iris.object.DecorationPart;
import com.volmit.iris.object.InferredType; import com.volmit.iris.object.InferredType;
@ -35,6 +36,7 @@ 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;
private GenLayerCarve glCarve;
private RNG rockRandom; private RNG rockRandom;
private int[] cacheHeightMap; private int[] cacheHeightMap;
private IrisBiome[] cacheTrueBiome; private IrisBiome[] cacheTrueBiome;
@ -55,6 +57,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
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));
} }
public KList<CaveResult> getCaves(int x, int z) public KList<CaveResult> getCaves(int x, int z)
@ -78,6 +81,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
try try
{ {
int highestPlaced = 0;
BlockData block; BlockData block;
int fluidHeight = getDimension().getFluidHeight(); int fluidHeight = getDimension().getFluidHeight();
double ox = getModifiedX(rx, rz); double ox = getModifiedX(rx, rz);
@ -87,6 +91,7 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
int depth = 0; int depth = 0;
double noise = getNoiseHeight(rx, rz); double noise = getNoiseHeight(rx, rz);
int height = (int) Math.round(noise) + fluidHeight; int height = (int) Math.round(noise) + fluidHeight;
boolean carvable = getDimension().isCarving() && height > getDimension().getCarvingMin();
IrisRegion region = sampleRegion(rx, rz); IrisRegion region = sampleRegion(rx, rz);
IrisBiome biome = sampleTrueBiome(rx, rz).getBiome(); 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); 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> layers = biome.generateLayers(wx, wz, 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(wx, wz, masterRandom, fluidHeight - height) : new KList<>();
cacheInternalBiome(x, z, biome); 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++) for(int k = Math.max(height, fluidHeight); k < Math.max(height, fluidHeight) + 3; k++)
{ {
if(k < Math.max(height, fluidHeight) + 3) 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--) for(int k = Math.max(height, fluidHeight); k >= 0; k--)
{ {
boolean cavernSurface = false;
if(k == 0) if(k == 0)
{ {
if(biomeMap != null)
{
sliver.set(k, biome.getDerivative());
biomeMap.setBiome(x, z, biome);
}
sliver.set(k, BEDROCK); sliver.set(k, BEDROCK);
continue; 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; boolean underwater = k > height && k <= fluidHeight;
if(biomeMap != null) 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); 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 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);
@ -154,15 +194,14 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
} }
sliver.set(k, block); sliver.set(k, block);
highestPlaced = Math.max(highestPlaced, k);
// Decorate underwater if(!cavernSurface && (k == height && block.getMaterial().isSolid() && k < fluidHeight))
if(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 land if((carvable && cavernSurface) || (k == Math.max(height, fluidHeight) && block.getMaterial().isSolid() && k < 255 && k > fluidHeight))
if(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);
} }
@ -205,6 +244,11 @@ public abstract class TerrainChunkGenerator extends ParallelChunkGenerator
} }
} }
} }
if(caching && highestPlaced < height)
{
cacheHeightMap[(z << 4) | x] = highestPlaced;
}
} }
catch(Throwable e) catch(Throwable e)

View File

@ -0,0 +1,45 @@
package com.volmit.iris.layer;
import com.volmit.iris.generator.DimensionChunkGenerator;
import com.volmit.iris.util.CellGenerator;
import com.volmit.iris.util.GenLayer;
import com.volmit.iris.util.IrisInterpolation;
import com.volmit.iris.util.M;
import com.volmit.iris.util.RNG;
public class GenLayerCarve extends GenLayer
{
private CellGenerator cell;
public GenLayerCarve(DimensionChunkGenerator iris, RNG rng)
{
super(iris, rng);
cell = new CellGenerator(rng.nextParallelRNG(-135486678));
}
public boolean isCarved(int xc, int y, int zc)
{
if(y > iris.getDimension().getCarvingMax() || y < iris.getDimension().getCarvingMin())
{
return false;
}
double x = ((double) xc / iris.getDimension().getCarvingZoom());
double z = ((double) zc / iris.getDimension().getCarvingZoom());
double opacity = Math.pow(IrisInterpolation.sinCenter(M.lerpInverse(iris.getDimension().getCarvingMin(), iris.getDimension().getCarvingMax(), y)), 4);
if(cell.getDistance(x - (Math.cos(y / iris.getDimension().getCarvingRippleThickness()) + 0.5D) / 2D, y / iris.getDimension().getCarvingSliverThickness(), z + (Math.sin(y / iris.getDimension().getCarvingRippleThickness()) + 0.5D) / 2D) < opacity * iris.getDimension().getCarvingEnvelope())
{
return true;
}
return false;
}
@Override
public double generate(double x, double z)
{
return 0;
}
}

View File

@ -34,7 +34,7 @@ public class PostSlabber extends IrisPostBlockFilter
int hc = highestTerrainBlock(x - 1, z); int hc = highestTerrainBlock(x - 1, z);
int hd = highestTerrainBlock(x, z - 1); int hd = highestTerrainBlock(x, z - 1);
if(ha == h + 1 || hb == h + 1 || hc == h + 1 || hd == h + 1) if((ha == h + 1 && isSolid(x + 1, ha, z)) || (hb == h + 1 && isSolid(x, hb, z + 1)) || (hc == h + 1 && isSolid(x - 1, hc, z)) || (hd == h + 1 && isSolid(x, hd, z - 1)))
{ {
BlockData d = gen.sampleTrueBiome(x, z).getBiome().getSlab().get(rng, x, h, z); BlockData d = gen.sampleTrueBiome(x, z).getBiome().getSlab().get(rng, x, h, z);

View File

@ -64,6 +64,11 @@ public class PostWallPatcher extends IrisPostBlockFilter
continue; continue;
} }
if(isAirOrWater(x, i, z))
{
continue;
}
setPostBlock(x, i, z, d); setPostBlock(x, i, z, d);
} }
} }

View File

@ -124,7 +124,7 @@ public class IrisBiomeDecorator
double xx = dispersion.equals(Dispersion.SCATTER) ? nrng.i(-100000, 100000) : x; double xx = dispersion.equals(Dispersion.SCATTER) ? nrng.i(-100000, 100000) : x;
double zz = dispersion.equals(Dispersion.SCATTER) ? nrng.i(-100000, 100000) : z; double zz = dispersion.equals(Dispersion.SCATTER) ? nrng.i(-100000, 100000) : z;
if(getGenerator(nrng).fitDoubleD(0D, 1D, xx, zz) <= chance) if(getGenerator(rng).fitDoubleD(0D, 1D, xx, zz) <= chance)
{ {
try try
{ {

View File

@ -54,6 +54,30 @@ public class IrisDimension extends IrisRegistrant
@Desc("Generate caves or not.") @Desc("Generate caves or not.")
private boolean caves = true; private boolean caves = true;
@DontObfuscate
@Desc("Carve terrain or not")
private double carvingZoom = 3.5;
@DontObfuscate
@Desc("Carving starts at this height")
private int carvingMin = 115;
@DontObfuscate
@Desc("The maximum height carving happens at")
private int carvingMax = 239;
@DontObfuscate
@Desc("The thickness of carvings (vertical)")
private double carvingSliverThickness = 5.5D;
@DontObfuscate
@Desc("The thickness of ripples on carved walls")
private double carvingRippleThickness = 3D;
@DontObfuscate
@Desc("How much of 3D space is carved out. Higher values make carvings cross into 3d space more often (bigger)")
private double carvingEnvelope = 0.335D;
@DontObfuscate @DontObfuscate
@Desc("Carve terrain or not") @Desc("Carve terrain or not")
private boolean carving = true; private boolean carving = true;

View File

@ -77,9 +77,17 @@ public class AtomicRegionData
return data; return data;
} }
ByteArrayTag btag = (ByteArrayTag) tag.get(rx + "." + rz); try
ByteArrayInputStream in = new ByteArrayInputStream(btag.getValue()); {
data.read(in); ByteArrayTag btag = (ByteArrayTag) tag.get(rx + "." + rz);
ByteArrayInputStream in = new ByteArrayInputStream(btag.getValue());
data.read(in);
}
catch(Throwable e)
{
}
return data; return data;
} }

View File

@ -3,6 +3,7 @@ package com.volmit.iris.object.atomics;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.locks.ReentrantLock;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
@ -25,6 +26,7 @@ public class AtomicSliver
private KMap<Integer, BlockData> block; private KMap<Integer, BlockData> block;
private KMap<Integer, IrisBiome> truebiome; private KMap<Integer, IrisBiome> truebiome;
private KMap<Integer, Biome> biome; private KMap<Integer, Biome> biome;
private ReentrantLock lock = new ReentrantLock();
private int highestBlock = 0; private int highestBlock = 0;
private int highestBiome = 0; private int highestBiome = 0;
private long last = M.ms(); private long last = M.ms();
@ -65,8 +67,17 @@ public class AtomicSliver
return; return;
} }
lock.lock();
block.put(h, d); block.put(h, d);
if(d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR))
{
lock.unlock();
return;
}
highestBlock = h > highestBlock ? h : highestBlock; highestBlock = h > highestBlock ? h : highestBlock;
lock.unlock();
} }
public void setSilently(int h, BlockData d) public void setSilently(int h, BlockData d)
@ -76,7 +87,9 @@ public class AtomicSliver
return; return;
} }
lock.lock();
block.put(h, d); block.put(h, d);
lock.unlock();
} }
public boolean isSolid(int h) public boolean isSolid(int h)
@ -98,17 +111,22 @@ public class AtomicSliver
public void set(int h, Biome d) public void set(int h, Biome d)
{ {
lock.lock();
biome.put(h, d); biome.put(h, d);
highestBiome = h > highestBiome ? h : highestBiome; highestBiome = h > highestBiome ? h : highestBiome;
lock.unlock();
} }
public void set(int h, IrisBiome d) public void set(int h, IrisBiome d)
{ {
lock.lock();
truebiome.put(h, d); truebiome.put(h, d);
lock.unlock();
} }
public void write(ChunkData d) public void write(ChunkData d)
{ {
lock.lock();
for(int i = 0; i <= highestBlock; i++) for(int i = 0; i <= highestBlock; i++)
{ {
if(block.get(i) == null) if(block.get(i) == null)
@ -121,10 +139,12 @@ public class AtomicSliver
d.setBlock(x, i, z, block.get(i)); d.setBlock(x, i, z, block.get(i));
} }
} }
lock.unlock();
} }
public void write(BiomeGrid d) public void write(BiomeGrid d)
{ {
lock.lock();
for(int i = 0; i <= highestBiome; i++) for(int i = 0; i <= highestBiome; i++)
{ {
if(biome.get(i) != null) if(biome.get(i) != null)
@ -132,15 +152,19 @@ public class AtomicSliver
d.setBiome(x, i, z, biome.get(i)); d.setBiome(x, i, z, biome.get(i));
} }
} }
lock.unlock();
} }
public void write(HeightMap height) public void write(HeightMap height)
{ {
lock.lock();
height.setHeight(x, z, highestBlock); height.setHeight(x, z, highestBlock);
lock.unlock();
} }
public void read(DataInputStream din) throws IOException public void read(DataInputStream din) throws IOException
{ {
lock.lock();
this.block = new KMap<Integer, BlockData>(); this.block = new KMap<Integer, BlockData>();
int h = din.readByte() - Byte.MIN_VALUE; int h = din.readByte() - Byte.MIN_VALUE;
highestBlock = h; highestBlock = h;
@ -149,10 +173,12 @@ public class AtomicSliver
{ {
block.put(i, BlockDataTools.getBlockData(din.readUTF())); block.put(i, BlockDataTools.getBlockData(din.readUTF()));
} }
lock.unlock();
} }
public void write(DataOutputStream dos) throws IOException public void write(DataOutputStream dos) throws IOException
{ {
lock.lock();
dos.writeByte(highestBlock + Byte.MIN_VALUE); dos.writeByte(highestBlock + Byte.MIN_VALUE);
for(int i = 0; i <= highestBlock; i++) for(int i = 0; i <= highestBlock; i++)
@ -160,10 +186,12 @@ public class AtomicSliver
BlockData dat = block.get(i); BlockData dat = block.get(i);
dos.writeUTF((dat == null ? AIR : dat).getAsString(true)); dos.writeUTF((dat == null ? AIR : dat).getAsString(true));
} }
lock.unlock();
} }
public void insert(AtomicSliver atomicSliver) public void insert(AtomicSliver atomicSliver)
{ {
lock.lock();
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
if(block.get(i) == null || block.get(i).equals(AIR)) if(block.get(i) == null || block.get(i).equals(AIR))
@ -177,10 +205,12 @@ public class AtomicSliver
block.put(i, b); block.put(i, b);
} }
} }
lock.unlock();
} }
public void inject(ChunkData currentData) public void inject(ChunkData currentData)
{ {
lock.lock();
for(int i = 0; i < 256; i++) for(int i = 0; i < 256; i++)
{ {
if(block.get(i) != null && !block.get(i).equals(AIR)) if(block.get(i) != null && !block.get(i).equals(AIR))
@ -189,6 +219,7 @@ public class AtomicSliver
currentData.setBlock(x, i, z, b); currentData.setBlock(x, i, z, b);
} }
} }
lock.unlock();
} }
public boolean isOlderThan(long m) public boolean isOlderThan(long m)

View File

@ -64,6 +64,18 @@ public abstract class IrisPostBlockFilter implements IPostBlockAccess
return d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR); return d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR);
} }
public boolean isSolid(int x, int y, int z)
{
BlockData d = getPostBlock(x, y, z);
return d.getMaterial().isSolid();
}
public boolean isAirOrWater(int x, int y, int z)
{
BlockData d = getPostBlock(x, y, z);
return d.getMaterial().equals(Material.WATER) || d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR);
}
public boolean isSlab(int x, int y, int z) public boolean isSlab(int x, int y, int z)
{ {
BlockData d = getPostBlock(x, y, z); BlockData d = getPostBlock(x, y, z);