Player NBT data is not server-client synced

Published by ahznb on
Status
Fixed
Issue description

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

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.

This fix would also address my issue with scoreboards not syncing so I really have to second this hard.

Entities in general are not the problem, only players are and this ticket is here for this exact reason

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)

PLAYER_PERSISTENT: client-server variable per player that is permanent for a player per map save

YEEEET :D I could finally work on Alloy and my thirst mod again :D

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.

It will be compatible, but cross-accessing is not possible at the moment due to the implementation details. One could copy data to NBT on the tick update of player to expose it as NBT to other mods.

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);
            }
        }
    }
}```

A code i use to sync it client side and server side is that

This will only work on SMP and will fail on multiplayer. You need to use networking and client packer handlers for this.

Use player variables as proposed by the ticket.

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

We can make any mods for multiplayer server

no NBT sync for block

 

how they marked it fixed??!!

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