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; }
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).field_150939_a == 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); return blockId; }