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
  • Syncing Tile Entity with GUI
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
McJty

Syncing Tile Entity with GUI

By McJty, September 2, 2014 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

McJty    2

McJty

McJty    2

  • Creeper Killer
  • McJty
  • Members
  • 2
  • 129 posts
Posted September 2, 2014

For 1.7.10.

 

I'm making a block that supports RF and implements IEnergyHandler. The block also has a GUI. When the GUI is open I want the GUI to automatically show the current RF in the block but it isn't updating automatically because the client side tileentity doesn't seem to be updated. How can I properly get the GUI to update the RF in real time?

 

I have a Container for my tile entity.

 

Thanks

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7594

diesieben07

diesieben07    7594

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7594
  • 55068 posts
Posted September 2, 2014

Look at ContainerFurnace, it has an example on how to synchronize numbers from the server to the client.

  • Quote

Share this post


Link to post
Share on other sites

Jwosty    9

Jwosty

Jwosty    9

  • Creeper Killer
  • Jwosty
  • Forge Modder
  • 9
  • 128 posts
Posted September 2, 2014

Use world.markBlockForUpdate on the server to, well, re-send the block and it's tile entity to every client.

  • Quote

I like to make mods, just like you. Here's one worth checking out

Share this post


Link to post
Share on other sites

diesieben07    7594

diesieben07

diesieben07    7594

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7594
  • 55068 posts
Posted September 2, 2014

Use world.markBlockForUpdate on the server to, well, re-send the block and it's tile entity to every client.

That alone doesn't update anything on the client.
  • Quote

Share this post


Link to post
Share on other sites

McJty    2

McJty

McJty    2

  • Creeper Killer
  • McJty
  • Members
  • 2
  • 129 posts
Posted September 3, 2014

Ok, I have examined the furnace code a bit and I think it does something fundamentally different from what I have been to do in tutorials. First I see that the important parts in the ContainerFurnace code that handle synchronizing the GUI have to do with ContainerFurnace.detectAndSendChanges() and also addCraftingToCrafters(). These functions basically update various variables (like furnaceCookTime, lastCookTime and so on) in the TileEntityFurnace instance. I assume they are updating the server side version of this tile entity there.

 

Then in GuiFurnace these tile entity variables are used to display the progress. Here is the source of my confusion. The way I do GUI's the tile entity instances on client side are different (copies?) from the tile entities on the server so when I change status variables in the server version they are not automatically synced to the tile entity that the GUI is currently looking at. Apparently this is not the case for how the furnace works.

 

So I decided to have a look on how the GUI is actually opened and found out this code (last parameter is the tile entity):

 

this.mc.displayGuiScreen(new GuiFurnace(this.inventory, p_146101_1_));

 

This is called from within BlockFurnace.onBlockActivated() when world.isRemote is false (so that means it is called on the server). Of course that way the GuiFurnace() instance is allocated with a reference to the server version of the tile entity. That way the GUI can correctly see all changes to that tile entity.

 

So now I'm wondering if I'm doing GUI's the wrong way. In my way of doing things (which I got from various tutorials on the web) I have a GuiProxy class which basically has this code:

 

    public Object getServerGuiElement(int guiid, EntityPlayer entityPlayer, World world, int x, int y, int z) {
        if (guiid == RFTools.GUI_CRAFTER) {
            TileEntity te = world.getTileEntity(x, y, z);
            if (te instanceof CrafterBlockTileEntity) {
                CrafterBlockTileEntity crafterBlockTileEntity = (CrafterBlockTileEntity) te;
                return new CrafterContainer(entityPlayer, crafterBlockTileEntity, 0, 0);
            }
        }
        return null;
    }

    @Override
    public Object getClientGuiElement(int guiid, EntityPlayer entityPlayer, World world, int x, int y, int z) {
        if (guiid == RFTools.GUI_CRAFTER) {
            TileEntity te = world.getTileEntity(x, y, z);
            if (te instanceof CrafterBlockTileEntity) {
                CrafterBlockTileEntity crafterBlockTileEntity = (CrafterBlockTileEntity) te;
                CrafterContainer testContainer = new CrafterContainer(entityPlayer, crafterBlockTileEntity, 256, 184);
                return new GuiCrafter(crafterBlockTileEntity, testContainer);
            }
        }
        return null;
    }

 

So my GuiCrafter class is instantiated on the client side with a client version of the tile entity.

 

Am I doing my GUI's wrong?

 

Thanks!

  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7594

diesieben07

diesieben07    7594

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7594
  • 55068 posts
Posted September 3, 2014

You have a bit of a misunderstanding there. BlockFurnace calls func_146101_a on the EntityPlayer instance, when it's activated on the serverside. On the serverside that player is actually an EntityPlayerMP though, which overrides this method to send a packet. The other version (in EntityPlayer) is just a relict from when Minecraft had 2 different codepaths for Singleplayer and Multiplayer.

 

What ContainerFurnace updates is actually the client-side TileEntity. detectAndSendChanges is called on the server, every tick. If one of the "watched" fields have changed since the last tick, sendProgressBarUpdate is called on the ICrafting (which is actually an EntityPlayerMP and ICrafting should better be called something like InventoryListener). That sends a Packet from the server to the client with the new value. That new value is then (on the client!) passed to updateProgressBar which sets the values on the TileEntity (again: on the client).

  • Quote

Share this post


Link to post
Share on other sites

McJty    2

McJty

McJty    2

  • Creeper Killer
  • McJty
  • Members
  • 2
  • 129 posts
Posted September 3, 2014

Thanks! That was the explanation I was looking for. Now it works!

  • 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 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • dotifo7120
      Do stuff right after login

      By dotifo7120 · Posted 29 minutes ago

      Thank you, works fine 🤗
    • diesieben07
      Do stuff right after login

      By diesieben07 · Posted 44 minutes ago

      Yes, it is server side only. For client-side you can use ClientPlayerNetworkEvent.LoggedInEvent.
    • dotifo7120
      Do stuff right after login

      By dotifo7120 · Posted 49 minutes ago

      Is it only server-side? I tried to use in client and the event wasn't firing. 🙁
    • diesieben07
      Do stuff right after login

      By diesieben07 · Posted 1 hour ago

      PlayerLoggedInEvent
    • dotifo7120
      Do stuff right after login

      By dotifo7120 · Posted 1 hour ago

      Is there an event called when a player enters into the world (fully logged)?
  • Topics

    • dotifo7120
      4
      Do stuff right after login

      By dotifo7120
      Started 1 hour ago

    • T_Jam1
      1
      Windows installer

      By T_Jam1
      Started 2 hours ago

    • Mounty
      3
      Meine Inkompetenz kennt mal wieder keine Grenzen.(Forge 1.16.1)

      By Mounty
      Started 4 hours ago

    • Amperka_pro
      5
      Как применить нбт к предмету.

      By Amperka_pro
      Started 5 hours ago

    • MistyMarshes
      9
      [1.16.4] Get IChunk World / get current World for the overworld.

      By MistyMarshes
      Started 16 hours ago

  • Who's Online (See full list)

    • Nuparu00
    • Beethoven92
    • bigsleezy21
    • Somonestolemyusername
    • 5y5t3m
    • magn919
    • ChampionAsh5357
    • Bubbabluehorn
    • Maewolf04
    • LexManos
    • Squrikle
    • Oscelot27
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • Syncing Tile Entity with GUI
  • Theme

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