Jump to content

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


Recommended Posts

Posted

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.

Posted

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()

Posted

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.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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