Jump to content

Help retrieving server packet information from static event handler


Turtledove

Recommended Posts

I'm overriding vanilla sword behavior, such that the player cannot swing their sword unless a certain amount of ticks have passed, which is determined by logic done on the server. I've got everything already setup, and the packets are successfully sent to client. However, I'm not sure how to retrieve this information within my input handler class's static mouse event, from my message handler. Is there a better way of doing this than creating a static member variable inside the event handler class?

Link to comment
Share on other sites

24 minutes ago, Turtledove said:

I'm overriding vanilla sword behavior, such that the player cannot swing their sword unless a certain amount of ticks have passed, which is determined by logic done on the server. I've got everything already setup, and the packets are successfully sent to client. However, I'm not sure how to retrieve this information within my input handler class's static mouse event, from my message handler. Is there a better way of doing this than creating a static member variable inside the event handler class?

Don't create a static variable. Use a capability to keep track of the cooldown per player.

Link to comment
Share on other sites

Just now, kaydogz said:

Don't create a static variable. Use a capability to keep track of the cooldown per player.

I already have the cooldown set up as a capability serverside with IPlayerData, which is also where it's incremented every tick. In my server to client message handler, do I just set that variable in the same class (but on the client) and access it as normal in the event handling method? So I guess in that case there'd be a server and client version of my IPlayerData running at the same time, correct?

Link to comment
Share on other sites

48 minutes ago, Turtledove said:

I already have the cooldown set up as a capability serverside with IPlayerData, which is also where it's incremented every tick. In my server to client message handler, do I just set that variable in the same class (but on the client) and access it as normal in the event handling method? So I guess in that case there'd be a server and client version of my IPlayerData running at the same time, correct?

Yes and remember you need to sync the values on each side.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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