Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Question) Trying to modify region binary to replace stuff in minecraft world using blockdata #158

Open
julianprincipe opened this issue Feb 3, 2022 · 0 comments

Comments

@julianprincipe
Copy link

julianprincipe commented Feb 3, 2022

I'm trying to write a simple script that replace NBT tags in a world, i'm testing it with a brand new world with a simple "give" command in a command block:

give @a golden_axe

My idea is to use get_blockdata() to unpack the binary, binary = binary.replace(b'minecraft:golden_axe', b'minecraft:golden_sword') to replace the item and write_blockdata() to write it to the file

This is the code i have:

for region in world.iter_regions():
            process_region_file(region, start, stop)
            for i in region.get_metadata():
                x = i.x
                z = i.z
                binary = region.get_blockdata(x,z)
                binary = binary.replace(b'minecraft:golden_axe', b'minecraft:golden_sword')
                nbt = region.write_blockdata(x, z, binary, compression=2)
                print(region.get_blockdata(x,z))

The code works with really specific stuff, i've managed to change random text in a command block but whenever i try to change items in a "give" command or something like that the command block just disappears.

I've manually checked the replacement by printing the binary and it works:
Command\x00\x1cgive @p minecraft:golden_axe gets replaced to: Command\x00\x1cgive @p minecraft:golden_sword in the binary, but when i open the world the command block isn't there and if i check the binary after opening the world it just disappears from the binary aswell

Any ideas why it happens? Would you approach this idea differently? I'm really confused

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant