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

Hi :)

 

I'm trying to execute some code when a gui chest is open.

To do that I do :

public void playerInteractEvent(PlayerInteractEvent event) {
	if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
		//Player right click on a block
		if(!event.entityPlayer.isSneaking()) {
			//Player is not sneaking
			TileEntity t = event.world.getTileEntity(event.x, event.y, event.z);
			if(t instanceof TileEntityChest) {
				FMLClientHandler.instance().displayGuiScreen(event.entityPlayer, new GuiChest(event.entityPlayer.inventory, (IInventory) t));
				event.setCanceled(true);
				// DO SOMETHING
			}
		}
	}
}

 

It's work, chest gui appears.

But when I select an Item, I have a IndexOfBoundException.

I suppose I don't give the good IIventory to this function but where can I find the good IIventory ?

 

Thanks a lot :)

You cancelled the event so the chest container isn't open on server side.

You'd need to use a IGuiHandler or GuiOpenEvent instead.

  • Author

Thanks for your reply, I didn't know the GuiOpenEvent it's very usefull :)

 

I have an other problem, my button doesn't' appear now :/

 

This is my code, it's short :

 

@SubscribeEvent
public void onGuiOpen(net.minecraftforge.client.event.GuiOpenEvent event) {
	System.out.println("A gui is open !");
	if(event.gui instanceof GuiContainer) {
		System.out.println("This is a GuiContainer");
		handleGuiContainerLayout((GuiContainer) event.gui);
	}
}

private void handleGuiContainerLayout(GuiContainer gui) {
	GuiSettlementsButton settlementButton = new GuiSettlementsButton(gui);
	List<Object> buttonList = GuiReflect.getInstance().getButtonList(gui);
	if(buttonList != null) {
		System.out.println("We will add our button !");

		buttonList.add(settlementButton);

		System.out.println(buttonList);
	}
}

 

 

This is the button code :

 

public class GuiSettlementsButton extends GuiButtonExt {

public GuiSettlementsButton(GuiContainer gui) {
	super(-1, GuiReflect.getInstance().getGuiLeft(gui), GuiReflect.getInstance().getGuiTop(gui)+gui.height+1,150,20, StatCollector.translateToLocal("tile.SettlementsGuiButton.name"));
}

@Override
public String toString() {
	return "GuiSettlementsButton :\n"
			+ "\tx : "+xPosition+"\n"
			+ "\ty : "+yPosition+"\n"
			+ "\twidth : "+width+"\n"
			+ "\theight : "+height+"\n"
			+ "\ttext : "+this.displayString;
}
}

 

I try with GuiButton instead of GuiButtonExt but, it's the same :/

 

And this is my log when I open a chest:

A gui is open !
This is a GuiContainer
We will add our button !
[GuiSettlementsButton :
x : 0
y : 1
width : 150
height : 20
text : Settlements]

 

I don't understand why this is write 2 times and why my button is not visible.

 

Could you help me ?

 

Thanks :)

 

EDIT : It's work fine now, I just don't understand what mean height, I think this was ySize.

So problem resolved ;)

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.