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). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
c908ed9ad7
commit
166f3f8eee
11 files changed
+524
-40
No files matched your search
@@ -0,0 +1,49 @@
|
||||
-- tools/fixtures/schematic.py helper: our model/schematic encoder's output for the reference readers (litemapy,
|
||||
-- nbtlib). Prints "<name>\t<hex>" lines. Inputs: the decoded fixtures of tests/gen/schematic, plus grids built here.
|
||||
local Schematic = require("@formats/model/schematic")
|
||||
local Bytes = require("@formats/core/Bytes")
|
||||
local Types = require("@formats/Types")
|
||||
local Fx = require("@tests/gen/schematic")
|
||||
|
||||
local function hex(b: buffer): string
|
||||
local t = table.create(buffer.len(b))
|
||||
for i = 0, buffer.len(b) - 1 do
|
||||
t[i + 1] = string.format("%02x", buffer.readu8(b, i))
|
||||
end
|
||||
return table.concat(t)
|
||||
end
|
||||
|
||||
local function emit(name: string, b: buffer?, e: any)
|
||||
if not b then
|
||||
error(name .. ": " .. tostring(e))
|
||||
end
|
||||
print(name .. "\t" .. hex(b))
|
||||
end
|
||||
|
||||
local byName = {}
|
||||
for _, c in Fx.cases do
|
||||
byName[c.name] = assert(Schematic.decode(Bytes.reader(buffer.fromstring(c.data))))
|
||||
end
|
||||
-- same variant (fields kept), and across variants
|
||||
emit("litemapy.litematic", Schematic.encode(byName.litemapy))
|
||||
emit("litemapy.schem", Schematic.encode(byName.litemapy, { variant = "schem", version = 2 }))
|
||||
emit("sponge2.schem", Schematic.encode(byName.sponge2))
|
||||
emit("sponge2.litematic", Schematic.encode(byName.sponge2, { variant = "litematic" }))
|
||||
emit("sponge3.schem", Schematic.encode(byName.sponge3))
|
||||
emit("sponge3v2.schem", Schematic.encode(byName.sponge3, { version = 2 }))
|
||||
emit("sponge1.schem", Schematic.encode(byName.sponge1))
|
||||
emit("mcedit.schematic", Schematic.encode(byName.mcedit))
|
||||
emit("worldedit_add.schematic", Schematic.encode(byName.worldedit_add))
|
||||
emit("sponge2.schematic", Schematic.encode(byName.sponge2, { variant = "schematic" }))
|
||||
emit("mcedit.schem", Schematic.encode(byName.mcedit, { variant = "schem" }))
|
||||
-- a colour grid (no block states): each palette colour becomes the block nearest in colour
|
||||
local v = Types.Voxels.new(4, 3, 2)
|
||||
v.palette[1] = { 160, 40, 35, 255 }
|
||||
v.palette[2] = { 125, 125, 125, 255 }
|
||||
v.palette[3] = { 60, 110, 230, 120 }
|
||||
for i = 0, 4 * 3 * 2 - 1 do
|
||||
buffer.writeu8(v.data, i, i % 4)
|
||||
end
|
||||
emit("colors.schem", Schematic.encode(v))
|
||||
emit("colors.litematic", Schematic.encode(v, { variant = "litematic" }))
|
||||
emit("colors.schematic", Schematic.encode(v, { variant = "schematic" }))
|
||||
@@ -119,6 +119,7 @@ def varints(idx):
|
||||
out.append(v)
|
||||
return bytes(out)
|
||||
def sponge(version, w, h, l, states, offset):
|
||||
states = list(dict.fromkeys(states))
|
||||
pal = {s: i for i, s in enumerate(states)}
|
||||
idx = [rng.randrange(len(states)) for _ in range(w * h * l)]
|
||||
data = ByteArray(np.frombuffer(varints(idx), dtype=np.int8))
|
||||
|
||||
Reference in new issue
Block a user