From 2096bcb5ab310292472708318ab965a89d75ac90 Mon Sep 17 00:00:00 2001 From: Lex Manos Date: Mon, 15 Dec 2014 06:57:59 -0800 Subject: [PATCH] Finish removing marker in mapping entry names. FMLMissingMappingsEvent/FMLModIdMappingEvent should fire with correct names now. --- .../net/minecraftforge/fml/common/Loader.java | 28 +++++++++++------- .../common/event/FMLMissingMappingsEvent.java | 8 ++--- .../common/event/FMLModIdMappingEvent.java | 18 +++++++----- .../fml/common/registry/GameData.java | 29 ++++++++++--------- 4 files changed, 48 insertions(+), 35 deletions(-) diff --git a/fml/src/main/java/net/minecraftforge/fml/common/Loader.java b/fml/src/main/java/net/minecraftforge/fml/common/Loader.java index 309d93ee5..b415b1191 100644 --- a/fml/src/main/java/net/minecraftforge/fml/common/Loader.java +++ b/fml/src/main/java/net/minecraftforge/fml/common/Loader.java @@ -37,6 +37,7 @@ import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent.MissingMappin import net.minecraftforge.fml.common.functions.ArtifactVersionNameFunction; import net.minecraftforge.fml.common.functions.ModIdFunction; import net.minecraftforge.fml.common.registry.GameData; +import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.ObjectHolderRegistry; import net.minecraftforge.fml.common.registry.GameRegistry.Type; import net.minecraftforge.fml.common.toposort.ModSorter; @@ -869,20 +870,25 @@ public class Loader * @param gameData GameData instance where the new map's config is to be loaded into. * @return List with the mapping results. */ - public List fireMissingMappingEvent(LinkedHashMap missing, boolean isLocalWorld, GameData gameData, Map remaps) + public List fireMissingMappingEvent(LinkedHashMap missingBlocks, LinkedHashMap missingItems, + boolean isLocalWorld, GameData gameData, Map remapBlocks, Map remapItems) { - if (missing.isEmpty()) // nothing to do + if (missingBlocks.isEmpty() && missingItems.isEmpty()) // nothing to do { return ImmutableList.of(); } - FMLLog.fine("There are %d mappings missing - attempting a mod remap", missing.size()); + FMLLog.fine("There are %d mappings missing - attempting a mod remap", missingBlocks.size() + missingItems.size()); ArrayListMultimap missingMappings = ArrayListMultimap.create(); - for (Map.Entry mapping : missing.entrySet()) + for (Map.Entry mapping : missingBlocks.entrySet()) { - int id = mapping.getValue(); - MissingMapping m = new MissingMapping(mapping.getKey(), id); + MissingMapping m = new MissingMapping(GameRegistry.Type.BLOCK, mapping.getKey(), mapping.getValue()); + missingMappings.put(m.name.substring(0, m.name.indexOf(':')), m); + } + for (Map.Entry mapping : missingItems.entrySet()) + { + MissingMapping m = new MissingMapping(GameRegistry.Type.ITEM, mapping.getKey(), mapping.getValue()); missingMappings.put(m.name.substring(0, m.name.indexOf(':')), m); } @@ -925,18 +931,18 @@ public class Loader } } - return GameData.processIdRematches(missingMappings.values(), isLocalWorld, gameData, remaps); + return GameData.processIdRematches(missingMappings.values(), isLocalWorld, gameData, remapBlocks, remapItems); } - public void fireRemapEvent(Map remaps) + public void fireRemapEvent(Map remapBlocks, Map remapItems) { - if (remaps.isEmpty()) + if (remapBlocks.isEmpty() && remapItems.isEmpty()) { FMLLog.finer("Skipping remap event - no remaps occured"); } else { - modController.propogateStateMessage(new FMLModIdMappingEvent(remaps)); + modController.propogateStateMessage(new FMLModIdMappingEvent(remapBlocks, remapItems)); } } @@ -975,4 +981,4 @@ public class Loader FMLLog.log(Level.INFO, e, "An error occurred writing the fml mod states file, your disabled change won't persist"); } } -} +} \ No newline at end of file diff --git a/fml/src/main/java/net/minecraftforge/fml/common/event/FMLMissingMappingsEvent.java b/fml/src/main/java/net/minecraftforge/fml/common/event/FMLMissingMappingsEvent.java index 055bb1b6e..a0049dc04 100644 --- a/fml/src/main/java/net/minecraftforge/fml/common/event/FMLMissingMappingsEvent.java +++ b/fml/src/main/java/net/minecraftforge/fml/common/event/FMLMissingMappingsEvent.java @@ -60,10 +60,10 @@ public class FMLMissingMappingsEvent extends FMLEvent { private Action action = Action.DEFAULT; private Object target; - public MissingMapping(String name, int id) + public MissingMapping(GameRegistry.Type type, String name, int id) { - this.type = name.charAt(0) == '\u0001' ? GameRegistry.Type.BLOCK : GameRegistry.Type.ITEM; - this.name = name.substring(1); + this.type = type; + this.name = name; this.id = id; } /** @@ -191,4 +191,4 @@ public class FMLMissingMappingsEvent extends FMLEvent { { return ImmutableList.copyOf(missing.values()); } -} +} \ No newline at end of file diff --git a/fml/src/main/java/net/minecraftforge/fml/common/event/FMLModIdMappingEvent.java b/fml/src/main/java/net/minecraftforge/fml/common/event/FMLModIdMappingEvent.java index 8bb74d028..99c3af3bc 100644 --- a/fml/src/main/java/net/minecraftforge/fml/common/event/FMLModIdMappingEvent.java +++ b/fml/src/main/java/net/minecraftforge/fml/common/event/FMLModIdMappingEvent.java @@ -17,23 +17,27 @@ public class FMLModIdMappingEvent extends FMLEvent { public final int newId; public final String tag; public final RemapTarget remapTarget; - public ModRemapping(int oldId, int newId, String tag) + public ModRemapping(int oldId, int newId, String tag, RemapTarget type) { this.oldId = oldId; this.newId = newId; - this.tag = tag.substring(1); - this.remapTarget = tag.charAt(0) == '\u0001' ? RemapTarget.BLOCK : RemapTarget.ITEM; + this.tag = tag; + this.remapTarget = type; } } public final ImmutableList remappedIds; - public FMLModIdMappingEvent(Map mappings) + public FMLModIdMappingEvent(Map blocks, Map items) { List remappings = Lists.newArrayList(); - for (Entry mapping : mappings.entrySet()) + for (Entry mapping : blocks.entrySet()) { - remappings.add(new ModRemapping(mapping.getValue()[0], mapping.getValue()[1], mapping.getKey())); + remappings.add(new ModRemapping(mapping.getValue()[0], mapping.getValue()[1], mapping.getKey(), RemapTarget.BLOCK)); + } + for (Entry mapping : items.entrySet()) + { + remappings.add(new ModRemapping(mapping.getValue()[0], mapping.getValue()[1], mapping.getKey(), RemapTarget.ITEM)); } Collections.sort(remappings, new Comparator() { @@ -45,4 +49,4 @@ public class FMLModIdMappingEvent extends FMLEvent { }); remappedIds = ImmutableList.copyOf(remappings); } -} +} \ No newline at end of file diff --git a/fml/src/main/java/net/minecraftforge/fml/common/registry/GameData.java b/fml/src/main/java/net/minecraftforge/fml/common/registry/GameData.java index 37e98bc03..c8a5e341b 100644 --- a/fml/src/main/java/net/minecraftforge/fml/common/registry/GameData.java +++ b/fml/src/main/java/net/minecraftforge/fml/common/registry/GameData.java @@ -336,8 +336,10 @@ public class GameData { public static List injectSnapshot(GameDataSnapshot snapshot, boolean injectFrozenData, boolean isLocalWorld) { FMLLog.info("Injecting existing block and item data into this %s instance", FMLCommonHandler.instance().getEffectiveSide().isServer() ? "server" : "client"); - Map remaps = Maps.newHashMap(); - LinkedHashMap missingMappings = new LinkedHashMap(); + Map remapBlocks = Maps.newHashMap(); + Map remapItems = Maps.newHashMap(); + LinkedHashMap missingBlocks = new LinkedHashMap(); + LinkedHashMap missingItems = new LinkedHashMap(); getMain().testConsistency(); getMain().iBlockRegistry.dump(); getMain().iItemRegistry.dump(); @@ -407,13 +409,13 @@ public class GameData { if (currId == -1) { FMLLog.info("Found a missing id from the world %s", itemName); - missingMappings.put(entry.getKey(), newId); + (isBlock ? missingBlocks : missingItems).put(entry.getKey(), newId); continue; // no block/item -> nothing to add } else if (currId != newId) { FMLLog.fine("Fixed %s id mismatch %s: %d (init) -> %d (map).", isBlock ? "block" : "item", itemName, currId, newId); - remaps.put(itemName, new Integer[] { currId, newId }); + (isBlock ? remapBlocks : remapItems).put(itemName, new Integer[] { currId, newId }); } // register @@ -440,22 +442,23 @@ public class GameData { } } - List missedMappings = Loader.instance().fireMissingMappingEvent(missingMappings, isLocalWorld, newData, remaps); + List missedMappings = Loader.instance().fireMissingMappingEvent(missingBlocks, missingItems, isLocalWorld, newData, remapBlocks, remapItems); if (!missedMappings.isEmpty()) return missedMappings; if (injectFrozenData) // add blocks + items missing from the map { - Map missingBlocks = frozen.iBlockRegistry.getEntriesNotIn(newData.iBlockRegistry); - Map missingItems = frozen.iItemRegistry.getEntriesNotIn(newData.iItemRegistry); + Map newBlocks = frozen.iBlockRegistry.getEntriesNotIn(newData.iBlockRegistry); + Map newItems = frozen.iItemRegistry.getEntriesNotIn(newData.iItemRegistry); - if (!missingBlocks.isEmpty() || !missingItems.isEmpty()) + if (!newBlocks.isEmpty() || !newItems.isEmpty()) { FMLLog.info("Injecting new block and item data into this server instance."); for (int pass = 0; pass < 2; pass++) { boolean isBlock = pass == 0; - Map missing = (pass == 0) ? missingBlocks : missingItems; + Map missing = (pass == 0) ? newBlocks : newItems; + Map remaps = (isBlock ? remapBlocks : remapItems); for (Entry entry : missing.entrySet()) { @@ -488,13 +491,13 @@ public class GameData { getMain().iBlockRegistry.dump(); getMain().iItemRegistry.dump(); - Loader.instance().fireRemapEvent(remaps); + Loader.instance().fireRemapEvent(remapBlocks, remapItems); // The id map changed, ensure we apply object holders ObjectHolderRegistry.INSTANCE.applyObjectHolders(); return ImmutableList.of(); } - public static List processIdRematches(Iterable missedMappings, boolean isLocalWorld, GameData gameData, Map remaps) + public static List processIdRematches(Iterable missedMappings, boolean isLocalWorld, GameData gameData, Map remapBlocks, Map remapItems) { List failed = Lists.newArrayList(); List ignored = Lists.newArrayList(); @@ -535,7 +538,7 @@ public class GameData { if (currId != newId) { FMLLog.info("Fixed %s id mismatch %s: %d (init) -> %d (map).", remap.type == Type.BLOCK ? "block" : "item", newName, currId, newId); - remaps.put(newName, new Integer[] { currId, newId }); + (remap.type == Type.BLOCK ? remapBlocks : remapItems).put(newName, new Integer[] { currId, newId }); } } else @@ -963,4 +966,4 @@ public class GameData { this.objectList.clear(); } } -} +} \ No newline at end of file