Fixes & merge

This commit is contained in:
Daniel Mills
2020-10-23 13:05:16 -04:00
parent 99022055cf
commit 5a6f6fba2e
6 changed files with 86 additions and 161 deletions

View File

@@ -1,131 +0,0 @@
package com.volmit.iris.generator;
import org.bukkit.Material;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.generator.atomics.HeightHunk;
import com.volmit.iris.generator.atomics.TerrainHunk;
import com.volmit.iris.generator.scaffold.TerrainStream;
import com.volmit.iris.noise.CNG;
import com.volmit.iris.object.NoiseStyle;
import com.volmit.iris.util.RNG;
public class IrisTerrainStream implements TerrainStream
{
private CNG cng = NoiseStyle.IRIS_DOUBLE.create(new RNG(1234)).scale(0.5);
private static final BlockData STONE = Material.STONE.createBlockData();
@Override
public long getSeed()
{
return 0;
}
@Override
public int getHeight()
{
return 64;
}
@Override
public int getNoise(int x, int z)
{
return (int) Math.round(cng.fitDouble(0, getHeight() - 1, (double) x, (double) z));
}
@Override
public HeightHunk genNoise(int x1, int z1, int x2, int z2)
{
HeightHunk b = new HeightHunk(x2 - x1, z2 - z1);
for(int i = 0; i < b.getW(); i++)
{
for(int j = 0; j < b.getD(); j++)
{
b.setHeight(i, getNoise(i + x1, j + z1), j);
}
}
return b;
}
@Override
public TerrainHunk genCarving(int x1, int z1, int x2, int z2, HeightHunk noise)
{
TerrainHunk t = new TerrainHunk(noise.getW(), getHeight(), noise.getD(), noise);
for(int i = 0; i < t.getW(); i++)
{
for(int k = 0; k < t.getD(); k++)
{
int height = t.getHeight().getHeight(i, k);
for(int j = 0; j <= height; j++)
{
t.setBlock(i, j, k, STONE);
}
}
}
return t;
}
@Override
public TerrainHunk genTerrain(int x1, int z1, int x2, int z2, TerrainHunk t)
{
boolean hard = false;
int lastHard = 255;
for(int i = 0; i < t.getW(); i++)
{
for(int k = 0; k < t.getW(); k++)
{
int height = t.getHeight().getHeight(i, k);
for(int j = height; j >= 0; j--)
{
boolean _hard = !t.getBlockData(i, j, k).getMaterial().equals(Material.VOID_AIR);
if(!hard && _hard)
{
lastHard = j;
hard = true;
}
else if(hard && (!_hard || j == 0))
{
generateSurface(x1, z1, i, lastHard, k, lastHard - j, t);
hard = false;
}
}
}
}
return t;
}
protected void generateSurface(int ox, int oz, int x, int y, int z, int depth, TerrainHunk t)
{
for(int i = y; i <= (y + depth); i++)
{
if(i == y)
{
t.setBlock(x, i, z, Material.GRASS_BLOCK.createBlockData());
}
}
}
@Override
public TerrainHunk genDecorations(int x1, int z1, int x2, int z2, TerrainHunk hunk)
{
// TODO Auto-generated method stub
return hunk;
}
@Override
public TerrainHunk genParallax(int x1, int z1, int x2, int z2, TerrainHunk hunk)
{
// TODO Auto-generated method stub
return hunk;
}
}

View File

@@ -1,64 +0,0 @@
package com.volmit.iris.generator.atomics;
public class HeightHunk extends Hunk<Byte>
{
public HeightHunk(int w, int d)
{
super(w, 1, d);
}
public void setHeight(int x, int y, int z)
{
set(x, 0, z, (byte) (y + Byte.MIN_VALUE));
}
public int getHeight(int x, int z)
{
return get(x, 0, z) - Byte.MIN_VALUE;
}
@SafeVarargs
public static HeightHunk combined(Byte defaultNode, HeightHunk... hunks)
{
int w = 0;
int d = 0;
for(HeightHunk i : hunks)
{
w = Math.max(w, i.getW());
d = Math.max(d, i.getD());
}
HeightHunk b = new HeightHunk(w, d);
b.fill((byte) (defaultNode + Byte.MIN_VALUE));
for(HeightHunk i : hunks)
{
b.insert(i);
}
return b;
}
@SafeVarargs
public static HeightHunk combined(HeightHunk... hunks)
{
int w = 0;
int d = 0;
for(HeightHunk i : hunks)
{
w = Math.max(w, i.getW());
d = Math.max(d, i.getD());
}
HeightHunk b = new HeightHunk(w, d);
for(HeightHunk i : hunks)
{
b.insert(i);
}
return b;
}
}

View File

@@ -1,280 +0,0 @@
package com.volmit.iris.generator.atomics;
import org.bouncycastle.util.Arrays;
import com.volmit.iris.util.Function3;
import com.volmit.iris.util.Supplier2;
import com.volmit.iris.util.Supplier3;
import lombok.Data;
@Data
public class Hunk<T>
{
protected final int w;
protected final int h;
protected final int d;
protected final T[] data;
@SuppressWarnings("unchecked")
public Hunk(int w, int h, int d)
{
this.w = w;
this.h = h;
this.d = d;
data = (T[]) new Object[w * h * d];
}
/**
* Create a new hunk from a section of this hunk.
*
*
* @param x1
* The min x (inclusive)
* @param y1
* The min y (inclusive)
* @param z1
* The min z (inclusive)
* @param x2
* The max x (exclusive)
* @param y2
* The max y (exclusive)
* @param z2
* The max z (exclusive)
* @return the new hunk (x2-x1, y2-y1, z2-z1)
*/
public Hunk<T> crop(int x1, int y1, int z1, int x2, int y2, int z2)
{
Hunk<T> h = new Hunk<T>(x2 - x1, y2 - y1, z2 - z1);
for(int i = x1; i < x2; i++)
{
for(int j = y1; j < y2; j++)
{
for(int k = z1; k < z2; k++)
{
h.set(i - x1, j - y1, k - z1, get(i, j, k));
}
}
}
return h;
}
/**
* Insert a hunk into this one with an offset the inserted hunk
*
* @param offX
* the offset from zero for x
* @param offY
* the offset from zero for y
* @param offZ
* the offset from zero for z
* @param hunk
* the hunk to insert
*/
public void insert(int offX, int offY, int offZ, Hunk<T> hunk)
{
insert(offX, offY, offZ, hunk, false);
}
/**
* Insert a hunk into this one
*
* @param hunk
* the hunk to insert
*/
public void insert(Hunk<T> hunk)
{
insert(0, 0, 0, hunk, false);
}
/**
* Insert a hunk into this one
*
* @param hunk
* the hunk to insert
* @param inverted
* invert the inserted hunk or not
*/
public void insert(Hunk<T> hunk, boolean inverted)
{
insert(0, 0, 0, hunk, inverted);
}
/**
* Insert a hunk into this one with an offset and possibly inverting the y of
* the inserted hunk
*
* @param offX
* the offset from zero for x
* @param offY
* the offset from zero for y
* @param offZ
* the offset from zero for z
* @param hunk
* the hunk to insert
* @param invertY
* should the inserted hunk be inverted
*/
public void insert(int offX, int offY, int offZ, Hunk<T> hunk, boolean invertY)
{
if(offX + (hunk.getW() - 1) >= w || offY + (hunk.getH() - 1) >= h || offZ + (hunk.getD() - 1) >= d || offX < 0 || offY < 0 || offZ < 0)
{
throw new RuntimeException("Cannot insert hunk " + hunk.getW() + "," + hunk.getH() + "," + hunk.getD() + " into Hunk " + w + "," + h + "," + d + " with offset " + offZ + "," + offY + "," + offZ);
}
for(int i = offX; i < offX + hunk.getW(); i++)
{
for(int j = offY; j < offY + hunk.getH(); j++)
{
for(int k = offZ; k < offZ + hunk.getD(); k++)
{
set(i, j, k, hunk.get(i - offX, j - offY, k - offZ));
}
}
}
}
public void set(int x, int z, int y1, int y2, T t)
{
set(x, x, y1, y2, z, z, t);
}
public void set(int x1, int y1, int z1, int x2, int y2, int z2, T t)
{
for(int i = x1; i <= x2; i++)
{
for(int j = y1; j <= y2; j++)
{
for(int k = z1; k <= z2; k++)
{
set(i, j, k, t);
}
}
}
}
public void set(int x, int y, int z, T t)
{
data[index(x, y, z)] = t;
}
public T get(int x, int y, int z)
{
return data[index(x, y, z)];
}
public void setInvertedY(int x, int y, int z, T t)
{
data[index(x, h - y, z)] = t;
}
public T getInvertedY(int x, int y, int z)
{
return data[index(x, h - y, z)];
}
protected int index(int x, int y, int z)
{
if(x >= w || y >= h || z >= d)
{
throw new RuntimeException(x + " " + y + " " + z + " is out of the bounds 0,0,0 - " + (w - 1) + "," + (h - 1) + "," + (d - 1));
}
return (z * w * h) + (y * w) + x;
}
public void fill(int ox, int oy, int oz, Function3<Integer, Integer, Integer, T> f)
{
for(int i = ox; i < ox + getW(); i++)
{
for(int j = oy; j < oy + getH(); j++)
{
for(int k = oz; k < oz + getD(); k++)
{
set(i - ox, j - oy, k - oz, f.apply(i, j, k));
}
}
}
}
public void forEach(Supplier3<Integer, Integer, Integer> t)
{
for(int i = 0; i < getW(); i++)
{
for(int j = 0; j < getH(); j++)
{
for(int k = 0; k < getD(); k++)
{
t.get(i, j, k);
}
}
}
}
public void forEachXZ(Supplier2<Integer, Integer> t)
{
for(int i = 0; i < getW(); i++)
{
for(int k = 0; k < getD(); k++)
{
t.get(i, k);
}
}
}
public void fill(T t)
{
Arrays.fill(data, t);
}
@SafeVarargs
public static <T> Hunk<T> combined(T defaultNode, Hunk<T>... hunks)
{
int w = 0;
int h = 0;
int d = 0;
for(Hunk<T> i : hunks)
{
w = Math.max(w, i.getW());
h = Math.max(h, i.getH());
d = Math.max(d, i.getD());
}
Hunk<T> b = new Hunk<T>(w, h, d);
b.fill(defaultNode);
for(Hunk<T> i : hunks)
{
b.insert(i);
}
return b;
}
@SafeVarargs
public static <T> Hunk<T> combined(Hunk<T>... hunks)
{
int w = 0;
int h = 0;
int d = 0;
for(Hunk<T> i : hunks)
{
w = Math.max(w, i.getW());
h = Math.max(h, i.getH());
d = Math.max(d, i.getD());
}
Hunk<T> b = new Hunk<T>(w, h, d);
for(Hunk<T> i : hunks)
{
b.insert(i);
}
return b;
}
}

View File

@@ -1,241 +0,0 @@
package com.volmit.iris.generator.atomics;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.BiomeGrid;
import org.bukkit.generator.ChunkGenerator.ChunkData;
import org.bukkit.material.MaterialData;
import com.volmit.iris.object.IrisBiome;
import com.volmit.iris.util.KList;
import lombok.Getter;
@SuppressWarnings("deprecation")
public class TerrainHunk extends Hunk<TerrainNode> implements BiomeGrid, ChunkData
{
@Getter
private HeightHunk height;
@Getter
private Hunk<IrisBiome> biome;
public TerrainHunk(int w, int h, int d)
{
super(w, h, d);
this.height = new HeightHunk(w, d);
this.biome = new Hunk<IrisBiome>(w, h, d);
}
public TerrainHunk(int w, int h, int d, HeightHunk hh)
{
super(w, h, d);
this.height = hh;
this.biome = new Hunk<IrisBiome>(w, h, d);
}
@Override
public int getMaxHeight()
{
return getH();
}
private void set(int x, int y, int z, BlockData block)
{
TerrainNode n = get(x, y, z);
if(n == null)
{
n = new TerrainNode(Biome.THE_VOID, block);
}
else
{
n = n.setBlockData(block);
}
set(x, y, z, n);
}
private void set(int x, int y, int z, Biome biome)
{
TerrainNode n = get(x, y, z);
if(n == null)
{
n = new TerrainNode(biome, Material.AIR.createBlockData());
}
else
{
n = n.setBiome(biome);
}
set(x, y, z, n);
}
@Override
public void setBlock(int x, int y, int z, Material material)
{
set(x, y, z, material.createBlockData());
}
@Override
public void setBlock(int x, int y, int z, MaterialData material)
{
set(x, y, z, material.getItemType().createBlockData());
}
@Override
public void setBlock(int x, int y, int z, BlockData blockData)
{
set(x, y, z, blockData);
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, Material material)
{
throw new RuntimeException("Not Supported");
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material)
{
throw new RuntimeException("Not Supported");
}
@Override
public void setRegion(int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, BlockData blockData)
{
throw new RuntimeException("Not Supported");
}
@Override
public Material getType(int x, int y, int z)
{
return getBlockData(x, y, z).getMaterial();
}
@Override
public MaterialData getTypeAndData(int x, int y, int z)
{
return new MaterialData(getBlockData(x, y, z).getMaterial());
}
@Override
public BlockData getBlockData(int x, int y, int z)
{
TerrainNode n = get(x, y, z);
if(n == null)
{
return Material.VOID_AIR.createBlockData();
}
return n.getBlockData();
}
@Override
public byte getData(int x, int y, int z)
{
throw new RuntimeException("Not Supported");
}
@Override
public Biome getBiome(int x, int z)
{
throw new RuntimeException("Not Supported");
}
@Override
public Biome getBiome(int x, int y, int z)
{
TerrainNode n = get(x, y, z);
if(n == null)
{
return Biome.THE_VOID;
}
return n.getBiome();
}
@Override
public void setBiome(int x, int z, Biome bio)
{
throw new RuntimeException("Not Supported");
}
@Override
public void setBiome(int x, int y, int z, Biome bio)
{
set(x, y, z, bio);
}
@SuppressWarnings("unchecked")
@SafeVarargs
public static TerrainHunk combined(TerrainNode defaultNode, TerrainHunk... hunks)
{
KList<HeightHunk> hhunks = new KList<>();
KList<Hunk<IrisBiome>> bhunks = new KList<>();
int w = 0;
int h = 0;
int d = 0;
for(TerrainHunk i : hunks)
{
hhunks.add(i.getHeight());
bhunks.add(i.getBiome());
w = Math.max(w, i.getW());
h = Math.max(h, i.getH());
d = Math.max(d, i.getD());
}
TerrainHunk b = new TerrainHunk(w, h, d);
b.fill(defaultNode);
for(TerrainHunk i : hunks)
{
b.insert(i);
}
b.height = HeightHunk.combined((byte) 0, hhunks.toArray(new HeightHunk[hhunks.size()]));
b.biome = Hunk.combined(null, hhunks.toArray(new Hunk[hhunks.size()]));
return b;
}
@SuppressWarnings("unchecked")
@SafeVarargs
public static TerrainHunk combined(TerrainHunk... hunks)
{
KList<HeightHunk> hhunks = new KList<>();
KList<Hunk<IrisBiome>> bhunks = new KList<>();
int w = 0;
int h = 0;
int d = 0;
for(TerrainHunk i : hunks)
{
hhunks.add(i.getHeight());
bhunks.add(i.getBiome());
w = Math.max(w, i.getW());
h = Math.max(h, i.getH());
d = Math.max(d, i.getD());
}
TerrainHunk b = new TerrainHunk(w, h, d);
for(TerrainHunk i : hunks)
{
b.insert(i);
}
b.height = HeightHunk.combined((byte) 0, hhunks.toArray(new HeightHunk[hhunks.size()]));
b.biome = Hunk.combined(null, hhunks.toArray(new Hunk[hhunks.size()]));
return b;
}
}

View File

@@ -1,61 +0,0 @@
package com.volmit.iris.generator.atomics;
import org.bukkit.block.Biome;
import org.bukkit.block.data.BlockData;
import com.volmit.iris.util.KList;
public class TerrainNode
{
private static final KList<BlockData> blockDataPalette = new KList<BlockData>();
private final byte biome;
private final short block;
private TerrainNode(byte biome, short block)
{
this.biome = biome;
this.block = block;
}
public TerrainNode(Biome biome, BlockData block)
{
this((byte) (biome.ordinal()), (short) (paletteOf(block)));
}
public TerrainNode setBlockData(BlockData block)
{
return new TerrainNode(biome, (short) (paletteOf(block)));
}
public TerrainNode setBiome(Biome biome)
{
return new TerrainNode((byte) (biome.ordinal()), block);
}
public BlockData getBlockData()
{
return blockDataPalette.get(block);
}
public Biome getBiome()
{
return Biome.values()[biome];
}
private static int paletteOf(BlockData b)
{
synchronized(blockDataPalette)
{
int v = blockDataPalette.indexOf(b);
if(v >= 0)
{
return v;
}
blockDataPalette.add(b);
return blockDataPalette.size() - 1;
}
}
}

View File

@@ -1,23 +0,0 @@
package com.volmit.iris.generator.scaffold;
import com.volmit.iris.generator.atomics.HeightHunk;
import com.volmit.iris.generator.atomics.TerrainHunk;
public interface TerrainStream
{
public long getSeed();
public int getHeight();
public int getNoise(int x, int z);
public HeightHunk genNoise(int x1, int z1, int x2, int z2);
public TerrainHunk genTerrain(int x1, int z1, int x2, int z2, TerrainHunk noise);
public TerrainHunk genCarving(int x1, int z1, int x2, int z2, HeightHunk noise);
public TerrainHunk genDecorations(int x1, int z1, int x2, int z2, TerrainHunk hunk);
public TerrainHunk genParallax(int x1, int z1, int x2, int z2, TerrainHunk hunk);
}