Hunky Stuff...

This commit is contained in:
Daniel Mills 2020-10-24 00:29:31 -04:00
parent e841bfad68
commit 1a0475433c
6 changed files with 293 additions and 20 deletions

View File

@ -26,6 +26,12 @@ public class ArrayHunk<T> implements Hunk<T>
data = (T[]) new Object[w * h * d];
}
@Override
public Hunk<T> croppedView(int x1, int y1, int z1, int x2, int y2, int z2)
{
return new HunkView<T>(this, x2 - x1, y2 - y1, z2 - z1, x1, y1, z1);
}
/**
* Create a new hunk from a section of this hunk.
*
@ -76,7 +82,7 @@ public class ArrayHunk<T> implements Hunk<T>
* the hunk to insert
*/
@Override
public void insert(int offX, int offY, int offZ, ArrayHunk<T> hunk)
public void insert(int offX, int offY, int offZ, Hunk<T> hunk)
{
insert(offX, offY, offZ, hunk, false);
}
@ -88,7 +94,7 @@ public class ArrayHunk<T> implements Hunk<T>
* the hunk to insert
*/
@Override
public void insert(ArrayHunk<T> hunk)
public void insert(Hunk<T> hunk)
{
insert(0, 0, 0, hunk, false);
}
@ -102,7 +108,7 @@ public class ArrayHunk<T> implements Hunk<T>
* invert the inserted hunk or not
*/
@Override
public void insert(ArrayHunk<T> hunk, boolean inverted)
public void insert(Hunk<T> hunk, boolean inverted)
{
insert(0, 0, 0, hunk, inverted);
}
@ -123,18 +129,18 @@ public class ArrayHunk<T> implements Hunk<T>
* should the inserted hunk be inverted
*/
@Override
public void insert(int offX, int offY, int offZ, ArrayHunk<T> hunk, boolean invertY)
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)
if(offX + (hunk.getWidth() - 1) >= w || offY + (hunk.getHeight() - 1) >= h || offZ + (hunk.getDepth() - 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);
throw new RuntimeException("Cannot insert hunk " + hunk.getWidth() + "," + hunk.getHeight() + "," + hunk.getDepth() + " into Hunk " + w + "," + h + "," + d + " with offset " + offZ + "," + offY + "," + offZ);
}
for(int i = offX; i < offX + hunk.getW(); i++)
for(int i = offX; i < offX + hunk.getWidth(); i++)
{
for(int j = offY; j < offY + hunk.getH(); j++)
for(int j = offY; j < offY + hunk.getHeight(); j++)
{
for(int k = offZ; k < offZ + hunk.getD(); k++)
for(int k = offZ; k < offZ + hunk.getDepth(); k++)
{
set(i, j, k, hunk.get(i - offX, j - offY, k - offZ));
}
@ -284,4 +290,34 @@ public class ArrayHunk<T> implements Hunk<T>
{
return d;
}
@Override
public Hunk<T> getFace(HunkFace f)
{
switch(f)
{
case BOTTOM:
return croppedView(0, 0, 0, getWidth() - 1, 0, getDepth() - 1);
case EAST:
return croppedView(getWidth() - 1, 0, 0, getWidth() - 1, getHeight() - 1, getDepth() - 1);
case NORTH:
return croppedView(0, 0, 0, getWidth() - 1, getHeight() - 1, 0);
case SOUTH:
return croppedView(0, 0, 0, 0, getHeight() - 1, getDepth() - 1);
case TOP:
return croppedView(0, getHeight() - 1, 0, getWidth() - 1, getHeight() - 1, getDepth() - 1);
case WEST:
return croppedView(0, 0, getDepth() - 1, getWidth() - 1, getHeight() - 1, getDepth() - 1);
default:
break;
}
return null;
}
@Override
public Hunk<T> getSource()
{
return null;
}
}

View File

@ -0,0 +1,152 @@
package com.volmit.iris.gen.v2.scaffold;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.ChunkData;
public class ChunkDataHunkView implements Hunk<BlockData>
{
private final ChunkData chunk;
public ChunkDataHunkView(ChunkData chunk)
{
this.chunk = chunk;
}
@Override
public int getWidth()
{
return 16;
}
@Override
public int getDepth()
{
return 16;
}
@Override
public int getHeight()
{
return chunk.getMaxHeight();
}
@Override
public Hunk<BlockData> croppedView(int x1, int y1, int z1, int x2, int y2, int z2)
{
return new HunkView<BlockData>(this, x2 - x1, y2 - y1, z2 - z1, x1, y1, z1);
}
@Override
public ArrayHunk<BlockData> crop(int x1, int y1, int z1, int x2, int y2, int z2)
{
ArrayHunk<BlockData> h = new ArrayHunk<BlockData>(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, Hunk<BlockData> hunk, boolean invertY)
{
if(offX + (hunk.getWidth() - 1) >= getWidth() || offY + (hunk.getHeight() - 1) >= getHeight() || offZ + (hunk.getDepth() - 1) >= getDepth() || offX < 0 || offY < 0 || offZ < 0)
{
throw new RuntimeException("Cannot insert hunk " + hunk.getWidth() + "," + hunk.getHeight() + "," + hunk.getDepth() + " into Hunk " + getWidth() + "," + getHeight() + "," + getDepth() + " with offset " + offZ + "," + offY + "," + offZ);
}
for(int i = offX; i < offX + hunk.getWidth(); i++)
{
for(int j = offY; j < offY + hunk.getHeight(); j++)
{
for(int k = offZ; k < offZ + hunk.getDepth(); 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, BlockData t)
{
if(x1 >= getWidth() || y1 >= getHeight() || z1 >= getDepth() || x2 >= getWidth() || y2 >= getHeight() || z2 >= getDepth())
{
throw new RuntimeException(x1 + "-" + x2 + " " + y1 + "-" + y2 + " " + z1 + "-" + z2 + " is out of the bounds 0,0,0 - " + (getWidth() - 1) + "," + (getHeight() - 1) + "," + (getDepth() - 1));
}
chunk.setRegion(x1, y1, z1, x2, y2, z2, t);
}
@Override
public void set(int x, int y, int z, BlockData t)
{
if(x >= getWidth() || y >= getHeight() || z >= getDepth())
{
throw new RuntimeException(x + " " + y + " " + z + " is out of the bounds 0,0,0 - " + (getWidth() - 1) + "," + (getHeight() - 1) + "," + (getDepth() - 1));
}
chunk.setBlock(x, y, z, t);
}
@Override
public BlockData get(int x, int y, int z)
{
if(x >= getWidth() || y >= getHeight() || z >= getDepth())
{
throw new RuntimeException(x + " " + y + " " + z + " is out of the bounds 0,0,0 - " + (getWidth() - 1) + "," + (getHeight() - 1) + "," + (getDepth() - 1));
}
return chunk.getBlockData(x, y, z);
}
@Override
public BlockData getClosest(int x, int y, int z)
{
return chunk.getBlockData(x >= getWidth() ? getWidth() + 1 : x, y >= getHeight() ? getHeight() - 1 : y, z >= getDepth() ? getDepth() - 1 : z);
}
@Override
public void fill(BlockData t)
{
set(0, 0, 0, getWidth(), getHeight(), getDepth(), t);
}
@Override
public Hunk<BlockData> getFace(HunkFace f)
{
switch(f)
{
case BOTTOM:
return croppedView(0, 0, 0, getWidth() - 1, 0, getDepth() - 1);
case EAST:
return croppedView(getWidth() - 1, 0, 0, getWidth() - 1, getHeight() - 1, getDepth() - 1);
case NORTH:
return croppedView(0, 0, 0, getWidth() - 1, getHeight() - 1, 0);
case SOUTH:
return croppedView(0, 0, 0, 0, getHeight() - 1, getDepth() - 1);
case TOP:
return croppedView(0, getHeight() - 1, 0, getWidth() - 1, getHeight() - 1, getDepth() - 1);
case WEST:
return croppedView(0, 0, getDepth() - 1, getWidth() - 1, getHeight() - 1, getDepth() - 1);
default:
break;
}
return null;
}
@Override
public Hunk<BlockData> getSource()
{
return null;
}
}

View File

@ -1,7 +1,27 @@
package com.volmit.iris.gen.v2.scaffold;
import org.bukkit.block.data.BlockData;
import org.bukkit.generator.ChunkGenerator.ChunkData;
public interface Hunk<T>
{
public static <T> Hunk<T> create(int w, int h, int d)
{
return new ArrayHunk<>(w, h, d);
}
public static <T> Hunk<T> view(Hunk<T> src)
{
return new HunkView<T>(src);
}
public static Hunk<BlockData> view(ChunkData src)
{
return new ChunkDataHunkView(src);
}
public Hunk<T> getSource();
/**
* @return The X length
*/
@ -17,6 +37,8 @@ public interface Hunk<T>
*/
public int getHeight();
public Hunk<T> getFace(HunkFace f);
/**
* Create a new view of this same hunk from a section of this hunk.
* Modifications are routed to this hunk!
@ -33,7 +55,7 @@ public interface Hunk<T>
* The max y (exclusive)
* @param z2
* The max z (exclusive)
* @return the new hunk (x2-x1, y2-y1, z2-z1)
* @return the cropped view of this hunk (x2-x1, y2-y1, z2-z1)
*/
public Hunk<T> croppedView(int x1, int y1, int z1, int x2, int y2, int z2);

View File

@ -0,0 +1,11 @@
package com.volmit.iris.gen.v2.scaffold;
public enum HunkFace
{
TOP,
BOTTOM,
EAST,
WEST,
NORTH,
SOUTH;
}

View File

@ -2,6 +2,9 @@ package com.volmit.iris.gen.v2.scaffold;
public class HunkView<T> implements Hunk<T>
{
private final int ox;
private final int oy;
private final int oz;
private final int w;
private final int h;
private final int d;
@ -13,11 +16,25 @@ public class HunkView<T> implements Hunk<T>
}
public HunkView(Hunk<T> src, int w, int h, int d)
{
this(src, w, h, d, 0, 0, 0);
}
public HunkView(Hunk<T> src, int w, int h, int d, int ox, int oy, int oz)
{
this.src = src;
this.w = w;
this.h = h;
this.d = d;
this.ox = ox;
this.oy = oy;
this.oz = oz;
}
@Override
public Hunk<T> croppedView(int x1, int y1, int z1, int x2, int y2, int z2)
{
return new HunkView<T>(this, x2 - x1, y2 - y1, z2 - z1, x1 + ox, y1 + oy, z1 + oz);
}
@Override
@ -40,18 +57,18 @@ public class HunkView<T> implements Hunk<T>
}
@Override
public void insert(int offX, int offY, int offZ, ArrayHunk<T> hunk, boolean invertY)
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)
if(offX + (hunk.getWidth() - 1) >= w || offY + (hunk.getHeight() - 1) >= h || offZ + (hunk.getDepth() - 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);
throw new RuntimeException("Cannot insert hunk " + hunk.getWidth() + "," + hunk.getHeight() + "," + hunk.getDepth() + " into Hunk " + w + "," + h + "," + d + " with offset " + offZ + "," + offY + "," + offZ);
}
for(int i = offX; i < offX + hunk.getW(); i++)
for(int i = offX; i < offX + hunk.getWidth(); i++)
{
for(int j = offY; j < offY + hunk.getH(); j++)
for(int j = offY; j < offY + hunk.getHeight(); j++)
{
for(int k = offZ; k < offZ + hunk.getD(); k++)
for(int k = offZ; k < offZ + hunk.getDepth(); k++)
{
set(i, j, k, hunk.get(i - offX, j - offY, k - offZ));
}
@ -78,7 +95,7 @@ public class HunkView<T> implements Hunk<T>
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);
src.set(x + ox, y + oy, z + oz, t);
}
@Override
@ -89,19 +106,19 @@ public class HunkView<T> implements Hunk<T>
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);
return src.get(x + ox, y + oy, z + oz);
}
@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);
return src.get(x >= w ? w + ox - 1 : x + ox, y >= h ? h + oy - 1 : y + oy, z >= d ? d + oz - 1 : z + oz);
}
@Override
public void fill(T t)
{
set(0, 0, 0, w - 1, h - 1, d - 1, t);
set(0 + ox, 0 + oy, 0 + oz, w - 1 + ox, h - 1 + oy, d - 1 + oz, t);
}
@Override
@ -122,4 +139,33 @@ public class HunkView<T> implements Hunk<T>
return h;
}
@Override
public Hunk<T> getFace(HunkFace f)
{
switch(f)
{
case BOTTOM:
return croppedView(0, 0, 0, getWidth() - 1, 0, getDepth() - 1);
case EAST:
return croppedView(getWidth() - 1, 0, 0, getWidth() - 1, getHeight() - 1, getDepth() - 1);
case NORTH:
return croppedView(0, 0, 0, getWidth() - 1, getHeight() - 1, 0);
case SOUTH:
return croppedView(0, 0, 0, 0, getHeight() - 1, getDepth() - 1);
case TOP:
return croppedView(0, getHeight() - 1, 0, getWidth() - 1, getHeight() - 1, getDepth() - 1);
case WEST:
return croppedView(0, 0, getDepth() - 1, getWidth() - 1, getHeight() - 1, getDepth() - 1);
default:
break;
}
return null;
}
@Override
public Hunk<T> getSource()
{
return src;
}
}

View File

@ -0,0 +1,6 @@
package com.volmit.iris.gen.v2.scaffold;
public interface TerrainGenerator
{
}