Unable to add Items to Inventory

Discussion in 'Spigot Plugin Development' started by TheSpherret, May 9, 2015.

  1. Can't setItem, addItem, setContents, tried running it on a different tick, tried updating inventory, nothing.
     
  2. What are the KVs in your map?
     
  3. That's irrelevant
     
  4. gigosaurus

    Supporter

    I really can't see why that isn't working, unless you're using your own custom ItemStack class which extends the Bukkit one, or setting the type int in the ItemStack to an invalid item ID, or even just messing around with the item registry.
     
  5. I'm doing none of that.
     
  6. Sourced from CraftBukkit maintained by Spigot ..

    Code (Java):
        public ItemStack[] getContents() {
            ItemStack[] items = new ItemStack[getSize()];
            net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();

            int size = Math.min(items.length, mcItems.length);
            for (int i = 0; i < size; i++) {
                items[i] = mcItems[i] == null ? null : CraftItemStack.asCraftMirror(mcItems[i]);
            }
            return items;
        }

      public void setContents(ItemStack[] items) {
      if (getInventory().getContents().length < items.length) {
      throw new IllegalArgumentException("Invalid inventory size; expected " + getInventory().getContents().length + " or less");
      }

      net.minecraft.server.ItemStack[] mcItems = getInventory().getContents();

      for (int i = 0; i < mcItems.length; i++) {
      if (i >= items.length) {
      mcItems[i] = null;
      } else {
      mcItems[i] = CraftItemStack.asNMSCopy(items[i]);
      }
      }
      }