Skip to content

Instantly share code, notes, and snippets.

@bblay
Last active November 20, 2024 19:51
Show Gist options
  • Save bblay/bac2a0b7e5fc6346299020183323b30c to your computer and use it in GitHub Desktop.
Save bblay/bac2a0b7e5fc6346299020183323b30c to your computer and use it in GitHub Desktop.
scan mc world
import os
from itertools import product
from nbt.chunk import AnvilChunk
from nbt.world import AnvilWorldFolder
def main():
search_terms = ['netherite', 'allthemod']
with open('out.txt', 'wt') as ofile:
world = AnvilWorldFolder(os.getcwd()) # a folder called "region" in current folder, downloaded from server
for region in world.iter_regions():
chunk_metas = region.get_metadata()
for chunk_meta in chunk_metas:
# print(chunk_meta.x, chunk_meta.z)
chunk_nbt = region.get_chunk(chunk_meta.x, chunk_meta.z)
# the library can't load some of the chunks, so we're not scanning the whole world :(
try:
chunk = AnvilChunk(chunk_nbt)
except Exception:
# print(f'error in chunk {chunk_meta.x} {chunk_meta.z}')
continue
if not chunk.sections:
continue
for x, y, z in product(range(16), range(256), range(16)):
block = chunk.get_block(x, y, z)
if not block:
continue
for search_term in search_terms:
if search_term in block:
msg = (f'chunk {chunk.coords[0].value} {chunk.coords[1].value} ({chunk.coords[0].value*16}, {chunk.coords[1].value*16}), '
f'meta {chunk_meta.x} {chunk_meta.z}, '
f'{block} {x} {y} {z}')
print(msg)
ofile.write(f'{msg}\n')
ofile.flush()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment