Jump to content

Syncing Player NBT To Client


Recommended Posts

I have itemstacks stored inside of the player's NBTTagCompound on the server side, but I want to render the items on the client side. As far as I know, the player's NBTTagCompound isn't synced automatically, so my issue is how to send the NBTTagCompound or ItemStacks to the client from the server.


I've tried looking online for solutions, but I only found articles regarding the old Packet system using CompressedStreamTools. I'm currently using the SimpleNetworkWrapper with classes implementing IMessage; is there anyway to input the ByteBuf as a stream object that can be used with CompressedStreamTools?


Another solution I tried was finding a way to compress an NBTTagCompound or a NonNullList into a byte array, but I haven't found any methods yet.


I'm not sure how to provide code for this, but here's how I'm storing the ItemStacks on the server:



        NBTTagCompound nbt = player.getEntityData();
        NBTTagCompound isNBT = nbt.getCompoundTag(QuickConsume.KEY);
        NonNullList<ItemStack> items = NonNullList.<ItemStack> withSize(3, ItemStack.EMPTY);
        ItemStackHelper.loadAllItems(isNBT, items);

        ItemStackHelper.saveAllItems(isNBT, items);
        nbt.setTag(QuickConsume.KEY, isNBT);

Edited by TLHPoE


Link to comment
Share on other sites

51 minutes ago, diesieben07 said:

First of all, stop using getEntityData. It has been replaced by  better system twice over already. First IExtendedEntityProperties, now capabilities.

Both allow you to actually store stuff attached to the player and don't force you to constantly serialize to and from NBT.

Ok, I've switched over to the capability system. Is there a way of synchronizing the capabilities with the client? It doesn't seem to at the moment.


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.

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.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.