diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/ArrayHunk.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/ArrayHunk.java index 082202ecf..450611d74 100644 --- a/src/main/java/com/volmit/iris/gen/v2/scaffold/ArrayHunk.java +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/ArrayHunk.java @@ -26,6 +26,12 @@ public class ArrayHunk implements Hunk data = (T[]) new Object[w * h * d]; } + @Override + public Hunk croppedView(int x1, int y1, int z1, int x2, int y2, int z2) + { + return new HunkView(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 implements Hunk * the hunk to insert */ @Override - public void insert(int offX, int offY, int offZ, ArrayHunk hunk) + public void insert(int offX, int offY, int offZ, Hunk hunk) { insert(offX, offY, offZ, hunk, false); } @@ -88,7 +94,7 @@ public class ArrayHunk implements Hunk * the hunk to insert */ @Override - public void insert(ArrayHunk hunk) + public void insert(Hunk hunk) { insert(0, 0, 0, hunk, false); } @@ -102,7 +108,7 @@ public class ArrayHunk implements Hunk * invert the inserted hunk or not */ @Override - public void insert(ArrayHunk hunk, boolean inverted) + public void insert(Hunk hunk, boolean inverted) { insert(0, 0, 0, hunk, inverted); } @@ -123,18 +129,18 @@ public class ArrayHunk implements Hunk * should the inserted hunk be inverted */ @Override - public void insert(int offX, int offY, int offZ, ArrayHunk hunk, boolean invertY) + public void insert(int offX, int offY, int offZ, Hunk 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 implements Hunk { return d; } + + @Override + public Hunk 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 getSource() + { + return null; + } } diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/ChunkDataHunkView.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/ChunkDataHunkView.java new file mode 100644 index 000000000..22c317b69 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/ChunkDataHunkView.java @@ -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 +{ + 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 croppedView(int x1, int y1, int z1, int x2, int y2, int z2) + { + return new HunkView(this, x2 - x1, y2 - y1, z2 - z1, x1, y1, z1); + } + + @Override + public ArrayHunk crop(int x1, int y1, int z1, int x2, int y2, int z2) + { + ArrayHunk h = new ArrayHunk(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 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 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 getSource() + { + return null; + } +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/Hunk.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/Hunk.java index ce9257068..1208f4085 100644 --- a/src/main/java/com/volmit/iris/gen/v2/scaffold/Hunk.java +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/Hunk.java @@ -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 { + public static Hunk create(int w, int h, int d) + { + return new ArrayHunk<>(w, h, d); + } + + public static Hunk view(Hunk src) + { + return new HunkView(src); + } + + public static Hunk view(ChunkData src) + { + return new ChunkDataHunkView(src); + } + + public Hunk getSource(); + /** * @return The X length */ @@ -17,6 +37,8 @@ public interface Hunk */ public int getHeight(); + public Hunk 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 * 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 croppedView(int x1, int y1, int z1, int x2, int y2, int z2); diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/HunkFace.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/HunkFace.java new file mode 100644 index 000000000..14e944913 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/HunkFace.java @@ -0,0 +1,11 @@ +package com.volmit.iris.gen.v2.scaffold; + +public enum HunkFace +{ + TOP, + BOTTOM, + EAST, + WEST, + NORTH, + SOUTH; +} diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/HunkView.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/HunkView.java index a2b06a378..6c596c889 100644 --- a/src/main/java/com/volmit/iris/gen/v2/scaffold/HunkView.java +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/HunkView.java @@ -2,6 +2,9 @@ package com.volmit.iris.gen.v2.scaffold; public class HunkView implements Hunk { + 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 implements Hunk } public HunkView(Hunk src, int w, int h, int d) + { + this(src, w, h, d, 0, 0, 0); + } + + public HunkView(Hunk 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 croppedView(int x1, int y1, int z1, int x2, int y2, int z2) + { + return new HunkView(this, x2 - x1, y2 - y1, z2 - z1, x1 + ox, y1 + oy, z1 + oz); } @Override @@ -40,18 +57,18 @@ public class HunkView implements Hunk } @Override - public void insert(int offX, int offY, int offZ, ArrayHunk hunk, boolean invertY) + public void insert(int offX, int offY, int offZ, Hunk 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 implements Hunk 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 implements Hunk 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 implements Hunk return h; } + @Override + public Hunk 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 getSource() + { + return src; + } } diff --git a/src/main/java/com/volmit/iris/gen/v2/scaffold/TerrainGenerator.java b/src/main/java/com/volmit/iris/gen/v2/scaffold/TerrainGenerator.java new file mode 100644 index 000000000..42d2bc143 --- /dev/null +++ b/src/main/java/com/volmit/iris/gen/v2/scaffold/TerrainGenerator.java @@ -0,0 +1,6 @@ +package com.volmit.iris.gen.v2.scaffold; + +public interface TerrainGenerator +{ + +}