| 1 | package net.minecraft.client.gui.inventory;
|
| 2 |
|
| 3 | import io.netty.buffer.Unpooled;
|
| 4 | import java.io.IOException;
|
| 5 | import net.minecraft.client.Minecraft;
|
| 6 | import net.minecraft.client.gui.GuiButton;
|
| 7 | import net.minecraft.client.gui.GuiScreen;
|
| 8 | import net.minecraft.client.renderer.GlStateManager;
|
| 9 | import net.minecraft.client.renderer.RenderHelper;
|
| 10 | import net.minecraft.client.resources.I18n;
|
| 11 | import net.minecraft.entity.player.InventoryPlayer;
|
| 12 | import net.minecraft.init.Items;
|
| 13 | import net.minecraft.inventory.ContainerBeacon;
|
| 14 | import net.minecraft.inventory.IInventory;
|
| 15 | import net.minecraft.item.ItemStack;
|
| 16 | import net.minecraft.network.PacketBuffer;
|
| 17 | import net.minecraft.network.play.client.C17PacketCustomPayload;
|
| 18 | import net.minecraft.potion.Potion;
|
| 19 | import net.minecraft.tileentity.TileEntityBeacon;
|
| 20 | import net.minecraft.util.ResourceLocation;
|
| 21 | import org.apache.logging.log4j.LogManager;
|
| 22 | import org.apache.logging.log4j.Logger;
|
| 23 |
|
| 24 | public class GuiBeacon extends GuiContainer
|
| 25 | {
|
| 26 | private static final Logger logger = LogManager.getLogger();
|
| 27 | private static final ResourceLocation beaconGuiTextures = new ResourceLocation("textures/gui/container/beacon.png");
|
| 28 | private IInventory tileBeacon;
|
| 29 | private GuiBeacon.ConfirmButton beaconConfirmButton;
|
| 30 | private boolean buttonsNotDrawn;
|
| 31 |
|
| 32 | public GuiBeacon(InventoryPlayer playerInventory, IInventory tileBeaconIn)
|
| 33 | {
|
| 34 | super(new ContainerBeacon(playerInventory, tileBeaconIn));
|
| 35 | this.tileBeacon = tileBeaconIn;
|
| 36 | this.xSize = 230;
|
| 37 | this.ySize = 219;
|
| 38 | }
|
| 39 |
|
| 40 | /**
|
| 41 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 42 | * window resizes, the buttonList is cleared beforehand.
|
| 43 | */
|
| 44 | public void initGui()
|
| 45 | {
|
| 46 | super.initGui();
|
| 47 | this.buttonList.add(this.beaconConfirmButton = new GuiBeacon.ConfirmButton(-1, this.guiLeft + 164, this.guiTop + 107));
|
| 48 | this.buttonList.add(new GuiBeacon.CancelButton(-2, this.guiLeft + 190, this.guiTop + 107));
|
| 49 | this.buttonsNotDrawn = true;
|
| 50 | this.beaconConfirmButton.enabled = false;
|
| 51 | }
|
| 52 |
|
| 53 | /**
|
| 54 | * Called from the main game loop to update the screen.
|
| 55 | */
|
| 56 | public void updateScreen()
|
| 57 | {
|
| 58 | super.updateScreen();
|
| 59 | int i = this.tileBeacon.getField(0);
|
| 60 | int j = this.tileBeacon.getField(1);
|
| 61 | int k = this.tileBeacon.getField(2);
|
| 62 |
|
| 63 | if (this.buttonsNotDrawn && i >= 0)
|
| 64 | {
|
| 65 | this.buttonsNotDrawn = false;
|
| 66 |
|
| 67 | for (int l = 0; l <= 2; ++l)
|
| 68 | {
|
| 69 | int i1 = TileEntityBeacon.effectsList[l].length;
|
| 70 | int j1 = i1 * 22 + (i1 - 1) * 2;
|
| 71 |
|
| 72 | for (int k1 = 0; k1 < i1; ++k1)
|
| 73 | {
|
| 74 | int l1 = TileEntityBeacon.effectsList[l][k1].id;
|
| 75 | GuiBeacon.PowerButton guibeacon$powerbutton = new GuiBeacon.PowerButton(l << 8 | l1, this.guiLeft + 76 + k1 * 24 - j1 / 2, this.guiTop + 22 + l * 25, l1, l);
|
| 76 | this.buttonList.add(guibeacon$powerbutton);
|
| 77 |
|
| 78 | if (l >= i)
|
| 79 | {
|
| 80 | guibeacon$powerbutton.enabled = false;
|
| 81 | }
|
| 82 | else if (l1 == j)
|
| 83 | {
|
| 84 | guibeacon$powerbutton.func_146140_b(true);
|
| 85 | }
|
| 86 | }
|
| 87 | }
|
| 88 |
|
| 89 | int i2 = 3;
|
| 90 | int j2 = TileEntityBeacon.effectsList[i2].length + 1;
|
| 91 | int k2 = j2 * 22 + (j2 - 1) * 2;
|
| 92 |
|
| 93 | for (int l2 = 0; l2 < j2 - 1; ++l2)
|
| 94 | {
|
| 95 | int i3 = TileEntityBeacon.effectsList[i2][l2].id;
|
| 96 | GuiBeacon.PowerButton guibeacon$powerbutton2 = new GuiBeacon.PowerButton(i2 << 8 | i3, this.guiLeft + 167 + l2 * 24 - k2 / 2, this.guiTop + 47, i3, i2);
|
| 97 | this.buttonList.add(guibeacon$powerbutton2);
|
| 98 |
|
| 99 | if (i2 >= i)
|
| 100 | {
|
| 101 | guibeacon$powerbutton2.enabled = false;
|
| 102 | }
|
| 103 | else if (i3 == k)
|
| 104 | {
|
| 105 | guibeacon$powerbutton2.func_146140_b(true);
|
| 106 | }
|
| 107 | }
|
| 108 |
|
| 109 | if (j > 0)
|
| 110 | {
|
| 111 | GuiBeacon.PowerButton guibeacon$powerbutton1 = new GuiBeacon.PowerButton(i2 << 8 | j, this.guiLeft + 167 + (j2 - 1) * 24 - k2 / 2, this.guiTop + 47, j, i2);
|
| 112 | this.buttonList.add(guibeacon$powerbutton1);
|
| 113 |
|
| 114 | if (i2 >= i)
|
| 115 | {
|
| 116 | guibeacon$powerbutton1.enabled = false;
|
| 117 | }
|
| 118 | else if (j == k)
|
| 119 | {
|
| 120 | guibeacon$powerbutton1.func_146140_b(true);
|
| 121 | }
|
| 122 | }
|
| 123 | }
|
| 124 |
|
| 125 | this.beaconConfirmButton.enabled = this.tileBeacon.getStackInSlot(0) != null && j > 0;
|
| 126 | }
|
| 127 |
|
| 128 | /**
|
| 129 | * Called by the controls from the buttonList when activated. (Mouse pressed for buttons)
|
| 130 | */
|
| 131 | protected void actionPerformed(GuiButton button) throws IOException
|
| 132 | {
|
| 133 | if (button.id == -2)
|
| 134 | {
|
| 135 | this.mc.displayGuiScreen((GuiScreen)null);
|
| 136 | }
|
| 137 | else if (button.id == -1)
|
| 138 | {
|
| 139 | String s = "MC|Beacon";
|
| 140 | PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
|
| 141 | packetbuffer.writeInt(this.tileBeacon.getField(1));
|
| 142 | packetbuffer.writeInt(this.tileBeacon.getField(2));
|
| 143 | this.mc.getNetHandler().addToSendQueue(new C17PacketCustomPayload(s, packetbuffer));
|
| 144 | this.mc.displayGuiScreen((GuiScreen)null);
|
| 145 | }
|
| 146 | else if (button instanceof GuiBeacon.PowerButton)
|
| 147 | {
|
| 148 | if (((GuiBeacon.PowerButton)button).func_146141_c())
|
| 149 | {
|
| 150 | return;
|
| 151 | }
|
| 152 |
|
| 153 | int j = button.id;
|
| 154 | int k = j & 255;
|
| 155 | int i = j >> 8;
|
| 156 |
|
| 157 | if (i < 3)
|
| 158 | {
|
| 159 | this.tileBeacon.setField(1, k);
|
| 160 | }
|
| 161 | else
|
| 162 | {
|
| 163 | this.tileBeacon.setField(2, k);
|
| 164 | }
|
| 165 |
|
| 166 | this.buttonList.clear();
|
| 167 | this.initGui();
|
| 168 | this.updateScreen();
|
| 169 | }
|
| 170 | }
|
| 171 |
|
| 172 | /**
|
| 173 | * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
|
| 174 | */
|
| 175 | protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
| 176 | {
|
| 177 | RenderHelper.disableStandardItemLighting();
|
| 178 | this.drawCenteredString(this.fontRendererObj, I18n.format("tile.beacon.primary", new Object[0]), 62, 10, 14737632);
|
| 179 | this.drawCenteredString(this.fontRendererObj, I18n.format("tile.beacon.secondary", new Object[0]), 169, 10, 14737632);
|
| 180 |
|
| 181 | for (GuiButton guibutton : this.buttonList)
|
| 182 | {
|
| 183 | if (guibutton.isMouseOver())
|
| 184 | {
|
| 185 | guibutton.drawButtonForegroundLayer(mouseX - this.guiLeft, mouseY - this.guiTop);
|
| 186 | break;
|
| 187 | }
|
| 188 | }
|
| 189 |
|
| 190 | RenderHelper.enableGUIStandardItemLighting();
|
| 191 | }
|
| 192 |
|
| 193 | /**
|
| 194 | * Args : renderPartialTicks, mouseX, mouseY
|
| 195 | */
|
| 196 | protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
|
| 197 | {
|
| 198 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 199 | this.mc.getTextureManager().bindTexture(beaconGuiTextures);
|
| 200 | int i = (this.width - this.xSize) / 2;
|
| 201 | int j = (this.height - this.ySize) / 2;
|
| 202 | this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
|
| 203 | this.itemRender.zLevel = 100.0F;
|
| 204 | this.itemRender.renderItemAndEffectIntoGUI(new ItemStack(Items.emerald), i + 42, j + 109);
|
| 205 | this.itemRender.renderItemAndEffectIntoGUI(new ItemStack(Items.diamond), i + 42 + 22, j + 109);
|
| 206 | this.itemRender.renderItemAndEffectIntoGUI(new ItemStack(Items.gold_ingot), i + 42 + 44, j + 109);
|
| 207 | this.itemRender.renderItemAndEffectIntoGUI(new ItemStack(Items.iron_ingot), i + 42 + 66, j + 109);
|
| 208 | this.itemRender.zLevel = 0.0F;
|
| 209 | }
|
| 210 |
|
| 211 | static class Button extends GuiButton
|
| 212 | {
|
| 213 | private final ResourceLocation field_146145_o;
|
| 214 | private final int field_146144_p;
|
| 215 | private final int field_146143_q;
|
| 216 | private boolean field_146142_r;
|
| 217 |
|
| 218 | protected Button(int p_i1077_1_, int p_i1077_2_, int p_i1077_3_, ResourceLocation p_i1077_4_, int p_i1077_5_, int p_i1077_6_)
|
| 219 | {
|
| 220 | super(p_i1077_1_, p_i1077_2_, p_i1077_3_, 22, 22, "");
|
| 221 | this.field_146145_o = p_i1077_4_;
|
| 222 | this.field_146144_p = p_i1077_5_;
|
| 223 | this.field_146143_q = p_i1077_6_;
|
| 224 | }
|
| 225 |
|
| 226 | public void drawButton(Minecraft mc, int mouseX, int mouseY)
|
| 227 | {
|
| 228 | if (this.visible)
|
| 229 | {
|
| 230 | mc.getTextureManager().bindTexture(GuiBeacon.beaconGuiTextures);
|
| 231 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 232 | this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height;
|
| 233 | int i = 219;
|
| 234 | int j = 0;
|
| 235 |
|
| 236 | if (!this.enabled)
|
| 237 | {
|
| 238 | j += this.width * 2;
|
| 239 | }
|
| 240 | else if (this.field_146142_r)
|
| 241 | {
|
| 242 | j += this.width * 1;
|
| 243 | }
|
| 244 | else if (this.hovered)
|
| 245 | {
|
| 246 | j += this.width * 3;
|
| 247 | }
|
| 248 |
|
| 249 | this.drawTexturedModalRect(this.xPosition, this.yPosition, j, i, this.width, this.height);
|
| 250 |
|
| 251 | if (!GuiBeacon.beaconGuiTextures.equals(this.field_146145_o))
|
| 252 | {
|
| 253 | mc.getTextureManager().bindTexture(this.field_146145_o);
|
| 254 | }
|
| 255 |
|
| 256 | this.drawTexturedModalRect(this.xPosition + 2, this.yPosition + 2, this.field_146144_p, this.field_146143_q, 18, 18);
|
| 257 | }
|
| 258 | }
|
| 259 |
|
| 260 | public boolean func_146141_c()
|
| 261 | {
|
| 262 | return this.field_146142_r;
|
| 263 | }
|
| 264 |
|
| 265 | public void func_146140_b(boolean p_146140_1_)
|
| 266 | {
|
| 267 | this.field_146142_r = p_146140_1_;
|
| 268 | }
|
| 269 | }
|
| 270 |
|
| 271 | class CancelButton extends GuiBeacon.Button
|
| 272 | {
|
| 273 | public CancelButton(int p_i1074_2_, int p_i1074_3_, int p_i1074_4_)
|
| 274 | {
|
| 275 | super(p_i1074_2_, p_i1074_3_, p_i1074_4_, GuiBeacon.beaconGuiTextures, 112, 220);
|
| 276 | }
|
| 277 |
|
| 278 | public void drawButtonForegroundLayer(int mouseX, int mouseY)
|
| 279 | {
|
| 280 | GuiBeacon.this.drawCreativeTabHoveringText(I18n.format("gui.cancel", new Object[0]), mouseX, mouseY);
|
| 281 | }
|
| 282 | }
|
| 283 |
|
| 284 | class ConfirmButton extends GuiBeacon.Button
|
| 285 | {
|
| 286 | public ConfirmButton(int p_i1075_2_, int p_i1075_3_, int p_i1075_4_)
|
| 287 | {
|
| 288 | super(p_i1075_2_, p_i1075_3_, p_i1075_4_, GuiBeacon.beaconGuiTextures, 90, 220);
|
| 289 | }
|
| 290 |
|
| 291 | public void drawButtonForegroundLayer(int mouseX, int mouseY)
|
| 292 | {
|
| 293 | GuiBeacon.this.drawCreativeTabHoveringText(I18n.format("gui.done", new Object[0]), mouseX, mouseY);
|
| 294 | }
|
| 295 | }
|
| 296 |
|
| 297 | class PowerButton extends GuiBeacon.Button
|
| 298 | {
|
| 299 | private final int field_146149_p;
|
| 300 | private final int field_146148_q;
|
| 301 |
|
| 302 | public PowerButton(int p_i1076_2_, int p_i1076_3_, int p_i1076_4_, int p_i1076_5_, int p_i1076_6_)
|
| 303 | {
|
| 304 | super(p_i1076_2_, p_i1076_3_, p_i1076_4_, GuiContainer.inventoryBackground, 0 + Potion.potionTypes[p_i1076_5_].getStatusIconIndex() % 8 * 18, 198 + Potion.potionTypes[p_i1076_5_].getStatusIconIndex() / 8 * 18);
|
| 305 | this.field_146149_p = p_i1076_5_;
|
| 306 | this.field_146148_q = p_i1076_6_;
|
| 307 | }
|
| 308 |
|
| 309 | public void drawButtonForegroundLayer(int mouseX, int mouseY)
|
| 310 | {
|
| 311 | String s = I18n.format(Potion.potionTypes[this.field_146149_p].getName(), new Object[0]);
|
| 312 |
|
| 313 | if (this.field_146148_q >= 3 && this.field_146149_p != Potion.regeneration.id)
|
| 314 | {
|
| 315 | s = s + " II";
|
| 316 | }
|
| 317 |
|
| 318 | GuiBeacon.this.drawCreativeTabHoveringText(s, mouseX, mouseY);
|
| 319 | }
|
| 320 | }
|
| 321 | }
|
| 322 |
|