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
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 andwrite_blockdata()
to write it to the fileThis is the code i have:
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 aswellAny ideas why it happens? Would you approach this idea differently? I'm really confused