    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 java.util.Iterator;
    008    import org.lwjgl.opengl.GL11;
    009
    010    @SideOnly(Side.CLIENT)
    011    public class GuiBeacon extends GuiContainer
    012    {
    013        private TileEntityBeacon beacon;
    014        private GuiBeaconButtonConfirm beaconConfirmButton;
    015        private boolean buttonsNotDrawn;
    016
    017        public GuiBeacon(InventoryPlayer par1, TileEntityBeacon par2)
    018        {
    019            super(new ContainerBeacon(par1, par2));
    020            this.beacon = par2;
    021            this.xSize = 230;
    022            this.ySize = 219;
    023        }
    024
    025        /**
    026         * Adds the buttons (and other controls) to the screen in question.
    027         */
    028        public void initGui()
    029        {
    030            super.initGui();
    031            this.controlList.add(this.beaconConfirmButton = new GuiBeaconButtonConfirm(this, -1, this.guiLeft + 164, this.guiTop + 107));
    032            this.controlList.add(new GuiBeaconButtonCancel(this, -2, this.guiLeft + 190, this.guiTop + 107));
    033            this.buttonsNotDrawn = true;
    034            this.beaconConfirmButton.enabled = false;
    035        }
    036
    037        /**
    038         * Called from the main game loop to update the screen.
    039         */
    040        public void updateScreen()
    041        {
    042            super.updateScreen();
    043
    044            if (this.buttonsNotDrawn && this.beacon.getLevels() >= 0)
    045            {
    046                this.buttonsNotDrawn = false;
    047                int var2;
    048                int var3;
    049                int var4;
    050                int var5;
    051                GuiBeaconButtonPower var6;
    052
    053                for (int var1 = 0; var1 <= 2; ++var1)
    054                {
    055                    var2 = TileEntityBeacon.effectsList[var1].length;
    056                    var3 = var2 * 22 + (var2 - 1) * 2;
    057
    058                    for (var4 = 0; var4 < var2; ++var4)
    059                    {
    060                        var5 = TileEntityBeacon.effectsList[var1][var4].id;
    061                        var6 = new GuiBeaconButtonPower(this, var1 << 8 | var5, this.guiLeft + 76 + var4 * 24 - var3 / 2, this.guiTop + 22 + var1 * 25, var5, var1);
    062                        this.controlList.add(var6);
    063
    064                        if (var1 >= this.beacon.getLevels())
    065                        {
    066                            var6.enabled = false;
    067                        }
    068                        else if (var5 == this.beacon.getPrimaryEffect())
    069                        {
    070                            var6.func_82254_b(true);
    071                        }
    072                    }
    073                }
    074
    075                byte var7 = 3;
    076                var2 = TileEntityBeacon.effectsList[var7].length + 1;
    077                var3 = var2 * 22 + (var2 - 1) * 2;
    078
    079                for (var4 = 0; var4 < var2 - 1; ++var4)
    080                {
    081                    var5 = TileEntityBeacon.effectsList[var7][var4].id;
    082                    var6 = new GuiBeaconButtonPower(this, var7 << 8 | var5, this.guiLeft + 167 + var4 * 24 - var3 / 2, this.guiTop + 47, var5, var7);
    083                    this.controlList.add(var6);
    084
    085                    if (var7 >= this.beacon.getLevels())
    086                    {
    087                        var6.enabled = false;
    088                    }
    089                    else if (var5 == this.beacon.getSecondaryEffect())
    090                    {
    091                        var6.func_82254_b(true);
    092                    }
    093                }
    094
    095                if (this.beacon.getPrimaryEffect() > 0)
    096                {
    097                    GuiBeaconButtonPower var8 = new GuiBeaconButtonPower(this, var7 << 8 | this.beacon.getPrimaryEffect(), this.guiLeft + 167 + (var2 - 1) * 24 - var3 / 2, this.guiTop + 47, this.beacon.getPrimaryEffect(), var7);
    098                    this.controlList.add(var8);
    099
    100                    if (var7 >= this.beacon.getLevels())
    101                    {
    102                        var8.enabled = false;
    103                    }
    104                    else if (this.beacon.getPrimaryEffect() == this.beacon.getSecondaryEffect())
    105                    {
    106                        var8.func_82254_b(true);
    107                    }
    108                }
    109            }
    110
    111            this.beaconConfirmButton.enabled = this.beacon.getStackInSlot(0) != null && this.beacon.getPrimaryEffect() > 0;
    112        }
    113
    114        /**
    115         * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e).
    116         */
    117        protected void actionPerformed(GuiButton par1GuiButton)
    118        {
    119            if (par1GuiButton.id == -2)
    120            {
    121                this.mc.displayGuiScreen((GuiScreen)null);
    122            }
    123            else if (par1GuiButton.id == -1)
    124            {
    125                String var2 = "MC|Beacon";
    126                ByteArrayOutputStream var3 = new ByteArrayOutputStream();
    127                DataOutputStream var4 = new DataOutputStream(var3);
    128
    129                try
    130                {
    131                    var4.writeInt(this.beacon.getPrimaryEffect());
    132                    var4.writeInt(this.beacon.getSecondaryEffect());
    133                    this.mc.getSendQueue().addToSendQueue(new Packet250CustomPayload(var2, var3.toByteArray()));
    134                }
    135                catch (Exception var6)
    136                {
    137                    var6.printStackTrace();
    138                }
    139
    140                this.mc.displayGuiScreen((GuiScreen)null);
    141            }
    142            else if (par1GuiButton instanceof GuiBeaconButtonPower)
    143            {
    144                if (((GuiBeaconButtonPower)par1GuiButton).func_82255_b())
    145                {
    146                    return;
    147                }
    148
    149                int var7 = par1GuiButton.id;
    150                int var8 = var7 & 255;
    151                int var9 = var7 >> 8;
    152
    153                if (var9 < 3)
    154                {
    155                    this.beacon.func_82128_d(var8);
    156                }
    157                else
    158                {
    159                    this.beacon.func_82127_e(var8);
    160                }
    161
    162                this.controlList.clear();
    163                this.initGui();
    164                this.updateScreen();
    165            }
    166        }
    167
    168        /**
    169         * Draw the foreground layer for the GuiContainer (everything in front of the items)
    170         */
    171        protected void drawGuiContainerForegroundLayer(int par1, int par2)
    172        {
    173            RenderHelper.disableStandardItemLighting();
    174            this.drawCenteredString(this.fontRenderer, StatCollector.translateToLocal("tile.beacon.primary"), 62, 10, 14737632);
    175            this.drawCenteredString(this.fontRenderer, StatCollector.translateToLocal("tile.beacon.secondary"), 169, 10, 14737632);
    176            Iterator var3 = this.controlList.iterator();
    177
    178            while (var3.hasNext())
    179            {
    180                GuiButton var4 = (GuiButton)var3.next();
    181
    182                if (var4.func_82252_a())
    183                {
    184                    var4.func_82251_b(par1 - this.guiLeft, par2 - this.guiTop);
    185                    break;
    186                }
    187            }
    188
    189            RenderHelper.enableGUIStandardItemLighting();
    190        }
    191
    192        /**
    193         * Draw the background layer for the GuiContainer (everything behind the items)
    194         */
    195        protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
    196        {
    197            int var4 = this.mc.renderEngine.getTexture("/gui/beacon.png");
    198            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    199            this.mc.renderEngine.bindTexture(var4);
    200            int var5 = (this.width - this.xSize) / 2;
    201            int var6 = (this.height - this.ySize) / 2;
    202            this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
    203            itemRenderer.zLevel = 100.0F;
    204            itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, new ItemStack(Item.emerald), var5 + 42, var6 + 109);
    205            itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, new ItemStack(Item.diamond), var5 + 42 + 22, var6 + 109);
    206            itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, new ItemStack(Item.ingotGold), var5 + 42 + 44, var6 + 109);
    207            itemRenderer.renderItemAndEffectIntoGUI(this.fontRenderer, this.mc.renderEngine, new ItemStack(Item.ingotIron), var5 + 42 + 66, var6 + 109);
    208            itemRenderer.zLevel = 0.0F;
    209        }
    210    }