Blackout Posted July 11, 2014 Posted July 11, 2014 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 Quote
GotoLink Posted July 11, 2014 Posted July 11, 2014 You cancelled the event so the chest container isn't open on server side. You'd need to use a IGuiHandler or GuiOpenEvent instead. Quote
Blackout Posted July 12, 2014 Author Posted July 12, 2014 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 Quote
Recommended Posts
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.