Jump to content

Recommended Posts

Posted

Hello,

 

does anyone know why the following code doesn't let you open the workbench Gui?

 

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
	if (!this.isArgSizeOkay(sender, args.length, 0)) return;
	if (!(sender instanceof EntityPlayer)) return;

	EntityPlayer player = (EntityPlayer)sender;
	player.displayGui(new BlockWorkbench.InterfaceCraftingTable(player.worldObj, player.getPosition()));
}

Regards,

 

IceTrailer

Posted

BlockWorkbench.InterfaceCraftingTable

opens

ContainerWorkbench

, which overrides

Container#canInteractWith

to return

false

if the block at the specified position isn't a Crafting Table. This is called every tick in

EntityPlayer#onUpdate

, if it returns

false

the

Container

and

GUIScreen

are closed.

 

You'll need to create your own

Container

that extends

ContainerWorkbench

and overrides

Container#canInteractWith

to return

true

if the player can interact with it (if there's no restrictions, just return

true

every time) and your own

GuiScreen

that extends

GuiContainer

, creates an instance of your

Container

class and renders like

GuiCrafting

. Use FML's

IGuiHandler

system to open your GUI.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

 

Well, I tried it to do it like you described, but I don't get the following.

 

your own
GuiScreen

that extends

GuiContainer

, creates an instance of your

Container

class and renders like

GuiCrafting

. Use FML's

IGuiHandler

system to open your GUI.

 

But thanks for your help. I think it's too ornate for only "/workbench" without having a crafting table  ;D

Regards,

 

IceTrailer

Posted

Look at

GuiCrafting

to see how the vanilla Crafting Table creates its client-side

Container

and renders the GUI. You can use the same code, but create an instance of your

Container

class instead of

ContainerWorkbench

.

 

BedrockMiner has a tutorial on the GUI Handler system here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

You imply it should be easy to create a workbench GUI without having an actual workbench at that location.  But it's not necessarily true because the workbench GUI interacts with the workbench itself (by holding items while they get crafted etc.).

 

That is all speculation I haven't worked with that particular object in the game.

Posted

You imply it should be easy to create a workbench GUI without having an actual workbench at that location.  But it's not necessarily true because the workbench GUI interacts with the workbench itself (by holding items while they get crafted etc.).

 

That is all speculation I haven't worked with that particular object in the game.

 

ContainerWorkbench

doesn't interact with the Crafting Table block at all except to check if the player is still in range of it. The Crafting Table doesn't have a

TileEntity

, it doesn't store any items;

ContainerWorkbench

creates its own temporary inventories to store the ingredients and result and drops these on the ground when the GUI closes.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.