| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import io.netty.buffer.Unpooled;
|
| 4 | import java.io.IOException;
|
| 5 | import net.minecraft.client.resources.I18n;
|
| 6 | import net.minecraft.command.server.CommandBlockLogic;
|
| 7 | import net.minecraft.network.PacketBuffer;
|
| 8 | import net.minecraft.network.play.client.C17PacketCustomPayload;
|
| 9 | import net.minecraft.util.IChatComponent;
|
| 10 | import org.apache.logging.log4j.LogManager;
|
| 11 | import org.apache.logging.log4j.Logger;
|
| 12 | import org.lwjgl.input.Keyboard;
|
| 13 |
|
| 14 | public class GuiCommandBlock extends GuiScreen
|
| 15 | {
|
| 16 | private static final Logger field_146488_a = LogManager.getLogger();
|
| 17 |
|
| 18 | /** Text field containing the command block's command. */
|
| 19 | private GuiTextField commandTextField;
|
| 20 | private GuiTextField previousOutputTextField;
|
| 21 |
|
| 22 | /** Command block being edited. */
|
| 23 | private final CommandBlockLogic localCommandBlock;
|
| 24 |
|
| 25 | /** "Done" button for the GUI. */
|
| 26 | private GuiButton doneBtn;
|
| 27 | private GuiButton cancelBtn;
|
| 28 | private GuiButton field_175390_s;
|
| 29 | private boolean field_175389_t;
|
| 30 |
|
| 31 | public GuiCommandBlock(CommandBlockLogic p_i45032_1_)
|
| 32 | {
|
| 33 | this.localCommandBlock = p_i45032_1_;
|
| 34 | }
|
| 35 |
|
| 36 | /**
|
| 37 | * Called from the main game loop to update the screen.
|
| 38 | */
|
| 39 | public void updateScreen()
|
| 40 | {
|
| 41 | this.commandTextField.updateCursorCounter();
|
| 42 | }
|
| 43 |
|
| 44 | /**
|
| 45 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 46 | * window resizes, the buttonList is cleared beforehand.
|
| 47 | */
|
| 48 | public void initGui()
|
| 49 | {
|
| 50 | Keyboard.enableRepeatEvents(true);
|
| 51 | this.buttonList.clear();
|
| 52 | this.buttonList.add(this.doneBtn = new GuiButton(0, this.width / 2 - 4 - 150, this.height / 4 + 120 + 12, 150, 20, I18n.format("gui.done", new Object[0])));
|
| 53 | this.buttonList.add(this.cancelBtn = new GuiButton(1, this.width / 2 + 4, this.height / 4 + 120 + 12, 150, 20, I18n.format("gui.cancel", new Object[0])));
|
| 54 | this.buttonList.add(this.field_175390_s = new GuiButton(4, this.width / 2 + 150 - 20, 150, 20, 20, "O"));
|
| 55 | this.commandTextField = new GuiTextField(2, this.fontRendererObj, this.width / 2 - 150, 50, 300, 20);
|
| 56 | this.commandTextField.setMaxStringLength(32767);
|
| 57 | this.commandTextField.setFocused(true);
|
| 58 | this.commandTextField.setText(this.localCommandBlock.getCommand());
|
| 59 | this.previousOutputTextField = new GuiTextField(3, this.fontRendererObj, this.width / 2 - 150, 150, 276, 20);
|
| 60 | this.previousOutputTextField.setMaxStringLength(32767);
|
| 61 | this.previousOutputTextField.setEnabled(false);
|
| 62 | this.previousOutputTextField.setText("-");
|
| 63 | this.field_175389_t = this.localCommandBlock.shouldTrackOutput();
|
| 64 | this.func_175388_a();
|
| 65 | this.doneBtn.enabled = this.commandTextField.getText().trim().length() > 0;
|
| 66 | }
|
| 67 |
|
| 68 | /**
|
| 69 | * Called when the screen is unloaded. Used to disable keyboard repeat events
|
| 70 | */
|
| 71 | public void onGuiClosed()
|
| 72 | {
|
| 73 | Keyboard.enableRepeatEvents(false);
|
| 74 | }
|
| 75 |
|
| 76 | /**
|
| 77 | * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
|
| 78 | */
|
| 79 | protected void actionPerformed(GuiButton button) throws IOException
|
| 80 | {
|
| 81 | if (button.enabled)
|
| 82 | {
|
| 83 | if (button.id == 1)
|
| 84 | {
|
| 85 | this.localCommandBlock.setTrackOutput(this.field_175389_t);
|
| 86 | this.mc.displayGuiScreen((GuiScreen)null);
|
| 87 | }
|
| 88 | else if (button.id == 0)
|
| 89 | {
|
| 90 | PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
|
| 91 | packetbuffer.writeByte(this.localCommandBlock.func_145751_f());
|
| 92 | this.localCommandBlock.func_145757_a(packetbuffer);
|
| 93 | packetbuffer.writeString(this.commandTextField.getText());
|
| 94 | packetbuffer.writeBoolean(this.localCommandBlock.shouldTrackOutput());
|
| 95 | this.mc.getNetHandler().addToSendQueue(new C17PacketCustomPayload("MC|AdvCdm", packetbuffer));
|
| 96 |
|
| 97 | if (!this.localCommandBlock.shouldTrackOutput())
|
| 98 | {
|
| 99 | this.localCommandBlock.setLastOutput((IChatComponent)null);
|
| 100 | }
|
| 101 |
|
| 102 | this.mc.displayGuiScreen((GuiScreen)null);
|
| 103 | }
|
| 104 | else if (button.id == 4)
|
| 105 | {
|
| 106 | this.localCommandBlock.setTrackOutput(!this.localCommandBlock.shouldTrackOutput());
|
| 107 | this.func_175388_a();
|
| 108 | }
|
| 109 | }
|
| 110 | }
|
| 111 |
|
| 112 | /**
|
| 113 | * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
|
| 114 | * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
|
| 115 | */
|
| 116 | protected void keyTyped(char typedChar, int keyCode) throws IOException
|
| 117 | {
|
| 118 | this.commandTextField.textboxKeyTyped(typedChar, keyCode);
|
| 119 | this.previousOutputTextField.textboxKeyTyped(typedChar, keyCode);
|
| 120 | this.doneBtn.enabled = this.commandTextField.getText().trim().length() > 0;
|
| 121 |
|
| 122 | if (keyCode != 28 && keyCode != 156)
|
| 123 | {
|
| 124 | if (keyCode == 1)
|
| 125 | {
|
| 126 | this.actionPerformed(this.cancelBtn);
|
| 127 | }
|
| 128 | }
|
| 129 | else
|
| 130 | {
|
| 131 | this.actionPerformed(this.doneBtn);
|
| 132 | }
|
| 133 | }
|
| 134 |
|
| 135 | /**
|
| 136 | * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
|
| 137 | */
|
| 138 | protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
|
| 139 | {
|
| 140 | super.mouseClicked(mouseX, mouseY, mouseButton);
|
| 141 | this.commandTextField.mouseClicked(mouseX, mouseY, mouseButton);
|
| 142 | this.previousOutputTextField.mouseClicked(mouseX, mouseY, mouseButton);
|
| 143 | }
|
| 144 |
|
| 145 | /**
|
| 146 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 147 | */
|
| 148 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 149 | {
|
| 150 | this.drawDefaultBackground();
|
| 151 | this.drawCenteredString(this.fontRendererObj, I18n.format("advMode.setCommand", new Object[0]), this.width / 2, 20, 16777215);
|
| 152 | this.drawString(this.fontRendererObj, I18n.format("advMode.command", new Object[0]), this.width / 2 - 150, 37, 10526880);
|
| 153 | this.commandTextField.drawTextBox();
|
| 154 | int i = 75;
|
| 155 | int j = 0;
|
| 156 | this.drawString(this.fontRendererObj, I18n.format("advMode.nearestPlayer", new Object[0]), this.width / 2 - 150, i + j++ * this.fontRendererObj.FONT_HEIGHT, 10526880);
|
| 157 | this.drawString(this.fontRendererObj, I18n.format("advMode.randomPlayer", new Object[0]), this.width / 2 - 150, i + j++ * this.fontRendererObj.FONT_HEIGHT, 10526880);
|
| 158 | this.drawString(this.fontRendererObj, I18n.format("advMode.allPlayers", new Object[0]), this.width / 2 - 150, i + j++ * this.fontRendererObj.FONT_HEIGHT, 10526880);
|
| 159 | this.drawString(this.fontRendererObj, I18n.format("advMode.allEntities", new Object[0]), this.width / 2 - 150, i + j++ * this.fontRendererObj.FONT_HEIGHT, 10526880);
|
| 160 | this.drawString(this.fontRendererObj, "", this.width / 2 - 150, i + j++ * this.fontRendererObj.FONT_HEIGHT, 10526880);
|
| 161 |
|
| 162 | if (this.previousOutputTextField.getText().length() > 0)
|
| 163 | {
|
| 164 | i = i + j * this.fontRendererObj.FONT_HEIGHT + 16;
|
| 165 | this.drawString(this.fontRendererObj, I18n.format("advMode.previousOutput", new Object[0]), this.width / 2 - 150, i, 10526880);
|
| 166 | this.previousOutputTextField.drawTextBox();
|
| 167 | }
|
| 168 |
|
| 169 | super.drawScreen(mouseX, mouseY, partialTicks);
|
| 170 | }
|
| 171 |
|
| 172 | private void func_175388_a()
|
| 173 | {
|
| 174 | if (this.localCommandBlock.shouldTrackOutput())
|
| 175 | {
|
| 176 | this.field_175390_s.displayString = "O";
|
| 177 |
|
| 178 | if (this.localCommandBlock.getLastOutput() != null)
|
| 179 | {
|
| 180 | this.previousOutputTextField.setText(this.localCommandBlock.getLastOutput().getUnformattedText());
|
| 181 | }
|
| 182 | }
|
| 183 | else
|
| 184 | {
|
| 185 | this.field_175390_s.displayString = "X";
|
| 186 | this.previousOutputTextField.setText("-");
|
| 187 | }
|
| 188 | }
|
| 189 | }
|
| 190 |
|