mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-04-10 17:56:08 +00:00
Tweaks
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package com.volmit.iris.generator;
|
||||
|
||||
public class IrisTerrainProvider
|
||||
{
|
||||
|
||||
}
|
||||
218
src/main/java/com/volmit/iris/generator/atomics/Hunk.java
Normal file
218
src/main/java/com/volmit/iris/generator/atomics/Hunk.java
Normal file
@@ -0,0 +1,218 @@
|
||||
package com.volmit.iris.generator.atomics;
|
||||
|
||||
import org.bouncycastle.util.Arrays;
|
||||
|
||||
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 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(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;
|
||||
}
|
||||
}
|
||||
204
src/main/java/com/volmit/iris/generator/atomics/TerrainHunk.java
Normal file
204
src/main/java/com/volmit/iris/generator/atomics/TerrainHunk.java
Normal file
@@ -0,0 +1,204 @@
|
||||
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;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class TerrainHunk extends Hunk<TerrainNode> implements BiomeGrid, ChunkData
|
||||
{
|
||||
public TerrainHunk(int w, int h, int d)
|
||||
{
|
||||
super(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.STONE.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);
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static TerrainHunk combined(TerrainNode defaultNode, TerrainHunk... hunks)
|
||||
{
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
int d = 0;
|
||||
|
||||
for(TerrainHunk i : hunks)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static TerrainHunk combined(TerrainHunk... hunks)
|
||||
{
|
||||
int w = 0;
|
||||
int h = 0;
|
||||
int d = 0;
|
||||
|
||||
for(TerrainHunk i : hunks)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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() + Byte.MIN_VALUE), (short) (paletteOf(block) + Short.MIN_VALUE));
|
||||
}
|
||||
|
||||
public TerrainNode setBlockData(BlockData block)
|
||||
{
|
||||
return new TerrainNode(biome, (short) (paletteOf(block) + Short.MIN_VALUE));
|
||||
}
|
||||
|
||||
public TerrainNode setBiome(Biome biome)
|
||||
{
|
||||
return new TerrainNode((byte) (biome.ordinal() + Byte.MIN_VALUE), 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.volmit.iris.generator.scaffold;
|
||||
|
||||
import com.volmit.iris.generator.atomics.TerrainHunk;
|
||||
|
||||
public class IrisTerrainStream implements TerrainStream
|
||||
{
|
||||
@Override
|
||||
public TerrainHunk generate(int x1, int z1, int x2, int z2)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerrainHunk generate(int x, int z)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.volmit.iris.generator.scaffold;
|
||||
|
||||
import com.volmit.iris.generator.atomics.TerrainHunk;
|
||||
|
||||
public interface TerrainStream
|
||||
{
|
||||
public TerrainHunk generate(int x1, int z1, int x2, int z2);
|
||||
|
||||
public TerrainHunk generate(int x, int z);
|
||||
}
|
||||
Reference in New Issue
Block a user