GuiScreenBook .java

net.minecraft.client.gui.GuiScreenBook (class): members: buttonPreviousPage, bookGettingSigned, bookGuiTextures, bookImageHeight, NextPageButton, bookObj.

net.minecraft.client.guiclass674 linesclientextends GuiScreen22.7 KB

API Surface (10)

void updateScreen()
void initGui()
void onGuiClosed()
void actionPerformed(GuiButton button)
void keyTyped(char typedChar, int keyCode)
void drawScreen(int mouseX, int mouseY, float partialTicks)
void mouseClicked(int mouseX, int mouseY, int mouseButton)
boolean handleComponentClick(IChatComponent component)
IChatComponent func_175385_b(int p_175385_1_, int p_175385_2_)
void drawButton(Minecraft mc, int mouseX, int mouseY)

Fields & Constants (22)

logger
bookGuiTextures
editingPlayer
bookObj
bookIsUnsigned
bookIsModified
bookGettingSigned
updateCount
bookImageWidth
bookImageHeight
bookTotalPages
currPage
bookPages
bookTitle
field_175386_A
field_175387_B
buttonNextPage
buttonPreviousPage
buttonDone
buttonSign
buttonFinalize
buttonCancel

String literals (14)

"textures/gui/book.png"
"pages"
"book.signButton"
"gui.done"
"book.finalizeButton"
"gui.cancel"
"MC|BEdit"
"MC|BSign"
"author"
"book.editTitle"
"book.byAuthor"
"book.finalizeWarning"
"book.pageIndicator"
"* Invalid book tag *"

Full Source

GuiScreenBook.java674 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.client.gui;
2
3
import com.google.common.collect.Lists;
4
import com.google.gson.JsonParseException;
5
import io.netty.buffer.Unpooled;
6
import java.io.IOException;
7
import java.util.List;
8
import net.minecraft.client.Minecraft;
9
import net.minecraft.client.renderer.GlStateManager;
10
import net.minecraft.client.resources.I18n;
11
import net.minecraft.entity.player.EntityPlayer;
12
import net.minecraft.event.ClickEvent;
13
import net.minecraft.init.Items;
14
import net.minecraft.item.ItemEditableBook;
15
import net.minecraft.item.ItemStack;
16
import net.minecraft.nbt.NBTTagCompound;
17
import net.minecraft.nbt.NBTTagList;
18
import net.minecraft.nbt.NBTTagString;
19
import net.minecraft.network.PacketBuffer;
20
import net.minecraft.network.play.client.C17PacketCustomPayload;
21
import net.minecraft.util.ChatAllowedCharacters;
22
import net.minecraft.util.ChatComponentText;
23
import net.minecraft.util.EnumChatFormatting;
24
import net.minecraft.util.IChatComponent;
25
import net.minecraft.util.ResourceLocation;
26
import org.apache.logging.log4j.LogManager;
27
import org.apache.logging.log4j.Logger;
28
import org.lwjgl.input.Keyboard;
29
30
public class GuiScreenBook extends GuiScreen
31
{
32
    private static final Logger logger = LogManager.getLogger();
33
    private static final ResourceLocation bookGuiTextures = new ResourceLocation("textures/gui/book.png");
34
35
    /** The player editing the book */
36
    private final EntityPlayer editingPlayer;
37
    private final ItemStack bookObj;
38
39
    /** Whether the book is signed or can still be edited */
40
    private final boolean bookIsUnsigned;
41
42
    /**
43
     * Whether the book's title or contents has been modified since being opened
44
     */
45
    private boolean bookIsModified;
46
47
    /** Determines if the signing screen is open */
48
    private boolean bookGettingSigned;
49
50
    /** Update ticks since the gui was opened */
51
    private int updateCount;
52
    private int bookImageWidth = 192;
53
    private int bookImageHeight = 192;
54
    private int bookTotalPages = 1;
55
    private int currPage;
56
    private NBTTagList bookPages;
57
    private String bookTitle = "";
58
    private List<IChatComponent> field_175386_A;
59
    private int field_175387_B = -1;
60
    private GuiScreenBook.NextPageButton buttonNextPage;
61
    private GuiScreenBook.NextPageButton buttonPreviousPage;
62
    private GuiButton buttonDone;
63
64
    /** The GuiButton to sign this book. */
65
    private GuiButton buttonSign;
66
    private GuiButton buttonFinalize;
67
    private GuiButton buttonCancel;
68
69
    public GuiScreenBook(EntityPlayer player, ItemStack book, boolean isUnsigned)
70
    {
71
        this.editingPlayer = player;
72
        this.bookObj = book;
73
        this.bookIsUnsigned = isUnsigned;
74
75
        if (book.hasTagCompound())
76
        {
77
            NBTTagCompound nbttagcompound = book.getTagCompound();
78
            this.bookPages = nbttagcompound.getTagList("pages", 8);
79
80
            if (this.bookPages != null)
81
            {
82
                this.bookPages = (NBTTagList)this.bookPages.copy();
83
                this.bookTotalPages = this.bookPages.tagCount();
84
85
                if (this.bookTotalPages < 1)
86
                {
87
                    this.bookTotalPages = 1;
88
                }
89
            }
90
        }
91
92
        if (this.bookPages == null && isUnsigned)
93
        {
94
            this.bookPages = new NBTTagList();
95
            this.bookPages.appendTag(new NBTTagString(""));
96
            this.bookTotalPages = 1;
97
        }
98
    }
99
100
    /**
101
     * Called from the main game loop to update the screen.
102
     */
103
    public void updateScreen()
104
    {
105
        super.updateScreen();
106
        ++this.updateCount;
107
    }
108
109
    /**
110
     * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
111
     * window resizes, the buttonList is cleared beforehand.
112
     */
113
    public void initGui()
114
    {
115
        this.buttonList.clear();
116
        Keyboard.enableRepeatEvents(true);
117
118
        if (this.bookIsUnsigned)
119
        {
120
            this.buttonList.add(this.buttonSign = new GuiButton(3, this.width / 2 - 100, 4 + this.bookImageHeight, 98, 20, I18n.format("book.signButton", new Object[0])));
121
            this.buttonList.add(this.buttonDone = new GuiButton(0, this.width / 2 + 2, 4 + this.bookImageHeight, 98, 20, I18n.format("gui.done", new Object[0])));
122
            this.buttonList.add(this.buttonFinalize = new GuiButton(5, this.width / 2 - 100, 4 + this.bookImageHeight, 98, 20, I18n.format("book.finalizeButton", new Object[0])));
123
            this.buttonList.add(this.buttonCancel = new GuiButton(4, this.width / 2 + 2, 4 + this.bookImageHeight, 98, 20, I18n.format("gui.cancel", new Object[0])));
124
        }
125
        else
126
        {
127
            this.buttonList.add(this.buttonDone = new GuiButton(0, this.width / 2 - 100, 4 + this.bookImageHeight, 200, 20, I18n.format("gui.done", new Object[0])));
128
        }
129
130
        int i = (this.width - this.bookImageWidth) / 2;
131
        int j = 2;
132
        this.buttonList.add(this.buttonNextPage = new GuiScreenBook.NextPageButton(1, i + 120, j + 154, true));
133
        this.buttonList.add(this.buttonPreviousPage = new GuiScreenBook.NextPageButton(2, i + 38, j + 154, false));
134
        this.updateButtons();
135
    }
136
137
    /**
138
     * Called when the screen is unloaded. Used to disable keyboard repeat events
139
     */
140
    public void onGuiClosed()
141
    {
142
        Keyboard.enableRepeatEvents(false);
143
    }
144
145
    private void updateButtons()
146
    {
147
        this.buttonNextPage.visible = !this.bookGettingSigned && (this.currPage < this.bookTotalPages - 1 || this.bookIsUnsigned);
148
        this.buttonPreviousPage.visible = !this.bookGettingSigned && this.currPage > 0;
149
        this.buttonDone.visible = !this.bookIsUnsigned || !this.bookGettingSigned;
150
151
        if (this.bookIsUnsigned)
152
        {
153
            this.buttonSign.visible = !this.bookGettingSigned;
154
            this.buttonCancel.visible = this.bookGettingSigned;
155
            this.buttonFinalize.visible = this.bookGettingSigned;
156
            this.buttonFinalize.enabled = this.bookTitle.trim().length() > 0;
157
        }
158
    }
159
160
    private void sendBookToServer(boolean publish) throws IOException
161
    {
162
        if (this.bookIsUnsigned && this.bookIsModified)
163
        {
164
            if (this.bookPages != null)
165
            {
166
                while (this.bookPages.tagCount() > 1)
167
                {
168
                    String s = this.bookPages.getStringTagAt(this.bookPages.tagCount() - 1);
169
170
                    if (s.length() != 0)
171
                    {
172
                        break;
173
                    }
174
175
                    this.bookPages.removeTag(this.bookPages.tagCount() - 1);
176
                }
177
178
                if (this.bookObj.hasTagCompound())
179
                {
180
                    NBTTagCompound nbttagcompound = this.bookObj.getTagCompound();
181
                    nbttagcompound.setTag("pages", this.bookPages);
182
                }
183
                else
184
                {
185
                    this.bookObj.setTagInfo("pages", this.bookPages);
186
                }
187
188
                String s2 = "MC|BEdit";
189
190
                if (publish)
191
                {
192
                    s2 = "MC|BSign";
193
                    this.bookObj.setTagInfo("author", new NBTTagString(this.editingPlayer.getName()));
194
                    this.bookObj.setTagInfo("title", new NBTTagString(this.bookTitle.trim()));
195
196
                    for (int i = 0; i < this.bookPages.tagCount(); ++i)
197
                    {
198
                        String s1 = this.bookPages.getStringTagAt(i);
199
                        IChatComponent ichatcomponent = new ChatComponentText(s1);
200
                        s1 = IChatComponent.Serializer.componentToJson(ichatcomponent);
201
                        this.bookPages.set(i, new NBTTagString(s1));
202
                    }
203
204
                    this.bookObj.setItem(Items.written_book);
205
                }
206
207
                PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
208
                packetbuffer.writeItemStackToBuffer(this.bookObj);
209
                this.mc.getNetHandler().addToSendQueue(new C17PacketCustomPayload(s2, packetbuffer));
210
            }
211
        }
212
    }
213
214
    /**
215
     * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
216
     */
217
    protected void actionPerformed(GuiButton button) throws IOException
218
    {
219
        if (button.enabled)
220
        {
221
            if (button.id == 0)
222
            {
223
                this.mc.displayGuiScreen((GuiScreen)null);
224
                this.sendBookToServer(false);
225
            }
226
            else if (button.id == 3 && this.bookIsUnsigned)
227
            {
228
                this.bookGettingSigned = true;
229
            }
230
            else if (button.id == 1)
231
            {
232
                if (this.currPage < this.bookTotalPages - 1)
233
                {
234
                    ++this.currPage;
235
                }
236
                else if (this.bookIsUnsigned)
237
                {
238
                    this.addNewPage();
239
240
                    if (this.currPage < this.bookTotalPages - 1)
241
                    {
242
                        ++this.currPage;
243
                    }
244
                }
245
            }
246
            else if (button.id == 2)
247
            {
248
                if (this.currPage > 0)
249
                {
250
                    --this.currPage;
251
                }
252
            }
253
            else if (button.id == 5 && this.bookGettingSigned)
254
            {
255
                this.sendBookToServer(true);
256
                this.mc.displayGuiScreen((GuiScreen)null);
257
            }
258
            else if (button.id == 4 && this.bookGettingSigned)
259
            {
260
                this.bookGettingSigned = false;
261
            }
262
263
            this.updateButtons();
264
        }
265
    }
266
267
    private void addNewPage()
268
    {
269
        if (this.bookPages != null && this.bookPages.tagCount() < 50)
270
        {
271
            this.bookPages.appendTag(new NBTTagString(""));
272
            ++this.bookTotalPages;
273
            this.bookIsModified = true;
274
        }
275
    }
276
277
    /**
278
     * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
279
     * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
280
     */
281
    protected void keyTyped(char typedChar, int keyCode) throws IOException
282
    {
283
        super.keyTyped(typedChar, keyCode);
284
285
        if (this.bookIsUnsigned)
286
        {
287
            if (this.bookGettingSigned)
288
            {
289
                this.keyTypedInTitle(typedChar, keyCode);
290
            }
291
            else
292
            {
293
                this.keyTypedInBook(typedChar, keyCode);
294
            }
295
        }
296
    }
297
298
    /**
299
     * Processes keystrokes when editing the text of a book
300
     */
301
    private void keyTypedInBook(char typedChar, int keyCode)
302
    {
303
        if (GuiScreen.isKeyComboCtrlV(keyCode))
304
        {
305
            this.pageInsertIntoCurrent(GuiScreen.getClipboardString());
306
        }
307
        else
308
        {
309
            switch (keyCode)
310
            {
311
                case 14:
312
                    String s = this.pageGetCurrent();
313
314
                    if (s.length() > 0)
315
                    {
316
                        this.pageSetCurrent(s.substring(0, s.length() - 1));
317
                    }
318
319
                    return;
320
321
                case 28:
322
                case 156:
323
                    this.pageInsertIntoCurrent("\n");
324
                    return;
325
326
                default:
327
                    if (ChatAllowedCharacters.isAllowedCharacter(typedChar))
328
                    {
329
                        this.pageInsertIntoCurrent(Character.toString(typedChar));
330
                    }
331
            }
332
        }
333
    }
334
335
    /**
336
     * Processes keystrokes when editing the title of a book
337
     */
338
    private void keyTypedInTitle(char p_146460_1_, int p_146460_2_) throws IOException
339
    {
340
        switch (p_146460_2_)
341
        {
342
            case 14:
343
                if (!this.bookTitle.isEmpty())
344
                {
345
                    this.bookTitle = this.bookTitle.substring(0, this.bookTitle.length() - 1);
346
                    this.updateButtons();
347
                }
348
349
                return;
350
351
            case 28:
352
            case 156:
353
                if (!this.bookTitle.isEmpty())
354
                {
355
                    this.sendBookToServer(true);
356
                    this.mc.displayGuiScreen((GuiScreen)null);
357
                }
358
359
                return;
360
361
            default:
362
                if (this.bookTitle.length() < 16 && ChatAllowedCharacters.isAllowedCharacter(p_146460_1_))
363
                {
364
                    this.bookTitle = this.bookTitle + Character.toString(p_146460_1_);
365
                    this.updateButtons();
366
                    this.bookIsModified = true;
367
                }
368
        }
369
    }
370
371
    /**
372
     * Returns the entire text of the current page as determined by currPage
373
     */
374
    private String pageGetCurrent()
375
    {
376
        return this.bookPages != null && this.currPage >= 0 && this.currPage < this.bookPages.tagCount() ? this.bookPages.getStringTagAt(this.currPage) : "";
377
    }
378
379
    /**
380
     * Sets the text of the current page as determined by currPage
381
     */
382
    private void pageSetCurrent(String p_146457_1_)
383
    {
384
        if (this.bookPages != null && this.currPage >= 0 && this.currPage < this.bookPages.tagCount())
385
        {
386
            this.bookPages.set(this.currPage, new NBTTagString(p_146457_1_));
387
            this.bookIsModified = true;
388
        }
389
    }
390
391
    /**
392
     * Processes any text getting inserted into the current page, enforcing the page size limit
393
     */
394
    private void pageInsertIntoCurrent(String p_146459_1_)
395
    {
396
        String s = this.pageGetCurrent();
397
        String s1 = s + p_146459_1_;
398
        int i = this.fontRendererObj.splitStringWidth(s1 + "" + EnumChatFormatting.BLACK + "_", 118);
399
400
        if (i <= 128 && s1.length() < 256)
401
        {
402
            this.pageSetCurrent(s1);
403
        }
404
    }
405
406
    /**
407
     * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
408
     */
409
    public void drawScreen(int mouseX, int mouseY, float partialTicks)
410
    {
411
        GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
412
        this.mc.getTextureManager().bindTexture(bookGuiTextures);
413
        int i = (this.width - this.bookImageWidth) / 2;
414
        int j = 2;
415
        this.drawTexturedModalRect(i, j, 0, 0, this.bookImageWidth, this.bookImageHeight);
416
417
        if (this.bookGettingSigned)
418
        {
419
            String s = this.bookTitle;
420
421
            if (this.bookIsUnsigned)
422
            {
423
                if (this.updateCount / 6 % 2 == 0)
424
                {
425
                    s = s + "" + EnumChatFormatting.BLACK + "_";
426
                }
427
                else
428
                {
429
                    s = s + "" + EnumChatFormatting.GRAY + "_";
430
                }
431
            }
432
433
            String s1 = I18n.format("book.editTitle", new Object[0]);
434
            int k = this.fontRendererObj.getStringWidth(s1);
435
            this.fontRendererObj.drawString(s1, i + 36 + (116 - k) / 2, j + 16 + 16, 0);
436
            int l = this.fontRendererObj.getStringWidth(s);
437
            this.fontRendererObj.drawString(s, i + 36 + (116 - l) / 2, j + 48, 0);
438
            String s2 = I18n.format("book.byAuthor", new Object[] {this.editingPlayer.getName()});
439
            int i1 = this.fontRendererObj.getStringWidth(s2);
440
            this.fontRendererObj.drawString(EnumChatFormatting.DARK_GRAY + s2, i + 36 + (116 - i1) / 2, j + 48 + 10, 0);
441
            String s3 = I18n.format("book.finalizeWarning", new Object[0]);
442
            this.fontRendererObj.drawSplitString(s3, i + 36, j + 80, 116, 0);
443
        }
444
        else
445
        {
446
            String s4 = I18n.format("book.pageIndicator", new Object[] {Integer.valueOf(this.currPage + 1), Integer.valueOf(this.bookTotalPages)});
447
            String s5 = "";
448
449
            if (this.bookPages != null && this.currPage >= 0 && this.currPage < this.bookPages.tagCount())
450
            {
451
                s5 = this.bookPages.getStringTagAt(this.currPage);
452
            }
453
454
            if (this.bookIsUnsigned)
455
            {
456
                if (this.fontRendererObj.getBidiFlag())
457
                {
458
                    s5 = s5 + "_";
459
                }
460
                else if (this.updateCount / 6 % 2 == 0)
461
                {
462
                    s5 = s5 + "" + EnumChatFormatting.BLACK + "_";
463
                }
464
                else
465
                {
466
                    s5 = s5 + "" + EnumChatFormatting.GRAY + "_";
467
                }
468
            }
469
            else if (this.field_175387_B != this.currPage)
470
            {
471
                if (ItemEditableBook.validBookTagContents(this.bookObj.getTagCompound()))
472
                {
473
                    try
474
                    {
475
                        IChatComponent ichatcomponent = IChatComponent.Serializer.jsonToComponent(s5);
476
                        this.field_175386_A = ichatcomponent != null ? GuiUtilRenderComponents.splitText(ichatcomponent, 116, this.fontRendererObj, true, true) : null;
477
                    }
478
                    catch (JsonParseException var13)
479
                    {
480
                        this.field_175386_A = null;
481
                    }
482
                }
483
                else
484
                {
485
                    ChatComponentText chatcomponenttext = new ChatComponentText(EnumChatFormatting.DARK_RED.toString() + "* Invalid book tag *");
486
                    this.field_175386_A = Lists.newArrayList(chatcomponenttext);
487
                }
488
489
                this.field_175387_B = this.currPage;
490
            }
491
492
            int j1 = this.fontRendererObj.getStringWidth(s4);
493
            this.fontRendererObj.drawString(s4, i - j1 + this.bookImageWidth - 44, j + 16, 0);
494
495
            if (this.field_175386_A == null)
496
            {
497
                this.fontRendererObj.drawSplitString(s5, i + 36, j + 16 + 16, 116, 0);
498
            }
499
            else
500
            {
501
                int k1 = Math.min(128 / this.fontRendererObj.FONT_HEIGHT, this.field_175386_A.size());
502
503
                for (int l1 = 0; l1 < k1; ++l1)
504
                {
505
                    IChatComponent ichatcomponent2 = (IChatComponent)this.field_175386_A.get(l1);
506
                    this.fontRendererObj.drawString(ichatcomponent2.getUnformattedText(), i + 36, j + 16 + 16 + l1 * this.fontRendererObj.FONT_HEIGHT, 0);
507
                }
508
509
                IChatComponent ichatcomponent1 = this.func_175385_b(mouseX, mouseY);
510
511
                if (ichatcomponent1 != null)
512
                {
513
                    this.handleComponentHover(ichatcomponent1, mouseX, mouseY);
514
                }
515
            }
516
        }
517
518
        super.drawScreen(mouseX, mouseY, partialTicks);
519
    }
520
521
    /**
522
     * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
523
     */
524
    protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
525
    {
526
        if (mouseButton == 0)
527
        {
528
            IChatComponent ichatcomponent = this.func_175385_b(mouseX, mouseY);
529
530
            if (this.handleComponentClick(ichatcomponent))
531
            {
532
                return;
533
            }
534
        }
535
536
        super.mouseClicked(mouseX, mouseY, mouseButton);
537
    }
538
539
    /**
540
     * Executes the click event specified by the given chat component
541
     *  
542
     * @param component The ChatComponent to check for click
543
     */
544
    protected boolean handleComponentClick(IChatComponent component)
545
    {
546
        ClickEvent clickevent = component == null ? null : component.getChatStyle().getChatClickEvent();
547
548
        if (clickevent == null)
549
        {
550
            return false;
551
        }
552
        else if (clickevent.getAction() == ClickEvent.Action.CHANGE_PAGE)
553
        {
554
            String s = clickevent.getValue();
555
556
            try
557
            {
558
                int i = Integer.parseInt(s) - 1;
559
560
                if (i >= 0 && i < this.bookTotalPages && i != this.currPage)
561
                {
562
                    this.currPage = i;
563
                    this.updateButtons();
564
                    return true;
565
                }
566
            }
567
            catch (Throwable var5)
568
            {
569
                ;
570
            }
571
572
            return false;
573
        }
574
        else
575
        {
576
            boolean flag = super.handleComponentClick(component);
577
578
            if (flag && clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
579
            {
580
                this.mc.displayGuiScreen((GuiScreen)null);
581
            }
582
583
            return flag;
584
        }
585
    }
586
587
    public IChatComponent func_175385_b(int p_175385_1_, int p_175385_2_)
588
    {
589
        if (this.field_175386_A == null)
590
        {
591
            return null;
592
        }
593
        else
594
        {
595
            int i = p_175385_1_ - (this.width - this.bookImageWidth) / 2 - 36;
596
            int j = p_175385_2_ - 2 - 16 - 16;
597
598
            if (i >= 0 && j >= 0)
599
            {
600
                int k = Math.min(128 / this.fontRendererObj.FONT_HEIGHT, this.field_175386_A.size());
601
602
                if (i <= 116 && j < this.mc.fontRendererObj.FONT_HEIGHT * k + k)
603
                {
604
                    int l = j / this.mc.fontRendererObj.FONT_HEIGHT;
605
606
                    if (l >= 0 && l < this.field_175386_A.size())
607
                    {
608
                        IChatComponent ichatcomponent = (IChatComponent)this.field_175386_A.get(l);
609
                        int i1 = 0;
610
611
                        for (IChatComponent ichatcomponent1 : ichatcomponent)
612
                        {
613
                            if (ichatcomponent1 instanceof ChatComponentText)
614
                            {
615
                                i1 += this.mc.fontRendererObj.getStringWidth(((ChatComponentText)ichatcomponent1).getChatComponentText_TextValue());
616
617
                                if (i1 > i)
618
                                {
619
                                    return ichatcomponent1;
620
                                }
621
                            }
622
                        }
623
                    }
624
625
                    return null;
626
                }
627
                else
628
                {
629
                    return null;
630
                }
631
            }
632
            else
633
            {
634
                return null;
635
            }
636
        }
637
    }
638
639
    static class NextPageButton extends GuiButton
640
    {
641
        private final boolean field_146151_o;
642
643
        public NextPageButton(int p_i46316_1_, int p_i46316_2_, int p_i46316_3_, boolean p_i46316_4_)
644
        {
645
            super(p_i46316_1_, p_i46316_2_, p_i46316_3_, 23, 13, "");
646
            this.field_146151_o = p_i46316_4_;
647
        }
648
649
        public void drawButton(Minecraft mc, int mouseX, int mouseY)
650
        {
651
            if (this.visible)
652
            {
653
                boolean flag = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
654
                GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
655
                mc.getTextureManager().bindTexture(GuiScreenBook.bookGuiTextures);
656
                int i = 0;
657
                int j = 192;
658
659
                if (flag)
660
                {
661
                    i += 23;
662
                }
663
664
                if (!this.field_146151_o)
665
                {
666
                    j += 13;
667
                }
668
669
                this.drawTexturedModalRect(this.xPosition, this.yPosition, i, j, 23, 13);
670
            }
671
        }
672
    }
673
}
674

Deobfuscated MCP 1.8.9 source of GuiScreenBook from Marcelektro/MavenMCP-1.8.9 (net/minecraft/client/gui/GuiScreenBook.java), stored verbatim.