Skip to content

Instantly share code, notes, and snippets.

@wgaylord
Last active October 9, 2020 19:43
Show Gist options
  • Save wgaylord/df226b26a09ffc5aaad3337e256141b0 to your computer and use it in GitHub Desktop.
Save wgaylord/df226b26a09ffc5aaad3337e256141b0 to your computer and use it in GitHub Desktop.
from quarry.types.buffer import Buffer
def unpack_chunk(buff):
x, z, full = buff.unpack('ii?') #Get chunk location and if its full
bitmask = buff.unpack_varint() #Bitmask of the chunk sections
heightmap = buff.unpack_nbt() #Get the heightmap?
biomeLength = 0
if full:
biomeLength = buff.unpack_varint() #Get biome length if full
biomeData = [buff.unpack_varint() for _ in range(biomeLength)] #Get biomes
size = buff.unpack_varint() #Get data section size
chunk_data = []
chunk_buff = Buffer(buff.read(size)) #Use another buffer to make sure all the bytes of size are read.
for u in range(16):
if (bitmask & (2**u)) > 0: #Only unpack chunks that exist
chunk_data.append(unpack_chunk_section(chunk_buff)) #unpack chunk section
else:
chunk_data.append(None)
entities = [buff.unpack_nbt() for _ in range(buff.unpack_varint())] #Unpack entities
return [x,z,full,biomeData,chunk_data,heightmap]
def unpack_chunk_section(buff):
non_air = buff.unpack("H")
bits_per_block = buff.unpack('B')
pallete = None
if bits_per_block <= 8:
pallete = [buff.unpack_varint() for _ in range(buff.unpack_varint())]
length = buff.unpack_varint()
data = [buff.unpack('L') for _ in range(length)]
return [non_air,length,bits_per_block,pallete,data]
[[4004, 256, 4, [0, 33, 1, 2, 3354, 4, 70, 10, 3886, 6, 69, 9670, 232], [286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286331153, 286335250, 286331169, 286331153, 287379729, 303239457, 286331153, 286331153, 554766610, 286339345, 555815441, 286331667, 286331409, 286331153, 286331409, 554767121, 554766609, 1092686129, 286331425, 286331411, 554766610, 287445265, 287445281, 554832149, 304156961, 286332177, 286331153, 287379729, 286331153, 554766865, 286396689, 286335521, 286331153, 308417041, 554770706, 286462241, 303174162, 303117073, 571543825, 554774817, 304156962, 286462257, 303174162, 555946801, 303174177, 287379729, 286396706, 286331153, 554770961, 1092686129, 303108385, 1091638803, 571609617, 304222481, 286400802, 286331153, 286335506, 287379729, 554766609, 554836305, 304222481, 555815185, 286331409, 571543829, 1896960337, 303112737, 572609874, 560341266, 554832162, 303440146, 554836257, 304222497, 287445522, 304161570, 303112481, 286397202, 555884834, 572601106, 287384081, 304226593, 555815185, 571543842, 554832402, 555832930, 571613730, 555898197, 571544082, 572592401, 572658210, 554833233, 303178273, 555820305, 571613714, 572596561, 554770962, 571544098, 1898254677, 571548178, 286610770, 572596513, 304174370, 572662289, 1918193944, 2165445154, 1901416744, 2183205410, 572658210, 572596770, 572662305, 303178274, 554770978, 304226833, 304226850, 572662305, 572658210, 572662289, 572662306, 572659026, 555885089, 572663125, 304226850, 571613521, 572662306, 572596757, 579347090, 573710866, 579348754, 572662306, 1915049301, 572662306, 1915049298, 572662306, 1918194978, 572662306, 1918194984, 2283938338, 1918194216, 2183275042, 576004642, 673325602, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572732194, 572663442, 590557986, 572664217, 858993442, 578984346, 858993186, 1922659703, 2003968546, 572872055, 2004296226, 576017703, 2004296226, 576016930, 679617058, 576016930, 2183275042, 576004642, 673325602, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662562, 572662306, 573780786, 572679826, 590558002, 572679834, 2738041650, 572692842, 2738041634, 580351863, 2004296226, 572684151, 2004316706, 572662391, 2004316706, 572858914, 1999053346, 572858914, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572666675, 572662306, 573780787, 572662306, 590558003, 572680594, 2738041650, 572692838, 858993442]], [8743, 119, 119, None, [2004296226, 673347447, 2004316706, 2283938423, 2004316706, 572662306, 1999053346, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662307, 572662306, 572732211, 572662306, 573780787, 572662306, 573780786, 572662306, 573780514, 572682871, 2003968546, 673325687, 2004296226, 2283938343, 2004296226, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 573080098, 572662306, 573080098, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662562, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 573055522, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 573080098, 572662306, 573080098, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 573080098, 572662306, 573080098, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572679714, 572662306, 572679714, 857874978, 572662306, 857874978, 572662306, 572662306, 572662306, 2988581410, 572662306]], [45602, 34, 34, None, [572662306, 3139576354, 572662306, 3149013538, 572662306, 3139576354, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 590488098, 572662306, 858923554, 572662307, 858923554, 572662307, 857892386, 857874978, 572679714, 858923554, 572662306, 858923554, 572662306, 858923554, 572662306, 2988581410, 572662311, 3139576354, 572662391, 3139576354]], [8738, 119, 39, None, [3149013538, 572684151, 3149013538, 572663666, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 572662306, 859412889, 572662307, 859412889, 572662323, 858990994, 572662579, 858954018, 858927923, 857874978, 858993458, 572662306, 858993186, 572662306, 858993186, 572662306, 3005358626, 572662311, 3139576354, 572662391, 3139576354, 572663671, 3149013538, 572684151, 3149013538, 572663671, 572662306, 572662306, 572662306, 572662313, 572662306, 572692889, 572662307, 865704345, 3139576371, 865704345, 3149013811, 865704345, 3149017907, 859412882, 3140629299, 858364194, 3140629299, 572662306, 3006477090, 572662306, 858989090, 572662306, 2988581410, 572662311, 3139576354, 572662311, 3139576354, 572662391, 3149013538, 572663671, 3149013538, 572662306, 2576949794, 572662306, 733094434, 572662425, 3149013538, 573151641, 3149603362, 865704345, 3149603363, 865704345, 3149013811, 865704345, 3149017907, 859412889, 3149017907, 841586978, 3149017907, 572662306, 3140624930, 572662306, 3005358626, 572662306, 2988597794, 572662306, 2988581410, 572662306, 3139576364, 572662306, 3139576354, 3257016866, 3149013538, 572662306, 225379601, 116299, 100812520, 17057592, 909392394, 843400406, 33590338, 272765060, 553714721, 138817800, 1124174947, 277094532, 1107363906, 142876804, 553715778, 138555788, 1661079651, 415641864, 1107397731]], [4228, 8, 33, None, [1090586690, 276972048, 587272324, 541200780, 1660978209, 415371528, 1107330081, 277094928]], [33025, 17, 8, [9, 2, 16, 4228, 0, 4228, 8, 66, 16, 4228, 0, 4228, 8, 66, 17, 8, 33, 0, 4228, 16, 66, 16, 4244, 1, 4, 33, 40, 66, 16, 4228, 0, 4228, 8, 66, 16, 4228, 0, 4228, 8, 66, 17, 4, 33, 0, 4228, 16, 2050, 4868, 1, 8, 33, 9, 2510, 4, 33, 0, 143516, 66, 16, 4228, 1, 8, 33, 8, 66], [138477700, 1662026768, 2353135880, 1107854369, 69271688, 1108361744, 2221080708, 554223153, 138543244, 1662026785, 138543368, 1108378640, 2216755464, 554189328, 2355298436, 554189329, 138543236]], None, None, None, None, None, None, None, None, None, None]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment