Advertisement
Guest User

LoMaS Class

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