Jump to content

[1.7.10] [SOLVED] Right Click Item opens a GUI problem


Rennancge

Recommended Posts

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;

}

 

}

 

Link to comment
Share on other sites

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

    }

 

Link to comment
Share on other sites

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.