Jump to content

Vanilla blocks with containers only calling displayGui() server side?


Recommended Posts

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/

Posted

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

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