mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-30 01:34:04 +00:00
Keep the declared size when the object codec decodes a file
This commit is contained in:
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. */
|
||||
|
||||
Reference in new issue
Block a user