    001package net.minecraft.client.gui;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.multiplayer.NetClientHandler;
    006import net.minecraft.network.packet.Packet19EntityAction;
    007import net.minecraft.util.StringTranslate;
    008
    009@SideOnly(Side.CLIENT)
    010public class GuiSleepMP extends GuiChat
    011{
    012    /**
    013     * Adds the buttons (and other controls) to the screen in question.
    014     */
    015    public void initGui()
    016    {
    017        super.initGui();
    018        StringTranslate stringtranslate = StringTranslate.getInstance();
    019        this.buttonList.add(new GuiButton(1, this.width / 2 - 100, this.height - 40, stringtranslate.translateKey("multiplayer.stopSleeping")));
    020    }
    021
    022    /**
    023     * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e).
    024     */
    025    protected void keyTyped(char par1, int par2)
    026    {
    027        if (par2 == 1)
    028        {
    029            this.wakeEntity();
    030        }
    031        else if (par2 == 28)
    032        {
    033            String s = this.inputField.getText().trim();
    034
    035            if (s.length() > 0)
    036            {
    037                this.mc.thePlayer.sendChatMessage(s);
    038            }
    039
    040            this.inputField.setText("");
    041            this.mc.ingameGUI.getChatGUI().resetScroll();
    042        }
    043        else
    044        {
    045            super.keyTyped(par1, par2);
    046        }
    047    }
    048
    049    /**
    050     * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    051     */
    052    protected void actionPerformed(GuiButton par1GuiButton)
    053    {
    054        if (par1GuiButton.id == 1)
    055        {
    056            this.wakeEntity();
    057        }
    058        else
    059        {
    060            super.actionPerformed(par1GuiButton);
    061        }
    062    }
    063
    064    /**
    065     * Wakes the entity from the bed
    066     */
    067    private void wakeEntity()
    068    {
    069        NetClientHandler netclienthandler = this.mc.thePlayer.sendQueue;
    070        netclienthandler.addToSendQueue(new Packet19EntityAction(this.mc.thePlayer, 3));
    071    }
    072}