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

Hey guys.

 

I'm working on a mod. There are two new blocks. Each block should open a GUI with a right mouse button.

 

Problem: The GUI don't open. No Errors. No messages in the console in eclipse.

 

 

Each block have an onBlockActivated like this, only the ID in par5EntityPlayer.opengui are different(0-1).

 

	public boolean onBlockActivated(World par1World, int par2, int par3,
		int par4, EntityPlayer par5EntityPlayer, int par6, float par7,
		float par8, float par9) {
	if (par1World.isRemote) {
		return true;
	} else if (!par5EntityPlayer.isSneaking()) {
		TileEntity var10 = (TileEntity) par1World.getBlockTileEntity(par2,
				par3, par4);
		if (var10 != null) {
			par5EntityPlayer.openGui(Basis.instance, 0, par1World, par2,
					par3, par4);

		}
		return true;
	} else {
		return false;
	}
}

 

Also I have an GuiHandler class with the methods getServerGuiElement and getClientGuiElement

 

getClientGuiElement:

 

public Object getClientGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	TileEntity entity = world.getBlockTileEntity(x, y, z);

	if (entity == null) {
		switch (ID) {
		case 0:
			return new GuiBlock1(player.inventory,
					((TileEntityBlock1) entity));
		case 1:
			return new GuiFlock2(player.inventory,
					((TileEntityBlock2) entity));

		}
	}


	return null;



}

 

getServerGuiElement:

 

public Object getServerGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	TileEntity entity = world.getBlockTileEntity(x, y, z);

	if (entity == null) {
		switch (ID) {
		case 0:
			return new ContainerBlock1(player.inventory,
					((TileEntityBlock1) entity));
		case 1:
			return new ContainerBlock2(player.inventory,
					((TileEntityBlock2) entity));


		}
	}

	return null;

}

 

And in the main class I added this:

 

public static GuiHandler handler;
NetworkRegistry.instance().registerGuiHandler(instance, handler);

  • Author

First of all you don't need to check for player sneaking, it is done by vanilla since on of the recent versions.

Then you should not reference your GuiScreens directly in your GuiHandler because that will make your mod only work in SP. Instead give that off to your ClientProxy.

For debugging you should try putting in System.out.println() calls in your GuiHandler to see if the methods that open your Gui are actually called.

Also make sure you are a @NetworkMod.

 

The blocks are furnaces, thats why I'm checking for sneaking. The methods don't get called.

The mod is a networkmod.

@NetworkMod(clientSideRequired = true, serverSideRequired = false)

 

But I don't understand what you mean with:

Then you should not reference your GuiScreens directly in your GuiHandler because that will make your mod only work in SP. Instead give that off to your ClientProxy.

 

Can you give me an example to understand this?

 

Thanks

  • Author

For goodness' sake! I'm such a noob! All I had to do is to implements IGuiHandler to the ClientProxy and to copy the methods from my guihandler class to Clientproxy. Damnit! Now i know this for the future. Thanks a lot man!

 

Greeting from Germany

 

/Offtopic

P.S.: I'm know like 1000% more happy! :D

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.