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

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;

}

 

}

 

  • Author

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();

    }

 

  • Author

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. :P

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.