This commit is contained in:
Daniel Mills 2021-01-08 10:12:10 -05:00
parent 3f9288c60f
commit 4b76b592d3
9 changed files with 252 additions and 20 deletions

View File

@ -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;

View File

@ -31,4 +31,16 @@ public class IrisJigsawPiece extends IrisRegistrant
@ArrayType(type = IrisJigsawPieceConnector.class, min = 1)
@Desc("The connectors this object contains")
private KList<IrisJigsawPieceConnector> connectors = new KList<>();
public IrisJigsawPieceConnector getConnector(IrisPosition relativePosition) {
for(IrisJigsawPieceConnector i : connectors)
{
if(i.getPosition().equals(relativePosition))
{
return i;
}
}
return null;
}
}

View File

@ -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<AxisAlignedBB> 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<BlockVector, BlockData> 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);

View File

@ -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);
}
}

View File

@ -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<IrisObjectRotation, IrisObject> 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;
}
}

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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<T> extends ArrayList<T> implements List<T>
{
@ -213,6 +214,13 @@ public class KList<T> extends ArrayList<T> implements List<T>
return this;
}
public KList<T> shuffle(Random rng)
{
Collections.shuffle(this, rng);
return this;
}
/**
* Sort the list (based on toString comparison)
*
@ -314,6 +322,19 @@ public class KList<T> extends ArrayList<T> implements List<T>
return v;
}
public KList<T> removeWhere(Predicate<T> 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<T> extends ArrayList<T> implements List<T>
}
}
}
public KList<T> shuffleCopy(Random rng) {
KList<T> t = copy();
t.shuffle(rng);
return t;
}
}

View File

@ -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> T pick(List<T> pieces) {
if(pieces.isEmpty())
{
return null;
}
if(pieces.size() == 1)
{
return pieces.get(0);
}
return pieces.get(nextInt(pieces.size()));
}
}