Jump to content

Recommended Posts

Posted

I storge data in an item's nbt, how can i get these data in the ContainerScreen and storge data into item's nbt again.

ReadMeFlowerBagDataFlow.thumb.png.9ae2b073d9f2b9f6a3e94406c0017f61.png

i have no idea how to communicate between client's screen and container.

My purpose is to save different data for different item and show them on gui

Posted
3 hours ago, diesieben07 said:

Show your code. I don't know why you put "Note! No linkage here!" there. There should be a linkage - if there isn't, it is a bug in your code.

Hi DieSieben

That diagram is for an ItemStack which has an inventory of other ItemStacks (held in an Item_Handler_Capability) 

 

There is no client side link between the Client ItemStack and the inventory contents of the Client Container.  If I recall correctly the Client ItemStack doesn't even get a copy of the server's ItemStackHandler unless you manually synchronise it.  

 

The equivalent diagram for TileEntity might be a bit clearer what the intent is, ie that the client side container is initialised with empty inventory that is not linked to the client-side inventory.  The synchronisation is always from server container to server inventory then to client inventory.  If you try to link the client-side container to the client-side inventory, you get two different synchronisation methods fighting with each other (quite noticeable when there is a bit of lag).

 

-TGG

image.thumb.png.9e8ffb233de323d814a950bfbf940945.png

 

 

Posted
4 hours ago, nooblong said:

I storge data in an item's nbt, how can i get these data in the ContainerScreen and storge data into item's nbt again.

ReadMeFlowerBagDataFlow.thumb.png.9ae2b073d9f2b9f6a3e94406c0017f61.png

i have no idea how to communicate between client's screen and container.

My purpose is to save different data for different item and show them on gui

Do you just want your ContainerScreen to read the NBT for an item?  That should be automatically transmitted to the client container, assuming you have set the NBT properly.  Your ContainerScreen should be able to just read the tag for the ItemStack.

Or do you mean - you want your screen to be able to modify the nbt for an item?

If so - your Screen will need to send custom packets to the server.  Have a look at the vanilla code for Screens, how they drag ItemStacks from one slot to another.  Basically, the screen sends a packet back to the server saying "drag the ItemStack from slot X to slot Y".

In your case - your Screen will need to send a packet to the server that says "Change the NBT for the ItemStack in slot X for the currently open container", and you will need a packet handler on the server that makes the corresponding modification to the ItemStack in the Server Container.

 

-TGG

 

 

Posted

 

8 hours ago, diesieben07 said:

This is the case for all inventories. This synchronization happens by the Container.

Are you sure?  Last time I checked (admittedly a few versions ago now), many of the client Inventories appear to be synchronised using NBT packets for their inventory contents even when there is no open container.

  

8 hours ago, diesieben07 said:

What? The container itself does not store items, at all. It only delegates to the inventory - on both server and client.

Based on my testing (from a few versions ago I admit), there are three inventories; one on the server and two on the client.

Using TileEntity as an example:

1a) The Server TileEntity has(is) an inventory.

1b) The Server Container gets a reference to that Inventory.

2) The Client TileEntity has(is) an inventory.  It is synchronised to the Server TileEntity via the usual packets for TileEntities.  It is not used by the Client Container.

3) The Client Container creates an empty Inventory which is then synchronised to the Server Container's referenced inventory using the Container packets.

 

If you're sure that's not right, I will spend some time testing it on vanilla to see what's actually happening.

 

Cheers

  TGG

 

Posted

OK, so if I understand you correctly, your point is that the client TileEntity has an Inventory but it's actually useless.  You can sync it if you like, and vanilla sometimes does, but it's not used for anything.

When the player opens a container, the client container gets a temporary inventory which is synched with the server via the container, not via the tileentity.  Vanilla usually creates a new temporary inventory, but if the mod wants to use the useless client inventory in the TileEntity instead of creating a new temporary inventory, it may as well.

 

When I tried it that way in 1.12.2 it led to occasional random visual glitches under stress testing.  The problem was particularly noticeable for TrackedInts being stored in the TileEntity (for example - the furnace burn progress would jump back and forth because it was being updated simultaneously by the GUI (container) packets and the TileEntity update packets), but also occasionally occurred for items in the inventory.  However if you don't dirty the server TileEntity, or the TileEntity update packets do not synch the inventory (for example you are using a Capability), then I imagine it's not a problem.

 

I can't think of any reason a client TileEntity would need to know the contents of the Inventory, unless it is changing its rendering like the campfire does.  In which case using the client tileentity as the container inventory would be a bad idea, i.e. because the tile entity update packets and the container modifications would clash with each other.  The worst symptom would be visual glitches I imagine.

 

-TGG

 

 

 

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



×
×
  • Create New...

Important Information

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