Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bitevo.Zetal.LoMaS.Specializations.GUI;
- import io.netty.buffer.Unpooled;
- import java.io.IOException;
- import java.util.List;
- import net.minecraft.client.Minecraft;
- import net.minecraft.client.gui.GuiTextField;
- import net.minecraft.client.gui.inventory.GuiContainer;
- import net.minecraft.client.renderer.GlStateManager;
- import net.minecraft.client.resources.I18n;
- import net.minecraft.entity.player.InventoryPlayer;
- import net.minecraft.inventory.Container;
- import bitevo.Zetal.LoMaS.Specializations.Inventory.SpecContainerRepair;
- import net.minecraft.inventory.ICrafting;
- import net.minecraft.inventory.IInventory;
- import net.minecraft.inventory.Slot;
- import net.minecraft.item.ItemStack;
- import net.minecraft.network.PacketBuffer;
- import net.minecraft.network.play.client.C17PacketCustomPayload;
- import net.minecraft.util.BlockPos;
- import net.minecraft.util.ResourceLocation;
- import net.minecraft.world.World;
- import net.minecraftforge.fml.relauncher.Side;
- import net.minecraftforge.fml.relauncher.SideOnly;
- import org.lwjgl.input.Keyboard;
- public class GuiSpecRepair extends GuiContainer implements ICrafting
- {
- private static final ResourceLocation anvilResource = new ResourceLocation("textures/gui/container/anvil.png");
- private SpecContainerRepair anvil;
- private GuiTextField nameField;
- private InventoryPlayer playerInventory;
- public GuiSpecRepair(InventoryPlayer p_i45508_1_, World worldIn)
- {
- super(new SpecContainerRepair(p_i45508_1_, worldIn, Minecraft.getMinecraft().thePlayer));
- this.playerInventory = p_i45508_1_;
- this.anvil = (SpecContainerRepair)this.inventorySlots;
- }
- public GuiSpecRepair(InventoryPlayer p_i45508_1_, BlockPos pos, World worldIn)
- {
- super(new SpecContainerRepair(p_i45508_1_, worldIn, pos, Minecraft.getMinecraft().thePlayer));
- this.playerInventory = p_i45508_1_;
- this.anvil = (SpecContainerRepair)this.inventorySlots;
- }
- /**
- * Adds the buttons (and other controls) to the screen in question.
- */
- public void initGui()
- {
- super.initGui();
- Keyboard.enableRepeatEvents(true);
- int i = (this.width - this.xSize) / 2;
- int j = (this.height - this.ySize) / 2;
- this.nameField = new GuiTextField(0, this.fontRendererObj, i + 42, j + 12, 103, 12);
- this.nameField.setTextColor(-1);
- this.nameField.setDisabledTextColour(-1);
- this.nameField.setEnableBackgroundDrawing(false);
- this.nameField.setMaxStringLength(40);
- this.inventorySlots.removeCraftingFromCrafters(this);
- this.inventorySlots.onCraftGuiOpened(this);
- }
- /**
- * Called when the screen is unloaded. Used to disable keyboard repeat events
- */
- public void onGuiClosed()
- {
- super.onGuiClosed();
- Keyboard.enableRepeatEvents(false);
- this.inventorySlots.removeCraftingFromCrafters(this);
- }
- /**
- * Draw the foreground layer for the GuiContainer (everything in front of the items). Args : mouseX, mouseY
- */
- protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
- {
- GlStateManager.disableLighting();
- GlStateManager.disableBlend();
- this.fontRendererObj.drawString(I18n.format("container.repair", new Object[0]), 40, 1, 4210752);
- if (this.anvil.maximumCost > 0)
- {
- int k = 8453920;
- boolean flag = true;
- String s = I18n.format("container.repair.cost", new Object[] {Integer.valueOf(this.anvil.maximumCost)});
- int ironCost = this.anvil.maximumCost;
- int emeraldCost = 0;
- while(ironCost - 10 >= 0)
- {
- ironCost = ironCost - 10;
- emeraldCost++;
- }
- if(emeraldCost < 10)
- {
- s = "Required Cores: " + emeraldCost + " " + ironCost;
- }
- else
- {
- s = "Required Cores: " + emeraldCost + " " + ironCost;
- }
- if (this.anvil.maximumCost >= 40 && !this.mc.thePlayer.capabilities.isCreativeMode)
- {
- s = I18n.format("container.repair.expensive", new Object[0]);
- k = 16736352;
- }
- else if (!this.anvil.getSlot(2).getHasStack())
- {
- flag = false;
- }
- else if (!this.anvil.getSlot(2).canTakeStack(this.playerInventory.player))
- {
- k = 16736352;
- }
- if (flag)
- {
- int l = -16777216 | (k & 16579836) >> 2 | k & -16777216;
- int i1 = this.xSize - 8 - this.fontRendererObj.getStringWidth(s);
- byte b0 = 67;
- if (this.fontRendererObj.getUnicodeFlag())
- {
- drawRect(i1 - 3, b0 - 2, this.xSize - 7, b0 + 10, -16777216);
- drawRect(i1 - 2, b0 - 1, this.xSize - 8, b0 + 9, -12895429);
- }
- else
- {
- this.fontRendererObj.drawString(s, i1, b0 + 1, l);
- this.fontRendererObj.drawString(s, i1 + 1, b0, l);
- this.fontRendererObj.drawString(s, i1 + 1, b0 + 1, l);
- }
- this.fontRendererObj.drawString(s, i1, b0, k);
- }
- }
- GlStateManager.enableLighting();
- }
- /**
- * Fired when a key is typed (except F11 who toggle full screen). This is the equivalent of
- * KeyListener.keyTyped(KeyEvent e). Args : character (character on the key), keyCode (lwjgl Keyboard key code)
- */
- protected void keyTyped(char typedChar, int keyCode) throws IOException
- {
- if (this.nameField.textboxKeyTyped(typedChar, keyCode))
- {
- this.renameItem();
- }
- else
- {
- super.keyTyped(typedChar, keyCode);
- }
- }
- private void renameItem()
- {
- String s = this.nameField.getText();
- Slot slot = this.anvil.getSlot(0);
- if (slot != null && slot.getHasStack() && !slot.getStack().hasDisplayName() && s.equals(slot.getStack().getDisplayName()))
- {
- s = "";
- }
- this.anvil.updateItemName(s);
- this.mc.thePlayer.sendQueue.addToSendQueue(new C17PacketCustomPayload("MC|ItemName", (new PacketBuffer(Unpooled.buffer())).writeString(s)));
- }
- /**
- * Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
- */
- protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException
- {
- super.mouseClicked(mouseX, mouseY, mouseButton);
- this.nameField.mouseClicked(mouseX, mouseY, mouseButton);
- }
- /**
- * Draws the screen and all the components in it. Args : mouseX, mouseY, renderPartialTicks
- */
- public void drawScreen(int mouseX, int mouseY, float partialTicks)
- {
- super.drawScreen(mouseX, mouseY, partialTicks);
- GlStateManager.disableLighting();
- GlStateManager.disableBlend();
- this.nameField.drawTextBox();
- }
- /**
- * Args : renderPartialTicks, mouseX, mouseY
- */
- protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
- {
- GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
- this.mc.getTextureManager().bindTexture(anvilResource);
- int k = (this.width - this.xSize) / 2;
- int l = (this.height - this.ySize) / 2;
- this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
- this.drawTexturedModalRect(k + 39, l + 8, 0, this.ySize + (this.anvil.getSlot(0).getHasStack() ? 0 : 16), 110, 16);
- if ((this.anvil.getSlot(0).getHasStack() || this.anvil.getSlot(1).getHasStack()) && !this.anvil.getSlot(2).getHasStack())
- {
- this.drawTexturedModalRect(k + 99, l + 28, this.xSize, 0, 28, 21);
- }
- }
- /**
- * Sends the contents of an inventory slot to the client-side Container. This doesn't have to match the actual
- * contents of that slot. Args: Container, slot number, slot contents
- *
- * @param containerToSend The container that is to be updated on the client.
- * @param slotInd The slot index that is to be updated.
- * @param stack The itemstack to be updated in the selected slot.
- */
- public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack)
- {
- if (slotInd == 0)
- {
- this.nameField.setText(stack == null ? "" : stack.getDisplayName());
- this.nameField.setEnabled(stack != null);
- if (stack != null)
- {
- this.renameItem();
- }
- }
- }
- /**
- * Sends two ints to the client-side Container. Used for furnace burning time, smelting progress, brewing progress,
- * and enchanting level. Normally the first int identifies which variable to update, and the second contains the new
- * value. Both are truncated to shorts in non-local SMP.
- *
- * @param containerIn The container sending a progress bar update.
- * @param varToUpdate The integer corresponding the variable to be updated.
- * @param newValue The value the variable is to be updated with.
- */
- public void sendProgressBarUpdate(Container containerIn, int varToUpdate, int newValue) {}
- public void func_175173_a(Container p_175173_1_, IInventory p_175173_2_) {}
- @Override
- public void updateCraftingInventory(Container containerToSend,
- List<ItemStack> itemsList) {
- this.sendSlotContents(containerToSend, 0, containerToSend.getSlot(0).getStack());
- }
- @Override
- public void sendAllWindowProperties(Container p_175173_1_,
- IInventory p_175173_2_) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement