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