Exemple #1
0
  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");
  }
Exemple #2
0
 private void set(GameData data) {
   iBlockRegistry.set(data.iBlockRegistry);
   iItemRegistry.set(data.iItemRegistry);
   availabilityMap.clear();
   availabilityMap.or(data.availabilityMap);
   blockedIds.clear();
   blockedIds.addAll(data.blockedIds);
 }
Exemple #3
0
  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;
  }
Exemple #4
0
  private void verifyItemBlockName(ItemBlock item) {
    String blockName = iBlockRegistry.getNameForObject(item.field_150939_a);
    String itemName = iItemRegistry.getNameForObject(item);

    if (blockName != null && !blockName.equals(itemName)) {
      FMLLog.bigWarning(
          "Block <-> ItemBlock name mismatch, block name %s, item name %s", blockName, itemName);
    }
  }
 private void copyGenericRegistries(GameData data) {
   for (Map.Entry<String, FMLControlledNamespacedRegistry<?>> e :
       data.genericRegistries.entrySet()) {
     FMLControlledNamespacedRegistry<?> orig = e.getValue();
     FMLControlledNamespacedRegistry<?> copy = orig.makeShallowCopy();
     // UGLY AS F**K
     copy.setFrom(orig);
     genericRegistries.put(e.getKey(), copy);
   }
 }
Exemple #6
0
  /**
   * 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);
  }
      public Entry(FMLControlledNamespacedRegistry registry) {
        this.ids = Maps.newHashMap();
        this.substitutions = Sets.newHashSet();
        this.aliases = Maps.newHashMap();
        this.blocked = Sets.newHashSet();

        registry.serializeInto(this.ids);
        registry.serializeSubstitutions(this.substitutions);
        registry.serializeAliases(this.aliases);

        if (GameData.getBlockRegistry() == registry || GameData.getItemRegistry() == registry) {
          this.blocked.addAll(GameData.getMain().blockedIds);
        }
      }
  private void verifyItemBlockName(ItemBlock item) {
    Object blockName = iBlockRegistry.getNameForObject(item.block);
    Object itemName = iItemRegistry.getNameForObject(item);

    // Vanilla has a mismatch:
    // Block <-> ItemBlock name mismatch, block name minecraft:standing_banner, item name
    // minecraft:banner
    // TODO: Untie these in the rest of the registry
    if (blockName != null
        && !blockName.equals(itemName)
        && !"minecraft:standing_banner".equals(blockName.toString())) {
      FMLLog.bigWarning(
          "Block <-> ItemBlock name mismatch, block name %s, item name %s", blockName, itemName);
    }
  }
  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;
  }
Exemple #10
0
  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;
  }