Jump to content

[SOLVED][1.8] Open crafting table gui on entity right click


Blue0500

Recommended Posts

I'm new at gui's so bear with me on this one. I'm trying to make the crafting gui open whenever the player right clicks on my entity. The entity and renderer are working fine, but it's the gui I'm having trouble with. I tried doing this:

 

FMLClientHandler.instance().displayGuiScreen(player, new GuiCrafting(player.inventory, player.worldObj, new BlockPos((int)player.posX, (int)player.posY, (int)player.posZ)));

 

and the gui opens, but whenever I pick up an ItemStack it puts it back down, picks up the ItemStack to the left, and then shuffles the entire inventory. I knew that couldn't be right, so I tried this, which is the vanilla crafting table code:

 

player.displayGui(new BlockWorkbench.InterfaceCraftingTable(player.worldObj, new BlockPos((int)player.posX, (int)player.posY, (int)player.posZ)));

 

but then the gui just flickered open for a second, and then closed. Then, I tried to make my own gui handler, which looks like this:

 

// Imports

public class CraftingGuiHandler implements IGuiHandler {

@Override
public Object getClientGuiElement(int arg0, EntityPlayer player, World world, int x, int y, int z) {
	return new GuiCrafting(player.inventory, world);
}

@Override
public Object getServerGuiElement(int arg0, EntityPlayer player, World world, int x, int y, int z) {
	return new ContainerWorkbench(player.inventory, world, new BlockPos(x, y, z));
}

}

 

I tryed opening it with this:

 

player.openGui(MyMod.Instance, 0, player.worldObj, (int)player.posX, (int)player.posY, (int)player.posZ);

 

but it just flickered again! Any help would be appreciated, because I'm out of ideas. Thanks!

 

Link to comment
Share on other sites

Ok I did what you said and basically copied the vanilla gui and container classes and made my own. While doing this, I saw this method:

 

public boolean canInteractWith(EntityPlayer arg0)

 

I set it to always return true and it worked! Then I realized it could be so much simpler: All I had to do was create a custom class that extends ContainerWorkbench and override this method. So now the gui works with the vanilla GuiCrafting class and my custom container. Thanks!

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.