WorldEdit icon indicating copy to clipboard operation
WorldEdit copied to clipboard

Make ^ support nbt (properly)

Open QuImUfu opened this issue 9 months ago • 3 comments

My implementation of #2733, It adds ^{=nbt} support, integrated in current ^ support to allow replacing/keeping arbitrary parts of a block.

Additionally, adds {nbt} support for merging NBT tags into existing ones.

Examples:

//replace chest ^barrel will keep orientation and NBT intact and just replace the block type, keeping e.g. contents as-is.
//replace chest ^[facing=north] will make all chest face north, keeping their NBT intact.
//replace chest,barrel ^{=LootTable:"minecraft:chests/simple_dungeon"} will make both, chests and barrels contain dungeon loot, while removing any potential other NBT.
//set ^{=} deletes nbt from selection. (does not work for LootTable tags due to a bug in vanilla MC I can't link here or find again because mojangs bug tracker is completely broken)
//replace decorated_pot ^{LootTable:"minecraft:chests/simple_dungeon"} will make pots contain dungeon loot while keeping their pattern. ...

QuImUfu avatar Mar 14 '25 23:03 QuImUfu

I have concerns about the exact syntax here, I don't think we should allow ^{} to be deletion / require a prefix comma -- this is inconsistent with the existing function.

As it stands, ^ is purely overwrite/additive. ^foo means "set block type to foo keeping all applicable state entries", ^[x=y] means "set the block state to the previous state with x set to y". I think it should remain that way for NBT as well, which would imply that ^{} is essentially a no-op and should be illegal syntax, as ^[] is today. If we want to add a variant that clears existing state, I think it should use a different prefix, or perhaps an extended one such as ^= ("equals" to imply removal of unwritten state).

octylFractal avatar Mar 16 '25 21:03 octylFractal

While I understand you concern, I have some concerns with merge only for ^:

The current syntax allows for simply including {} to sidestep any NBT handling and (if implemented correctly, I probably will have to fix that) prevent any performance penalty.

If we do merge only, we need to add a different way to have ^[..=..] and ^.. keep (with related performance penalty) or drop NBT.

I'd suggest following to make it more consistent, without introducing a new prefix:
Changing {,..} to just {..} and {..} to {=..} or ={..} (the second being slightly confusing in combination with other overrides) and keeping merging as default this way. But that'd still include new syntax for ^ only applicable to NBT (we could also add ^[=..] but that would be a mostly useless feature just for consistencies’ sake).

If you have a different idea on how that could be implemented more consistently, I'm very open to suggestions.

QuImUfu avatar Mar 16 '25 23:03 QuImUfu

I have changed it to merge by default and set with {=...}.

QuImUfu avatar Mar 21 '25 13:03 QuImUfu