Exemplo n.º 1
0
  @Override
  public boolean equals(Object o) {
    // if the object is a mismatched type, its not equal
    if (o == null || !(o instanceof BlockData)) return false;

    // otherwise, check that the data is all equivalent
    BlockData ob = (BlockData) o;
    return ob.getMaterial().equals(getMaterial()) && ob.getData() == getData();
  }
Exemplo n.º 2
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();
  }