Beispiel #1
0
  private void reg(Material material, ItemType type) {
    if (material.isBlock() != (type instanceof BlockType)) {
      throw new IllegalArgumentException(
          "Cannot mismatch item and block: " + material + ", " + type);
    }

    if (idToType.containsKey(material.getId())) {
      throw new IllegalArgumentException(
          "Cannot use "
              + type
              + " for "
              + material
              + ", is already "
              + idToType.get(material.getId()));
    }

    idToType.put(material.getId(), type);
    type.setId(material.getId());

    if (material.isBlock()) {
      nextBlockId = Math.max(nextBlockId, material.getId() + 1);
    } else {
      nextItemId = Math.max(nextItemId, material.getId() + 1);
    }
  }
Beispiel #2
0
  /**
   * Register a new, non-Vanilla ItemType. It will be assigned an ID automatically.
   *
   * @param type the ItemType to register.
   */
  public void register(ItemType type) {
    int id;
    if (type instanceof BlockType) {
      id = nextBlockId;
    } else {
      id = nextItemId;
    }

    while (idToType.containsKey(id)) {
      ++id;
    }

    idToType.put(id, type);
    type.setId(id);

    if (type instanceof BlockType) {
      nextBlockId = id + 1;
    } else {
      nextItemId = id + 1;
    }
  }