private void testConsistency() { // test if there's an entry for every set bit in availabilityMap for (int i = availabilityMap.nextSetBit(0); i >= 0; i = availabilityMap.nextSetBit(i + 1)) { if (iBlockRegistry.getRaw(i) == null && iItemRegistry.getRaw(i) == null && !blockedIds.contains(i)) { throw new IllegalStateException( String.format("availabilityMap references empty entries for id %d.", i)); } } for (int pass = 0; pass < 2; pass++) { boolean isBlock = pass == 0; String type = isBlock ? "block" : "item"; FMLControlledNamespacedRegistry<?> registry = isBlock ? iBlockRegistry : iItemRegistry; registry.validateContent( (isBlock ? MAX_BLOCK_ID : MAX_ITEM_ID), type, availabilityMap, blockedIds, iBlockRegistry); } FMLLog.fine("Registry consistency check successful"); }
/** * Free the specified slot. * * <p>The slot must not be occupied by something else than the specified object within the same * type. The same object is permitted for handling duplicate registrations. * * @param id id to free * @param obj object allowed besides different types (block vs item) */ private void freeSlot(int id, Object obj) { FMLControlledNamespacedRegistry<?> registry = (obj instanceof Block) ? iBlockRegistry : iItemRegistry; Object thing = registry.getRaw(id); if (thing != null && thing != obj) { throw new IllegalStateException( String.format("Can't free registry slot %d occupied by %s", id, thing)); } availabilityMap.clear(id); }
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; }