Jump to content

Recommended Posts

Posted

So I have a block which opens a GUI just fine, but when I implement that into an item it doesn't open! Any ideas?

 

Item Class:

package mod.Item;

import mod.MagikBase;
import mod.lib.GuiIDs;
import mod.proxy.CommonProxy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class portableMagik extends Item {

public portableMagik(int par1) {
	super(par1);
	// TODO Auto-generated constructor stub
}

@Override
public String getTextureFile()
{
    	return CommonProxy.ITEMS_PNG;
}

@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer entityplayer)
{
	entityplayer.openGui(MagikBase.instance, GuiIDs.CRAFTER, entityplayer.worldObj, (int) entityplayer.posX, (int) entityplayer.posY, (int) entityplayer.posZ);
	return par1ItemStack;
}
}

If you found this post helpful, please take your time to give me a "Thank You". :)

Posted

If you've done it with a block before, you've probably done a check for the Blocks TileEntity in the GuiHandler and probably also used it in the Container class, the item doesn't have a TileEntity of course. You'll have to leave that check out and change the Container class around a bit.

Ok, I'll try that asap.

If you found this post helpful, please take your time to give me a "Thank You". :)

Posted

It could also be that onItemRightClick is only firing server side, which of course is not going to open any GUIs.

 

also, you are skipping the FML call, which handles the server-client comms packet to open the GUI client side if the call is made on the server.

 

use

if(!world.isremote)

{

FMLNetworkHandler.openGUI(params....<same as your openGUI call>)

}

 

in your onRightClick code. 

 

This will also require a properly setup IGuiHandler.

 

 

Then, simply do the openGUI call on server side and it will both open the container server side (if used), and open the GUI client side.  (Note, if you return NULL from the server getGuiElement method, it will NOT send the openGUI packet to client side, so these must be GuiContainer instances (even if just populated with an empty/dummy container)).

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.

Announcements



×
×
  • Create New...

Important Information

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