I’m working on a project to read Minecraft .mca files, scan for container entities (chests, shulker boxes, furnaces, barrels), and save their contents into spreadsheets using anvil-parser. However, I’m encountering issues accessing the data correctly.
import os
import anvil
import json
import pandas as pd
def scan_chunk_for_containers(chunk):
containers = []
for entity in chunk.entities:
if entity['id'] in ['minecraft:chest', 'minecraft:shulker_box', 'minecraft:furnace', 'minecraft:barrel']:
containers.append(entity)
return containers
def process_region_file(region_file_path, output_folder):
region = anvil.Region.from_file(region_file_path)
all_containers = []
for chunk_x in range(32):
for chunk_z in range(32):
if region.chunk_location(chunk_x, chunk_z) is not None:
try:
chunk = region.get_chunk(chunk_x, chunk_z)
containers = scan_chunk_for_containers(chunk)
all_containers.extend(containers)
except anvil.errors.ChunkNotFound:
continue
if all_containers:
output_file_path = os.path.join(output_folder, os.path.basename(region_file_path) + '_containers.json')
with open(output_file_path, 'w') as output_file:
json.dump(all_containers, output_file, indent=4)
# Convert to DataFrame and save as spreadsheet
df = pd.json_normalize(all_containers)
spreadsheet_path = os.path.join(output_folder, os.path.basename(region_file_path) + '_containers.xlsx')
df.to_excel(spreadsheet_path, index=False)
print(f"Saved container data to {spreadsheet_path}")
def main():
region_folder = "path goes here"
output_folder = "output path goes here"
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for file_name in os.listdir(region_folder):
if file_name.endswith('.mca'):
region_file_path = os.path.join(region_folder, file_name)
process_region_file(region_file_path, output_folder)
if __name__ == "__main__":
main()
I get the following error:
AttributeError: 'Chunk' object has no attribute 'sections'
How can I correctly access container entities? I tried some other ways but I feel like at this point I have no clue. The world is 1.20.4. I’d greatly appreciate any help!