model formats (mca..x3d): comments are specs only

This commit is contained in:
4DBug committed 2026-11-01 01:54:32 -05:00
1 parent 0bd7b87d2b
commit b952c10222
49 files changed
+310 -936

No files matched your search

+7 -11
View File
@@ -1,9 +1,7 @@
--!strict
-- model/mca/Chunk: the blocks of one Anvil chunk's NBT, from the Minecraft wiki "Chunk format" page, in the three
-- layouts it has had: 1.18+ (root sections[] with block_states { palette, data }, non-spanning packing, at least
-- 4 bits, yPos), 1.13 - 1.17 (Level.Sections[] with Palette + BlockStates, spanning before DataVersion 2529 =
-- 20w17a), and before 1.13 (Level.Sections[] with Blocks / Add / Data nibble arrays, numeric ids through
-- codecs/model/Minecraft legacyState). Each section is 16 x 16 x 16 cells in Minecraft's order (x, then z, then y).
-- model/mca/Chunk: an Anvil chunk's blocks (Minecraft wiki "Chunk format"): 1.18+ sections[] block_states
-- (non-spanning, >= 4 bits); 1.13 - 1.17 Level.Sections[] Palette + BlockStates (spanning before DataVersion 2529 =
-- 20w17a); pre-1.13 Blocks / Add / Data nibble arrays. A section is 16 x 16 x 16 cells, x then z then y.
local Types = require("@rosetta/Types")
local Nbt = require("@rosetta/codecs/text/Nbt")
local Mc = require("@rosetta/codecs/model/Minecraft")
@@ -12,14 +10,14 @@ local Chunk = {}
local Packed = Mc.Packed
export type Section = { y: number, states: { string }, cells: buffer } -- cells: u16 per cell, 4096, x-z-y order
export type Section = { y: number, states: { string }, cells: buffer } -- u16 per cell, 4096, x-z-y order
export type Blocks = {
x: number, -- chunk coordinates (xPos / zPos)
x: number, -- xPos / zPos
z: number,
dataVersion: number?,
sections: { Section },
blockEntities: { any }, -- the chunk's records as they are (absolute x, y, z)
entities: { any }, -- entities stored in the chunk (before 1.17)
blockEntities: { any }, -- absolute x, y, z
entities: { any }, -- before 1.17
}
local function int(v: any): number?
@@ -31,7 +29,6 @@ local function list(v: any): { any }
return if type(v) == "table" and not Nbt.isTag(v) and not Types.isObject(v) then v else {}
end
-- a palette section (1.13+): states from the palette compounds, cells from the packed array
local function paletted(y: number, palette: { any }, data: any, minBits: number, spanning: boolean): (Section?, string?)
local states = table.create(#palette) :: { string }
for i, c in palette do
@@ -58,7 +55,6 @@ local function paletted(y: number, palette: { any }, data: any, minBits: number,
return { y = y, states = states, cells = cells }, nil
end
-- blocks(root) -> Blocks | nil, message: the sections of a decoded chunk
function Chunk.blocks(root: any): (Blocks?, string?)
if type(root) ~= "table" or not Types.isObject(root) then
return nil, "chunk NBT is not a compound"