private int registerBlock(Block block, String name, int idHint) {
    // handle ItemBlock-before-Block registrations
    ItemBlock itemBlock = null;

    for (Item item : iItemRegistry.typeSafeIterable()) // find matching ItemBlock
    {
      if (item instanceof ItemBlock && ((ItemBlock) item).block == block) {
        itemBlock = (ItemBlock) item;
        break;
      }
    }

    if (itemBlock
        != null) // has ItemBlock, adjust id and clear the slot already occupied by the
                 // corresponding item
    {
      idHint = iItemRegistry.getId(itemBlock);
      FMLLog.fine("Found matching ItemBlock %s for Block %s at id %d", itemBlock, block, idHint);
      freeSlot(
          idHint,
          block); // temporarily free the slot occupied by the Item for the block registration
    }

    // add
    int blockId = iBlockRegistry.add(idHint, name, block, availabilityMap);

    if (itemBlock != null) // verify
    {
      if (blockId != idHint)
        throw new IllegalStateException(
            String.format(
                "Block at itemblock id %d insertion failed, got id %d.", idHint, blockId));
      verifyItemBlockName(itemBlock);
    }

    useSlot(blockId);
    ((RegistryDelegate.Delegate<Block>) block.delegate).setName(name);

    for (IBlockState state : ((List<IBlockState>) block.getBlockState().getValidStates())) {
      GameData.BLOCKSTATE_TO_ID.put(state, blockId << 4 | block.getMetaFromState(state));
    }

    return blockId;
  }
 /** Block the specified id from being reused. */
 private void block(int id) {
   blockedIds.add(id);
   useSlot(id);
 }
  private int registerItem(Item item, String name, int idHint) {
    if (item instanceof ItemBlock
        && !(item
            instanceof
            ItemBanner)) // ItemBlock, adjust id and clear the slot already occupied by the
                         // corresponding block
    {
      Block block = ((ItemBlock) item).block;
      if (idHint != -1 && getMain().blockSubstitutions.containsKey(name)) {
        block = getMain().blockSubstitutions.get(name);
      }
      int id = iBlockRegistry.getId(block);

      if (id == -1) // ItemBlock before its Block
      {
        if (idHint < 0
            || availabilityMap.get(idHint)
            || idHint
                > MAX_BLOCK_ID) // non-suitable id, allocate one in the block id range, add would
                                // use the item id range otherwise
        {
          id =
              availabilityMap.nextClearBit(
                  MIN_BLOCK_ID); // find suitable id here, iItemRegistry would search from
                                 // MIN_ITEM_ID
          if (id > MAX_BLOCK_ID)
            throw new RuntimeException(
                String.format("Invalid id %d - maximum id range exceeded.", id));
          FMLLog.fine(
              "Allocated id %d for ItemBlock %s in the block id range, original id requested: %d.",
              id, name, idHint);
        } else // idHint is suitable without changes
        {
          id = idHint;
        }
      } else // ItemBlock after its Block
      {
        if (FMLControlledNamespacedRegistry.DEBUG)
          FMLLog.fine(
              "Found matching Block %s for ItemBlock %s at id %d, original id requested: %d",
              block, item, id, idHint);
        freeSlot(
            id, item); // temporarily free the slot occupied by the Block for the item registration
      }

      idHint = id;
    }

    int itemId = iItemRegistry.add(idHint, name, item, availabilityMap);

    if (item instanceof ItemBlock) // verify
    {
      if (itemId != idHint)
        throw new IllegalStateException(
            String.format("ItemBlock at block id %d insertion failed, got id %d.", idHint, itemId));
      verifyItemBlockName((ItemBlock) item);
    }

    // block the Block Registry slot with the same id
    useSlot(itemId);
    ((RegistryDelegate.Delegate<Item>) item.delegate).setName(name);
    return itemId;
  }