Advertisement
Guest User

Untitled

a guest
Aug 6th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.54 KB | None | 0 0
  1. /**
  2.  * @author Intektor
  3.  */
  4. public class GuiMagazineTable extends GuiContainer {
  5.  
  6.     private static final ResourceLocation texture = new ResourceLocation(CounterGuns.MODID, "textures/gui/magazine_table.png");
  7.  
  8.     List<MagazineRegistry.MagazineRegistryEntry> magazinesToChoose = new ArrayList<>();
  9.  
  10.     int currentMagazineChosenID;
  11.  
  12.     final int buttonLeft = 0, buttonRight = 1;
  13.  
  14.     public GuiMagazineTable(Container inventorySlotsIn) {
  15.         super(inventorySlotsIn);
  16.     }
  17.  
  18.     @Override
  19.     public void initGui() {
  20.         super.initGui();
  21.  
  22.         buttonList.clear();
  23.  
  24.         int i = (this.width - this.xSize) / 2;
  25.         int j = (this.height - this.ySize) / 2;
  26.  
  27.         buttonList.add(new GuiButton(buttonLeft, i + 24 - 11, j + 5, 10, 20, "<"));
  28.         buttonList.add(new GuiButton(buttonRight, i + 24 + 17, j + 5, 10, 20, ">"));
  29.         buttonList.get(buttonLeft).visible = false;
  30.         buttonList.get(buttonRight).visible = false;
  31.  
  32.         prevStackIn0 = null;
  33.     }
  34.  
  35.     @Override
  36.     public void updateScreen() {
  37.         ItemStack stack = inventorySlots.getInventory().get(0);
  38.         if (!ItemStackHelper.areItemStacksCompletelyIdentical(prevStackIn0, stack)) {
  39.             prevStackIn0 = stack;
  40.             if (stack != null && stack.getItem() instanceof ItemGunStandardBullet) {
  41.                 ItemGunStandardBullet gun = (ItemGunStandardBullet) stack.getItem();
  42.                 magazinesToChoose = MagazineRegistry.INSTANCE.findMagazines(gun.matchingCaliber());
  43.                 currentMagazineChosenID = 0;
  44.                 CounterGuns.network.sendToServer(new ChangeMagazineTypeGuiMagazineMessageToServer(0));
  45.             } else {
  46.                 CounterGuns.network.sendToServer(new ChangeMagazineTypeGuiMagazineMessageToServer(-1));
  47.             }
  48.             buttonList.get(buttonLeft).visible = stack != null && stack.getItem() instanceof ItemGun;
  49.             buttonList.get(buttonRight).visible = stack != null && stack.getItem() instanceof ItemGun;
  50.         }
  51.  
  52.         super.updateScreen();
  53.     }
  54.  
  55.     @Override
  56.     protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
  57.         GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
  58.         this.mc.getTextureManager().bindTexture(texture);
  59.         int i = (this.width - this.xSize) / 2;
  60.         int j = (this.height - this.ySize) / 2;
  61.         this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize);
  62.     }
  63.  
  64.     ItemStack prevStackIn0;
  65.  
  66.     @Override
  67.     protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
  68.         ItemStack stack = inventorySlots.getInventory().get(0);
  69.         int i = (this.width - this.xSize) / 2;
  70.         int j = (this.height - this.ySize) / 2;
  71.  
  72.         if (stack == null) {
  73.             int x = 24;
  74.             int y = 34 - 16 * 2;
  75.             CGRenderHelper.renderVirtualSlot(new ItemStack(CounterGuns.desert_eagle), x, y);
  76.             CGRenderHelper.renderVirtualSlot(new ItemStack(CounterGuns.m_0_223), x, y + 16);
  77.         } else {
  78.             if (stack.getItem() instanceof ItemGun) {
  79.                 if (!magazinesToChoose.isEmpty() && currentMagazineChosenID < magazinesToChoose.size()) {
  80.                     MagazineRegistry.MagazineRegistryEntry chosen = magazinesToChoose.get(currentMagazineChosenID);
  81.                     VirtualSlotRenderer renderer2 = new VirtualSlotRenderer(width, height);
  82.                     renderer2.addStack(new ItemStack(chosen.magazine), false, true, 24, 7, null);
  83.                     renderer2.render(mouseX, mouseY, i, j);
  84.                     int x = 52;
  85.                     int y = 35 + 18;
  86.                     VirtualSlotRenderer renderer = new VirtualSlotRenderer(width, height);
  87.                     for (ItemStack craft : chosen.crafting) {
  88.                         renderer.addStack(craft, true, true, x, y, null);
  89.                         x += 18;
  90.                     }
  91.                     renderer.render(mouseX, mouseY, i, j);
  92.                 }
  93.             } else if (stack.getItem() instanceof ItemMagazine) {
  94.                 ItemMagazine mag = (ItemMagazine) stack.getItem();
  95.                 VirtualSlotRenderer renderer = new VirtualSlotRenderer(width, height);
  96.                 int x = 52;
  97.                 int y = 35 + 18;
  98.                 for (ItemStack craft : MagazineRegistry.INSTANCE.getEntryForMagazine(mag).refillItems) {
  99.                     renderer.addStack(craft, true, true, x, y, null);
  100.                     x += 18;
  101.                 }
  102.                 renderer.render(mouseX, mouseY, i, j);
  103.             }
  104.         }
  105.     }
  106.  
  107.     public boolean isPointInRegion(int x, int y, int width, int height, int pX, int pY) {
  108.         return pX >= x && pX <= x + width && pY >= y && pY <= y + height;
  109.     }
  110.  
  111.     @Override
  112.     protected void actionPerformed(GuiButton button) throws IOException {
  113.         switch (button.id) {
  114.             case buttonLeft:
  115.                 if (currentMagazineChosenID > 0) {
  116.                     currentMagazineChosenID--;
  117.                     CounterGuns.network.sendToServer(new ChangeMagazineTypeGuiMagazineMessageToServer(currentMagazineChosenID));
  118.                 }
  119.                 break;
  120.             case buttonRight:
  121.                 if (currentMagazineChosenID < magazinesToChoose.size() - 1) {
  122.                     currentMagazineChosenID++;
  123.                     CounterGuns.network.sendToServer(new ChangeMagazineTypeGuiMagazineMessageToServer(currentMagazineChosenID));
  124.                 }
  125.                 break;
  126.         }
  127.     }
  128.  
  129.     @Override
  130.     public void onGuiClosed() {
  131.         super.onGuiClosed();
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement