Jump to content

1.12 Item GUI for writing information


Lumby

Recommended Posts

Hi, I want to create a letter item where if you use it the item opens a GUI for you to type in, which then adds that string to the NBTTagcompound of the item, just like ItemWritableBook. ItemWritableBook, however, simply called player.openBook() which leads to an empty method with no code, so I don't understand how the entire process should be undertaken. Are there any possible resources or mods that have a similar functionality that someone can point me towards as an example? Thanks in advance!

Link to comment
Share on other sites

player.openBook() would be implemented in more than one place. One would be server side (EntityPlayerMP) and one would be client side (EntityPlayerClient, I think). That's where you need to look.

  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I found it, thank you for your help! EntityPlayer seems to be extended by EntityPlayerMP and AbstractClientPlayer, the latter I'm guessing is the one that handles client side code. The AbstractClientPlayer is instantiated by EntityPlayerSP, which is where I found the other openBook() implementation. 

 

My question now is, how do I emulate this approach on my item? Do I simply have two if conditions like so, where the conditions check whether world.isRemote to execute client side or server side specific code?:

	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
		
		ItemStack itemstack = playerIn.getHeldItem(handIn);
		
		if (!worldIn.isRemote){
			//emulate EntityPlayerMP code by doing a bunch of packet stuff

		}else if(worldIn.isRemote){
			//emulate ENtityPlayerSP code like so this.mc.displayGuiScreen(new myCustomItemGUI(this, stack, true));
		}
		
		
		return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
	}

 

Edited by Lumby
EDIT: tidied up spacing for the code segment
Link to comment
Share on other sites

Forge also supplies an easier way of opening a GUI, not sure what the current name is, but it was Player#openGui(...).

 

You'll still want to look at the vanilla gui classes to see how to handle player input and saving the data though.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.

Announcements



×
×
  • Create New...

Important Information

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