sandstone
sandstone copied to clipboard
`NBT.stringify` does not escape things correctly when used in JSON (as opposed to commands)
NBT.stringify({ test: '\n' })
should output "{test:'\n'}"
when used in a JSON file, not "{test:'\\n'}"
. This input impossible to specify in commands validly though.
Minimal reproduction code:
LootTable('test:book', {
type: 'command',
pools: [{
rolls: 1,
entries: [{
type: 'minecraft:item',
name: 'minecraft:writable_book',
functions: [{
function: 'set_nbt',
tag: NBT.stringify({
pages: ['line 1\nline 2']
})
}]
}],
bonus_rolls: 0
}]
});
Minecraft does not recognize this NBT as valid. Entering /loot give @s loot test:book
will not work. Opening the outputted loot table file shows this error:
And Minecraft logs this error:
I'm fairly sure you actually can't have newlines in NBT text. Are you sure there is any valid output?
Yes you can, and removing the double slashes fixes it.
Can you show me a detailed example? Minecraft does not seem to accept \n
, while \\n
is accepted.
This works:
This doesn't:
This NBT is not in a Minecraft command. It's in a string in a JSON file.
I realize this issue is more complicated that I thought, because it seems escaping needs to be done differently between NBT in a JSON string and NBT in a command.
Edit: Never mind, \n
isn't even valid in NBT for a command, escaped or not. It's not a valid escape sequence.