use of net.minecraftforge.fml.common.event.FMLMissingMappingsEvent in project Railcraft by Railcraft.
the class MappingRegistry method getMissingMappingFromFML.
private Object getMissingMappingFromFML(boolean isBlock, String name, int i) {
ResourceLocation location = new ResourceLocation(name);
String modName = name.split(":")[0];
if (Loader.isModLoaded(modName)) {
try {
FMLMissingMappingsEvent.MissingMapping mapping = new FMLMissingMappingsEvent.MissingMapping(isBlock ? GameRegistry.Type.BLOCK : GameRegistry.Type.ITEM, location, i);
ListMultimap<String, FMLMissingMappingsEvent.MissingMapping> missingMapping = ArrayListMultimap.create();
missingMapping.put(modName, mapping);
FMLMissingMappingsEvent event = new FMLMissingMappingsEvent(missingMapping);
for (ModContainer container : Loader.instance().getModList()) {
if (container instanceof FMLModContainer) {
event.applyModContainer(container);
((FMLModContainer) container).handleModStateEvent(event);
if (mapping.getAction() != FMLMissingMappingsEvent.Action.DEFAULT) {
break;
}
}
}
if (mapping.getAction() == FMLMissingMappingsEvent.Action.REMAP) {
return mapping.getTarget();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
use of net.minecraftforge.fml.common.event.FMLMissingMappingsEvent in project MinecraftForge by MinecraftForge.
the class ForgeModContainer method missingMapping.
@Subscribe
public void missingMapping(FMLMissingMappingsEvent event) {
for (FMLMissingMappingsEvent.MissingMapping entry : event.getAll()) {
if (//This item changed from 1.11 -> 1.11.2
entry.name.equals("minecraft:totem")) {
ResourceLocation newTotem = new ResourceLocation("minecraft:totem_of_undying");
entry.remap(ForgeRegistries.ITEMS.getValue(newTotem));
}
}
}
use of net.minecraftforge.fml.common.event.FMLMissingMappingsEvent 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);
}
Aggregations