fix offset with shrinkwrap

This commit is contained in:
Julian Krings
2025-12-18 11:05:14 +01:00
parent a251d192ad
commit 7cd43791f4
3 changed files with 35 additions and 7 deletions

View File

@@ -69,7 +69,7 @@ public class PlannedPiece {
this.setRotation(rot);
this.ogObject = data.getObjectLoader().load(piece.getObject());
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.object.setLoadKey(piece.getObject());
this.ogObject.setLoadKey(piece.getObject());

View File

@@ -98,6 +98,8 @@ public class IrisObject extends IrisRegistrant {
@Getter
@Setter
private transient Vector3i center;
@Getter
private transient Vector3i shrinkOffset;
public IrisObject(int w, int h, int d) {
blocks = new VectorMap<>();
@@ -106,6 +108,7 @@ public class IrisObject extends IrisRegistrant {
this.h = h;
this.d = d;
center = new Vector3i(w / 2, h / 2, d / 2);
shrinkOffset = new Vector3i(0, 0, 0);
var lock = new ReentrantReadWriteLock();
readLock = lock.readLock();
writeLock = lock.writeLock();
@@ -504,8 +507,8 @@ public class IrisObject extends IrisRegistrant {
}
public void shrinkwrap() {
BlockVector min = new BlockVector();
BlockVector max = new BlockVector();
BlockVector min = new BlockVector(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE);
BlockVector max = new BlockVector(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE);
for (BlockVector i : blocks.keys()) {
min.setX(Math.min(min.getX(), i.getX()));
@@ -520,6 +523,31 @@ public class IrisObject extends IrisRegistrant {
h = max.getBlockY() - min.getBlockY() + 1;
d = max.getBlockZ() - min.getBlockZ() + 1;
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() {
@@ -1150,8 +1178,8 @@ public class IrisObject extends IrisRegistrant {
blocks = d;
states = dx;
writeLock.unlock();
shrinkwrap();
writeLock.unlock();
}
public void place(Location at) {

View File

@@ -101,15 +101,15 @@ public class IrisObjectRotation {
return e.rotateCopy(this);
}
public IrisJigsawPiece rotateCopy(IrisJigsawPiece v) {
public IrisJigsawPiece rotateCopy(IrisJigsawPiece v, IrisPosition offset) {
IrisJigsawPiece piece = v.copy();
for (IrisJigsawPieceConnector i : piece.getConnectors()) {
i.setPosition(rotate(i.getPosition()));
i.setPosition(rotate(i.getPosition()).add(offset));
i.setDirection(rotate(i.getDirection()));
}
try {
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());
} catch (NullPointerException ignored) {}