alex4200 / pyblock Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Hello! Thank you for your library!
I am trying to migrate a modpack and my situation is that capitalization has changed on some NBT data.
In other words, I am searching through all inventories in a Minecraft world, and trying to replace the lowercase "items" tags with the proper "Items" tags.
Player inventories are already corrected, so what remains is to search block entities. Your library looked ideal for that.
My strategy is to try and get every chunk to load, by requesting a block from every chunk:
world = pyblock.Editor('')
# Force load all chunks
for x_pos in range(-25000, 25000, 16):
for z_pos in range(-25000, 25000, 16):
world.get_block(x_pos, 0, z_pos)
Next, I search through all loaded block entities, and of course check for an inventory, etc. If I find a tag that needs to be corrected, I write the change and then add the entity to the list of entities that need updated:
if str(entity['Items'][i]['id']) == 'simple_backpack:backpack':
# Change capitalization
entity['Items'][i]['tag']['backpack']['Items'] = entity['Items'][i]['tag']['backpack']['items']
# Save to list of pending updates
region_coords, chunk_coords, _, _ = pyblock.tools.block_to_id_index(entity['x'].value, entity['y'].value, entity['z'].value)
key = (region_coords, chunk_coords)
world.entities[key].append(entity)
(This is simplified; my code recursively checks tags in case inventories are nested.)
Then of course when I'm done, I call world.done()
to write all changes.
Calling world.done()
in my code does not save any changes, because world.done()
is looking for changes in world.blocks_map
. I haven't created any such changes, because I didn't move or copy block entities, I only wanted to make changes to their tags.
I would like to suggest that the library should save changes in these cases. What's tricky (from my uninformed POV) is actually changing the block entity rather than adding a duplicate.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.