Search in sources :

Example 1 with MissingMapping

use of net.minecraftforge.fml.common.event.FMLMissingMappingsEvent.MissingMapping in project MinecraftForge by MinecraftForge.

the class Loader method fireMissingMappingEvent.

/**
     * Fire a FMLMissingMappingsEvent to let mods determine how blocks/items defined in the world
     * save, but missing from the runtime, are to be handled.
     *
     * @param missingBlocks Map containing the missing block names with their associated id. Remapped blocks will be removed from it.
     * @param missingItems Map containing the missing block names with their associated id. Remapped items will be removed from it.
     * @param isLocalWorld Whether this is executing for a world load (local/server) or a client.
     * @param remapBlocks Returns a map containing the remapped block names and an array containing the original and new id for the block.
     * @param remapItems Returns a map containing the remapped item names and an array containing the original and new id for the item.
     * @return List with the names of the failed remappings.
     */
public List<String> fireMissingMappingEvent(Map<ResourceLocation, Integer> missingBlocks, Map<ResourceLocation, Integer> missingItems, boolean isLocalWorld, Map<ResourceLocation, Integer[]> remapBlocks, Map<ResourceLocation, Integer[]> remapItems) {
    if (// nothing to do
    missingBlocks.isEmpty() && missingItems.isEmpty()) {
        return ImmutableList.of();
    }
    FMLLog.fine("There are %d mappings missing - attempting a mod remap", missingBlocks.size() + missingItems.size());
    ArrayListMultimap<String, MissingMapping> missingMappings = ArrayListMultimap.create();
    for (Map.Entry<ResourceLocation, Integer> mapping : missingBlocks.entrySet()) {
        MissingMapping m = new MissingMapping(GameRegistry.Type.BLOCK, mapping.getKey(), mapping.getValue());
        missingMappings.put(m.resourceLocation.getResourceDomain(), m);
    }
    for (Map.Entry<ResourceLocation, Integer> mapping : missingItems.entrySet()) {
        MissingMapping m = new MissingMapping(GameRegistry.Type.ITEM, mapping.getKey(), mapping.getValue());
        missingMappings.put(m.resourceLocation.getResourceDomain(), m);
    }
    FMLMissingMappingsEvent missingEvent = new FMLMissingMappingsEvent(missingMappings);
    modController.propogateStateMessage(missingEvent);
    if (// local world, warn about entries still being set to the default action
    isLocalWorld) {
        boolean didWarn = false;
        for (MissingMapping mapping : missingMappings.values()) {
            if (mapping.getAction() == FMLMissingMappingsEvent.Action.DEFAULT) {
                if (!didWarn) {
                    FMLLog.severe("There are unidentified mappings in this world - we are going to attempt to process anyway");
                    didWarn = true;
                }
                FMLLog.severe("Unidentified %s: %s, id %d", mapping.type == Type.BLOCK ? "block" : "item", mapping.name, mapping.id);
            }
        }
    } else // remote world, fail on entries with the default action
    {
        List<String> missedMapping = new ArrayList<String>();
        for (MissingMapping mapping : missingMappings.values()) {
            if (mapping.getAction() == FMLMissingMappingsEvent.Action.DEFAULT) {
                missedMapping.add(mapping.name);
            }
        }
        if (!missedMapping.isEmpty()) {
            return ImmutableList.copyOf(missedMapping);
        }
    }
    return PersistentRegistryManager.processIdRematches(missingMappings.values(), isLocalWorld, missingBlocks, missingItems, remapBlocks, remapItems);
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) ArrayList(java.util.ArrayList) MissingMapping(net.minecraftforge.fml.common.event.FMLMissingMappingsEvent.MissingMapping) FMLMissingMappingsEvent(net.minecraftforge.fml.common.event.FMLMissingMappingsEvent) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashBiMap(com.google.common.collect.HashBiMap)

Aggregations

BiMap (com.google.common.collect.BiMap)1 HashBiMap (com.google.common.collect.HashBiMap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 FMLMissingMappingsEvent (net.minecraftforge.fml.common.event.FMLMissingMappingsEvent)1 MissingMapping (net.minecraftforge.fml.common.event.FMLMissingMappingsEvent.MissingMapping)1