| 1 | package net.minecraft.client.gui;
|
| 2 |
|
| 3 | import io.netty.buffer.Unpooled;
|
| 4 | import java.io.IOException;
|
| 5 | import java.util.List;
|
| 6 | import net.minecraft.client.Minecraft;
|
| 7 | import net.minecraft.client.gui.inventory.GuiContainer;
|
| 8 | import net.minecraft.client.renderer.GlStateManager;
|
| 9 | import net.minecraft.client.resources.I18n;
|
| 10 | import net.minecraft.entity.player.InventoryPlayer;
|
| 11 | import net.minecraft.inventory.Container;
|
| 12 | import net.minecraft.inventory.ContainerRepair;
|
| 13 | import net.minecraft.inventory.ICrafting;
|
| 14 | import net.minecraft.inventory.IInventory;
|
| 15 | import net.minecraft.inventory.Slot;
|
| 16 | import net.minecraft.item.ItemStack;
|
| 17 | import net.minecraft.network.PacketBuffer;
|
| 18 | import net.minecraft.network.play.client.C17PacketCustomPayload;
|
| 19 | import net.minecraft.util.ResourceLocation;
|
| 20 | import net.minecraft.world.World;
|
| 21 | import org.lwjgl.input.Keyboard;
|
| 22 |
|
| 23 | public class GuiRepair extends GuiContainer implements ICrafting
|
| 24 | {
|
| 25 | private static final ResourceLocation anvilResource = new ResourceLocation("textures/gui/container/anvil.png");
|
| 26 | private ContainerRepair anvil;
|
| 27 | private GuiTextField nameField;
|
| 28 | private InventoryPlayer playerInventory;
|
| 29 |
|
| 30 | public GuiRepair(InventoryPlayer inventoryIn, World worldIn)
|
| 31 | {
|
| 32 | super(new ContainerRepair(inventoryIn, worldIn, Minecraft.getMinecraft().thePlayer));
|
| 33 | this.playerInventory = inventoryIn;
|
| 34 | this.anvil = (ContainerRepair)this.inventorySlots;
|
| 35 | }
|
| 36 |
|
| 37 | /**
|
| 38 | * Adds the buttons (and other controls) to the screen in question. Called when the GUI is displayed and when the
|
| 39 | * window resizes, the buttonList is cleared beforehand.
|
| 40 | */
|
| 41 | public void initGui()
|
| 42 | {
|
| 43 | super.initGui();
|
| 44 | Keyboard.enableRepeatEvents(true);
|
| 45 | int i = (this.width - this.xSize) / 2;
|
| 46 | int j = (this.height - this.ySize) / 2;
|
| 47 | this.nameField = new GuiTextField(0, this.fontRendererObj, i + 62, j + 24, 103, 12);
|
| 48 | this.nameField.setTextColor(-1);
|
| 49 | this.nameField.setDisabledTextColour(-1);
|
| 50 | this.nameField.setEnableBackgroundDrawing(false);
|
| 51 | this.nameField.setMaxStringLength(30);
|
| 52 | this.inventorySlots.removeCraftingFromCrafters(this);
|
| 53 | this.inventorySlots.onCraftGuiOpened(this);
|
| 54 | }
|
| 55 |
|
| 56 | /**
|
| 57 | * Called when the screen is unloaded. Used to disable keyboard repeat events
|
| 58 | */
|
| 59 | public void onGuiClosed()
|
| 60 | {
|
| 61 | super.onGuiClosed();
|
| 62 | Keyboard.enableRepeatEvents(false);
|
| 63 | this.inventorySlots.removeCraftingFromCrafters(this);
|
| 64 | }
|
| 65 |
|
| 66 | /**
|
| 67 | * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
|
| 68 | */
|
| 69 | protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
|
| 70 | {
|
| 71 | GlStateManager.disableLighting();
|
| 72 | GlStateManager.disableBlend();
|
| 73 | this.fontRendererObj.drawString(I18n.format("container.repair", new Object[0]), 60, 6, 4210752);
|
| 74 |
|
| 75 | if (this.anvil.maximumCost > 0)
|
| 76 | {
|
| 77 | int i = 8453920;
|
| 78 | boolean flag = true;
|
| 79 | String s = I18n.format("container.repair.cost", new Object[] {Integer.valueOf(this.anvil.maximumCost)});
|
| 80 |
|
| 81 | if (this.anvil.maximumCost >= 40 && !this.mc.thePlayer.capabilities.isCreativeMode)
|
| 82 | {
|
| 83 | s = I18n.format("container.repair.expensive", new Object[0]);
|
| 84 | i = 16736352;
|
| 85 | }
|
| 86 | else if (!this.anvil.getSlot(2).getHasStack())
|
| 87 | {
|
| 88 | flag = false;
|
| 89 | }
|
| 90 | else if (!this.anvil.getSlot(2).canTakeStack(this.playerInventory.player))
|
| 91 | {
|
| 92 | i = 16736352;
|
| 93 | }
|
| 94 |
|
| 95 | if (flag)
|
| 96 | {
|
| 97 | int j = -16777216 | (i & 16579836) >> 2 | i & -16777216;
|
| 98 | int k = this.xSize - 8 - this.fontRendererObj.getStringWidth(s);
|
| 99 | int l = 67;
|
| 100 |
|
| 101 | if (this.fontRendererObj.getUnicodeFlag())
|
| 102 | {
|
| 103 | drawRect(k - 3, l - 2, this.xSize - 7, l + 10, -16777216);
|
| 104 | drawRect(k - 2, l - 1, this.xSize - 8, l + 9, -12895429);
|
| 105 | }
|
| 106 | else
|
| 107 | {
|
| 108 | this.fontRendererObj.drawString(s, k, l + 1, j);
|
| 109 | this.fontRendererObj.drawString(s, k + 1, l, j);
|
| 110 | this.fontRendererObj.drawString(s, k + 1, l + 1, j);
|
| 111 | }
|
| 112 |
|
| 113 | this.fontRendererObj.drawString(s, k, l, i);
|
| 114 | }
|
| 115 | }
|
| 116 |
|
| 117 | GlStateManager.enableLighting();
|
| 118 | }
|
| 119 |
|
| 120 | /**
|
| 121 | * Fired when a key is typed (except F11 which toggles full screen). This is the equivalent of
|
| 122 | * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
|
| 123 | */
|
| 124 | protected void keyTyped(char typedChar, int keyCode) throws IOException
|
| 125 | {
|
| 126 | if (this.nameField.textboxKeyTyped(typedChar, keyCode))
|
| 127 | {
|
| 128 | this.renameItem();
|
| 129 | }
|
| 130 | else
|
| 131 | {
|
| 132 | super.keyTyped(typedChar, keyCode);
|
| 133 | }
|
| 134 | }
|
| 135 |
|
| 136 | private void renameItem()
|
| 137 | {
|
| 138 | String s = this.nameField.getText();
|
| 139 | Slot slot = this.anvil.getSlot(0);
|
| 140 |
|
| 141 | if (slot != null && slot.getHasStack() && !slot.getStack().hasDisplayName() && s.equals(slot.getStack().getDisplayName()))
|
| 142 | {
|
| 143 | s = "";
|
| 144 | }
|
| 145 |
|
| 146 | this.anvil.updateItemName(s);
|
| 147 | this.mc.thePlayer.sendQueue.addToSendQueue(new C17PacketCustomPayload("MC|ItemName", (new PacketBuffer(Unpooled.buffer())).writeString(s)));
|
| 148 | }
|
| 149 |
|
| 150 | /**
|
| 151 | * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
|
| 152 | */
|
| 153 | protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
|
| 154 | {
|
| 155 | super.mouseClicked(mouseX, mouseY, mouseButton);
|
| 156 | this.nameField.mouseClicked(mouseX, mouseY, mouseButton);
|
| 157 | }
|
| 158 |
|
| 159 | /**
|
| 160 | * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
|
| 161 | */
|
| 162 | public void drawScreen(int mouseX, int mouseY, float partialTicks)
|
| 163 | {
|
| 164 | super.drawScreen(mouseX, mouseY, partialTicks);
|
| 165 | GlStateManager.disableLighting();
|
| 166 | GlStateManager.disableBlend();
|
| 167 | this.nameField.drawTextBox();
|
| 168 | }
|
| 169 |
|
| 170 | /**
|
| 171 | * Args : renderPartialTicks, mouseX, mouseY
|
| 172 | */
|
| 173 | protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
|
| 174 | {
|
| 175 | GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
| 176 | this.mc.getTextureManager().bindTexture(anvilResource);
|
| 177 | int i = (this.width - this.xSize) / 2;
|
| 178 | int j = (this.height - this.ySize) / 2;
|
| 179 | this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
|
| 180 | this.drawTexturedModalRect(i + 59, j + 20, 0, this.ySize + (this.anvil.getSlot(0).getHasStack() ? 0 : 16), 110, 16);
|
| 181 |
|
| 182 | if ((this.anvil.getSlot(0).getHasStack() || this.anvil.getSlot(1).getHasStack()) && !this.anvil.getSlot(2).getHasStack())
|
| 183 | {
|
| 184 | this.drawTexturedModalRect(i + 99, j + 45, this.xSize, 0, 28, 21);
|
| 185 | }
|
| 186 | }
|
| 187 |
|
| 188 | /**
|
| 189 | * update the crafting window inventory with the items in the list
|
| 190 | */
|
| 191 | public void updateCraftingInventory(Container containerToSend, List<ItemStack> itemsList)
|
| 192 | {
|
| 193 | this.sendSlotContents(containerToSend, 0, containerToSend.getSlot(0).getStack());
|
| 194 | }
|
| 195 |
|
| 196 | /**
|
| 197 | * Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual
|
| 198 | * contents of that slot. Args: Container, slot number, slot contents
|
| 199 | */
|
| 200 | public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack)
|
| 201 | {
|
| 202 | if (slotInd == 0)
|
| 203 | {
|
| 204 | this.nameField.setText(stack == null ? "" : stack.getDisplayName());
|
| 205 | this.nameField.setEnabled(stack != null);
|
| 206 |
|
| 207 | if (stack != null)
|
| 208 | {
|
| 209 | this.renameItem();
|
| 210 | }
|
| 211 | }
|
| 212 | }
|
| 213 |
|
| 214 | /**
|
| 215 | * Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress,
|
| 216 | * and enchanting level. Normally the first int identifies which variable to update, and the second contains the new
|
| 217 | * value. Both are truncated to shorts in non-local SMP.
|
| 218 | */
|
| 219 | public void sendProgressBarUpdate(Container containerIn, int varToUpdate, int newValue)
|
| 220 | {
|
| 221 | }
|
| 222 |
|
| 223 | public void sendAllWindowProperties(Container p_175173_1_, IInventory p_175173_2_)
|
| 224 | {
|
| 225 | }
|
| 226 | }
|
| 227 |
|