Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • how ContainerScreen get data from Container
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 0
nooblong

how ContainerScreen get data from Container

By nooblong, November 24, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

nooblong    0

nooblong

nooblong    0

  • Tree Puncher
  • nooblong
  • Members
  • 0
  • 9 posts
Posted November 24, 2020

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

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7597

diesieben07

diesieben07    7597

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7597
  • 55122 posts
Posted November 24, 2020

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.

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    819

TheGreyGhost

TheGreyGhost    819

  • Reality Controller
  • TheGreyGhost
  • Members
  • 819
  • 3280 posts
Posted November 24, 2020
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

 

 

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    819

TheGreyGhost

TheGreyGhost    819

  • Reality Controller
  • TheGreyGhost
  • Members
  • 819
  • 3280 posts
Posted November 24, 2020
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

 

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7597

diesieben07

diesieben07    7597

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7597
  • 55122 posts
Posted November 24, 2020
2 hours ago, TheGreyGhost said:

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.  

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

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7597

diesieben07

diesieben07    7597

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7597
  • 55122 posts
Posted November 24, 2020
2 hours ago, TheGreyGhost said:

The synchronisation is always from server container to server inventory then to client inventory. 

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

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    819

TheGreyGhost

TheGreyGhost    819

  • Reality Controller
  • TheGreyGhost
  • Members
  • 819
  • 3280 posts
Posted November 25, 2020

 

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

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7597

diesieben07

diesieben07    7597

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7597
  • 55122 posts
Posted November 25, 2020
7 hours ago, TheGreyGhost said:

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.

On initial chunk load they are - yes. But that's just because vanilla's TileEntity#getUpdateTag default implementation is franky terrible and sends way too much data.

The contents of a container are synced through SWindowItems (sent when the container is opened) and SSetSlotPacket (when a change is detected). The Slots then write-through directly to the underlying inventory.

 

7 hours ago, TheGreyGhost said:

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.

2 and 3 depends. Vanilla does it this way for many inventory. However this is not at all required. The client can receive additional info in it's "open GUI" packet and use the inventory from the tile entity, entity, or whatever. And that is what I've seen any mod I have looked at do.

  • Quote

Share this post


Link to post
Share on other sites

TheGreyGhost    819

TheGreyGhost

TheGreyGhost    819

  • Reality Controller
  • TheGreyGhost
  • Members
  • 819
  • 3280 posts
Posted November 25, 2020

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

 

 

 

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7597

diesieben07

diesieben07    7597

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7597
  • 55122 posts
Posted November 25, 2020
15 minutes ago, TheGreyGhost said:

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.

Dirtying the entity (markDirty) does not send the update packet. Only a full block update will send it, or you can send it manually.

 

And yes, in my opinion the update packet (and update tag - there are actually two syncing mechanisms for tile entities, one for the initial chunk load and one for later updates) should not contain the full TE NBT, instead they should contain specialized data for what is needed on the client.

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 0
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • DaemonUmbra
      I just started modding minecraft and I thought i had finished modding it but Titanium mod isn't loading properly. Can someone help me fix this?

      By DaemonUmbra · Posted 2 minutes ago

      Please read the error...
    • DaemonUmbra
      HELP! WORLD WONT WORK

      By DaemonUmbra · Posted 3 minutes ago

      I told you to delete a file in the save, not the save itself Go into the save and delete forge-server.toml from serverconfig
    • Gubipe
      Minecraft.getMinecraft().thePlayer.swingItem(); wont attack

      By Gubipe · Posted 1 hour ago

      I am making the two mods with the same functionality. One is 1.16.4 and the other is 1.8.9. The current one is 1.8.9 and then I shall try to port it over to 1.16.4
    • poopoodice
      Minecraft.getMinecraft().thePlayer.swingItem(); wont attack

      By poopoodice · Posted 1 hour ago

      It's for animation only. Btw what version are you using?
    • TheDonkey_King
      I just started modding minecraft and I thought i had finished modding it but Titanium mod isn't loading properly. Can someone help me fix this?

      By TheDonkey_King · Posted 1 hour ago

      What file?
  • Topics

    • TheDonkey_King
      5
      I just started modding minecraft and I thought i had finished modding it but Titanium mod isn't loading properly. Can someone help me fix this?

      By TheDonkey_King
      Started 7 hours ago

    • BIGDog8808
      11
      HELP! WORLD WONT WORK

      By BIGDog8808
      Started 8 hours ago

    • Gubipe
      2
      Minecraft.getMinecraft().thePlayer.swingItem(); wont attack

      By Gubipe
      Started 3 hours ago

    • mightymoy
      8
      Cant craft items in modded server

      By mightymoy
      Started Yesterday at 03:00 AM

    • tinyborisYT
      2
      [1.12.2] Crash at Launch, No clue why

      By tinyborisYT
      Started 3 hours ago

  • Who's Online (See full list)

    • DaemonUmbra
    • TheDonkey_King
    • LK1905
    • RafaMv
    • CandyDino76
    • Choonster
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • how ContainerScreen get data from Container
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community