Jump to content

[SOLVED] [1.12.2] GUI for showing custom player capabilities not updating


Recommended Posts

Posted (edited)

I am making a mod where I need to show a GUI on the player's screen showing their current mana/max mana. The problem is, even if the values update, the GUI doesn't, it just shows the default values. I'm new to 1.12.2 modding, so I don't really know what might be causing it. Help would be greatly appreciated.

 

GUI class:

  Reveal hidden contents

 

Mana class:

  Reveal hidden contents

 

IMana interface:

  Reveal hidden contents

 

CapabilityMana class:

  Reveal hidden contents

 

CapabilityProviderSerializable class:

  Reveal hidden contents

 

CapabilityProviderSimple class:

  Reveal hidden contents

 

CapabilityUtils class:

  Reveal hidden contents

 

InjectionUtils class:

  Reveal hidden contents

 

Edited by FlashHUN
marked as solved
Posted
  On 2/28/2019 at 8:00 PM, diesieben07 said:
  • For the future, please use code blocks for posting your code. It's almost unreadable otherwise.
  • Your CapabilityUtils.getCapability method is useless. Just call getCapability. There is no point in calling hasCapability beforehand to check.
  • You are most likely updating the values on the server side, as you should. But then you are not notifying the client of these changes.
    You have to send a packet updating the client capability under the following circumstances:
    • PlayerLoggedInEvent
    • PlayerChangedDimensionEvent
    • PlayerRespawnEvent
    • Whenever the data changes
  • If you do not plan on exposing your capability as an API for other mods, there is no point writing an interface for it. You can just use your implementation class and avoid the indirection and extra code.
  • PlayerTickEvent fires twice per tick. Check TickEvent#phase.
Expand  

 

I understand what I need to do and the basics of how I need to do it, but I cannot make it work. How can I make a packet that gets data from the

CapabilityMana

class (I'm guessing?) and sends it to the client through the PacketHandler? I know how to set up a PacketHandler, I just never really worked with packets and player nbt before and this is what's getting me stuck.

Also, is there any way to detect the data changing automatically instead of having to flood classes that change a lot of things with sending packets when changing?

Posted
  On 3/1/2019 at 7:51 AM, diesieben07 said:

Not sure where you got NBT from. NBT is usually used for saving to disk. You have to write the data in your capability to the buffer provided to you in your IMessage.

Expand  

Like I said, I haven't really worked with the newer versions, but thanks for clarifying. I cannot seem to figure out what is wrong though. I haven't found any examples that I could learn how to do it from and I don't seem to be capable of doing it without one. I never really worked with packets before and it just seems like a lot at first.

 

 

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.