diff --git a/src/main/java/com/volmit/iris/object/IrisAxisRotationClamp.java b/src/main/java/com/volmit/iris/object/IrisAxisRotationClamp.java index 14830b139..c0b3f9a0c 100644 --- a/src/main/java/com/volmit/iris/object/IrisAxisRotationClamp.java +++ b/src/main/java/com/volmit/iris/object/IrisAxisRotationClamp.java @@ -52,6 +52,12 @@ public class IrisAxisRotationClamp @Desc("Iris spins the axis but not freely. For example an interval of 90 would mean 4 possible angles (right angles) degrees. \nSetting this to 0 means totally free rotation.\n\nNote that a lot of structures can have issues with non 90 degree intervals because the minecraft block resolution is so low.") private double interval = 0; + public void minMax(double fd) + { + min = fd; + max = fd; + } + public boolean isUnlimited() { return min == max && min == 0; diff --git a/src/main/java/com/volmit/iris/object/IrisJigsawPiece.java b/src/main/java/com/volmit/iris/object/IrisJigsawPiece.java index 24f5f8cf1..fe2305dbb 100644 --- a/src/main/java/com/volmit/iris/object/IrisJigsawPiece.java +++ b/src/main/java/com/volmit/iris/object/IrisJigsawPiece.java @@ -31,4 +31,16 @@ public class IrisJigsawPiece extends IrisRegistrant @ArrayType(type = IrisJigsawPieceConnector.class, min = 1) @Desc("The connectors this object contains") private KList connectors = new KList<>(); + + public IrisJigsawPieceConnector getConnector(IrisPosition relativePosition) { + for(IrisJigsawPieceConnector i : connectors) + { + if(i.getPosition().equals(relativePosition)) + { + return i; + } + } + + return null; + } } diff --git a/src/main/java/com/volmit/iris/object/IrisObject.java b/src/main/java/com/volmit/iris/object/IrisObject.java index 4d1a1caf9..273b1c68f 100644 --- a/src/main/java/com/volmit/iris/object/IrisObject.java +++ b/src/main/java/com/volmit/iris/object/IrisObject.java @@ -2,6 +2,8 @@ package com.volmit.iris.object; import com.volmit.iris.Iris; import com.volmit.iris.manager.IrisDataManager; +import com.volmit.iris.scaffold.cache.AtomicCache; +import com.volmit.iris.util.AxisAlignedBB; import com.volmit.iris.util.*; import lombok.Data; import lombok.EqualsAndHashCode; @@ -33,6 +35,25 @@ public class IrisObject extends IrisRegistrant private transient BlockVector center; private transient volatile boolean smartBored = false; private transient IrisLock lock = new IrisLock("Preloadcache"); + private transient AtomicCache aabb; + + public AxisAlignedBB getAABB() + { + return aabb.aquire(() -> { + int[] v = new int[]{0,0,0,0,0,0}; + for(BlockVector i : blocks.k()) + { + v[0] = Math.min(v[0], i.getBlockX()); + v[1] = Math.min(v[1], i.getBlockY()); + v[2] = Math.min(v[2], i.getBlockZ()); + v[3] = Math.max(v[3], i.getBlockX()); + v[4] = Math.max(v[4], i.getBlockY()); + v[5] = Math.max(v[5], i.getBlockZ()); + } + + return new AxisAlignedBB(new IrisPosition(v[0], v[1], v[2]), new IrisPosition(v[3], v[4], v[5])); + }); + } public void ensureSmartBored(boolean debug) { @@ -628,13 +649,14 @@ public class IrisObject extends IrisRegistrant return y; } + public IrisObject rotateCopy(IrisObjectRotation rt) { + IrisObject copy = copy(); + copy.rotate(rt, 0, 0, 0); + return copy; + } + public void rotate(IrisObjectRotation r, int spinx, int spiny, int spinz) { - if(shitty) - { - return; - } - KMap v = blocks.copy(); blocks.clear(); @@ -646,11 +668,6 @@ public class IrisObject extends IrisRegistrant public void place(Location at) { - if(shitty) - { - return; - } - for(BlockVector i : blocks.keySet()) { at.clone().add(0, getCenter().getY(), 0).add(i).getBlock().setBlockData(blocks.get(i), false); @@ -659,11 +676,6 @@ public class IrisObject extends IrisRegistrant public void placeCenterY(Location at) { - if(shitty) - { - return; - } - for(BlockVector i : blocks.keySet()) { at.clone().add(getCenter().getX(), getCenter().getY(), getCenter().getZ()).add(i).getBlock().setBlockData(blocks.get(i), false); @@ -672,11 +684,6 @@ public class IrisObject extends IrisRegistrant public void unplaceCenterY(Location at) { - if(shitty) - { - return; - } - for(BlockVector i : blocks.keySet()) { at.clone().add(getCenter().getX(), getCenter().getY(), getCenter().getZ()).add(i).getBlock().setBlockData(Material.AIR.createBlockData(), false); diff --git a/src/main/java/com/volmit/iris/object/IrisPosition.java b/src/main/java/com/volmit/iris/object/IrisPosition.java index d53a38d36..9c0f8d2d5 100644 --- a/src/main/java/com/volmit/iris/object/IrisPosition.java +++ b/src/main/java/com/volmit/iris/object/IrisPosition.java @@ -25,4 +25,8 @@ public class IrisPosition @DontObfuscate @Desc("The z position") private int z = 0; + + public IrisPosition add(IrisPosition relativePosition) { + return new IrisPosition(relativePosition.x+x, relativePosition.y+y, relativePosition.z + z); + } } diff --git a/src/main/java/com/volmit/iris/scaffold/jigsaw/IrisRotationSet.java b/src/main/java/com/volmit/iris/scaffold/jigsaw/IrisRotationSet.java new file mode 100644 index 000000000..92f15dc5c --- /dev/null +++ b/src/main/java/com/volmit/iris/scaffold/jigsaw/IrisRotationSet.java @@ -0,0 +1,47 @@ +package com.volmit.iris.scaffold.jigsaw; + +import com.volmit.iris.object.IrisAxisRotationClamp; +import com.volmit.iris.object.IrisObject; +import com.volmit.iris.object.IrisObjectRotation; +import com.volmit.iris.util.KMap; +import lombok.Data; + +@Data +public class IrisRotationSet +{ + private KMap cache; + private IrisObject base; + + public IrisRotationSet(IrisObject base) + { + this.base = base; + this.cache = new KMap<>(); + } + + public IrisObject getObject(double x, double y, double z) + { + IrisObjectRotation rt = new IrisObjectRotation(); + rt.setEnabled(true); + IrisAxisRotationClamp rtx = new IrisAxisRotationClamp(); + rtx.setEnabled(x != 0); + rtx.setMax(x); + rt.setXAxis(rtx); + IrisAxisRotationClamp rty = new IrisAxisRotationClamp(); + rty.setEnabled(y != 0); + rty.setMax(y); + rt.setXAxis(rty); + IrisAxisRotationClamp rtz = new IrisAxisRotationClamp(); + rtz.setEnabled(z != 0); + rtz.setMax(z); + rt.setXAxis(rtz); + + if(cache.containsKey(rt)) + { + return cache.get(rt); + } + + IrisObject rotated = base.rotateCopy(rt); + cache.put(rt, rotated); + return rotated; + } +} diff --git a/src/main/java/com/volmit/iris/util/AlignedPoint.java b/src/main/java/com/volmit/iris/util/AlignedPoint.java new file mode 100644 index 000000000..ce9b86fd3 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/AlignedPoint.java @@ -0,0 +1,46 @@ +package com.volmit.iris.util; + +public class AlignedPoint +{ + private double x; + private double y; + private double z; + + public AlignedPoint(double x, double y, double z) + { + this.x = x; + this.y = y; + this.z = z; + } + + public double getX() + { + return x; + } + + public void setX(double x) + { + this.x = x; + } + + public double getY() + { + return y; + } + + public void setY(double y) + { + this.y = y; + } + + public double getZ() + { + return z; + } + + public void setZ(double z) + { + this.z = z; + } + +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/AxisAlignedBB.java b/src/main/java/com/volmit/iris/util/AxisAlignedBB.java new file mode 100644 index 000000000..18639dba9 --- /dev/null +++ b/src/main/java/com/volmit/iris/util/AxisAlignedBB.java @@ -0,0 +1,68 @@ +package com.volmit.iris.util; + +import com.volmit.iris.object.IrisPosition; + +public class AxisAlignedBB +{ + private double xa; + private double xb; + private double ya; + private double yb; + private double za; + private double zb; + + public AxisAlignedBB(double xa, double xb, double ya, double yb, double za, double zb) + { + this.xa = xa; + this.xb = xb; + this.ya = ya; + this.yb = yb; + this.za = za; + this.zb = zb; + } + + public AxisAlignedBB shifted(IrisPosition p) + { + return shifted(p.getX(), p.getY(), p.getZ()); + } + + public AxisAlignedBB shifted(double x, double y, double z) + { + return new AxisAlignedBB(min().add(new IrisPosition((int)x,(int)y,(int)z)), max().add(new IrisPosition((int)x,(int)y,(int)z))); + } + + public AxisAlignedBB(AlignedPoint a, AlignedPoint b) + { + this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ()); + } + + public AxisAlignedBB(IrisPosition a, IrisPosition b) + { + this(a.getX(), b.getX(), a.getY(), b.getY(), a.getZ(), b.getZ()); + } + + public boolean contains(AlignedPoint p) + { + return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb; + } + + public boolean contains(IrisPosition p) + { + return p.getX() >= xa && p.getX() <= xb && p.getY() >= ya && p.getZ() <= yb && p.getZ() >= za && p.getZ() <= zb; + } + + public boolean intersects(AxisAlignedBB s) + { + return this.xb >= s.xa && this.yb >= s.ya && this.zb >= s.za && s.xb >= this.xa && s.yb >= this.ya && s.zb >= this.za; + } + + public IrisPosition max() + { + return new IrisPosition((int)xb, (int)yb, (int)zb); + } + + public IrisPosition min() + { + return new IrisPosition((int)xa, (int)ya, (int)za); + } +} \ No newline at end of file diff --git a/src/main/java/com/volmit/iris/util/KList.java b/src/main/java/com/volmit/iris/util/KList.java index bdddefc83..b2c1b688a 100644 --- a/src/main/java/com/volmit/iris/util/KList.java +++ b/src/main/java/com/volmit/iris/util/KList.java @@ -4,6 +4,7 @@ import com.google.common.util.concurrent.AtomicDoubleArray; import java.util.*; import java.util.function.Function; +import java.util.function.Predicate; public class KList extends ArrayList implements List { @@ -213,6 +214,13 @@ public class KList extends ArrayList implements List return this; } + + public KList shuffle(Random rng) + { + Collections.shuffle(this, rng); + return this; + } + /** * Sort the list (based on toString comparison) * @@ -314,6 +322,19 @@ public class KList extends ArrayList implements List return v; } + public KList removeWhere(Predicate t) + { + for(T i : copy()) + { + if(t.test(i)) + { + remove(i); + } + } + + return this; + } + /** * Adds T to the list, ignores if null * @@ -730,4 +751,10 @@ public class KList extends ArrayList implements List } } } + + public KList shuffleCopy(Random rng) { + KList t = copy(); + t.shuffle(rng); + return t; + } } diff --git a/src/main/java/com/volmit/iris/util/RNG.java b/src/main/java/com/volmit/iris/util/RNG.java index 5917f9c6b..2724deb1b 100644 --- a/src/main/java/com/volmit/iris/util/RNG.java +++ b/src/main/java/com/volmit/iris/util/RNG.java @@ -1,6 +1,7 @@ package com.volmit.iris.util; import java.nio.charset.StandardCharsets; +import java.util.List; import java.util.Random; import java.util.UUID; @@ -177,4 +178,18 @@ public class RNG extends Random public boolean chance(double chance) { return chance >= nextDouble(); } + + public T pick(List pieces) { + if(pieces.isEmpty()) + { + return null; + } + + if(pieces.size() == 1) + { + return pieces.get(0); + } + + return pieces.get(nextInt(pieces.size())); + } }