diff --git a/src/main/java/net/minecraftforge/fml/common/FMLContainer.java b/src/main/java/net/minecraftforge/fml/common/FMLContainer.java index 43a84747e..92c225830 100644 --- a/src/main/java/net/minecraftforge/fml/common/FMLContainer.java +++ b/src/main/java/net/minecraftforge/fml/common/FMLContainer.java @@ -267,7 +267,7 @@ public class FMLContainer extends DummyModContainer implements WorldAccessContai ResourceLocation entryLoc; if ("fml:blocks".equals(key)) entryLoc = PersistentRegistryManager.BLOCKS; else if ("fml:items".equals(key)) entryLoc = PersistentRegistryManager.ITEMS; - else if ("fmlgr:villagerprofessions".equals(key)) entryLoc = new ResourceLocation("minecraft:villagerprofessions"); + else if ("fmlgr:villagerprofessions".equals(key)) entryLoc = VillagerRegistry.PROFESSIONS; else entryLoc = new ResourceLocation(key); snapshot.entries.put(entryLoc, entry); diff --git a/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java index e35847845..073f07a60 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/FMLControlledNamespacedRegistry.java @@ -713,4 +713,15 @@ public class FMLControlledNamespacedRegistry extends RegistryNamespacedDefaul { blockedIds.add(id); } + + public void noitifyCallbacks() + { + if (addCallback == null) + return; + + for (I i : this.underlyingIntegerMap) + { + addCallback.onAdd(i, this.underlyingIntegerMap.get(i)); + } + } } diff --git a/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java b/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java index daf8b669b..955c6b41f 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/PersistentRegistryManager.java @@ -23,11 +23,13 @@ import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.potion.Potion; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.EnhancedRuntimeException; import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLLog; import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.StartupQuery; import net.minecraftforge.fml.common.ZipperUtil; +import net.minecraftforge.fml.common.EnhancedRuntimeException.WrappedPrintStream; import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent; /** @@ -138,7 +140,7 @@ public class PersistentRegistryManager public static List injectSnapshot(GameDataSnapshot snapshot, boolean injectFrozenData, boolean isLocalWorld) { - FMLLog.info("Injecting existing block and item data into this {} instance", FMLCommonHandler.instance().getEffectiveSide().isServer() ? "server" : "client"); + FMLLog.info("Injecting existing block and item data into this %s instance", FMLCommonHandler.instance().getEffectiveSide().isServer() ? "server" : "client"); final Map> remaps = Maps.newHashMap(); final LinkedHashMap> missing = Maps.newLinkedHashMap(); @@ -208,11 +210,40 @@ public class PersistentRegistryManager } } - private static void loadRegistry(ResourceLocation registryName, PersistentRegistry from, PersistentRegistry to, Class regType) + private static void loadRegistry(final ResourceLocation registryName, final PersistentRegistry from, final PersistentRegistry to, Class regType) { FMLControlledNamespacedRegistry fromRegistry = from.getRegistry(registryName, regType); - FMLControlledNamespacedRegistry toRegistry = to.getOrShallowCopyRegistry(registryName, regType, fromRegistry); - toRegistry.set(fromRegistry); + if (fromRegistry == null) + { + FMLControlledNamespacedRegistry toRegistry = to.getRegistry(registryName, regType); + if (toRegistry == null) + { + throw new EnhancedRuntimeException("Could not find registry to load: " + registryName){ + private static final long serialVersionUID = 1L; + @Override + protected void printStackTrace(WrappedPrintStream stream) + { + stream.println("Looking For: " + registryName); + stream.println("Found From:"); + for (ResourceLocation name : from.registries.keySet()) + stream.println(" " + name); + stream.println("Found To:"); + for (ResourceLocation name : to.registries.keySet()) + stream.println(" " + name); + } + }; + } + // We found it in to, so lets trust to's state... + // This happens when connecting to a server that doesn't have this registry. + // Such as a 1.8.0 Forge server with 1.8.8+ Forge. + // We must however, re-fire the callbacks as some internal data may be corrupted {potions} + toRegistry.noitifyCallbacks(); + } + else + { + FMLControlledNamespacedRegistry toRegistry = to.getOrShallowCopyRegistry(registryName, regType, fromRegistry); + toRegistry.set(fromRegistry); + } } private static void loadFrozenDataToStagingRegistry(Map> remaps, ResourceLocation registryName, Class regType) @@ -225,10 +256,16 @@ public class PersistentRegistryManager private static void loadPersistentDataToStagingRegistry(boolean injectFrozenData, Map> remaps, LinkedHashMap> missing, Map.Entry snapEntry, Class regType) { ResourceLocation registryName = snapEntry.getKey(); + + //Translate old names + if ("fml:blocks".equals(registryName.toString())) registryName = PersistentRegistryManager.BLOCKS; + else if ("fml:items".equals(registryName.toString())) registryName = PersistentRegistryManager.ITEMS; + else if ("fmlgr:villagerprofessions".equals(registryName.toString())) registryName = VillagerRegistry.PROFESSIONS; + FMLControlledNamespacedRegistry currentRegistry = PersistentRegistry.ACTIVE.getRegistry(registryName, regType); if (currentRegistry == null) { - FMLLog.severe("An unknown persistent registry type {} has been encountered. This Forge instance cannot understand it.", registryName); + FMLLog.severe("An unknown persistent registry type \"%s\" has been encountered. This Forge instance cannot understand it.", registryName); StartupQuery.abort(); } FMLControlledNamespacedRegistry newRegistry = PersistentRegistry.STAGING.getOrShallowCopyRegistry(registryName, regType, currentRegistry); diff --git a/src/main/java/net/minecraftforge/fml/common/registry/VillagerRegistry.java b/src/main/java/net/minecraftforge/fml/common/registry/VillagerRegistry.java index 17c37c12c..7eef45e0b 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/VillagerRegistry.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/VillagerRegistry.java @@ -53,6 +53,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; */ public class VillagerRegistry { + public static final ResourceLocation PROFESSIONS = new ResourceLocation("minecraft:villagerprofessions"); private static final VillagerRegistry INSTANCE = new VillagerRegistry(); private Map, IVillageCreationHandler> villageCreationHandlers = Maps.newHashMap(); @@ -206,7 +207,7 @@ public class VillagerRegistry } private boolean hasInit = false; - private FMLControlledNamespacedRegistry professions = PersistentRegistryManager.createRegistry(new ResourceLocation("minecraft:villagerprofessions"), VillagerProfession.class, null, 1024, 0, true, null); + private FMLControlledNamespacedRegistry professions = PersistentRegistryManager.createRegistry(PROFESSIONS, VillagerProfession.class, null, 1024, 0, true, null); private void init()