diff --git a/src/main/java/com/volmit/iris/util/function/Supplier3R.java b/src/main/java/com/volmit/iris/util/function/Supplier3R.java new file mode 100644 index 000000000..82997a4ad --- /dev/null +++ b/src/main/java/com/volmit/iris/util/function/Supplier3R.java @@ -0,0 +1,23 @@ +/* + * Iris is a World Generator for Minecraft Bukkit Servers + * Copyright (c) 2021 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.volmit.iris.util.function; + +public interface Supplier3R { + TTTT get(T t, TT tt, TTT ttt); +} diff --git a/src/main/java/com/volmit/iris/util/hunk/Hunk.java b/src/main/java/com/volmit/iris/util/hunk/Hunk.java index f868e5839..b87d3c4ed 100644 --- a/src/main/java/com/volmit/iris/util/hunk/Hunk.java +++ b/src/main/java/com/volmit/iris/util/hunk/Hunk.java @@ -19,6 +19,7 @@ package com.volmit.iris.util.hunk; import com.volmit.iris.Iris; +import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.util.collection.KList; import com.volmit.iris.util.function.*; import com.volmit.iris.util.hunk.io.HunkIOAdapter; @@ -244,18 +245,6 @@ public interface Hunk { return new InvertedHunkView(this); } - default Hunk rotateX(double degrees) { - return new RotatedXHunkView(this, degrees); - } - - default Hunk rotateY(double degrees) { - return new RotatedYHunkView(this, degrees); - } - - default Hunk rotateZ(double degrees) { - return new RotatedZHunkView(this, degrees); - } - default int getMaximumDimension() { return Math.max(getWidth(), Math.max(getHeight(), getDepth())); } @@ -1284,7 +1273,34 @@ public interface Hunk { return t; } - default Hunk rotate(double x, double y, double z) + static IrisPosition rotatedBounding(int w, int h, int d, double x, double y, double z) + { + int[] iii = {0,0,0}; + int[] aaa = {w,h,d}; + int[] aai = {w,h,0}; + int[] iaa = {0,h,d}; + int[] aia = {w,0,d}; + int[] iai = {0,h,0}; + int[] iia = {0,0,d}; + int[] aii = {w,0,0}; + rotate(x,y,z,iii); + rotate(x,y,z,aaa); + rotate(x,y,z,aai); + rotate(x,y,z,iaa); + rotate(x,y,z,aia); + rotate(x,y,z,iai); + rotate(x,y,z,iia); + rotate(x,y,z,aii); + int maxX = max(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]); + int minX = min(iii[0], aaa[0], aai[0], iaa[0], aia[0], iai[0], iia[0], aii[0]); + int maxY = max(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]); + int minY = min(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]); + int maxZ = max(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); + int minZ = min(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); + return new IrisPosition(maxX - minX, maxY - minY, maxZ - minZ); + } + + default Hunk rotate(double x, double y, double z, Supplier3R> builder) { int w = getWidth(); int h = getHeight(); @@ -1314,7 +1330,7 @@ public interface Hunk { int minY = min(iii[1], aaa[1], aai[1], iaa[1], aia[1], iai[1], iia[1], aii[1]); int maxZ = max(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); int minZ = min(iii[2], aaa[2], aai[2], iaa[2], aia[2], iai[2], iia[2], aii[2]); - Hunk r = Hunk.newArrayHunk(maxX - minX, maxY - minY, maxZ - minZ); + Hunk r = builder.get(maxX - minX, maxY - minY, maxZ - minZ); int[] cr = {(maxX - minX)/2,(maxY - minY)/2,(maxZ - minZ)/2}; for(i = 0; i < w; i++) diff --git a/src/main/java/com/volmit/iris/util/matter/Matter.java b/src/main/java/com/volmit/iris/util/matter/Matter.java index dc4ebb29e..8ca26d34d 100644 --- a/src/main/java/com/volmit/iris/util/matter/Matter.java +++ b/src/main/java/com/volmit/iris/util/matter/Matter.java @@ -18,7 +18,9 @@ package com.volmit.iris.util.matter; +import com.volmit.iris.engine.object.basic.IrisPosition; import com.volmit.iris.util.data.Varint; +import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.math.BlockPosition; import java.io.*; @@ -177,6 +179,28 @@ public interface Matter { return (MatterSlice) getSlice(c); } + /** + * Rotate a matter object into a new object + * @param x the x rotation (degrees) + * @param y the y rotation (degrees) + * @param z the z rotation (degrees) + * @return the new rotated matter object + */ + default Matter rotate(double x, double y, double z) + { + IrisPosition rs = Hunk.rotatedBounding(getWidth(), getHeight(), getDepth(), x, y, z); + Matter n = new IrisMatter(rs.getX(), rs.getY(), rs.getZ()); + n.getHeader().setAuthor(getHeader().getAuthor()); + n.getHeader().setCreatedAt(getHeader().getCreatedAt()); + + for(Class i : getSliceTypes()) + { + getSlice(i).rotateSliceInto(n, x, y, z); + } + + return n; + } + /** * Check if a slice exists for a given type * diff --git a/src/main/java/com/volmit/iris/util/matter/MatterSlice.java b/src/main/java/com/volmit/iris/util/matter/MatterSlice.java index 24a266017..e1f89b934 100644 --- a/src/main/java/com/volmit/iris/util/matter/MatterSlice.java +++ b/src/main/java/com/volmit/iris/util/matter/MatterSlice.java @@ -24,6 +24,7 @@ import com.volmit.iris.util.hunk.Hunk; import com.volmit.iris.util.hunk.storage.MappedHunk; import org.bukkit.World; import org.bukkit.block.data.BlockData; +import org.objectweb.asm.ClassWriter; import java.io.DataInputStream; import java.io.DataOutputStream; @@ -147,4 +148,9 @@ public interface MatterSlice extends Hunk { setRaw(pos[0], pos[1], pos[2], palette.readNode(din)); } } + + default void rotateSliceInto(Matter n, double x, double y, double z) + { + rotate(x,y,z, (_x, _y, _z) -> n.slice(getType())); + } }