Fire the ModIdRemappingEvent on the Forge Event bus. Closes #5632

Signed-off-by: cpw <cpw+github@weeksfamily.ca>
This commit is contained in:
cpw 2019-03-25 21:41:28 -04:00
parent e0e999da0d
commit 944d760855
No known key found for this signature in database
GPG Key ID: 8EB3DF749553B1B7
2 changed files with 9 additions and 5 deletions

View File

@ -39,8 +39,7 @@ import net.minecraft.util.ResourceLocation;
* this event to update caches or other in-mod artifacts that might be impacted by an ID
* change.
*
* @see net.minecraftforge.fml.common.Mod.EventHandler for how to subscribe to this event
* @author cpw
* Fired on the {@link net.minecraftforge.common.MinecraftForge#EVENT_BUS}
*/
public class FMLModIdMappingEvent extends ModLifecycleEvent
{

View File

@ -48,6 +48,7 @@ import net.minecraftforge.fml.StartupQuery;
import net.minecraftforge.fml.common.EnhancedRuntimeException;
import net.minecraftforge.fml.common.registry.VillagerRegistry.VillagerProfession;
import net.minecraftforge.fml.common.thread.EffectiveSide;
import net.minecraftforge.fml.event.lifecycle.FMLModIdMappingEvent;
import net.minecraftforge.fml.loading.AdvancedLogMessageAdapter;
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
@ -224,7 +225,7 @@ public class GameData
});
// the id mapping is finalized, no ids actually changed but this is a good place to tell everyone to 'bake' their stuff.
//Loader.instance().fireRemapEvent(ImmutableMap.of(), true);
fireRemapEvent(ImmutableMap.of(), true);
LOGGER.debug(REGISTRIES, "All registries frozen");
}
@ -247,7 +248,7 @@ public class GameData
}
RegistryManager.ACTIVE.registries.forEach((name, reg) -> reg.bake());
// the id mapping has reverted, fire remap events for those that care about id changes
//Loader.instance().fireRemapEvent(ImmutableMap.of(), true);
fireRemapEvent(ImmutableMap.of(), true);
ObjectHolderRegistry.applyObjectHolders();
// the id mapping has reverted, ensure we sync up the object holders
@ -737,7 +738,7 @@ public class GameData
});
// Tell mods that the ids have changed
//Loader.instance().fireRemapEvent(remaps, false);
fireRemapEvent(remaps, false);
// The id map changed, ensure we apply object holders
ObjectHolderRegistry.applyObjectHolders();
@ -746,6 +747,10 @@ public class GameData
return ArrayListMultimap.create();
}
private static void fireRemapEvent(final Map<ResourceLocation, Map<ResourceLocation, Integer[]>> remaps, final boolean isFreezing) {
MinecraftForge.EVENT_BUS.post(new FMLModIdMappingEvent(remaps, isFreezing));
}
//Has to be split because of generics, Yay!
private static <T extends IForgeRegistryEntry<T>> void loadPersistentDataToStagingRegistry(RegistryManager pool, RegistryManager to, Map<ResourceLocation, Integer[]> remaps, Map<ResourceLocation, Integer> missing, ResourceLocation name, ForgeRegistry.Snapshot snap, Class<T> regType)
{