Ejemplo n.º 1
0
  // get primary BlockData type from Inventory
  @SuppressWarnings("unchecked")
  public static BlockData fromInventory(Inventory inv) {
    Map<BlockData, Integer> count = new DefaultedMap(0);
    for (ItemStack item : inv)
      if (item != null) {
        BlockData bd = BlockData.fromItemStack(item);
        count.put(bd, item.getAmount() + count.get(bd));
      }

    Map.Entry<BlockData, Integer> best = null;
    for (Map.Entry<BlockData, Integer> entry : count.entrySet())
      if (best == null || entry.getValue() > best.getValue()) best = entry;

    return best == null ? null : best.getKey();
  }