I'm trying to modify the short "lvl" tag within a compound tag in "ench:[]" on an item in a chest, without changing anything else about the item or the chest. I know of more complicated ways to do this that involve multiple commands, systems of hoppers, destroying and replacing the chest, etc. but I was hoping it could be done in one command with /blockdata. My current command looks like this:
There is an iron sword with Sharpness I in the chest. I want the command to change it to Sharpness 2, leaving all others items, and item properties intact. Unfortunately, this command completely replaces the Items tag. Expected, but unfortunate. Is there any way to have it only replace the last compound tag, or at most the ench:[] tag?
Rollback Post to RevisionRollBack
Truly he is my rock and my salvation; he is my fortress, I will not be shaken. ~Psalms 62:6
Does it have to only replace one part of the enchantment? Can't you just make another item replace it, that's exactly the same, except what you want changed?
No, because the item could have any number of other enchantments on it that need to remain unchanged. I could testforblock each case, but that would be more work than an alternative method. So yeah.
Rollback Post to RevisionRollBack
Truly he is my rock and my salvation; he is my fortress, I will not be shaken. ~Psalms 62:6
/blockdata 94 4 23 {Items:[{id:"minecraft:iron_sword",tag:{ench:[{id:16,lvl:2}]}}]}
There is an iron sword with Sharpness I in the chest. I want the command to change it to Sharpness 2, leaving all others items, and item properties intact. Unfortunately, this command completely replaces the Items tag. Expected, but unfortunate. Is there any way to have it only replace the last compound tag, or at most the ench:[] tag?
/blockdata 94 4 23 {Items:[{Slot:0,id:iron_sword,Count:1,tag:{ench:[{id:16,lvl:2}]}}]}
You forgot the slot tag. Although you must change it yourself as I do not know what slot the item is in.
Here's a slot graph I made... Right now...
Edit: There is one downfall to the blockdata, as it will over-write other items (So with the current command, all other items are deleted)
You can also use /replaceitem...
/replaceitem block 94 4 23 slot.container.0 iron_sword 1 0 {ench:[{id:16,lvl:2}]}
This method is better as it will only over-write 1 slot, rather than all of them.
I'll have to resort to a more complex method then.