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

Sending Packets? #202

Closed
Terrails opened this issue Feb 23, 2017 · 7 comments
Closed

Sending Packets? #202

Terrails opened this issue Feb 23, 2017 · 7 comments

Comments

@Terrails
Copy link

How should I send a packet with a thirst level to the client. People requested to I add a feature to keep thirst on death in my mod, but I'm having problems with syncing client and server. 40% of time when you die thirst has a visual bug where its full until I update it with losing or gaining it. I saw to you use write NBT in your ThirstHandler and read it in MessageUpdateStat but is there a way to I just send the thirst level without implemeting IThirst?

@Adubbz
Copy link
Member

Adubbz commented Feb 23, 2017

Thirst data is intended to be read/written using ThirstHelper. I'm not sure why you'd need to handle sending data yourself, something like this should suffice:

IThirst thirstData = ThirstHelper.getThirstData(player);
thirstData.setThirst(whatever);

@Terrails
Copy link
Author

Terrails commented Feb 23, 2017

Doesn't help... I'm not sure what the problem is.
My thirst is 19 and I can drink water but every time I die there is a chance to my bar gets full like this (You can see to something Overrides it and gets it to full):
ezgif-1-92c1d94879
This is the code I use
https://github.com/Terrails/KeepHunger/blob/master/src/main/java/terrails/keephunger/event/TANEvent.java#L57

@Adubbz
Copy link
Member

Adubbz commented Feb 23, 2017

You should be using the player clone event to do that, by the time the spawn event is fired the new player has already been created and the values have been reset

@Terrails
Copy link
Author

Still doesn't work... I'm not sure what's happening, I tried removing my entityPlayer.setThirst and only using the thirstData.setThirst.
https://github.com/Terrails/KeepHunger/blob/master/src/main/java/terrails/keephunger/event/TANEvent.java#L30

@Adubbz
Copy link
Member

Adubbz commented Feb 24, 2017

Looking into it now, the change packet is actually received by the client, however sometimes at the time of receiving it Minecraft.getMinecraft().player still refers to the player that has just died, meaning no change actually ends up occurring. Seems like it's some sort of timing issue. I'd imagine if you kept track of the newly respawned player entity and then perform the update on the first PlayerTickEvent it'd work correctly.

I'll keep digging and see what I can find, however the above would work as a workaround

@Adubbz
Copy link
Member

Adubbz commented Feb 24, 2017

Looking at the code I'm not sure I see any alternative ways of implementing it on our side to work around the issue. Essentially all you'd need to do is add the player to some sort of 'need to update' list, save their previous thirst value, and then update it during the PlayerTickEvent respawn event as suggested earlier using ThirstHelper

EDIT: Updated to include diesieben's suggestion

@diesieben07
Copy link

The timing issue is because you do are trying to send packets in the clone event, which is not guaranteed to work, like you discovered. You have to delay the syncing until the respawn event. Just sending the data always in respawn event should not hurt anyone.

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

3 participants