mojira.dev
MC-24390

Books don't sign properly for me! I don't get the chance to edit the title when trying to sign again!

What I expected to happen was...:
I was writing in a book and I pressed sign. I typed a name and hit cancel by accident. I pressed sign again. I thought I would get to change the name.

What actually happened was...:
I was writing a book with the book and quill. I pressed sign and publish it. I wrote the title and was about to hit sign and close, but at the last second I remembered to add something. I hit cancel and added that thing. I hit sign again, and I didn't get a chance to change the book's title. I actually messed up on the title so it looks ugly!

Steps to Reproduce:

  1. Get a fresh book and quill

  2. Write a short thing like "123"

  3. Press "sign"

  4. Make a short title like "Code"

  5. Press cancel

  6. Try pressing sign again

  7. The Book and Quill signs without asking for the book title again


Code analysis by @unknown can be found in this comment.

Related issues

Comments

migrated

Can confirm

Torabi

Confirmed. The cancel button works properly, as long as the title is blank. It you type something, and then delete it completely, it still works. However, if you type in a title, push cancel, and then click "Sign", it will skip the title entry screen, finishing the book with whatever was typed in before.

marcono1234

Confirmed for:

  • 15w34d Step 2 is not necissarily needed

marcono1234

Confirmed for

  • 15w49b

In MCP 1.8 the problem seems to be that somehow the method protected void actionPerformed(GuiButton button) throws IOException in /Client/src/net/minecraft/client/gui/GuiScreenBook.java triggers twice:

  1. Player presses "Sign" button (method actionPerformed is called)

  2. Method updateButtons is called making "Sign and Close" button visible

  3. actionPerformed is triggered again for "Sign and Close" button

marcono1234

The reason for that is Minecraft's custom GUI implementation.
In /Client/src/net/minecraft/client/gui/GuiScreen.java (MCP 1.8 name) the mouseClicked method looks like this:

/**
 * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
 */
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
{
	if (mouseButton == 0)
	{
		for (int var4 = 0; var4 < this.buttonList.size(); ++var4)
		{
			GuiButton var5 = (GuiButton)this.buttonList.get(var4);

			if (var5.mousePressed(this.mc, mouseX, mouseY))
			{
				this.selectedButton = var5;
				var5.playPressSound(this.mc.getSoundHandler());
				this.actionPerformed(var5);
			}
		}
	}
}

One problem is that there is no break; after a button being at this position was found. Another one is that this only iterates over buttons, however backgrounds like the world loading screen (see MC-92079) are not in these lists and do not exist as GUIs which is one reason why you can click through them. The gui list should also have the structure: [background, ..., foreground] and the for loop should iterate the other way around (This only works if no strange situations exist like: "A overlaps B, B overlaps C and C overlaps A" where C would be in front and behind A at the same time).
Another problem is the mousePressed method of GuiButton s:

/**
 * Returns true if the mouse has been pressed on this control. Equivalent of MouseListener.mousePressed(MouseEvent e).
 */
public boolean mousePressed(Minecraft mc, int mouseX, int mouseY)
{
	return this.enabled && this.visible && mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
}

Like you can see here it only returns true if the button is visible and enabled. This would however mean that you could click through disabled visible buttons. So having proper getter methods and doing the visible and enabled test in GuiScreen might be the better choice.

So now this is what currently causes this bug:

  1. Clicking on "Sign"

    1. "Sign" button is being tested: enabled and visible

      1. "Sign and Close" button becomes visible (and enabled because you entered a title before, see description of the bug report)

    2. "Sign and Close" button is being tested: enabled and visible

      1. Book gets signed and closed

marcono1234

Could you please include this in the description or link to the comment?

migrated

Is this still an issue in the latest snapshot 16w44a? If so please update the affected versions.

This is an automated comment on any open or reopened issue with out-of-date affected versions.

JUE13

Can confirm for 1.12.1.

kumasasa
  • Confirmed for 1.12.2

  • Fixed in 18w19b:

    • When pressing "cancel" the book returns into edit mode, you can continue editing or try to sign again.

migrated

(Unassigned)

Confirmed

Minecraft 1.6.2, Minecraft 1.7.4, Minecraft 14w02c, Minecraft 15w34d, Minecraft 15w49b, Minecraft 16w32b, Minecraft 1.11.2, Minecraft 1.12.1, Minecraft 1.12.2

Minecraft 18w19b

Retrieved