public ItemStack handle(EntityPlayer player, int mouseButton, Slot slot) {
    if (mouseButton > 0) {
      slot.putStack(null);
    } else if (mouseButton == 0) {
      ItemStack stack;
      InventoryPlayer playerInv = player.inventory;
      slot.onSlotChanged();
      ItemStack stackSlot = slot.getStack();
      ItemStack stackHeld = playerInv.getItemStack();

      if (stackSlot == null && stackHeld != null && slot.slotNumber != 22) {
        if (isItemValid(stackHeld)) {
          ItemStack copy = stackHeld.copy();
          copy.stackSize = 1;
          slot.putStack(copy);
        }
      }

      if (stackHeld == null) {
        if (tile instanceof TileFishSorter) {
          ((TileFishSorter) tile).swapSide(slot.slotNumber);
        }
      }
    }

    return null;
  }
 private ItemStack slotClickPhantom(
     Slot slot, int mouseButton, int modifier, EntityPlayer player) {
   ItemStack stack = null;
   if (mouseButton == 2) {
     if (((IPhantomSlot) slot).canAdjust()) slot.putStack(null);
   } else if (mouseButton == 0 || mouseButton == 1) {
     InventoryPlayer playerInv = player.inventory;
     slot.onSlotChanged();
     ItemStack stackSlot = slot.getStack();
     ItemStack stackHeld = playerInv.getItemStack();
     if (stackSlot != null) stack = stackSlot.copy();
     if (stackSlot == null) {
       if (stackHeld != null && slot.isItemValid(stackHeld))
         fillPhantomSlot(slot, stackHeld, mouseButton);
     } else if (stackHeld == null) {
       adjustPhantomSlot(slot, mouseButton, modifier);
       slot.onPickupFromSlot(player, playerInv.getItemStack());
     } else if (slot.isItemValid(stackHeld)) {
       if (ItemUtil.canStacksMerge(stackSlot, stackHeld))
         adjustPhantomSlot(slot, mouseButton, modifier);
       else fillPhantomSlot(slot, stackHeld, mouseButton);
     }
   }
   return stack;
 }
  @Override
  public ItemStack slotClick(int id, int button, ClickType clickType, EntityPlayer player) {
    Slot slot = id < 0 ? null : this.inventorySlots.get(id);
    if (!(slot instanceof IESlot.Ghost)) return super.slotClick(id, button, clickType, player);
    // Spooky Ghost Slots!!!!
    ItemStack stack = null;
    ItemStack stackSlot = slot.getStack();
    if (stackSlot != null) stack = stackSlot.copy();

    if (button == 2) slot.putStack(null);
    else if (button == 0 || button == 1) {
      InventoryPlayer playerInv = player.inventory;
      ItemStack stackHeld = playerInv.getItemStack();
      if (stackSlot == null) {
        if (stackHeld != null && slot.isItemValid(stackHeld)) {
          slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
        }
      } else if (stackHeld == null) {
        slot.putStack(null);
      } else if (slot.isItemValid(stackHeld)) {
        slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
      }
    } else if (button == 5) {
      InventoryPlayer playerInv = player.inventory;
      ItemStack stackHeld = playerInv.getItemStack();
      if (!slot.getHasStack()) {
        slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
      }
    }
    return stack;
  }
  /**
   * @author blood - May 13th, 2016
   * @reason SpongeForge requires an overwrite so we do it here instead.
   */
  @Overwrite
  public EntityItem dropOneItem(boolean dropAll) {
    if (this.worldObj.isRemote) {
      return this.dropItem(
          this.inventory.decrStackSize(
              this.inventory.currentItem,
              dropAll && this.inventory.getCurrentItem() != null
                  ? this.inventory.getCurrentItem().stackSize
                  : 1),
          false,
          true);
    }

    ItemStack stack = inventory.getCurrentItem();

    if (stack == null) {
      return null;
    }

    if (SpongeImplHooks.onDroppedByPlayer(stack.getItem(), stack, (EntityPlayer) (Object) this)) {
      int count =
          dropAll && this.inventory.getCurrentItem() != null
              ? this.inventory.getCurrentItem().stackSize
              : 1;
      return SpongeImplHooks.onPlayerToss(
          (EntityPlayer) (Object) this,
          inventory.decrStackSize(inventory.currentItem, count),
          true);
    }

    return null;
  }
  @Override
  public HashMap<Integer, ItemStack> addItem(ItemStack... items) {
    HashMap<Integer, ItemStack> leftover = new HashMap<Integer, ItemStack>();

    InventoryPlayer inv = (InventoryPlayer) inventory;
    int count = 0;
    for (ItemStack i : items) {
      net.minecraft.item.ItemStack internal = BukkitItemStack.createNMSItemStack(i);
      if (!inv.addItemStackToInventory(internal)) {
        int origsize = internal.stackSize;
        internal.stackSize--;

        while (!inv.addItemStackToInventory(internal)) {
          internal.stackSize--;
          if (internal.stackSize == 0) {
            break;
          }
        }

        leftover.put(
            count,
            new BukkitItemStack(
                internal.itemID, origsize - internal.stackSize, (short) internal.getItemDamage()));
      }
      count++;
    }
    return leftover;
  }
Beispiel #6
0
  /** Callback for when the crafting gui is closed. */
  public void onCraftGuiClosed(EntityPlayer par1EntityPlayer) {
    InventoryPlayer var2 = par1EntityPlayer.inventory;

    if (var2.getItemStack() != null) {
      par1EntityPlayer.dropPlayerItem(var2.getItemStack());
      var2.setItemStack((ItemStack) null);
    }
  }
 public void refreshState() {
   hasValidItem =
       (inventory.getStackInSlot(slot) != null
           && ((inventory.getStackInSlot(slot).getItem() instanceof IConfigurableItem
                   && !((IConfigurableItem) inventory.getStackInSlot(slot).getItem())
                       .getFields(inventory.getStackInSlot(slot), slot)
                       .isEmpty())
               || inventory.getStackInSlot(slot).getItem() instanceof IInventoryTool));
 }
  @Override
  public void renderBackground(
      Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
    Minecraft.getMinecraft().renderEngine.bindTexture(texture);
    int heightOffset = isMouseOver(mouseX, mouseY) ? 36 : 18;
    if (!hasValidItem) drawTexturedModalRect(x, y, 0, 0, getWidth(), getHeight());
    else drawTexturedModalRect(x, y, 0, heightOffset, getWidth(), getHeight());

    if (inventory.getStackInSlot(slot) != null) {
      drawItemStack(inventory.getStackInSlot(slot), x + 1, y + 1, "null");
    }
  }
 @Override
 public void renderFinal(Minecraft minecraft, int offsetX, int offsetY, int mouseX, int mouseY) {
   if (isMouseOver(mouseX, mouseY) && hasValidItem) {
     List<String> list = new ArrayList<String>();
     List<ItemConfigField> fields =
         ((IConfigurableItem) inventory.getStackInSlot(slot).getItem())
             .getFields(inventory.getStackInSlot(slot), slot);
     for (ItemConfigField field : fields) {
       list.add(field.getLocalizedName() + ": " + field.getFormatedValue());
     }
     drawHoveringText(list, mouseX + offsetX, mouseY + offsetY + 10, fontRendererObj);
   }
 }
  public ArmorExtendedContainer(InventoryPlayer inventoryplayer, ArmorExtended armor) {
    invPlayer = inventoryplayer;
    this.armor = armor;

    this.addSlotToContainer(new SlotAccessory(armor, 0, 80, 17));
    this.addSlotToContainer(new SlotAccessory(armor, 1, 80, 35));
    this.addSlotToContainer(new SlotAccessory(armor, 2, 116, 17));
    this.addSlotToContainer(new SlotAccessory(armor, 3, 116, 35));
    this.addSlotToContainer(new SlotAccessory(armor, 4, 152, 53));
    this.addSlotToContainer(new SlotAccessory(armor, 5, 152, 35));
    this.addSlotToContainer(new SlotAccessory(armor, 6, 152, 17));
    for (int playerArmor = 0; playerArmor < 4; ++playerArmor) {
      this.addSlotToContainer(
          new SlotArmorCopy(
              this,
              inventoryplayer,
              inventoryplayer.getSizeInventory() - 1 - playerArmor,
              98,
              8 + playerArmor * 18,
              playerArmor));
    }

    for (int column = 0; column < 3; column++) {
      for (int row = 0; row < 9; row++) {
        this.addSlotToContainer(
            new Slot(inventoryplayer, row + column * 9 + 9, 8 + row * 18, 84 + column * 18));
      }
    }

    for (int column = 0; column < 9; column++) {
      this.addSlotToContainer(new Slot(inventoryplayer, column, 8 + column * 18, 142));
    }
  }
 private boolean swapToItem(InventoryPlayer inventory, int itemID) {
   int slot = getInventorySlotWithItem(inventory, itemID);
   if (slot > -1 && slot < 9) {
     inventory.currentItem = slot;
     return true;
   }
   return false;
 }
  public ContainerPlayer(
      final InventoryPlayer par1InventoryPlayer, boolean par2, EntityPlayer par3EntityPlayer) {
    this.isLocalWorld = par2;
    this.thePlayer = par3EntityPlayer;
    this.addSlotToContainer(
        new SlotCrafting(
            par1InventoryPlayer.player, this.craftMatrix, this.craftResult, 0, 144, 36));
    int i;
    int j;

    for (i = 0; i < 2; ++i) {
      for (j = 0; j < 2; ++j) {
        this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 88 + j * 18, 26 + i * 18));
      }
    }

    for (i = 0; i < 4; ++i) {
      final int k = i;
      this.addSlotToContainer(
          new Slot(
              par1InventoryPlayer, par1InventoryPlayer.getSizeInventory() - 1 - i, 8, 8 + i * 18) {
            private static final String __OBFID = "CL_00001755";
            /**
             * Returns the maximum stack size for a given slot (usually the same as
             * getInventoryStackLimit(), but 1 in the case of armor slots)
             */
            public int getSlotStackLimit() {
              return 1;
            }
            /**
             * Check if the stack is a valid item for this slot. Always true beside for the armor
             * slots.
             */
            public boolean isItemValid(ItemStack par1ItemStack) {
              if (par1ItemStack == null) return false;
              return par1ItemStack.getItem().isValidArmor(par1ItemStack, k, thePlayer);
            }
            /** Returns the icon index on items.png that is used as background image of the slot. */
            @SideOnly(Side.CLIENT)
            public IIcon getBackgroundIconIndex() {
              return ItemArmor.func_94602_b(k);
            }
          });
    }

    for (i = 0; i < 3; ++i) {
      for (j = 0; j < 9; ++j) {
        this.addSlotToContainer(
            new Slot(par1InventoryPlayer, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18));
      }
    }

    for (i = 0; i < 9; ++i) {
      this.addSlotToContainer(new Slot(par1InventoryPlayer, i, 8 + i * 18, 142));
    }

    this.onCraftMatrixChanged(this.craftMatrix);
  }
Beispiel #13
0
  public ContainerPlayer(
      final InventoryPlayer par1InventoryPlayer, boolean par2, EntityPlayer par3EntityPlayer) {
    this.isLocalWorld = par2;
    this.thePlayer = par3EntityPlayer;
    this.addSlotToContainer(
        new SlotCrafting(
            par1InventoryPlayer.player, this.craftMatrix, this.craftResult, 0, 144, 36));
    int var4;
    int var5;

    for (var4 = 0; var4 < 2; ++var4) {
      for (var5 = 0; var5 < 2; ++var5) {
        this.addSlotToContainer(
            new Slot(this.craftMatrix, var5 + var4 * 2, 88 + var5 * 18, 26 + var4 * 18));
      }
    }

    for (var4 = 0; var4 < 4; ++var4) {
      final int var44 = var4;
      this.addSlotToContainer(
          new Slot(
              par1InventoryPlayer,
              par1InventoryPlayer.getSizeInventory() - 1 - var4,
              8,
              8 + var4 * 18) {
            private static final String __OBFID = "CL_00001755";

            public int getSlotStackLimit() {
              return 1;
            }

            public boolean isItemValid(ItemStack par1ItemStack) {
              return par1ItemStack == null
                  ? false
                  : (par1ItemStack.getItem() instanceof ItemArmor
                      ? ((ItemArmor) par1ItemStack.getItem()).armorType == var44
                      : (par1ItemStack.getItem() != Item.getItemFromBlock(Blocks.pumpkin)
                              && par1ItemStack.getItem() != Items.skull
                          ? false
                          : var44 == 0));
            }
          });
    }

    for (var4 = 0; var4 < 3; ++var4) {
      for (var5 = 0; var5 < 9; ++var5) {
        this.addSlotToContainer(
            new Slot(par1InventoryPlayer, var5 + (var4 + 1) * 9, 8 + var5 * 18, 84 + var4 * 18));
      }
    }

    for (var4 = 0; var4 < 9; ++var4) {
      this.addSlotToContainer(new Slot(par1InventoryPlayer, var4, 8 + var4 * 18, 142));
    }

    this.onCraftMatrixChanged(this.craftMatrix);
  }
Beispiel #14
0
 /**
  * Draw the foreground layer for the GuiContainer (everything in front of the items). Args :
  * mouseX, mouseY
  */
 @Override
 protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
   fontRendererObj.drawString(
       field_175380_I == null ? I18n.format("container.enchant", new Object[0]) : field_175380_I,
       12,
       5,
       4210752);
   fontRendererObj.drawString(
       I18n.format(field_175379_F.getInventoryName(), new Object[0]), 8, ySize - 96 + 2, 4210752);
 }
  public ContainerPlayer(final InventoryPlayer playerInventory, boolean localWorld, Player player) {
    this.isLocalWorld = localWorld;
    this.thePlayer = player;
    this.addSlotToContainer(
        new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 144, 36));

    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 2; ++j) {
        this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 88 + j * 18, 26 + i * 18));
      }
    }

    for (int k = 0; k < 4; ++k) {
      final int k_f = k;
      this.addSlotToContainer(
          new Slot(playerInventory, playerInventory.getSizeInventory() - 1 - k, 8, 8 + k * 18) {
            public int getSlotStackLimit() {
              return 1;
            }

            public boolean isItemValid(ItemStack stack) {
              return stack == null
                  ? false
                  : (stack.getItem() instanceof ItemArmor
                      ? ((ItemArmor) stack.getItem()).armorType == k_f
                      : (stack.getItem() != Item.getItemFromBlock(Blocks.pumpkin)
                              && stack.getItem() != Items.skull
                          ? false
                          : k_f == 0));
            }
          });
    }

    for (int l = 0; l < 3; ++l) {
      for (int j1 = 0; j1 < 9; ++j1) {
        this.addSlotToContainer(
            new Slot(playerInventory, j1 + (l + 1) * 9, 8 + j1 * 18, 84 + l * 18));
      }
    }

    for (int i1 = 0; i1 < 9; ++i1) {
      this.addSlotToContainer(new Slot(playerInventory, i1, 8 + i1 * 18, 142));
    }

    this.onCraftMatrixChanged(this.craftMatrix);
  }
Beispiel #16
0
 public void buyGun(int i, InventoryPlayer inventory, GunBoxType type) {
   if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
     FlansMod.proxy.buyGun(type, i);
   }
   if (i <= type.numGuns && type.guns[i] != null) {
     boolean canBuy = true;
     for (ItemStack check : type.gunParts[i]) {
       int numMatchingStuff = 0;
       for (int j = 0; j < inventory.getSizeInventory(); j++) {
         ItemStack stack = inventory.getStackInSlot(j);
         if (stack != null
             && stack.itemID == check.itemID
             && stack.getItemDamage() == check.getItemDamage()) {
           numMatchingStuff += stack.stackSize;
         }
       }
       if (numMatchingStuff < check.stackSize) {
         canBuy = false;
       }
     }
     if (canBuy) {
       for (ItemStack remove : type.gunParts[i]) {
         int amountLeft = remove.stackSize;
         for (int j = 0; j < inventory.getSizeInventory(); j++) {
           ItemStack stack = inventory.getStackInSlot(j);
           if (amountLeft > 0
               && stack != null
               && stack.itemID == remove.itemID
               && stack.getItemDamage() == remove.getItemDamage()) {
             amountLeft -= inventory.decrStackSize(j, amountLeft).stackSize;
           }
         }
       }
       if (!inventory.addItemStackToInventory(new ItemStack(type.guns[i].getItem()))) {
         // Drop gun on floor
       }
     } else {
       // Cant buy
       // TODO : Add flashing red squares around the items you lack
     }
   }
 }
 @Override
 public void setItemInHand(ItemStack stack) {
   realInv.setInventorySlotContents(getHeldItemSlot(), BukkitItemStack.createNMSItemStack(stack));
 }
Beispiel #18
0
  public ItemStack slotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
    ItemStack var5 = null;
    InventoryPlayer var6 = par4EntityPlayer.inventory;
    Slot var7;
    ItemStack var8;
    int var10;
    ItemStack var11;

    if ((par3 == 0 || par3 == 1) && (par2 == 0 || par2 == 1)) {
      if (par1 == -999) {
        if (var6.getItemStack() != null && par1 == -999) {
          if (par2 == 0) {
            par4EntityPlayer.dropPlayerItem(var6.getItemStack());
            var6.setItemStack((ItemStack) null);
          }

          if (par2 == 1) {
            // CraftBukkit start - store a reference
            ItemStack itemstack3 = var6.getItemStack();
            par4EntityPlayer.dropPlayerItem(itemstack3.splitStack(1));

            if (itemstack3.stackSize == 0) {
              // CraftBukkit end
              var6.setItemStack((ItemStack) null);
            }
          }
        }
      } else if (par3 == 1) {
        var7 = (Slot) this.inventorySlots.get(par1);

        if (var7 != null && var7.canTakeStack(par4EntityPlayer)) {
          var8 = this.transferStackInSlot(par4EntityPlayer, par1);

          if (var8 != null) {
            int var12 = var8.itemID;
            var5 = var8.copy();

            if (var7 != null && var7.getStack() != null && var7.getStack().itemID == var12) {
              this.retrySlotClick(par1, par2, true, par4EntityPlayer);
            }
          }
        }
      } else {
        if (par1 < 0) {
          return null;
        }

        var7 = (Slot) this.inventorySlots.get(par1);

        if (var7 != null) {
          var8 = var7.getStack();
          ItemStack var13 = var6.getItemStack();

          if (var8 != null) {
            var5 = var8.copy();
          }

          if (var8 == null) {
            if (var13 != null && var7.isItemValid(var13)) {
              var10 = par2 == 0 ? var13.stackSize : 1;

              if (var10 > var7.getSlotStackLimit()) {
                var10 = var7.getSlotStackLimit();
              }

              if (var13.stackSize >= var10) // CraftBukkit
              var7.putStack(var13.splitStack(var10));

              if (var13.stackSize == 0) {
                var6.setItemStack((ItemStack) null);
              }
            }
          } else if (var7.canTakeStack(par4EntityPlayer)) {
            if (var13 == null) {
              var10 = par2 == 0 ? var8.stackSize : (var8.stackSize + 1) / 2;
              var11 = var7.decrStackSize(var10);
              var6.setItemStack(var11);

              if (var8.stackSize == 0) {
                var7.putStack((ItemStack) null);
              }

              var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack());
            } else if (var7.isItemValid(var13)) {
              if (var8.itemID == var13.itemID
                  && var8.getItemDamage() == var13.getItemDamage()
                  && ItemStack.areItemStackTagsEqual(var8, var13)) {
                var10 = par2 == 0 ? var13.stackSize : 1;

                if (var10 > var7.getSlotStackLimit() - var8.stackSize) {
                  var10 = var7.getSlotStackLimit() - var8.stackSize;
                }

                if (var10 > var13.getMaxStackSize() - var8.stackSize) {
                  var10 = var13.getMaxStackSize() - var8.stackSize;
                }

                var13.splitStack(var10);

                if (var13.stackSize == 0) {
                  var6.setItemStack((ItemStack) null);
                }

                var8.stackSize += var10;
              } else if (var13.stackSize <= var7.getSlotStackLimit()) {
                var7.putStack(var13);
                var6.setItemStack(var8);
              }
            } else if (var8.itemID == var13.itemID
                && var13.getMaxStackSize() > 1
                && (!var8.getHasSubtypes() || var8.getItemDamage() == var13.getItemDamage())
                && ItemStack.areItemStackTagsEqual(var8, var13)) {
              var10 = var8.stackSize;

              if (var10 > 0 && var10 + var13.stackSize <= var13.getMaxStackSize()) {
                var13.stackSize += var10;
                var8 = var7.decrStackSize(var10);

                if (var8.stackSize == 0) {
                  var7.putStack((ItemStack) null);
                }

                var7.onPickupFromSlot(par4EntityPlayer, var6.getItemStack());
              }
            }
          }

          var7.onSlotChanged();
        }
      }
    } else if (par3 == 2 && par2 >= 0 && par2 < 9) {
      var7 = (Slot) this.inventorySlots.get(par1);

      if (var7.canTakeStack(par4EntityPlayer)) {
        var8 = var6.getStackInSlot(par2);
        boolean var9 = var8 == null || var7.inventory == var6 && var7.isItemValid(var8);
        var10 = -1;

        if (!var9) {
          var10 = var6.getFirstEmptyStack();
          var9 |= var10 > -1;
        }

        if (var7.getHasStack() && var9) {
          var11 = var7.getStack();
          var6.setInventorySlotContents(par2, var11);

          if ((var7.inventory != var6 || !var7.isItemValid(var8)) && var8 != null) {
            if (var10 > -1) {
              var6.addItemStackToInventory(var8);
              var7.decrStackSize(var11.stackSize);
              var7.putStack((ItemStack) null);
              var7.onPickupFromSlot(par4EntityPlayer, var11);
            }
          } else {
            var7.decrStackSize(var11.stackSize);
            var7.putStack(var8);
            var7.onPickupFromSlot(par4EntityPlayer, var11);
          }
        } else if (!var7.getHasStack() && var8 != null && var7.isItemValid(var8)) {
          var6.setInventorySlotContents(par2, (ItemStack) null);
          var7.putStack(var8);
        }
      }
    } else if (par3 == 3
        && par4EntityPlayer.capabilities.isCreativeMode
        && var6.getItemStack() == null
        && par1 >= 0) {
      var7 = (Slot) this.inventorySlots.get(par1);

      if (var7 != null && var7.getHasStack()) {
        var8 = var7.getStack().copy();
        var8.stackSize = var8.getMaxStackSize();
        var6.setItemStack(var8);
      }
    }

    return var5;
  }
  public ContainerTravellersInv(InventoryPlayer invPlayer) {
    this.player = invPlayer.player;
    this.invTG = new InventoryTG(this, player);
    if (!player.worldObj.isRemote)
      this.invTG.stackList = TravellersGearAPI.getExtendedInventory(player);
    this.invBaubles = ModCompatability.getNewBaublesInv(player);
    ModCompatability.setBaubleContainer(invBaubles, this);
    if (!player.worldObj.isRemote)
      ModCompatability.setBaubleInvStacklist(invBaubles, BaublesApi.getBaubles(player));

    crafting =
        addSlot(new SlotCrafting(invPlayer.player, this.craftMatrix, this.craftResult, 0, 144, 36));
    int i;
    int j;
    for (i = 0; i < 2; ++i) {
      for (j = 0; j < 2; ++j) {
        this.addSlot(new Slot(this.craftMatrix, j + i * 2, 106 + j * 18, 26 + i * 18));
      }
    }
    nonInventorySlots = 0 + (crafting >= 0 ? 5 : 0);

    vanillaArmor[0] =
        addSlot(
            new SlotRestricted(
                invPlayer,
                invPlayer.getSizeInventory() - 1 - 0,
                6,
                26,
                player,
                SlotRestricted.SlotType.VANILLA_HELM));
    vanillaArmor[1] =
        addSlot(
            new SlotRestricted(
                invPlayer,
                invPlayer.getSizeInventory() - 1 - 1,
                6,
                44,
                player,
                SlotRestricted.SlotType.VANILLA_CHEST));
    vanillaArmor[2] =
        addSlot(
            new SlotRestricted(
                invPlayer,
                invPlayer.getSizeInventory() - 1 - 2,
                6,
                62,
                player,
                SlotRestricted.SlotType.VANILLA_LEGS));
    vanillaArmor[3] =
        addSlot(
            new SlotRestricted(
                invPlayer,
                invPlayer.getSizeInventory() - 1 - 3,
                6,
                80,
                player,
                SlotRestricted.SlotType.VANILLA_BOOTS));
    nonInventorySlots +=
        (vanillaArmor[0] >= 0 ? 1 : 0)
            + (vanillaArmor[1] >= 0 ? 1 : 0)
            + (vanillaArmor[2] >= 0 ? 1 : 0)
            + (vanillaArmor[3] >= 0 ? 1 : 0);

    travGear[0] =
        addSlot(
            new SlotRestricted(this.invTG, 0, 42, 8, player, SlotRestricted.SlotType.TRAVEL_CLOAK));
    travGear[1] =
        addSlot(
            new SlotRestricted(
                this.invTG, 1, 78, 26, player, SlotRestricted.SlotType.TRAVEL_SHOULDER));
    travGear[2] =
        addSlot(
            new SlotRestricted(
                this.invTG, 2, 78, 62, player, SlotRestricted.SlotType.TRAVEL_VAMBRACE));
    travGear[3] =
        addSlot(
            new SlotRestricted(this.invTG, 3, 6, 98, player, SlotRestricted.SlotType.TRAVEL_TITLE));
    nonInventorySlots +=
        (travGear[0] >= 0 ? 1 : 0)
            + (travGear[1] >= 0 ? 1 : 0)
            + (travGear[2] >= 0 ? 1 : 0)
            + (travGear[3] >= 0 ? 1 : 0);

    if (TravellersGear.BAUBLES && invBaubles != null) {
      baubles[0] =
          addSlot(
              new SlotRestricted(
                  this.invBaubles, 0, 24, 8, player, SlotRestricted.SlotType.BAUBLE_NECK));
      baubles[1] =
          addSlot(
              new SlotRestricted(
                  this.invBaubles, 1, 24, 98, player, SlotRestricted.SlotType.BAUBLE_RING));
      baubles[2] =
          addSlot(
              new SlotRestricted(
                  this.invBaubles, 2, 42, 98, player, SlotRestricted.SlotType.BAUBLE_RING));
      baubles[3] =
          addSlot(
              new SlotRestricted(
                  this.invBaubles, 3, 78, 44, player, SlotRestricted.SlotType.BAUBLE_BELT));
      nonInventorySlots +=
          (baubles[0] >= 0 ? 1 : 0)
              + (baubles[1] >= 0 ? 1 : 0)
              + (baubles[2] >= 0 ? 1 : 0)
              + (baubles[3] >= 0 ? 1 : 0);
    }

    this.invMari = ModCompatability.getMariInventory(player);
    if (TravellersGear.MARI && invMari != null) {
      mari[0] =
          addSlot(
              new SlotRestricted(
                  this.invMari, 0, 60, 98, player, SlotRestricted.SlotType.MARI_RING));
      mari[1] =
          addSlot(
              new SlotRestricted(
                  this.invMari, 1, 78, 80, player, SlotRestricted.SlotType.MARI_BRACELET));
      mari[2] =
          addSlot(
              new SlotRestricted(
                  this.invMari, 2, 60, 8, player, SlotRestricted.SlotType.MARI_NECKLACE));
      nonInventorySlots += (mari[0] >= 0 ? 1 : 0) + (mari[1] >= 0 ? 1 : 0) + (mari[2] >= 0 ? 1 : 0);
    }

    this.invTConArmor = ModCompatability.getTConArmorInv(player);
    if (TravellersGear.TCON && invTConArmor != null) {
      tcon[0] =
          addSlot(
              new SlotRestricted(
                  this.invTConArmor, 1, 78, 98, player, SlotRestricted.SlotType.TINKERS_GLOVE));
      tcon[1] =
          addSlot(
              new SlotRestricted(
                  this.invTConArmor, 2, 78, 8, player, SlotRestricted.SlotType.TINKERS_BAG));
      tcon[2] =
          addSlot(
              new SlotRestricted(
                  this.invTConArmor, 6, 191, 31, player, SlotRestricted.SlotType.TINKERS_HEART_R));
      tcon[3] =
          addSlot(
              new SlotRestricted(
                  this.invTConArmor, 5, 191, 49, player, SlotRestricted.SlotType.TINKERS_HEART_Y));
      tcon[4] =
          addSlot(
              new SlotRestricted(
                  this.invTConArmor, 4, 191, 67, player, SlotRestricted.SlotType.TINKERS_HEART_G));
      //			tcon[5]=addSlot(new SlotRestricted(this.invTConArmor, 3, 6, 31, player,
      // SlotRestricted.SlotType.TINKERS_BELT));// (doesn't work)
      tcon[5] =
          addSlot(
              new SlotRestricted(
                  this.invTConArmor, 0, 6, 31, player, SlotRestricted.SlotType.TINKERS_MASK));
      nonInventorySlots +=
          (tcon[0] >= 0 ? 1 : 0)
              + (tcon[1] >= 0 ? 1 : 0)
              + (tcon[2] >= 0 ? 1 : 0)
              + (tcon[3] >= 0 ? 1 : 0)
              + (tcon[4] >= 0 ? 1 : 0)
              + (tcon[5] >= 0 ? 1 : 0);
    }
    // PLAYER INVENTORY
    playerInventorySlots = 0;
    playerHotbarSlots = 0;
    for (i = 0; i < 3; ++i)
      for (j = 0; j < 9; ++j)
        if (this.addSlot(
                new Slot(invPlayer, j + (i + 1) * 9, 6 + j * 18 + (j > 4 ? 10 : 0), 119 + i * 18))
            >= 0) playerInventorySlots++;
    for (i = 0; i < 9; ++i)
      if (this.addSlot(new Slot(invPlayer, i, 6 + i * 18 + (i > 4 ? 10 : 0), 173)) >= 0)
        playerHotbarSlots++;

    this.onCraftMatrixChanged(this.craftMatrix);
  }
  public void func_73863_a(int p_73863_1_, int p_73863_2_, float p_73863_3_) {
    this.func_73873_v_();
    int var4 = this.field_74198_m;
    int var5 = this.field_74197_n;
    this.func_74185_a(p_73863_3_, p_73863_1_, p_73863_2_);
    GL11.glDisable('\u803a');
    RenderHelper.func_74518_a();
    GL11.glDisable(2896);
    GL11.glDisable(2929);
    super.func_73863_a(p_73863_1_, p_73863_2_, p_73863_3_);
    RenderHelper.func_74520_c();
    GL11.glPushMatrix();
    GL11.glTranslatef((float) var4, (float) var5, 0.0F);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    GL11.glEnable('\u803a');
    this.field_82320_o = null;
    short var6 = 240;
    short var7 = 240;
    OpenGlHelper.func_77475_a(OpenGlHelper.field_77476_b, (float) var6 / 1.0F, (float) var7 / 1.0F);
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

    int var9;
    for (int var13 = 0; var13 < this.field_74193_d.field_75151_b.size(); ++var13) {
      Slot var14 = (Slot) this.field_74193_d.field_75151_b.get(var13);
      this.func_74192_a(var14);
      if (this.func_74186_a(var14, p_73863_1_, p_73863_2_)) {
        this.field_82320_o = var14;
        GL11.glDisable(2896);
        GL11.glDisable(2929);
        int var8 = var14.field_75223_e;
        var9 = var14.field_75221_f;
        this.func_73733_a(var8, var9, var8 + 16, var9 + 16, -2130706433, -2130706433);
        GL11.glEnable(2896);
        GL11.glEnable(2929);
      }
    }

    this.func_74189_g(p_73863_1_, p_73863_2_);
    InventoryPlayer var15 = this.field_73882_e.field_71439_g.field_71071_by;
    ItemStack var16 = this.field_85050_q == null ? var15.func_70445_o() : this.field_85050_q;
    if (var16 != null) {
      byte var18 = 8;
      var9 = this.field_85050_q == null ? 8 : 16;
      if (this.field_85050_q != null && this.field_90018_r) {
        var16 = var16.func_77946_l();
        var16.field_77994_a = MathHelper.func_76123_f((float) var16.field_77994_a / 2.0F);
      }

      this.func_85044_b(var16, p_73863_1_ - var4 - var18, p_73863_2_ - var5 - var9);
    }

    if (this.field_85045_v != null) {
      float var17 = (float) (Minecraft.func_71386_F() - this.field_85046_u) / 100.0F;
      if (var17 >= 1.0F) {
        var17 = 1.0F;
        this.field_85045_v = null;
      }

      var9 = this.field_85047_t.field_75223_e - this.field_85049_r;
      int var10 = this.field_85047_t.field_75221_f - this.field_85048_s;
      int var11 = this.field_85049_r + (int) ((float) var9 * var17);
      int var12 = this.field_85048_s + (int) ((float) var10 * var17);
      this.func_85044_b(this.field_85045_v, var11, var12);
    }

    if (var15.func_70445_o() == null
        && this.field_82320_o != null
        && this.field_82320_o.func_75216_d()) {
      ItemStack var19 = this.field_82320_o.func_75211_c();
      this.func_74184_a(var19, p_73863_1_ - var4 + 8, p_73863_2_ - var5 + 8);
    }

    GL11.glPopMatrix();
    GL11.glEnable(2896);
    GL11.glEnable(2929);
    RenderHelper.func_74519_b();
  }
public final class BattlegearClientEvents implements IResourceManagerReloadListener {

  private final BattlegearInGameGUI inGameGUI;
  public final QuiverModel quiverModel;
  public final ResourceLocation quiverDetails;
  public final ResourceLocation quiverBase;
  // public static final ResourceLocation patterns = new ResourceLocation("battlegear2",
  // "textures/heraldry/Patterns-small.png");
  // public static int storageIndex;

  private static final int MAIN_INV = InventoryPlayer.getHotbarSize();
  public static final GuiPlaceableButton[] tabsList = {
    new GuiBGInventoryButton(0), new GuiSigilButton(1)
  };
  public static final BattlegearClientEvents INSTANCE = new BattlegearClientEvents();
  private String[] attributeNames;

  private BattlegearClientEvents() {
    inGameGUI = new BattlegearInGameGUI();
    quiverModel = new QuiverModel();
    quiverDetails =
        new ResourceLocation("battlegear2", "textures/armours/quiver/QuiverDetails.png");
    quiverBase = new ResourceLocation("battlegear2", "textures/armours/quiver/QuiverBase.png");
    ((IReloadableResourceManager) FMLClientHandler.instance().getClient().getResourceManager())
        .registerReloadListener(this);
  }

  /** Offset battle slots rendering according to config values */
  @SubscribeEvent(priority = EventPriority.HIGHEST)
  public void postRenderBar(RenderItemBarEvent.BattleSlots event) {
    if (!event.isMainHand) {
      event.xOffset += BattlegearConfig.battleBarOffset[0];
      event.yOffset += BattlegearConfig.battleBarOffset[1];
    } else {
      event.xOffset += BattlegearConfig.battleBarOffset[2];
      event.yOffset += BattlegearConfig.battleBarOffset[3];
    }
  }

  /** Offset quiver slots rendering according to config values */
  @SubscribeEvent(priority = EventPriority.HIGHEST)
  public void postRenderQuiver(RenderItemBarEvent.QuiverSlots event) {
    event.xOffset += BattlegearConfig.quiverBarOffset[0];
    event.yOffset += BattlegearConfig.quiverBarOffset[1];
  }

  /** Offset shield stamina rendering according to config values */
  @SubscribeEvent(priority = EventPriority.HIGHEST)
  public void postRenderShield(RenderItemBarEvent.ShieldBar event) {
    event.xOffset += BattlegearConfig.shieldBarOffset[0];
    event.yOffset += BattlegearConfig.shieldBarOffset[1];
  }

  /** Render all the Battlegear HUD elements */
  @SubscribeEvent(receiveCanceled = true)
  public void postRenderOverlay(RenderGameOverlayEvent.Post event) {
    if (event.type == RenderGameOverlayEvent.ElementType.HOTBAR
        && (BattlegearConfig.forceHUD || !event.isCanceled())) {
      inGameGUI.renderGameOverlay(event.partialTicks);
    }
  }

  /**
   * Bend the models when the item in left hand is used And stop the right hand inappropriate
   * bending
   */
  @SubscribeEvent(priority = EventPriority.LOW)
  public void renderPlayerLeftItemUsage(RenderLivingEvent.Pre event) {
    if (event.entity instanceof EntityPlayer) {
      EntityPlayer entityPlayer = (EntityPlayer) event.entity;
      ItemStack offhand =
          ((InventoryPlayerBattle) entityPlayer.inventory).getCurrentOffhandWeapon();
      if (offhand != null && event.renderer instanceof RenderPlayer) {
        ModelPlayer renderer = ((RenderPlayer) event.renderer).getPlayerModel();
        renderer.heldItemLeft = 1;
        if (entityPlayer.getItemInUseCount() > 0 && entityPlayer.getItemInUse() == offhand) {
          EnumAction enumaction = offhand.getItemUseAction();
          if (enumaction == EnumAction.BLOCK) {
            renderer.heldItemLeft = 3;
          } else if (enumaction == EnumAction.BOW) {
            renderer.aimedBow = true;
          }
          ItemStack mainhand = entityPlayer.inventory.getCurrentItem();
          renderer.heldItemRight = mainhand != null ? 1 : 0;
        } else if (((IBattlePlayer) entityPlayer).isBlockingWithShield()) {
          renderer.heldItemLeft = 3;
        }
      }
    }
  }

  /** Reset models to default values */
  @SubscribeEvent(priority = EventPriority.LOW)
  public void resetPlayerLeftHand(RenderPlayerEvent.Post event) {
    event.renderer.getPlayerModel().heldItemLeft = 0;
  }

  private static final int SKELETON_ARROW = 5;
  /** Render quiver on skeletons if possible */
  @SubscribeEvent
  public void renderLiving(RenderLivingEvent.Post event) {

    if (BattlegearConfig.enableSkeletonQuiver
        && event.entity instanceof EntitySkeleton
        && event.renderer instanceof RenderSkeleton) {

      GL11.glPushMatrix();
      GL11.glDisable(GL11.GL_CULL_FACE);

      GL11.glColor3f(1, 1, 1);
      Minecraft.getMinecraft().getTextureManager().bindTexture(quiverDetails);

      GL11.glTranslatef((float) event.x, (float) event.y, (float) event.z);

      GL11.glScalef(1, -1, 1);

      float f2 =
          interpolateRotation(event.entity.prevRenderYawOffset, event.entity.renderYawOffset, 0);

      GL11.glRotatef(180.0F - f2, 0.0F, 1.0F, 0.0F);

      if (event.entity.deathTime > 0) {
        float f3 =
            ((float) event.entity.deathTime + BattlegearClientTickHandeler.getPartialTick() - 1.0F)
                / 20.0F
                * 1.6F;
        f3 = MathHelper.sqrt_float(f3);

        if (f3 > 1.0F) {
          f3 = 1.0F;
        }

        GL11.glRotatef(-f3 * 90, 0.0F, 0.0F, 1.0F);
      }

      GL11.glTranslatef(0, -1.5F, 0);

      GL11.glRotatef(event.entity.rotationPitch, 0, 1, 0);

      if (event.entity.getEquipmentInSlot(3) != null) { // chest armor
        GL11.glTranslatef(0, 0, BattlegearRenderHelper.RENDER_UNIT);
      }
      ((ModelBiped) event.renderer.mainModel)
          .bipedBody.postRender(BattlegearRenderHelper.RENDER_UNIT);
      GL11.glScalef(1.05F, 1.05F, 1.05F);
      quiverModel.render(SKELETON_ARROW, BattlegearRenderHelper.RENDER_UNIT);

      Minecraft.getMinecraft().getTextureManager().bindTexture(quiverBase);
      GL11.glColor3f(0.10F, 0.10F, 0.10F);
      quiverModel.render(0, BattlegearRenderHelper.RENDER_UNIT);
      GL11.glColor3f(1, 1, 1);

      GL11.glEnable(GL11.GL_CULL_FACE);
      GL11.glPopMatrix();
    }
  }

  /** Counter the bow use fov jerkyness with the draw enchantment */
  @SubscribeEvent
  public void onBowFOV(FOVUpdateEvent event) {
    ItemStack stack = event.entity.getItemInUse();
    if (EnchantmentHelper.getEnchantmentLevel(BaseEnchantment.bowCharge, stack) > 0) {
      int i = event.entity.getItemInUseDuration();
      float f1 = (float) i / 20.0F;
      if (f1 > 1.0F) {
        f1 = 1.0F;
      } else {
        f1 *= f1;
      }
      event.newfov /= 1.0F - f1 * 0.15F;
    }
  }

  /** Fixes pick block */
  @SubscribeEvent(priority = EventPriority.HIGHEST)
  public void replacePickBlock(MouseEvent event) {
    if (event.buttonstate) {
      Minecraft mc = FMLClientHandler.instance().getClient();
      if (mc.thePlayer != null) {
        if (event.button - 100 == mc.gameSettings.keyBindPickBlock.getKeyCode()) {
          event.setCanceled(true);
          if (!((IBattlePlayer) mc.thePlayer).isBattlemode()) {
            boolean isCreative = mc.thePlayer.capabilities.isCreativeMode;
            ItemStack stack = getItemFromPointedAt(mc.objectMouseOver, mc.thePlayer);
            if (stack != null) {
              int k = -1;
              ItemStack temp;
              for (int slot = 0; slot < MAIN_INV; slot++) {
                temp = mc.thePlayer.inventory.getStackInSlot(slot);
                if (temp != null
                    && stack.isItemEqual(temp)
                    && ItemStack.areItemStackTagsEqual(stack, temp)) {
                  k = slot;
                  break;
                }
              }
              if (isCreative && k == -1) {
                k = mc.thePlayer.inventory.getFirstEmptyStack();
                if (k < 0 || k >= MAIN_INV) {
                  k = mc.thePlayer.inventory.currentItem;
                }
              }
              if (k >= 0 && k < MAIN_INV) {
                mc.thePlayer.inventory.currentItem = k;
                Battlegear.packetHandler.sendPacketToServer(
                    new PickBlockPacket(stack, k).generatePacket());
              }
            }
          }
        }
      }
    }
  }

  /**
   * Equivalent code to the creative pick block
   *
   * @param target The client target vector
   * @param player The player trying to pick
   * @return the stack expected for the creative pick button
   */
  private static ItemStack getItemFromPointedAt(MovingObjectPosition target, EntityPlayer player) {
    if (target != null) {
      if (target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
        BlockPos pos = target.getBlockPos();
        World world = player.getEntityWorld();
        Block block = world.getBlockState(pos).getBlock();
        if (block.isAir(world, pos)) {
          return null;
        }
        return block.getPickBlock(target, world, pos);
      } else {
        if (target.typeOfHit != MovingObjectPosition.MovingObjectType.ENTITY
            || target.entityHit == null
            || !player.capabilities.isCreativeMode) {
          return null;
        }
        return target.entityHit.getPickedResult(target);
      }
    }
    return null;
  }

  /**
   * Returns a rotation angle that is inbetween two other rotation angles. par1 and par2 are the
   * angles between which to interpolate, par3 is probably a float between 0.0 and 1.0 that tells us
   * where "between" the two angles we are. Example: par1 = 30, par2 = 50, par3 = 0.5, then return =
   * 40
   */
  public float interpolateRotation(float par1, float par2, float par3) {
    float f3 = par2 - par1;

    while (f3 < -180.0F) {
      f3 += 360.0F;
    }

    while (f3 >= 180.0F) {
      f3 -= 360.0F;
    }

    return par1 + par3 * f3;
  }

  /** Register a few "item" icons */
  @SubscribeEvent
  public void preStitch(TextureStitchEvent.Pre event) {
    ClientProxy.backgroundIcon =
        new TextureAtlasSprite[] {
          event.map.registerSprite(new ResourceLocation("battlegear2:items/slots/mainhand")),
          event.map.registerSprite(new ResourceLocation("battlegear2:items/slots/offhand"))
        };

    // storageIndex = PatternStore.DEFAULT.buildPatternAndStore(patterns);
    /*CrestImages.initialise(Minecraft.getMinecraft().getResourceManager());
    for (HeraldryPattern pattern : HeraldryPattern.patterns) {
        pattern.registerIcon(event.map);
    }*/
  }

  /**
   * Change attribute format when displayed on item tooltip
   *
   * @param event
   */
  @SubscribeEvent
  public void onItemTooltip(ItemTooltipEvent event) {
    for (String txt : event.toolTip) {
      if (txt.startsWith(EnumChatFormatting.BLUE.toString())) {
        if (txt.contains(attributeNames[0]) || txt.contains(attributeNames[2]))
          event.toolTip.set(
              event.toolTip.indexOf(txt),
              EnumChatFormatting.DARK_GREEN
                  + EnumChatFormatting.getTextWithoutFormattingCodes(txt));
        else if (txt.contains(attributeNames[3]))
          event.toolTip.set(
              event.toolTip.indexOf(txt), EnumChatFormatting.DARK_GREEN + reformat(txt, 3));
        else if (txt.contains(attributeNames[1]))
          event.toolTip.set(event.toolTip.indexOf(txt), EnumChatFormatting.GOLD + reformat(txt, 1));
      }
    }
    if (event.itemStack.getItem() instanceof IBackStabbable) {
      event.toolTip.add(
          EnumChatFormatting.GOLD
              + StatCollector.translateToLocal("attribute.name.weapon.backstab"));
    }
  }

  // Equivalent of the ItemStack decimal formatter used in attribute tooltip display
  private static final Pattern FLOAT = Pattern.compile("\\d.\\d+");

  /**
   * Format into "ratio" attribute localization
   *
   * @param txt current attribute local
   * @param type the attribute index
   * @return the new localization
   */
  private String reformat(String txt, int type) {
    String result = EnumChatFormatting.getTextWithoutFormattingCodes(txt);
    Matcher matcher = FLOAT.matcher(result);
    if (matcher.find()) {
      int start = matcher.start();
      int end = matcher.end();
      String temp = result.substring(start, end).replace(",", ".");
      try {
        float value = Float.valueOf(temp) * 100;
        temp = ".plus.1";
        if (start > 0 && result.charAt(start - 1) == '-') {
          temp = ".take.1";
        }
        return StatCollector.translateToLocalFormatted(
            "attribute.modifier" + temp,
            ItemStack.DECIMALFORMAT.format(value),
            attributeNames[type]);
      } catch (NumberFormatException notNumber) {
        notNumber.printStackTrace();
      }
    }

    return result;
  }

  /**
   * Help translating attributes
   *
   * @param attribute
   * @return the attribute name into the current language
   */
  private String toLocal(BaseAttribute attribute) {
    return StatCollector.translateToLocal(
        "attribute.name." + attribute.getAttributeUnlocalizedName());
  }

  /** Reload translation caches */
  @Override
  public void onResourceManagerReload(IResourceManager resourceManager) {
    attributeNames =
        new String[] {
          toLocal(Attributes.armourPenetrate),
          toLocal(Attributes.daze),
          toLocal(Attributes.extendedReach),
          toLocal(Attributes.attackSpeed)
        };
  }

  @SubscribeEvent(priority = EventPriority.LOW)
  public void postInitGui(GuiScreenEvent.InitGuiEvent.Post event) {
    if (Battlegear.battlegearEnabled && event.gui instanceof InventoryEffectRenderer) {
      if (!ClientProxy.tconstructEnabled
          || FMLClientHandler.instance().getClientPlayerEntity().capabilities.isCreativeMode) {
        onOpenGui(
            event.buttonList,
            ((InventoryEffectRenderer) event.gui).guiLeft - 30,
            ((InventoryEffectRenderer) event.gui).guiTop);
      }
    }
  }

  /**
   * Helper method to add buttons to a gui when opened
   *
   * @param buttons the List<GuiButton> of the opened gui
   * @param guiLeft horizontal placement parameter
   * @param guiTop vertical placement parameter
   */
  public static void onOpenGui(List buttons, int guiLeft, int guiTop) {
    if (BattlegearConfig.enableGuiButtons) {
      int count = 0;
      for (GuiPlaceableButton tab : tabsList) {
        GuiPlaceableButton button = tab.copy();
        button.place(count, guiLeft, guiTop);
        button.id =
            buttons.size()
                + 2; // Due to GuiInventory and GuiContainerCreative button performed actions,
        // without them having buttons...
        count++;
        buttons.add(button);
      }
    }
  }
}
 @Override
 public ItemStack getHelmet() {
   return new BukkitItemStack(realInv.armorItemInSlot(3));
 }
 @Override
 public int clear(int id, int data) {
   return realInv.clearInventory(id, data);
 }
 @Override
 public ItemStack getChestplate() {
   return new BukkitItemStack(realInv.armorItemInSlot(2));
 }
 @Override
 public ItemStack getLeggings() {
   return new BukkitItemStack(realInv.armorItemInSlot(1));
 }
 @Override
 public ItemStack getBoots() {
   return new BukkitItemStack(realInv.armorItemInSlot(0));
 }
 @Override
 public ItemStack getItemInHand() {
   return new BukkitItemStack(realInv.getCurrentItem());
 }
  public ContainerCosArmor(
      InventoryPlayer invPlayer, InventoryCosArmor invCosArmor, EntityPlayer player) {
    this.player = player;

    // CraftingResult
    addSlotToContainer(new SlotCrafting(player, craftMatrix, craftResult, 0, 154, 28));

    // CraftingGrid
    for (int i = 0; i < 2; i++)
      for (int j = 0; j < 2; j++)
        addSlotToContainer(new Slot(craftMatrix, j + i * 2, 98 + j * 18, 18 + i * 18));

    // NormalArmor
    for (int i = 0; i < 4; i++) {
      final int j = i;
      final EntityPlayer k = player;
      addSlotToContainer(
          new Slot(
              invPlayer,
              invPlayer.getSizeInventory() - 1 - invPlayer.offHandInventory.size() - i,
              8,
              8 + i * 18) {

            @Override
            public int getSlotStackLimit() {
              return 1;
            }

            @SideOnly(Side.CLIENT)
            @Override
            public String getSlotTexture() {
              return ItemArmor.EMPTY_SLOT_NAMES[VALID_EQUIPMENT_SLOTS[j].getIndex()];
            }

            @Override
            public boolean isItemValid(ItemStack stack) {
              if (stack == null || stack.func_190926_b()) return false;

              return stack.getItem().isValidArmor(stack, VALID_EQUIPMENT_SLOTS[j], k);
            }
          });
    }

    // CosmeticArmor
    for (int i = 0; i < 4; i++) {
      final int j = i;
      final EntityPlayer k = player;
      addSlotToContainer(
          new Slot(invCosArmor, invCosArmor.getSizeInventory() - 1 - i, 98 + i * 18, 62) {

            @Override
            public int getSlotStackLimit() {
              return 1;
            }

            @SideOnly(Side.CLIENT)
            @Override
            public String getSlotTexture() {
              return ItemArmor.EMPTY_SLOT_NAMES[VALID_EQUIPMENT_SLOTS[j].getIndex()];
            }

            @Override
            public boolean isItemValid(ItemStack stack) {
              if (stack == null || stack.func_190926_b()) return false;

              return stack.getItem().isValidArmor(stack, VALID_EQUIPMENT_SLOTS[j], k);
            }
          });
    }

    // PlayerInventory
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < 9; j++)
        addSlotToContainer(new Slot(invPlayer, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18));

    // PlayerHotBar
    for (int i = 0; i < 9; i++) addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142));

    // Off-Hand Slot
    addSlotToContainer(
        new Slot(invPlayer, 40, 77, 62) {

          @SideOnly(Side.CLIENT)
          @Override
          public String getSlotTexture() {
            return "minecraft:items/empty_armor_slot_shield";
          }
        });

    onCraftMatrixChanged(craftMatrix);
  }