Guest User

wirelesschestguicontainer

a guest
May 4th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.82 KB | None | 0 0
  1. package com.cclloyd.ccmodpack;
  2.  
  3. import net.minecraft.client.Minecraft;
  4. import net.minecraft.client.gui.GuiButton;
  5. import net.minecraft.client.gui.inventory.GuiContainer;
  6. import net.minecraft.client.renderer.GlStateManager;
  7. import net.minecraft.entity.player.InventoryPlayer;
  8. import net.minecraft.util.ResourceLocation;
  9. import net.minecraftforge.fml.relauncher.Side;
  10. import net.minecraftforge.fml.relauncher.SideOnly;
  11.  
  12. @SideOnly(Side.CLIENT)
  13. public class WirelessChestGuiContainer extends GuiContainer {
  14.    
  15.     /**
  16.      * GuiInventoryBasic is a simple gui that does nothing but draw a background image and a line of text on the screen
  17.      * everything else is handled by the vanilla container code
  18.      */
  19.    
  20.     private static final ResourceLocation texture = new ResourceLocation("ccmodpack", "textures/gui/container/wirelessChest.png");
  21.     private WirelessChestEntity wirelessChestEntity;
  22.    
  23.     public WirelessChestGuiContainer(InventoryPlayer invPlayer, WirelessChestEntity tile) {
  24.         super(new WirelessChestContainer(invPlayer, tile));
  25.         wirelessChestEntity = tile;
  26.         // Set the width and height of the gui.  Should match the size of the texture!
  27.         xSize = 176;
  28.         ySize = 184;
  29.         this.xSize = 176;
  30.         this.ySize = 184;
  31.     }
  32.  
  33.  
  34.     // draw the background for the GUI - rendered first
  35.     @Override
  36.     protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) {
  37.         // Bind the image texture of our custom container
  38.         Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
  39.         // Draw the image
  40.         GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  41.         drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
  42.     }
  43.  
  44.     // draw the foreground for the GUI - rendered after the slots, but before the dragged items and tooltips
  45.     // renders relative to the top left corner of the background
  46.     @Override
  47.     protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
  48.         //final int LABEL_XPOS = this.xSize / 2 - 10;
  49.         //final int LABEL_YPOS = 5;
  50.         //this.guiLeft = (this.width - this.xSize) / 2;
  51.         //this.guiTop = (this.height - this.ySize) / 2;
  52.         //int posX = this.guiLeft;
  53.         //int posY = this.guiTop;
  54.         //int center = this.xSize / 2 + this.guiLeft;
  55.         //fontRendererObj.drawString("0000", this.guiLeft / 2, 4, Color.darkGray.getRGB());
  56.  
  57.     }
  58.  
  59.    
  60.     @SuppressWarnings("unchecked")
  61.     public void initGui() {
  62.         super.initGui();
  63.         this.mc.thePlayer.openContainer = this.inventorySlots;
  64.         this.guiLeft = (this.width - this.xSize) / 2;
  65.         this.guiTop = (this.height - this.ySize) / 2;
  66.         int posX = this.guiLeft;
  67.         int posY = this.guiTop;
  68.         int center = this.xSize / 2 + posX;
  69.        
  70.         int width1000 = 40;
  71.         int width100 = 33;
  72.         int width10 = 28;
  73.         int width1 = 20;
  74.        
  75.         int posX1000 = 50;
  76.         int posX100 = 67;
  77.         int posX10 = 36;
  78.         int posX1 = 11;
  79.  
  80.         int center1000 = center - (width1000 / 2);
  81.         int center100 = center - (width100 / 2);
  82.         int center10 = center - (width10 / 2);
  83.         int center1 = center - (width1 / 2);
  84.         int posY1000 = posY + 4;
  85.         int posY100 = posY + 25;
  86.         int posY10 = posY100;
  87.         int posY1 = posY100;
  88.        
  89.         this.buttonList.add(new GuiButton(1, center1000 - posX1000, posY1000, width1000, 20, "-1000"));
  90.         this.buttonList.add(new GuiButton(2, center1000 + posX1000, posY1000, width1000, 20, "+1000"));
  91.        
  92.         this.buttonList.add(new GuiButton(3, center100 - posX100, posY100, width100, 20, "-100"));
  93.         this.buttonList.add(new GuiButton(4, center100 + posX100, posY100, width100, 20, "+100"));
  94.        
  95.         this.buttonList.add(new GuiButton(5, center10 - posX10, posY10, width10, 20, "-10"));
  96.         this.buttonList.add(new GuiButton(6, center10 + posX10, posY10, width10, 20, "+10"));
  97.        
  98.         this.buttonList.add(new GuiButton(7, center1 - posX1, posY1, width1, 20, "-1"));
  99.         this.buttonList.add(new GuiButton(8, center1 + posX1, posY1, width1, 20, "+1"));
  100.  
  101.         this.buttonList.add(new DisabledButton(0, center - (45 / 2), posY1000, 45, 20, wirelessChestEntity.getFrequencyString()));
  102.     }
  103.    
  104.     @SuppressWarnings("unchecked")
  105.     @Override
  106.     protected void actionPerformed(GuiButton button) {
  107.         this.guiLeft = (this.width - this.xSize) / 2;
  108.         this.guiTop = (this.height - this.ySize) / 2;
  109.         int posX = this.guiLeft;
  110.         int posY = this.guiTop;
  111.         int center = this.xSize / 2 + posX;
  112.         int posY1000 = posY + 4;
  113.  
  114.  
  115.         if (button.id == 1) {
  116.             if (wirelessChestEntity.getFrequency() < 1000)
  117.                 wirelessChestEntity.setFrequency(0);
  118.             else
  119.                 wirelessChestEntity.setFrequency(wirelessChestEntity.getFrequency() - 1000);
  120.         }
  121.         if (button.id == 2) {
  122.             if (wirelessChestEntity.getFrequency() > 8999)
  123.                 wirelessChestEntity.setFrequency(9999);
  124.             else
  125.                 wirelessChestEntity.setFrequency(wirelessChestEntity.getFrequency() + 1000);
  126.         }
  127.        
  128.         this.buttonList.remove(this.buttonList.size() - 1);
  129.         this.buttonList.add(new DisabledButton(0, center - (45 / 2), posY1000, 45, 20, wirelessChestEntity.getFrequencyString()));
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment