mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
f
This commit is contained in:
parent
356c97a4b2
commit
87cce116af
@ -1,64 +0,0 @@
|
||||
package com.volmit.iris.gen.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;
|
||||
}
|
||||
}
|
@ -1,283 +0,0 @@
|
||||
package com.volmit.iris.gen.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, Hunk<Double> noise)
|
||||
{
|
||||
super(w, h, d);
|
||||
this.height = new HeightHunk(w, d);
|
||||
this.biome = new Hunk<IrisBiome>(w, h, d);
|
||||
|
||||
for(int i = 0; i < w; i++)
|
||||
{
|
||||
for(int j = 0; j < d; j++)
|
||||
{
|
||||
height.setHeight(i, noise.highestNonNull(i, j), j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
public BlockData getBlockDataOrNull(int x, int y, int z)
|
||||
{
|
||||
TerrainNode n = get(x, y, z);
|
||||
|
||||
if(n == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void into(ChunkData c)
|
||||
{
|
||||
|
||||
for(int i = 0; i < w; i++)
|
||||
{
|
||||
for(int j = 0; j < h; j++)
|
||||
{
|
||||
for(int k = 0; k < d; k++)
|
||||
{
|
||||
BlockData n = getBlockData(i, j, k);
|
||||
|
||||
if(n == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
c.setBlock(i, j, k, n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,61 +0,0 @@
|
||||
package com.volmit.iris.gen.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;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +1,23 @@
|
||||
package com.volmit.iris.gen.atomics;
|
||||
package com.volmit.iris.gen.v2.scaffold;
|
||||
|
||||
import org.bouncycastle.util.Arrays;
|
||||
|
||||
import com.volmit.iris.Iris;
|
||||
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>
|
||||
public class ArrayHunk<T> implements Hunk<T>
|
||||
{
|
||||
protected final int w;
|
||||
protected final int h;
|
||||
protected final int d;
|
||||
protected final T[] data;
|
||||
private final int w;
|
||||
private final int h;
|
||||
private final int d;
|
||||
private final T[] data;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Hunk(int w, int h, int d)
|
||||
public ArrayHunk(int w, int h, int d)
|
||||
{
|
||||
if(w * h * d < 0)
|
||||
{
|
||||
Iris.error(w + " " + h + " " + d + " is not valid!");
|
||||
throw new RuntimeException("Unsupported size " + w + " " + h + " " + d);
|
||||
}
|
||||
|
||||
this.w = w;
|
||||
@ -49,9 +44,10 @@ public class Hunk<T>
|
||||
* 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)
|
||||
@Override
|
||||
public ArrayHunk<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);
|
||||
ArrayHunk<T> h = new ArrayHunk<T>(x2 - x1, y2 - y1, z2 - z1);
|
||||
|
||||
for(int i = x1; i < x2; i++)
|
||||
{
|
||||
@ -79,7 +75,8 @@ public class Hunk<T>
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
*/
|
||||
public void insert(int offX, int offY, int offZ, Hunk<T> hunk)
|
||||
@Override
|
||||
public void insert(int offX, int offY, int offZ, ArrayHunk<T> hunk)
|
||||
{
|
||||
insert(offX, offY, offZ, hunk, false);
|
||||
}
|
||||
@ -90,7 +87,8 @@ public class Hunk<T>
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
*/
|
||||
public void insert(Hunk<T> hunk)
|
||||
@Override
|
||||
public void insert(ArrayHunk<T> hunk)
|
||||
{
|
||||
insert(0, 0, 0, hunk, false);
|
||||
}
|
||||
@ -103,7 +101,8 @@ public class Hunk<T>
|
||||
* @param inverted
|
||||
* invert the inserted hunk or not
|
||||
*/
|
||||
public void insert(Hunk<T> hunk, boolean inverted)
|
||||
@Override
|
||||
public void insert(ArrayHunk<T> hunk, boolean inverted)
|
||||
{
|
||||
insert(0, 0, 0, hunk, inverted);
|
||||
}
|
||||
@ -123,7 +122,8 @@ public class Hunk<T>
|
||||
* @param invertY
|
||||
* should the inserted hunk be inverted
|
||||
*/
|
||||
public void insert(int offX, int offY, int offZ, Hunk<T> hunk, boolean invertY)
|
||||
@Override
|
||||
public void insert(int offX, int offY, int offZ, ArrayHunk<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)
|
||||
{
|
||||
@ -142,14 +142,25 @@ public class Hunk<T>
|
||||
}
|
||||
}
|
||||
|
||||
public void set(int x, int z, int y1, int y2, T t)
|
||||
{
|
||||
for(int i = y1; i <= y2; i++)
|
||||
{
|
||||
set(x, i, z, t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a region
|
||||
*
|
||||
* @param x1
|
||||
* inclusive 1st x
|
||||
* @param y1
|
||||
* inclusive 1st y
|
||||
* @param z1
|
||||
* inclusive 1st z
|
||||
* @param x2
|
||||
* inclusive 2nd x
|
||||
* @param y2
|
||||
* inclusive 2nd y
|
||||
* @param z2
|
||||
* inclusive 2nd z
|
||||
* @param t
|
||||
* the value to set
|
||||
*/
|
||||
@Override
|
||||
public void set(int x1, int y1, int z1, int x2, int y2, int z2, T t)
|
||||
{
|
||||
for(int i = x1; i <= x2; i++)
|
||||
@ -164,41 +175,58 @@ public class Hunk<T>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a value at the given position
|
||||
*
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @param t
|
||||
* the value
|
||||
*/
|
||||
@Override
|
||||
public void set(int x, int y, int z, T t)
|
||||
{
|
||||
data[index(x, y, z)] = t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a value at the given position
|
||||
*
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @return the value or null
|
||||
*/
|
||||
@Override
|
||||
public T get(int x, int y, int z)
|
||||
{
|
||||
return data[index(x, y, z)];
|
||||
}
|
||||
|
||||
public T get(int x, int y, int z, T oob)
|
||||
{
|
||||
if(x >= w || y >= h || z >= d)
|
||||
{
|
||||
return oob;
|
||||
}
|
||||
|
||||
return data[index(x, y, z)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value to the closest valid position
|
||||
*
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @return the value closest to the border of the hunk
|
||||
*/
|
||||
@Override
|
||||
public T getClosest(int x, int y, int z)
|
||||
{
|
||||
return data[index(x >= w ? w - 1 : x, y >= h ? h - 1 : y, z >= d ? d - 1 : 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)
|
||||
@ -209,68 +237,29 @@ public class Hunk<T>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(T t)
|
||||
{
|
||||
Arrays.fill(data, t);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> Hunk<T> combined(T defaultNode, Hunk<T>... hunks)
|
||||
public static <T> ArrayHunk<T> combined(ArrayHunk<T>... hunks)
|
||||
{
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
int d = 0;
|
||||
|
||||
for(Hunk<T> i : hunks)
|
||||
for(ArrayHunk<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);
|
||||
ArrayHunk<T> b = new ArrayHunk<T>(w, h, d);
|
||||
|
||||
for(Hunk<T> i : hunks)
|
||||
for(ArrayHunk<T> i : hunks)
|
||||
{
|
||||
b.insert(i);
|
||||
}
|
||||
@ -278,40 +267,21 @@ public class Hunk<T>
|
||||
return b;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T> Hunk<T> combined(Hunk<T>... hunks)
|
||||
@Override
|
||||
public int getWidth()
|
||||
{
|
||||
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());
|
||||
return w;
|
||||
}
|
||||
|
||||
Hunk<T> b = new Hunk<T>(w, h, d);
|
||||
|
||||
for(Hunk<T> i : hunks)
|
||||
@Override
|
||||
public int getDepth()
|
||||
{
|
||||
b.insert(i);
|
||||
return h;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public int highestNonNull(int x, int z)
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
for(int i = h - 1; i >= 0; i--)
|
||||
{
|
||||
if(get(x, i, z) != null)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return d;
|
||||
}
|
||||
}
|
10
src/main/java/com/volmit/iris/gen/v2/scaffold/GenStage.java
Normal file
10
src/main/java/com/volmit/iris/gen/v2/scaffold/GenStage.java
Normal file
@ -0,0 +1,10 @@
|
||||
package com.volmit.iris.gen.v2.scaffold;
|
||||
|
||||
public enum GenStage
|
||||
{
|
||||
NOISE,
|
||||
CARVING,
|
||||
TERRAIN,
|
||||
DECORATION,
|
||||
PARALLAX,
|
||||
}
|
179
src/main/java/com/volmit/iris/gen/v2/scaffold/Hunk.java
Normal file
179
src/main/java/com/volmit/iris/gen/v2/scaffold/Hunk.java
Normal file
@ -0,0 +1,179 @@
|
||||
package com.volmit.iris.gen.v2.scaffold;
|
||||
|
||||
public interface Hunk<T>
|
||||
{
|
||||
/**
|
||||
* @return The X length
|
||||
*/
|
||||
public int getWidth();
|
||||
|
||||
/**
|
||||
* @return The Z length
|
||||
*/
|
||||
public int getDepth();
|
||||
|
||||
/**
|
||||
* @return The Y length
|
||||
*/
|
||||
public int getHeight();
|
||||
|
||||
/**
|
||||
* Create a new view of this same hunk from a section of this hunk.
|
||||
* Modifications are routed to 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> croppedView(int x1, int y1, int z1, int x2, int y2, int z2);
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
default void insert(int offX, int offY, int offZ, Hunk<T> hunk)
|
||||
{
|
||||
insert(0, 0, 0, hunk, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a hunk into this one
|
||||
*
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
*/
|
||||
default void insert(Hunk<T> hunk)
|
||||
{
|
||||
insert(hunk, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a hunk into this one
|
||||
*
|
||||
* @param hunk
|
||||
* the hunk to insert
|
||||
* @param inverted
|
||||
* invert the inserted hunk or not
|
||||
*/
|
||||
default 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);
|
||||
|
||||
/**
|
||||
* Set a region
|
||||
*
|
||||
* @param x1
|
||||
* inclusive 1st x
|
||||
* @param y1
|
||||
* inclusive 1st y
|
||||
* @param z1
|
||||
* inclusive 1st z
|
||||
* @param x2
|
||||
* inclusive 2nd x
|
||||
* @param y2
|
||||
* inclusive 2nd y
|
||||
* @param z2
|
||||
* inclusive 2nd z
|
||||
* @param t
|
||||
* the value to set
|
||||
*/
|
||||
public void set(int x1, int y1, int z1, int x2, int y2, int z2, T t);
|
||||
|
||||
/**
|
||||
* Set a value at the given position
|
||||
*
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @param t
|
||||
* the value
|
||||
*/
|
||||
public void set(int x, int y, int z, T t);
|
||||
|
||||
/**
|
||||
* Get a value at the given position
|
||||
*
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @return the value or null
|
||||
*/
|
||||
public T get(int x, int y, int z);
|
||||
|
||||
/**
|
||||
* Get the value to the closest valid position
|
||||
*
|
||||
* @param x
|
||||
* the x
|
||||
* @param y
|
||||
* the y
|
||||
* @param z
|
||||
* the z
|
||||
* @return the value closest to the border of the hunk
|
||||
*/
|
||||
public T getClosest(int x, int y, int z);
|
||||
|
||||
public void fill(T t);
|
||||
}
|
125
src/main/java/com/volmit/iris/gen/v2/scaffold/HunkView.java
Normal file
125
src/main/java/com/volmit/iris/gen/v2/scaffold/HunkView.java
Normal file
@ -0,0 +1,125 @@
|
||||
package com.volmit.iris.gen.v2.scaffold;
|
||||
|
||||
public class HunkView<T> implements Hunk<T>
|
||||
{
|
||||
private final int w;
|
||||
private final int h;
|
||||
private final int d;
|
||||
private final Hunk<T> src;
|
||||
|
||||
public HunkView(Hunk<T> src)
|
||||
{
|
||||
this(src, src.getWidth(), src.getHeight(), src.getDepth());
|
||||
}
|
||||
|
||||
public HunkView(Hunk<T> src, int w, int h, int d)
|
||||
{
|
||||
this.src = src;
|
||||
this.w = w;
|
||||
this.h = h;
|
||||
this.d = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayHunk<T> crop(int x1, int y1, int z1, int x2, int y2, int z2)
|
||||
{
|
||||
ArrayHunk<T> h = new ArrayHunk<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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(int offX, int offY, int offZ, ArrayHunk<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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x1, int y1, int z1, int x2, int y2, int z2, T t)
|
||||
{
|
||||
if(x1 >= w || y1 >= h || z1 >= d || x2 >= w || y2 >= h || z2 >= d)
|
||||
{
|
||||
throw new RuntimeException(x1 + "-" + x2 + " " + y1 + "-" + y2 + " " + z1 + "-" + z2 + " is out of the bounds 0,0,0 - " + (w - 1) + "," + (h - 1) + "," + (d - 1));
|
||||
}
|
||||
|
||||
src.set(x1, y1, z1, x2, y2, z2, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int x, int y, int z, T t)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
src.set(x, y, z, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T get(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 src.get(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getClosest(int x, int y, int z)
|
||||
{
|
||||
return src.get(x >= w ? w - 1 : x, y >= h ? h - 1 : y, z >= d ? d - 1 : z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(T t)
|
||||
{
|
||||
set(0, 0, 0, w - 1, h - 1, d - 1, t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth()
|
||||
{
|
||||
return w;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDepth()
|
||||
{
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight()
|
||||
{
|
||||
return h;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user