Keep the declared size when the object codec decodes a file

This commit is contained in:
piexel committed 2026-11-10 02:10:23 +01:00
1 parent ff23e2fb7b
commit 5ab99210b2
3 files changed
+140 -1

No files matched your search

@@ -56,6 +56,24 @@ public final class ObjectGeometry {
}
}
/**
* Like {@link #of}, but the bounds are the size the object file declares around its center, not the box of its blocks,
* so the file can be written again at the size it had.
*/
public static GeneratedObject ofDeclared(IrisObject object) {
object.readLock.lock();
try {
int centerX = object.w / 2;
int centerY = object.h / 2;
int centerZ = object.d / 2;
BlockBox declared = new BlockBox(-centerX, -centerY, -centerZ,
object.w - centerX, object.h - centerY, object.d - centerZ);
return new GeneratedObject(declared, CENTER, blocksOf(object), List.of());
} finally {
object.readLock.unlock();
}
}
private static List<ObjectBlock> blocksOf(IrisObject object) {
Map<BlockPosition, ObjectBlock> blocks = new LinkedHashMap<>();
for (Map.Entry<IrisBlockVector, PlatformBlockState> entry : object.blocks) {
@@ -62,7 +62,7 @@ public final class IrisObjectCodec implements ObjectCodec {
} catch (Throwable failure) {
throw new IOException("Cannot read an " + EXTENSION + " object: " + failure.getMessage(), failure);
}
return ObjectGeometry.of(object);
return ObjectGeometry.ofDeclared(object);
}
/** Iris keys an object's blocks by their offset from its center, so the local positions are the keys. */