mcworldlib
mcworldlib copied to clipboard
Unable to modify entities list
Hello,
I am using this library to try to remove a huge number of entities (cobblestone item drops) in a specific chunk. The world is for a modded 1.20.1 version of Minecraft. The issue is when I try to clear the list of entities and then save the region, the file changes on disk but the entities are still there when opening the game or re-running the code. Here is the code, it searches all chunks for any with more than 300 entities:
import mcworldlib as mc
import sys
world = mc.load(sys.argv[1])
entities = world.entities[mc.OVERWORLD]
for i, (coordRegion, entitiesList) in enumerate(entities.items()):
for i2, (coordChunk, chunk) in enumerate(entitiesList.items()):
if len(chunk.entities) > 300:
print(coordRegion, coordChunk, len(chunk.entities))
input("Press enter to continue.")
chunk.entities.clear() # also tried `chunk.entities = []`, `chunk.entities = nbtlib.List([])`
entitiesList.save()
For my Minecraft world, it prints that a region file with >300 entities is r.-2.-1.mca (attached here) and that the chunk at (7,26) has 234448 entities. Here is the output (presumably, the Player is not found because this is a server world?):
Level has no Player, possibly malformed: None
( -2, -1) ( 7, 26) 234448
Press enter to continue.
When I open that mca file in NBTExplorer, expanding that chunk doesn't actually seem to work, it just makes the + button disappear:
The mca file produced by mcworldlib is considerably smaller (728 KB instead of the original 3757 KB) but when running the same script again it has the same output (that there are 234448 entities). Additionally, opening the new mca file in NBTExplorer has the same issue with the + button.
Finally, I went into the game and ran kill @e[type=minecraft:item,nbt={Item:{id:"minecraft:cobblestone"}}] at the location, and the resulting mca file is no longer detected as having any entities at that chunk within mcworldlib. Opening the mca file in NBTExplorer shows that there is no entry for any chunk at (7,26).
What would be a good first step so I can investigate this issue further to identify the cause of the problem?