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:
Get a fresh book and quill
Write a short thing like "123"
Press "sign"
Make a short title like "Code"
Press cancel
Try pressing sign again
The Book and Quill signs without asking for the book title again
Code analysis by @unknown can be found in this comment.
Related issues
is duplicated by
Comments


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.

Confirmed for:
15w34d Step 2 is not necissarily needed

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:
Player presses "Sign" button (method
actionPerformed
is called)Method
updateButtons
is called making "Sign and Close" button visibleactionPerformed
is triggered again for "Sign and Close" button

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:
Clicking on "Sign"
"Sign" button is being tested: enabled and visible
"Sign and Close" button becomes visible (and enabled because you entered a title before, see description of the bug report)
"Sign and Close" button is being tested: enabled and visible
Book gets signed and closed

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

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.

Can confirm for 1.12.1.

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.
Can confirm