private int registerItem(Item item, String name, int idHint) { if (item instanceof ItemBlock) // ItemBlock, adjust id and clear the slot already occupied by the corresponding // block { Block block = ((ItemBlock) item).field_150939_a; 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 { 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); return itemId; }
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; }
private List<String> loadGenericRegistries(GameDataSnapshot snapshot, GameData existing) { List<String> result = Lists.newArrayList(); for (Map.Entry<String, FMLControlledNamespacedRegistry<?>> e : existing.genericRegistries.entrySet()) { String regName = e.getKey(); FMLControlledNamespacedRegistry<?> registry = e.getValue(); FMLControlledNamespacedRegistry<?> newRegistry = genericRegistries.get(regName); if (newRegistry == null) { newRegistry = registry.makeShallowCopy(); genericRegistries.put(regName, newRegistry); } GameDataSnapshot.Entry regSnap = snapshot.entries.get("fmlgr:" + regName); if (regSnap == null) { FMLLog.info( "Weird, there was no registry data for registry %s found in the snapshot", regName); continue; } for (Entry<String, Integer> entry : regSnap.ids.entrySet()) { String entryName = entry.getKey(); int entryId = entry.getValue(); int currId = registry.getId(entryName); if (currId == -1) { FMLLog.info("Found a missing id in registry %s from the world %s", regName, entryName); result.add(regName + "{" + entryName + "}=" + entryId); continue; // no block/item -> nothing to add } else if (currId != entryId) { FMLLog.fine( "Fixed registry %s id mismatch %s: %d (init) -> %d (map).", regName, entryName, currId, entryId); } newRegistry.add(entryId, entryName, registry.getRaw(entryName)); } } return result; }