Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.19] Creating new Packet


Zanckor
 Share

Recommended Posts

Posted (edited)

Okay, its done, but, when I want to regen my Ki, it still not working cause it is on PlayerTickEvent.

 

I've upload my new code to github

 

Btw, my code is a bit ugly cause I'm just testing

Edited by Zanckor
Link to comment
Share on other sites

59 minutes ago, Zanckor said:

it still not working cause it is on PlayerTickEvent

is the EventHandler called?
are the values correctly calculated and updated in your Capability?
use debbuger to check

Link to comment
Share on other sites

1 minute ago, Zanckor said:

So, i need to call this custom packet on ServerTickEvent, but this dont will lag player?

you can regenderate your Ki on server and client, if the Ki is fully regenderate on server send a Packet to the client which makes sure the values are the same
but this means you have to check whenever the client whats to call a action if the Ki value does match with the server on

and yeah you should avoid sending Packets each tick

Link to comment
Share on other sites

Wait a second xD, so, i need to put my regen code on server side, and then sync it from server to client, arent?

But, I still dont know how to put this code on server side, i mean, if i put it on ServerTickEvent i cant put (Player player = e.getPlayer), so, how server know to which player is this info

Link to comment
Share on other sites

30 minutes ago, Zanckor said:

But, I still dont know how to put this code on server side, i mean, if i put it on ServerTickEvent i cant put (Player player = e.getPlayer), so, how server know to which player is this info

check if the player of the Event is an instance of ServerPlayer

Link to comment
Share on other sites

Posted (edited)

Okay, so, i should do something like, if(player instanceof ServerPlayer){ RegenCode } and, if(player instanceof Player) { RegenCode }, but when, on server side, Current Ki is full, 0, or whatever i want, send a packet to check if both values are the same, and if not change client value

 

Edit: Okay, i realized that its better just make it server side, and whenever i need to use it, like, before attacking with ki, send a packet to sync it

Edited by Zanckor
Link to comment
Share on other sites

1 hour ago, Zanckor said:

Okay, so, i should do something like, if(player instanceof ServerPlayer){ RegenCode } and, if(player instanceof Player) { RegenCode }, but when, on server side, Current Ki is full, 0, or whatever i want, send a packet to check if both values are the same, and if not change client value

Edit: Okay, i realized that its better just make it server side, and whenever i need to use it, like, before attacking with ki, send a packet to sync it

logic like this should always be done on server and only sync it to the client if it is necessary

Link to comment
Share on other sites

  • 2 weeks later...

you sending the Packet from client to sever, this means you can not do this in your handle method

Player player = (Player) Minecraft.getInstance().getCameraEntity();

you should use the player from the Context (Context#getSender)

why did you return a boolean from the handle method?

  • Thanks 1
Link to comment
Share on other sites

9 minutes ago, Luis_ST said:

why did you return a boolean from the handle method?

I've seen it on another packet, so i thougth it should be a boolean method, but can it be public void handle?

Link to comment
Share on other sites

12 hours ago, Luis_ST said:

why did you return a boolean from the handle method?

The consumer for SimpleChannel can be both a BiConsumer or a ToBooleanBiFunction. In the latter case the boolean return value will be used for NetworkEvent.Context#setPacketHandled, which otherwise you'd have to call manually.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.