Redo chat parsing and validation#24
Conversation
|
@creesch the structure from prismarine-chat is out-of-date. The |
| // that automatically pauses when tab is inactive | ||
| if (timestamp - lastUpdate >= updateInterval) { | ||
| const elements = document.getElementsByClassName('minecraft-obfuscated'); | ||
| const elements = document.getElementsByClassName('mc-obfuscated'); |
There was a problem hiding this comment.
I threw in this random change because the different class name format was upsetting me.
41c9c2b to
29639fa
Compare
| * }} HoverEventContents | ||
| * @typedef {Object} ShowEntityHoverEvent | ||
| * @property {'show_entity'} action - Displays entity information | ||
| * @property {{ type: string, id: unknown, name?: string }} contents - The entity data to show |
There was a problem hiding this comment.
I left id as unknown. It seems it should be a UUID string, but it's coming through as an array of 4 numbers (which could make sense if the 4 numbers are 1:1 with a UUID at 32 bits each). So perhaps we're doing a different serialization than the Wiki expects.
There was a problem hiding this comment.
Oh btw
So perhaps we're doing a different serialization than the Wiki expects.
We are using native serialization, its also possible the wiki is incorrect. There is also differences between bedrock and java. Which wiki have you been looking at?
29639fa to
3c3f552
Compare
| div.innerHTML = parseMinecraftText(json); | ||
|
|
||
| /** @type {unknown} */ | ||
| const json = JSON.parse(rawJson); |
There was a problem hiding this comment.
I feel like this would fail. While the variable is called rawJSON it is already parsed and an object when received through websockets.
Trying to parse a js object as JSON again will throw a syntax error.
That is entirely possible as they support multiple version of minecraft, if we are sure it is no longer used by newer versions of minecraft we can leave that field out I am not planning on figuring out support for older versions of minecraft. I'll have a proper look a bit later, on the face of it it seems fairly solid. Some things that do jump out:
|
|
Little bit of work todo It looks like |
|
Also going to be a bit real, I like code to be actually tested before a PR is made. Or have the PR marked as a draft if you haven't been able to test it. |
|
That's fair. I did test the PR. I did not see any errors when I tested. I do not have a good understanding of what cases to run through. |
Interesting, I just realized that this only happens in a game I am running locally. I did open it up to LAN so it acts as a server and the same still happens there.
At the very least the messages from above ;) I have also been using https://mcstacker.net/1.21.php to create |
|
So it looks like that in Minecraft's chat format, the elements in the |
I think that's an issue if:
|
|
Alright, did some testing and seems to work as expected now. |

Fixes #20
chat.mjswhere I thought we stored parsed messages