Jump to content

[1.9] Custom GUI doesn't open [Solved]


Kuuu

Recommended Posts

Hello, I'm updating my mod to 1.9, can't get GUIs to open.

 

onBlockActivated is called but GUI doesn't show up

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
    {
        if (worldIn.isRemote)
        {
            return true;
        }
        else
        {
        	System.out.println("onBlockActived was called! Trying to open GUI");
        	playerIn.openGui(More.instance, 0, worldIn, pos.getX(), pos.getY(), pos.getZ());
            return true;
        }
    }

 

Here is my GuiHandler:

 

 

public class MoreGuiHandler implements IGuiHandler {
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world,
		int x, int y, int z) {
	BlockPos pos = new BlockPos(x, y, z);
	TileEntity tile_entity = world.getTileEntity(pos);
	switch (id) {
	case 0:
		return id == 0
				&& world.getBlockState(pos).getBlock() == MoreBlocks.inventor_table ? new ContainerInventorTable(
				player.inventory, world, pos) : null;
	case 1:
		return id == 1
				&& ((world.getBlockState(pos).getBlock() == MoreBlocks.uranium_furnace) || (world.getBlockState(pos).getBlock() == MoreBlocks.lit_uranium_furnace)) ? new ContainerUraniumFurnace(
				player.inventory, (TileEntityUraniumFurnace)tile_entity)
				: null;
	case 2:
		return id == 2
				&& ((world.getBlockState(pos).getBlock() == MoreBlocks.uranium_compressor) || (world.getBlockState(pos).getBlock() == MoreBlocks.lit_uranium_compressor)) ? new ContainerUraniumCompressor(
				player.inventory, (TileEntityUraniumCompressor) tile_entity)
				: null;
	}
	return null;
}

@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world,
		int x, int y, int z) {
	BlockPos pos = new BlockPos(x, y, z);
	TileEntity tile_entity = world.getTileEntity(pos);
	switch (id) {
	case 0:
		return id == 0 && world.getBlockState(pos).getBlock() == MoreBlocks.inventor_table ? new InventorTableGui(
				player.inventory, world) : null;
	case 1:
		return id == 1
				&& ((world.getBlockState(pos).getBlock() == MoreBlocks.uranium_furnace) || (world.getBlockState(pos).getBlock() == MoreBlocks.lit_uranium_furnace)) ? new UraniumFurnaceGui(
				player.inventory, (TileEntityUraniumFurnace)tile_entity)
				: null;
	case 2:
		return id == 2
				&& ((world.getBlockState(pos).getBlock() == MoreBlocks.uranium_compressor) || (world.getBlockState(pos).getBlock() == MoreBlocks.lit_uranium_compressor)) ? new UraniumCompressorGui(
				player.inventory, (TileEntityUraniumCompressor) tile_entity)
				: null;
	}
	return null;
}
}

 

 

 

Thanks in advance!

Link to comment
Share on other sites

You need to call openGui on both the client and the server.

 

This is not true.

 

When called on the server side,

EntityPlayer#openGUI

sends a packet to the player's client that opens the appropriate

GuiScreen

. Calling it on the client side will open the

GuiScreen

, but this will be replaced as soon as the packet is received from the server.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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

×
×
  • Create New...

Important Information

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