001 package net.minecraft.src; 002 003 import cpw.mods.fml.common.Side; 004 import cpw.mods.fml.common.asm.SideOnly; 005 import java.io.ByteArrayOutputStream; 006 import java.io.DataOutputStream; 007 import org.lwjgl.input.Keyboard; 008 009 @SideOnly(Side.CLIENT) 010 public class GuiCommandBlock extends GuiScreen 011 { 012 private GuiTextField field_82318_a; 013 private final TileEntityCommandBlock field_82317_b; 014 015 public GuiCommandBlock(TileEntityCommandBlock par1) 016 { 017 this.field_82317_b = par1; 018 } 019 020 /** 021 * Called from the main game loop to update the screen. 022 */ 023 public void updateScreen() 024 { 025 this.field_82318_a.updateCursorCounter(); 026 } 027 028 /** 029 * Adds the buttons (and other controls) to the screen in question. 030 */ 031 public void initGui() 032 { 033 StringTranslate var1 = StringTranslate.getInstance(); 034 Keyboard.enableRepeatEvents(true); 035 this.controlList.clear(); 036 this.controlList.add(new GuiButton(0, this.width / 2 - 100, this.height / 4 + 96 + 12, var1.translateKey("gui.done"))); 037 this.controlList.add(new GuiButton(1, this.width / 2 - 100, this.height / 4 + 120 + 12, var1.translateKey("gui.cancel"))); 038 this.field_82318_a = new GuiTextField(this.fontRenderer, this.width / 2 - 150, 60, 300, 20); 039 this.field_82318_a.setMaxStringLength(32767); 040 this.field_82318_a.setFocused(true); 041 this.field_82318_a.setText(this.field_82317_b.func_82353_c()); 042 } 043 044 /** 045 * Called when the screen is unloaded. Used to disable keyboard repeat events 046 */ 047 public void onGuiClosed() 048 { 049 Keyboard.enableRepeatEvents(false); 050 } 051 052 /** 053 * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e). 054 */ 055 protected void actionPerformed(GuiButton par1GuiButton) 056 { 057 if (par1GuiButton.enabled) 058 { 059 if (par1GuiButton.id == 1) 060 { 061 this.mc.displayGuiScreen((GuiScreen)null); 062 } 063 else if (par1GuiButton.id == 0) 064 { 065 String var2 = "MC|AdvCdm"; 066 ByteArrayOutputStream var3 = new ByteArrayOutputStream(); 067 DataOutputStream var4 = new DataOutputStream(var3); 068 069 try 070 { 071 var4.writeInt(this.field_82317_b.xCoord); 072 var4.writeInt(this.field_82317_b.yCoord); 073 var4.writeInt(this.field_82317_b.zCoord); 074 Packet.writeString(this.field_82318_a.getText(), var4); 075 this.mc.getSendQueue().addToSendQueue(new Packet250CustomPayload(var2, var3.toByteArray())); 076 } 077 catch (Exception var6) 078 { 079 var6.printStackTrace(); 080 } 081 082 this.mc.displayGuiScreen((GuiScreen)null); 083 } 084 } 085 } 086 087 /** 088 * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). 089 */ 090 protected void keyTyped(char par1, int par2) 091 { 092 this.field_82318_a.textboxKeyTyped(par1, par2); 093 ((GuiButton)this.controlList.get(0)).enabled = this.field_82318_a.getText().trim().length() > 0; 094 095 if (par1 == 13) 096 { 097 this.actionPerformed((GuiButton)this.controlList.get(0)); 098 } 099 } 100 101 /** 102 * Called when the mouse is clicked. 103 */ 104 protected void mouseClicked(int par1, int par2, int par3) 105 { 106 super.mouseClicked(par1, par2, par3); 107 this.field_82318_a.mouseClicked(par1, par2, par3); 108 } 109 110 /** 111 * Draws the screen and all the components in it. 112 */ 113 public void drawScreen(int par1, int par2, float par3) 114 { 115 StringTranslate var4 = StringTranslate.getInstance(); 116 this.drawDefaultBackground(); 117 this.drawCenteredString(this.fontRenderer, var4.translateKey("advMode.setCommand"), this.width / 2, this.height / 4 - 60 + 20, 16777215); 118 this.drawString(this.fontRenderer, var4.translateKey("advMode.command"), this.width / 2 - 150, 47, 10526880); 119 this.drawString(this.fontRenderer, var4.translateKey("advMode.nearestPlayer"), this.width / 2 - 150, 97, 10526880); 120 this.drawString(this.fontRenderer, var4.translateKey("advMode.randomPlayer"), this.width / 2 - 150, 108, 10526880); 121 this.drawString(this.fontRenderer, var4.translateKey("advMode.allPlayers"), this.width / 2 - 150, 119, 10526880); 122 this.field_82318_a.drawTextBox(); 123 super.drawScreen(par1, par2, par3); 124 } 125 }