Rennancge Posted February 13, 2016 Share Posted February 13, 2016 Hello guys, I am making an item that opens a custom GUI when is right clicked but anything happens. I made the GuiHandler, Container and GUI, as below: Item class public class ItemMagicFinder extends ItemMagic{ public ItemMagicFinder() { super(1000); setCreativeTab(DynamicCraft.dynamicTab); } @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { player.openGui(DynamicCraft.mod, DynamicCraft.guiIdMagicFinder, world, (int) player.posX, (int) player.posY, (int) player.posZ); return itemStack; } } GuiHandler public class GuiHandler implements IGuiHandler{ @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); ItemStack stack = null; if(player.getHeldItem() != null) stack = player.getHeldItem(); if(entity != null){ switch (ID) { case DynamicCraft.guiIdInfusion: if(entity instanceof TileEntityInfusionAltar) { return new ContainerInfusionAltar(player.inventory, (TileEntityInfusionAltar) entity); } return null; case DynamicCraft.guiIdMagicFinder: if(stack.getItem() instanceof ItemMagicFinder) { return new ContainerMagicFinder(player, player.inventory, stack, new InventoryMagicFinder(player.getHeldItem())); } return null; default: return null; } } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); ItemStack stack = null; if(player.getHeldItem() != null) stack = player.getHeldItem(); if(entity != null){ switch (ID) { case DynamicCraft.guiIdInfusion: if(entity instanceof TileEntityInfusionAltar) { return new GuiInfusionAltar(player.inventory, (TileEntityInfusionAltar) entity); } return null; case DynamicCraft.guiIdMagicFinder: if(stack.getItem() instanceof ItemMagicFinder) { System.out.println("Sim, é instance de MagicFinder"); return new GuiMagicFinder(player, player.inventory, stack, new InventoryMagicFinder(player.getHeldItem())); } return null; default: return null; } } return null; } Gui public class GuiMagicFinder extends GuiContainer{ private static final ResourceLocation texture = new ResourceLocation("dynamiccraft", "textures/gui/magicfinder.png"); public GuiMagicFinder(EntityPlayer player, InventoryPlayer inv, ItemStack stack,InventoryMagicFinder inventoryItem) { super(new ContainerMagicFinder(player, inv, stack, inventoryItem)); this.xSize = 176; this.ySize = 165; } @Override protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); this.mc.getTextureManager().bindTexture(texture); this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); } } Container public class ContainerMagicFinder extends Container{ public ContainerMagicFinder(EntityPlayer player, InventoryPlayer inv, ItemStack stack, InventoryMagicFinder inventoryItem) { int i; for (i = 0; i < 3; ++i) { for (int j = 0; j < 9; ++j) { this.addSlotToContainer(new Slot(inv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } for (i = 0; i < 9; ++i) { this.addSlotToContainer(new Slot(inv, i, 8 + i * 18, 142)); } } @Override public boolean canInteractWith(EntityPlayer player) { return true; } } Quote Link to comment Share on other sites More sharing options...
Failender Posted February 13, 2016 Share Posted February 13, 2016 are you registering the gui handler? Quote Link to comment Share on other sites More sharing options...
Rennancge Posted February 13, 2016 Author Share Posted February 13, 2016 are you registering the gui handler? Yes, I have a tile entity with gui that works perfectly, but not the Item. Registering GUI Handler on CommonProxy: public void registerNetworkStuff() { NetworkRegistry.INSTANCE.registerGuiHandler(DynamicCraft.mod, new GuiHandler()); NetworkHandler.initServerMessages(); } Quote Link to comment Share on other sites More sharing options...
Rennancge Posted February 13, 2016 Author Share Posted February 13, 2016 Your GuiHandler always checks if a TileEntity exists at the supplied position and does nothing if there is none. Oh thanks! I didn't saw it. Quote Link to comment Share on other sites More sharing options...
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.