InventivetalentDev / GlowAPI

MIT License
58 stars 35 forks source link

The Crouch Mystery #127

Closed iHDeveloper closed 2 years ago

iHDeveloper commented 2 years ago

A mystery that awaits us

It took about a week to figure out and solve the issue, probably @InventivetalentDev would have resolved it faster and quicker, but it was fun to solve for me. :)

Description

It appears that when the player sneaks/crouches in 1.19+. The glow around the player vanishes sadly.

Cause

After doing a deep investigation into NMS. I reached to this analysis provided in the picture below.

glow-api-analysis Analysis of outgoing packets from the server to the target (player)

It appears that when the player sneaks (crouches) a metadata packet is sent with the sneaking flag enabled (and without the glow flag enabled as expected). What's interesting here is that the sneaking flag is stored in the ENTITY_SHARED_FLAGS data watcher object. (are we expecting many entities being able to sneak? I don't really know. It will be fun to see though. lol)

This metadata packet is sent from an update players function that gets triggered from PlayerChunkMap tick method. The entity tracker gets called (by the update players function) and sends to the player the metadata packet of its new state.

Screenshots

player-standing-with-glow

player-sneaking-with-glow

Solution

We inject a packet handler using PacketListenerAPI to catch any metadata packet with the interested data watcher object (ENTITY_SHARED_FLAGS).

Then, we compare the glow data between the player who receives the packet and the entity thats the target of the glow flag in the metadata packet. We modify the packet when one of the parties are registered in the GlowAPI. If not, we just ignore the packet and proceed to listen to other packets.

Note: I added a map to register the entity unique id (UUID) by the entity id. It helps to avoid the async access to Bukkit/CraftBukkit APIs. And, it provides easy access in general. When the entity id is not found we just ignore modifying the packet in general.

Additional Fixes

Notes

References

TherealB9B commented 2 years ago

Also does this fix the glow vanishing with sprinting? Iirc it goes away while sprinting too and idk anything about github stuff so is this fix already in any jar file that works on 1.19.2?

iHDeveloper commented 2 years ago

Also does this fix the glow vanishing with sprinting? Iirc it goes away while sprinting too and idk anything about github stuff so is this fix already in any jar file that works on 1.19.2?

Picture the PR as installing a body guard that make sure that every party involved with GlowAPI has the right glow information. This body guard will ignore anything unrelated to GlowAPI. So, anything like spiriting or sneaking will not matter as much as long as this body guard is making sure the right glow information is given to the right players/entities.

Basically, it will also fix the sprinting issue. :)

TherealB9B commented 2 years ago

Also does this fix the glow vanishing with sprinting? Iirc it goes away while sprinting too and idk anything about github stuff so is this fix already in any jar file that works on 1.19.2?

Picture the PR as installing a body guard that make sure that every party involved with GlowAPI has the right glow information. This body guard will ignore anything unrelated to GlowAPI. So, anything like spiriting or sneaking will not matter as much as long as this body guard is making sure the right glow information is given to the right players/entities.

Basically, it will also fix the sprinting issue. :)

Great! But wdym with the first part?

iHDeveloper commented 2 years ago

Basically it makes sure that the correct glow information provided by the GlowAPI is already sent to the player

TherealB9B commented 2 years ago

Basically it makes sure that the correct glow information provided by the GlowAPI is already sent to the player

Ah okay. So will the fix be in the next update/jar of glowapi?

iHDeveloper commented 2 years ago

That I leave to Inventivetalent. She can review it whenever she wants. After all, she is the expert. No need for rushing :)

TherealB9B commented 2 years ago

That I leave to Inventivetalent. She can review it whenever she wants. After all, she is the expert. No need for rushing :)

Yeah I understand. Sorry if it sounded like I was rushing/pushing anyone btw. I was just curious haha

iHDeveloper commented 2 years ago

It's okay. I was just answering your question. If you have any about the PR, you can ask them here.

iHDeveloper commented 2 years ago

This PR will also solve the new issued issue #128 due to the solution being at the packet level (Supposing the entity will not show unless with a packet that shows it and a metadata that describes it).

Note: This is purely speculative analysis. I didn't give it a test. But, I will soon :)

srnyx commented 2 years ago

This PR will also solve the new issued issue #128 due to the solution being at the packet level (Supposing the entity will not show unless with a packet that shows it and a metadata that describes it).

Note: This is purely speculative analysis. I didn't give it a test. But, I will soon :)

Yep, looks to fixed, thank you! @InventivetalentDev

srnyx commented 2 years ago

Although... I think it broke color codes somehow (it only started doing this when I started using this GlowAPI PR): image

InventivetalentDev commented 2 years ago

@srnyx I don't see anything that would break color codes specifically, maybe there's something else interfering with it?
I'll also go ahead and redirect your thanks to @iHDeveloper, he put all the work into this! ^^