mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-05-19 16:10:42 +00:00
fix offset with shrinkwrap
This commit is contained in:
@@ -69,7 +69,7 @@ public class PlannedPiece {
|
|||||||
this.setRotation(rot);
|
this.setRotation(rot);
|
||||||
this.ogObject = data.getObjectLoader().load(piece.getObject());
|
this.ogObject = data.getObjectLoader().load(piece.getObject());
|
||||||
this.object = structure.rotated(piece, rotation);
|
this.object = structure.rotated(piece, rotation);
|
||||||
this.piece = rotation.rotateCopy(piece);
|
this.piece = rotation.rotateCopy(piece, new IrisPosition(object.getShrinkOffset()));
|
||||||
this.piece.setLoadKey(piece.getLoadKey());
|
this.piece.setLoadKey(piece.getLoadKey());
|
||||||
this.object.setLoadKey(piece.getObject());
|
this.object.setLoadKey(piece.getObject());
|
||||||
this.ogObject.setLoadKey(piece.getObject());
|
this.ogObject.setLoadKey(piece.getObject());
|
||||||
|
|||||||
@@ -98,6 +98,8 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private transient Vector3i center;
|
private transient Vector3i center;
|
||||||
|
@Getter
|
||||||
|
private transient Vector3i shrinkOffset;
|
||||||
|
|
||||||
public IrisObject(int w, int h, int d) {
|
public IrisObject(int w, int h, int d) {
|
||||||
blocks = new VectorMap<>();
|
blocks = new VectorMap<>();
|
||||||
@@ -106,6 +108,7 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
this.h = h;
|
this.h = h;
|
||||||
this.d = d;
|
this.d = d;
|
||||||
center = new Vector3i(w / 2, h / 2, d / 2);
|
center = new Vector3i(w / 2, h / 2, d / 2);
|
||||||
|
shrinkOffset = new Vector3i(0, 0, 0);
|
||||||
var lock = new ReentrantReadWriteLock();
|
var lock = new ReentrantReadWriteLock();
|
||||||
readLock = lock.readLock();
|
readLock = lock.readLock();
|
||||||
writeLock = lock.writeLock();
|
writeLock = lock.writeLock();
|
||||||
@@ -504,8 +507,8 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void shrinkwrap() {
|
public void shrinkwrap() {
|
||||||
BlockVector min = new BlockVector();
|
BlockVector min = new BlockVector(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||||
BlockVector max = new BlockVector();
|
BlockVector max = new BlockVector(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
|
||||||
|
|
||||||
for (BlockVector i : blocks.keys()) {
|
for (BlockVector i : blocks.keys()) {
|
||||||
min.setX(Math.min(min.getX(), i.getX()));
|
min.setX(Math.min(min.getX(), i.getX()));
|
||||||
@@ -520,6 +523,31 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
h = max.getBlockY() - min.getBlockY() + 1;
|
h = max.getBlockY() - min.getBlockY() + 1;
|
||||||
d = max.getBlockZ() - min.getBlockZ() + 1;
|
d = max.getBlockZ() - min.getBlockZ() + 1;
|
||||||
center = new Vector3i(w / 2, h / 2, d / 2);
|
center = new Vector3i(w / 2, h / 2, d / 2);
|
||||||
|
|
||||||
|
Vector3i offset = new Vector3i(
|
||||||
|
-center.getBlockX() - min.getBlockX(),
|
||||||
|
-center.getBlockY() - min.getBlockY(),
|
||||||
|
-center.getBlockZ() - min.getBlockZ()
|
||||||
|
);
|
||||||
|
if (offset.getBlockX() == 0 && offset.getBlockY() == 0 && offset.getBlockZ() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
VectorMap<BlockData> b = new VectorMap<>();
|
||||||
|
VectorMap<TileData> s = new VectorMap<>();
|
||||||
|
|
||||||
|
blocks.forEach((vector, data) -> {
|
||||||
|
vector.add(offset);
|
||||||
|
b.put(vector, data);
|
||||||
|
});
|
||||||
|
|
||||||
|
states.forEach((vector, data) -> {
|
||||||
|
vector.add(offset);
|
||||||
|
s.put(vector, data);
|
||||||
|
});
|
||||||
|
|
||||||
|
shrinkOffset = offset;
|
||||||
|
blocks = b;
|
||||||
|
states = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clean() {
|
public void clean() {
|
||||||
@@ -1150,8 +1178,8 @@ public class IrisObject extends IrisRegistrant {
|
|||||||
|
|
||||||
blocks = d;
|
blocks = d;
|
||||||
states = dx;
|
states = dx;
|
||||||
writeLock.unlock();
|
|
||||||
shrinkwrap();
|
shrinkwrap();
|
||||||
|
writeLock.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void place(Location at) {
|
public void place(Location at) {
|
||||||
|
|||||||
@@ -101,15 +101,15 @@ public class IrisObjectRotation {
|
|||||||
return e.rotateCopy(this);
|
return e.rotateCopy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IrisJigsawPiece rotateCopy(IrisJigsawPiece v) {
|
public IrisJigsawPiece rotateCopy(IrisJigsawPiece v, IrisPosition offset) {
|
||||||
IrisJigsawPiece piece = v.copy();
|
IrisJigsawPiece piece = v.copy();
|
||||||
for (IrisJigsawPieceConnector i : piece.getConnectors()) {
|
for (IrisJigsawPieceConnector i : piece.getConnectors()) {
|
||||||
i.setPosition(rotate(i.getPosition()));
|
i.setPosition(rotate(i.getPosition()).add(offset));
|
||||||
i.setDirection(rotate(i.getDirection()));
|
i.setDirection(rotate(i.getDirection()));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var translate = piece.getPlacementOptions().getTranslate();
|
var translate = piece.getPlacementOptions().getTranslate();
|
||||||
var pos = rotate(new IrisPosition(translate.getX(), translate.getY(), translate.getZ()));
|
var pos = rotate(new IrisPosition(translate.getX(), translate.getY(), translate.getZ())).add(offset);
|
||||||
translate.setX(pos.getX()).setY(pos.getY()).setZ(pos.getZ());
|
translate.setX(pos.getX()).setY(pos.getY()).setZ(pos.getZ());
|
||||||
} catch (NullPointerException ignored) {}
|
} catch (NullPointerException ignored) {}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user