ws-voxel: model/schematic (.schem v1-3, .schematic, .litematic read + write), codecs/model/Minecraft (block states, default colours, legacy ids, packed arrays)

Types change (backward compatible): Types.Voxels gains optional blocks (VoxelBlocks: exact block states as
u16 indices into a state palette, block entities, entities) and colors (exact u32 RGBA per cell).
This commit is contained in:
4DBug committed 2026-10-31 14:37:43 -05:00
1 parent 7fc5d3f5f0
commit fea56f4391
11 files changed
+524 -40

No files matched your search

+5 -5
View File
@@ -67,18 +67,18 @@ function Sponge.read(s: any, maxCells: number): ({ Common.Region }?, any)
end
end
local off = Common.ints(s.Offset) or { 0, 0, 0 }
return {
local regions: { Common.Region } = {
{
name = nil,
size = { sx, sy, sz },
size = { sx, sy :: number, sz :: number },
position = { off[1] or 0, off[2] or 0, off[3] or 0 },
states = states,
indices = Packed.fromYzx(yzx, sx, sy :: number, sz :: number),
blockEntities = bes,
entities = Common.list(s.Entities),
},
},
{ version = version, dataVersion = Common.int(s.DataVersion), metadata = s.Metadata }
}
return regions, { version = version, dataVersion = Common.int(s.DataVersion), metadata = s.Metadata }
end
-- write(region, version, dataVersion, base?) -> the Schematic compound (v3: the caller wraps it in the root) | nil,
@@ -101,7 +101,7 @@ function Sponge.write(r: Common.Region, version: number, dataVersion: number, ba
for _, be in r.blockEntities do
table.insert(bes, Common.flatBlockEntity(be, if version >= 3 then "data" else "pos"))
end
local ents = if #r.entities > 0 then r.entities else nil
local ents = if #r.entities > 0 then r.entities else Nbt.list("compound") -- optional, but readers expect it
local off = Nbt.intArray({ r.position[1], r.position[2], r.position[3] })
local fields: { { any } } = {
{ "Version", version },