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

I always get tripped up on this when creating container blocks...

 

I'm trying to make a simple mod that is essentially a furnace that doesn't need fuel.  So I copied most of the furnace stuff (BlockFurnace, TileEntityFurnace, ContainerFurnace, GuiFurnace, SlotFurnaceOutput).

 

The thing is that I'm having trouble with the onBlockActivated() method in the block class.  If I write it like BlockFurnace (which calls displayGUI() only on server side) nothing shows up.  If I call the displayGUI() only on client side, the GUI shows up but acts weird (understandably since server sync gets messed up).  If I display gui in both server and client side it seems to work properly.

 

To explain further, the vanilla BlockFurnace has:

    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        if (worldIn.isRemote)
        {
            return true;
        }
        else
        {
            TileEntity tileentity = worldIn.getTileEntity(pos);

            if (tileentity instanceof TileEntityFurnace)
            {
                playerIn.displayGUIChest((TileEntityFurnace)tileentity);
            }

            return true;
        }
    }

 

But I can only get similar code to work if I also call gui to display on client side with something like this:

    @Override
public boolean onBlockActivated(World parWorld, BlockPos parBlockPos, IBlockState parIBlockState, EntityPlayer parPlayer, EnumFacing parSide, float hitX, float hitY, float hitZ)
    {
        if (parWorld.isRemote)
        {
        	// DEBUG
        	System.out.println("BlockGrinder onBlockActivated() on client side");
		Minecraft.getMinecraft().displayGuiScreen(new GuiGrinder(parPlayer.inventory, (TileEntityGrinder)parWorld.getTileEntity(parBlockPos)));
            return true;
        }
        else
        {
        	// DEBUG
        	System.out.println("BlockGrinder onBlockActivated() on server side");
            parPlayer.displayGui((TileEntityGrinder)parWorld.getTileEntity(parBlockPos));

            return true;
        }
    }

 

How does the vanilla furnace get away with only calling display GUI on server side?  Is this because the built in Gui classes have packets that sync them to client?  Is my approach okay (it seems to work in sense that I can move things around between slots fine and the slot contents are remembered each time I open the gui)?

 

I'm sure I'm missing something fundamental and always seem to get confused by this whenever I work with guis for containers...

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

  • Author

And a IGuiHandler for mod-guis.

 

Okay, it definitely seemed like there was something missing.

 

But interesting thing is my way (opening GUI on both sides) seems to work -- the gui displays, I'm able to move things around in the slots, and the contents of the slots is remembered each time I open gui and also remembered across saves.  What's the downside?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

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.