Jump to content

[Solved] [1.10.2] Sending Packet When Attaching Capabilities


TheXFactor117

Recommended Posts

I'm trying to add a capability to entities (specific mobs) that gives them a certain level. I've got the capability working, everything works fine server-side, I just have to get this information to the player to render it on the screen whenever the player looks at the mob. The problem I'm having is getting this information to the player.

 

From what I can tell, the AttachCapabilitiesEvent is fired both client and server. Changing this to fire only on one side doesn't work, because the capability doesn't seem attached on the other side (or am I wrong because if I am this would likely fix my issue). I originally set the value of the level when attaching the capability, but I don't think I can do that because that's where I would need to send my packet. I've tried setting the level using EntityJoinWorldEvent and sending the packet from there, but the client doesn't get notified (according to the RenderGameOverlayEvent), yet the packet prints out the correct level on the client-side. This leads me to believe that the way I'm accessing the capability from RenderGameOverlayEvent isn't correct (I'm almost certain this is the problem now). In the end, I'm kind of just stuck, so any help is appreciated.

 

- AttachCapabilitiesEvent

- EntityJoinWorldEvent

- RenderGameOverlayEvent

 

If you need more code, everything should be accessible from GitHub.

Developer of Levels and Lost Eclipse

Link to comment
Share on other sites

PacketEnemyLevel

does absolutely nothing when it's received by the client, so the client-side

IEnemyLevel

instance is never updated.

 

You need to send the entity ID and the level in the packet, then retrieve the

Entity

with that ID from the client

World

and update its

IEnemyLevel

instance.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Note that you don't need to send the entity ID unless you also plan to send this packet to players other than the one updating the capability, i.e. if you are going to display this information to other players. Otherwise, the packet is already sent to the player which you can retrieve using the message context, so the entity ID is superfluous.

Link to comment
Share on other sites

Note that you don't need to send the entity ID unless you also plan to send this packet to players other than the one updating the capability, i.e. if you are going to display this information to other players. Otherwise, the packet is already sent to the player which you can retrieve using the message context, so the entity ID is superfluous.

 

The capability is for arbitrary mobs in the world, not players. The entity ID is required to determine which mob to update the data for.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

PlayerEvent.StartTracking

is probably a better event to use here. This will be fired when a player starts tracking the entity, after the entity's spawn packet has been sent to the client; so the entity will likely exist by the time your packet is received.

 

The entity will only exist on the clients of players close enough to it. If they're too far away or in another dimension, their clients won't know anything about it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.