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

Mixed list; string as compound #97

Closed
Gjum opened this issue Aug 16, 2024 · 4 comments
Closed

Mixed list; string as compound #97

Gjum opened this issue Aug 16, 2024 · 4 comments

Comments

@Gjum
Copy link
Member

Gjum commented Aug 16, 2024

In the 1.20 protocol, most chat is represented as NBT. Chat has several situations (translate, extra) where an array can contain either more chat elements, or simple strings. In this case, Mojang represents strings as compounds with a single "" key:

Show example
{
	"type": "compound",
	"value": {
		"translate": {
			"type": "string",
			"value": "commands.teleport.success.location.single"
		},
		"with": {
			"type": "list",
			"value": {
				"type": "compound",
				"value": [
					{ "text": { "type": "string", "value": "PlayerName" } },
					{ "": { "type": "string", "value": "-123.5" } },
					{ "": { "type": "string", "value": "63.5" } },
					{ "": { "type": "string", "value": "-45.5" } }
				]
			}
		}
	}
}

My use case is converting the chat NBT to the old format: new ChatMessage(NBT.simplify(packet.message))

To solve this, simplify() could convert { "": { "type": "string", "value": "some text" } } to "some text".

This would also eliminate the need for special handling via processNbtMessage etc.

Related:
PrismarineJS/prismarine-chat#103
PrismarineJS/prismarine-chat#104

@extremeheat
Copy link
Member

I guess it could, but this doesn't seem correct in the sense that simplify is no longer removing type wrappers but changing the underlying data structure. This could be a problem as it breaks creating a potential reverse simplify() function in the future.

@Gjum
Copy link
Member Author

Gjum commented Aug 18, 2024

I consider the {"":...} hack to be a (quirky) type wrapper (as NBT does not allow mixed types in an array in any way compatible with the standard type wrapping).
It can be undone by noticing that the array contains both objects and strings in this case, and converting it to a compound array encoding strings with the same {"":...}.
By the way, how will a reverse simplify() function decide whether an array of (incidentally) integer values should be turned back into an (original) array of floats? Maybe some similar approach applies here as well.

@extremeheat
Copy link
Member

extremeheat commented Aug 18, 2024

Related to what I mentioned is #39. Turning to string is a completely different type than an object with one key in it, and it's not something that can be extended as a primitive type.

@Gjum
Copy link
Member Author

Gjum commented Aug 18, 2024

Thank you for clarifying. In that case I agree that it may be better to strictly stick with the NBT spec here and deal with the use of the hack one level higher in prismarine-chat and wherever else it may show up.

@Gjum Gjum closed this as completed Aug 18, 2024
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

2 participants