Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

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!

  • Author

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.