Currently when one sets a custom NBT tag it is set on one side only. It would be nice if it can be auto set on both sides if requested by the modder (maybe as a function block?)
Issue comments
Duplicate: https://mcreator.net/tracker/issue/57476
This feature will be added in 2020.4. As syncing is only problematic with players as they need data on client-side for display, a different approach was taken.
There are now two new global variable types: PLAYER_LIFETIME and PLAYER_PERSISTENT
There two variable types can be used with normal variable procedures and in UIs. Their scope is:
- PLAYER_LIFETIME: client-server variable per player for the time of his lifetime (variables reset on death)
- PLAYER_PERSISTENT: client-server variable per player that is permanent for a player per map save
Marking as fixed.
ALELOUYA! All the love of the world for you! However, I hope we will be able to create new variables as with NBT tags. I mean, with NBT Tags we can create a new one in changing the name, and we can do this by using another variable. So it will be nie to have the same thing for Global variables (otherwise, my camera mod won't work 😢).
Yay it was added! (Wait, Does this work for all players or just one? Sorry I don't know how nbt data works)
Per player, this system uses the Forge capability system and attaches new "variable" capability to the player.
I hope we will be able to create new variables as with NBT tags. I mean, with NBT Tags we can create a new one in changing the name, and we can do this by using another variable.
This is the reason why I could not make this work with NBT. This system uses Forge capability system and serializes each variable separately. If I would just serialize all NBT tags to support all cases, not just specifically defined tasks, this would overload network communication and also introduce potential problems.
So only variables defined at compile time can be synced to the client.
A code i use to sync it client side and server side is that
```}
}
private int serverMana = 0;
@SubscribeEvent
public void playerTick(TickEvent.PlayerTickEvent event)
{
if (!event.player.world.isRemote)
{
serverMana = event.player.getPersistentData().getInt("PlayerMana");
}
else {
if (serverMana != 0) {
event.player.getPersistentData().putInt("PlayerMana", serverMana);
}
}
}
}```
Hey , its been a while :)
I still have a problem with the NBT Tags. I understand that instead of using NBT tags for players, it´s better to use global variables like player_persistent.
But in my case I give a nonstackable item some NBT tags because this item is supposed to store certain information. (no player should have these information, only the item - respectively the player transfers these information onto the item so the player doesnt have them anymore).
The problem on multiplayer here, however, is that it is still not synchronized with the server. Is there a way to bypass this?
Something like a global Item_persistent variable xD ?
It would help me very much! Thank you! <3
This issue remains with item nbt, is there a way to implement a new variable set for items? number and logic being the most important in my opinion but string can be very useful aswell, as for some reason my nbt variables do not apply to items, for exmaple i have a block that applies an nbt string tag to any item inserted and modified using a button that triggers the procedure, but when i check the nbt (returning it to a chat message) the string shows empty. I hope that can be worked on, i tried everything to make it work but with no luck
Syncing data is more advanced than just a simple procedure block as we need to use packets and this is not really possible to implement universally for all use cases.
For overlays, we can add a way to obtain player NBT data, though, I am changing the ticket to this as this could be implemented.
So the overlay would query entity NBT data from the server-side and display it on the client-side.