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

Force Update Forge All modded Capabilities For EntityPlayer


jredfox
 Share

Recommended Posts

I have the EntityPlayerMP object and new nbt for the player how do I force update this player object I got with some capabilities I got from another nbttagcompound? I want all forge capabilities to update since player.readFromNBT() doesn't do it for me.

Edited by jredfox
Link to comment
Share on other sites

  • Replies 53
  • Created
  • Last Reply

Top Posters In This Topic

9 hours ago, diesieben07 said:

Oh god, not this again...

 

  • You most likely do not want NBT.
  • Yes, readFromNBT reads the capability data.

I want to swap players capabilities all of them between two players if you use a certain item. ForgeCaps where the capabilities are always stored doesn't seem to update the capabilities readFromNBT(). I tested it with a couple mods they don't seem to sync of course they had guis. Maybe it's because it was a slightly older version but, I think the same issue persists is there a way to get around it like manually firing Entity Construction event?

Note everything is done via the server side

Edited by jredfox
Link to comment
Share on other sites

2 hours ago, diesieben07 said:

No, there is no API to make mods re-sync their data to the client.

not asking for one what makes it update to begin with it has to know or they wouldn't appear on startup and the capabilities also wouldn't be registered.

It also is resisted on the server could I simply unregister and re-register all of them or better yet make the player a whole new entity player object?

Edited by jredfox
Link to comment
Share on other sites

2 hours ago, diesieben07 said:

Mods probably send their data during PlayerLoggedInEvent and similar.

ok so would firing that event cause issues if somehow the capabilities get registered twice?

 

I will try and mess with this a bit more what happens when the player is cloned does that update everything where is the code starting when the player is being cloned?

Edited by jredfox
Link to comment
Share on other sites

8 hours ago, jredfox said:

ok so would firing that event cause issues if somehow the capabilities get registered twice?

It will not cause capabilities to register twice (registration happens during AttachCapabilityEvent). However it will make all handlers fire, you will get all actions from mod that happen during player login. This is most likely not what you want.

 

8 hours ago, jredfox said:

I will try and mess with this a bit more what happens when the player is cloned does that update everything where is the code starting when the player is being cloned?

I have no idea what you are trying to say. Updates happen when the mods see the need for it. There is no common entry point to "update everything". No, you cannot bend over backwards and make it magically appear. What you want is not possible.

Link to comment
Share on other sites

46 minutes ago, diesieben07 said:

It will not cause capabilities to register twice (registration happens during AttachCapabilityEvent). However it will make all handlers fire, you will get all actions from mod that happen during player login. This is most likely not what you want.

 

I have no idea what you are trying to say. Updates happen when the mods see the need for it. There is no common entry point to "update everything". No, you cannot bend over backwards and make it magically appear. What you want is not possible.

well I needed it happen at x point there should be a method in forge like entities have readNBT() that's stupid if they never synced changes and never made a reset method or update all

Link to comment
Share on other sites

Misread the question

17 minutes ago, diesieben07 said:

I... what?

^^^ He makes a good point why would forge ever make something for you that you should make yourself by overriding about 3 methods?

 

You can have your tile entities extend a Base class that automagically handles this for you...

If this is what you would like, try looking at

https://www.programcreek.com/java-api-examples/?code=canitzp/Metalworks/Metalworks-master/src/main/java/de/canitzp/metalworks/machine/TileBase.java#

and

https://www.programcreek.com/java-api-examples/?code=canitzp/Metalworks/Metalworks-master/src/main/java/de/canitzp/metalworks/packet/PacketSyncTileEntity.java#

It automagically writes all your capabilities to NBT & syncs it every half second. 
I had quite a few problems with it (Not syncing even when explicitly told to, writing every face to NBT, syncing way too often). I've solved them so you might want to check out my implementation of it (my version can also write stuff other than caps to NBT)

 

My version of the Base tile class

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityBase.java

My Sync Packet class and my networking class

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/handler/network/PacketSyncTileEntity.java

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/handler/network/PacketHandler.java

2 classes that use it in my mod (Turbine is very simple, but only writes capabilities while Wire also writes "lastRecieved")

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityTurbine.java

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityWire.java

 

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

On 4/29/2018 at 4:34 AM, diesieben07 said:

Oh god, not this again...

 

  • You most likely do not want NBT.
  • Yes, readFromNBT reads the capability data.

ok then maybe the client isn't receiving the data. Does readEntityFromNBT() send a packet to the client maybe I need to create a packet to send to the client to update NBT? is there already a packet that does this?

 

I hope it's not the fact that the data doesn't change on the gui but, is changed on the capabilities so I can actually wip up a fix for mods with capabilities and guis

Edited by jredfox
Link to comment
Share on other sites

On 4/30/2018 at 4:37 AM, Cadiboo said:

Misread the question

^^^ He makes a good point why would forge ever make something for you that you should make yourself by overriding about 3 methods?

 

You can have your tile entities extend a Base class that automagically handles this for you...

If this is what you would like, try looking at

https://www.programcreek.com/java-api-examples/?code=canitzp/Metalworks/Metalworks-master/src/main/java/de/canitzp/metalworks/machine/TileBase.java#

and

https://www.programcreek.com/java-api-examples/?code=canitzp/Metalworks/Metalworks-master/src/main/java/de/canitzp/metalworks/packet/PacketSyncTileEntity.java#

It automagically writes all your capabilities to NBT & syncs it every half second. 
I had quite a few problems with it (Not syncing even when explicitly told to, writing every face to NBT, syncing way too often). I've solved them so you might want to check out my implementation of it (my version can also write stuff other than caps to NBT)

 

My version of the Base tile class

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityBase.java

My Sync Packet class and my networking class

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/handler/network/PacketSyncTileEntity.java

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/handler/network/PacketHandler.java

2 classes that use it in my mod (Turbine is very simple, but only writes capabilities while Wire also writes "lastRecieved")

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityTurbine.java

https://github.com/Cadiboo/WIPTech/blob/master/src/main/java/cadiboo/wiptech/tileentity/TileEntityWire.java

 

I don't want it syncing every second just when I want it updating and preferable the client isn't required server side mod only. What about a packet to readFromNBT() to the client and will that update the forge capabilities? So like a readFromNBT() packet to the client for capabilities only?

if you read it's not my object necessary it could be a player or another entity

stop with the crossing lines plz

Edited by jredfox
Link to comment
Share on other sites

1 hour ago, jredfox said:

ok then maybe the client isn't receiving the data. Does readEntityFromNBT() send a packet to the client maybe I need to create a packet to send to the client to update NBT? is there already a packet that does this?

None of this is the case. Reading from NBT does not send a packet.

And such a packet does not exist. Reading from NBT on the client is not what you want. What you want is not possible.

Link to comment
Share on other sites

46 minutes ago, diesieben07 said:

None of this is the case. Reading from NBT does not send a packet.

And such a packet does not exist. Reading from NBT on the client is not what you want. What you want is not possible.

well what I seen is there are two sides server and client both have nbt so if server has values updated and client does not then it should update capabilities on client side since they occur on both sides?

then what am I looking to do you said so yourself it should update capabilities data calling readFromNBT()

then why does the player inventory update when I say readFromNBT() on server and not capabilities that has to be client synced for the inventories what about capabilities. If it honestly isn't possible then this is a forge bug and should be reported since readFromNBT() should update data

Edited by jredfox
Link to comment
Share on other sites

11 minutes ago, jredfox said:

well what I seen is there are two sides server and client both have nbt so if server has values updated and client does not then it should update capabilities on client side since they occur on both sides?

This is not how NBT works.

NBT is a data serialization format. It is used for saving to disk. The client does not "have NBT" (neither does the server, but it at least uses it).

 

12 minutes ago, jredfox said:

then what am I looking to do you said so yourself it should update capabilities data calling readFromNBT()

It reads the server-side capability, yes.

 

12 minutes ago, jredfox said:

then why does the player inventory update when I say readFromNBT() on server and not capabilities that has to be client synced for the inventories what about capabilities.

The player inventory is constantly monitored by the game on the server side since it may change from certain events (e.g. you pick up an item) and synced if necessary. Not all capabilities do this, in fact most probably don't. This is fine, since there is no mechanism to "just update data of an entity". If you want to so, the best way is to kill the entity and spawn a new one.

 

13 minutes ago, jredfox said:

If it honestly isn't possible then this is a forge bug and should be reported since readFromNBT() should update data

readFromNBT is for when the entity is loaded from disk. You should not be calling it in the first place. This is not a bug. You are using things in ways they are not designed to be used.

"I used this screwdriver to polish my car, but it really didn't polish it. This screwdriver must be broken!"

Link to comment
Share on other sites

39 minutes ago, diesieben07 said:

This is not how NBT works.

NBT is a data serialization format. It is used for saving to disk. The client does not "have NBT" (neither does the server, but it at least uses it).

 

It reads the server-side capability, yes.

 

The player inventory is constantly monitored by the game on the server side since it may change from certain events (e.g. you pick up an item) and synced if necessary. Not all capabilities do this, in fact most probably don't. This is fine, since there is no mechanism to "just update data of an entity". If you want to so, the best way is to kill the entity and spawn a new one.

 

readFromNBT is for when the entity is loaded from disk. You should not be calling it in the first place. This is not a bug. You are using things in ways they are not designed to be used.

"I used this screwdriver to polish my car, but it really didn't polish it. This screwdriver must be broken!"

readFromNBT() does occur on client look at the code there is no file argument. readFromNBT() is simply to update variables there is no file argument. There are also client only variables written to nbt does it get saved ever I don't know. Look at player.writeToNBT() in console on client and server side there are a couple tags on client that are not on server.

Silkspawners main mechanic is to break block save it to stack (writeToNBT) and placeBlock(readFromNBT) both of which are never saved to the disk during that process until the itemstack or tile entity decides to save the data. The client even had to readFromNBT of the tile entity otherwise for a couple ticks it would display pig. Those methods are for saving .comparing, and manipulating data which means it's not always stored to the disk but, yes eventually that's it's main function is serialization with the exception of commands and mods that decide to do stuff to manipulate and update variables

you are talking about serialization methods yes those occur only from the disk and do call readFromNBT() after they get the nbt

Edited by jredfox
Link to comment
Share on other sites

"If you want to so, the best way is to kill the entity and spawn a new one."

Ok how do I do this make the player = new player and then tell client it's a new player then use it to update from the nbt I gathered from a file I serialized to nbt?

I heard something about player cloning how do I do this on command while still serializing from nbt?

Edited by jredfox
Link to comment
Share on other sites

35 minutes ago, jredfox said:

readFromNBT() does occur on client look at the code

Where? If you are so sure about it, post exact locations where the client calls it.

 

36 minutes ago, jredfox said:

there is no file argument

Wat? How is that relevant?

 

36 minutes ago, jredfox said:

readFromNBT() is simply to update variables there is no file argument. There are also client only variables written to nbt does it get saved ever I don't know. Look at player.writeToNBT() in console on client and server side there are a couple tags on client that are not on server.

This is complete bs. The client never saves an entity to NBT. Please clarify which client only variables you are talking about.

 

36 minutes ago, jredfox said:

The client even had to readFromNBT of the tile entity otherwise for a couple ticks it would display pig.

TileEntities are something else. They use (in vanilla, mods do not necessarily use this) NBT for syncing the data to the client. This is a completely separate process and does not use the same methods as saving to disk.

 

37 minutes ago, jredfox said:

Ok how do I do this make the player = new player and then tell client it's a new player then use it to update from the nbt I gathered from a file I serialized to nbt?

Regarding players you'd probably have to do some form of the respawning process. But this might make data disappear, since some mods will reset counters, stats, etc. on death/respawn.

 

Ultimately again: What you want is not possible, since there are no APIs for it. There is no concept of "apply new data to this entity" in Minecraft.

Link to comment
Share on other sites

11 minutes ago, diesieben07 said:

Where? If you are so sure about it, post exact locations where the client calls it.

 

Wat? How is that relevant?

 

This is complete bs. The client never saves an entity to NBT. Please clarify which client only variables you are talking about.

 

TileEntities are something else. They use (in vanilla, mods do not necessarily use this) NBT for syncing the data to the client. This is a completely separate process and does not use the same methods as saving to disk.

 

Regarding players you'd probably have to do some form of the respawning process. But this might make data disappear, since some mods will reset counters, stats, etc. on death/respawn.

 

Ultimately again: What you want is not possible, since there are no APIs for it. There is no concept of "apply new data to this entity" in Minecraft.

you said create a new one. How do I clone the player then with a different nbt then it's own and set it to be the new player for the client? Assuming I already set the uuid most and least from the current player?

Edited by jredfox
Link to comment
Share on other sites

Look at the respawning process for how to clone the player. Then deserialize the new instance from your modified NBT before fully respawning it.

It might work. It might break completely.

 

Also, please stop referring to things "having NBT". It is wildly inaccurate and conveys a wrong understanding about how all of this works.

Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Look at the respawning process for how to clone the player. Then deserialize the new instance from your modified NBT before fully respawning it.

It might work. It might break completely.

 

Also, please stop referring to things "having NBT". It is wildly inaccurate and conveys a wrong understanding about how all of this works.

Well the re spawn process doesn't even give out a new player I am pretty sure but, I will check it out. 

What about when the client logs onto the server and the entity is created there can that be hacked into giving out a new player from the old one? Where is that code located at?

Link to comment
Share on other sites

Just now, jredfox said:

Well the re spawn process doesn't even give out a new player I am pretty sure but, I will check it out. 

Yes, it does. This is why PlayerEvent.Clone exists.

 

Just now, jredfox said:

What about when the client logs onto the server and the entity is created there can that be hacked into giving out a new player from the old one? Where is that code located at?

We already had this. It would trigger everything that happens on login, such as welcome messages, login stats, etc.

Link to comment
Share on other sites

6 minutes ago, diesieben07 said:

Yes, it does. This is why PlayerEvent.Clone exists.

 

We already had this. It would trigger everything that happens on login, such as welcome messages, login stats, etc.

Well I could simply look at the logic and not fire the forge events so the messages don't appear and manually handle the capabilities

the player event clone exists but, I have no clue when it's fired? I believe I tried dying before and it didn't fire let me check

Edited by jredfox
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 Privacy Policy.