Jump to content

[Solved + Explained] Sync Custom Client+Server Chest?


gokiburi

Recommended Posts

Edit + Explanation: Turns out you have to create and manage a packet with data to send to the client yourself.

 

As I was creating a chest that had individual stack sizes saved and loaded for use elsewhere, I wrote an NBTTagCompound that sent the information of the array:

Forge 4.2.5

@Override
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
for ( int i = 0; i < inv.length; i++ ){
	tag.setInteger("StackSize"+i, stackSize[i]);
}
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, tag);
}

 

Forge 4.1.1:

@Override
public Packet getAuxillaryInfoPacket()
{
NBTTagCompound tag = new NBTTagCompound();
for ( int i = 0; i < inv.length; i++ ){
	tag.setInteger("StackSize"+i, stackSize[i]);
}
return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, tag);
}

 

I also had to read that data and load it into the array:

 

@Override
public void onDataPacket(NetworkManager net, Packet132TileEntityData pkt)
{
NBTTagCompound tag = pkt.customParam1;
for ( int i = 0; i < inv.length; i++ ){
	stackSize[i] = tag.getInteger("StackSize"+i);
}
}

 

Using these functions, I was able to get the CLIENT chest reading the right value. I chose to send an Integer because this chest handles large values of items, not single stacks.

 

-- Original Post --

 

I've made a custom chest that stores a stackSize in a separate NBT tag from the normal itemStack tags.

I save and load the integer value successfully, but the CLIENT does not recognize this.

 

The readFromNBT event is thrown once, while during init the tileEntity is created multiple times, at least once for CLIENT and once for SERVER.

 

Apparently, CLIENT chests do not perform a readFromNBT function, and thus I can not load the value on the CLIENT chest.

Right now, I can take the item out, but the CLIENT returns a stack size of 0 while the SERVER returns a proper stack size.

 

Is it possible to make a CLIENT tileEntity call readFromNBT? If not, is there a recommended way to let my CLIENT tileEntity know what stackSize it should be using?

 

Below is the output from which I inferred my current situation (all I did was load the world, open the gui and click slot 1):

 

InfiniChest Init (Server Side?)
InfiniChest: Read from NBT (Size 32) [slot 1]
InfiniChest Init (Client Side?)
Taking out a 0 stack. (Client?)
New Stored Amount: 0.
Taking out a 32 stack. (Server?)
New Stored Amount: 0.

Link to comment
Share on other sites

Where does the getAuxillaryInfoPacket() function come from, i am trying to a similar thing but i don't know where to put that function, the onDataPacket(NetworkManager net, Packet132TileEntityData pkt) is in TileEntity, but no getAuxillaryInfoPacket()

 

In the latest Forge, the getAuxillaryInfoPacket function was renamed to getDescriptionPacket.

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
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.