From 4f6aabda0976b1273532599b7664763b536425b7 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 10 Dec 2013 19:25:49 -0500 Subject: [PATCH] Add in a remapping event for mods to consume. --- .../main/java/cpw/mods/fml/common/Loader.java | 13 +++++ .../common/event/FMLModIdMappingEvent.java | 48 +++++++++++++++++++ .../mods/fml/common/registry/GameData.java | 7 ++- 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 fml/src/main/java/cpw/mods/fml/common/event/FMLModIdMappingEvent.java diff --git a/fml/src/main/java/cpw/mods/fml/common/Loader.java b/fml/src/main/java/cpw/mods/fml/common/Loader.java index 780fc13b4..737610638 100644 --- a/fml/src/main/java/cpw/mods/fml/common/Loader.java +++ b/fml/src/main/java/cpw/mods/fml/common/Loader.java @@ -47,6 +47,7 @@ import cpw.mods.fml.common.LoaderState.ModState; import cpw.mods.fml.common.discovery.ModDiscoverer; import cpw.mods.fml.common.event.FMLInterModComms; import cpw.mods.fml.common.event.FMLLoadEvent; +import cpw.mods.fml.common.event.FMLModIdMappingEvent; import cpw.mods.fml.common.functions.ArtifactVersionNameFunction; import cpw.mods.fml.common.functions.ModIdFunction; import cpw.mods.fml.common.registry.GameData; @@ -837,4 +838,16 @@ public class Loader FMLLog.info("Attempting connection with missing mods %s at %s", difference, side); return true; } + + public void fireRemapEvent(Map remaps) + { + if (remaps.isEmpty()) + { + FMLLog.finest("Skipping remap event - no remaps occured"); + } + else + { + modController.propogateStateMessage(new FMLModIdMappingEvent(remaps)); + } + } } diff --git a/fml/src/main/java/cpw/mods/fml/common/event/FMLModIdMappingEvent.java b/fml/src/main/java/cpw/mods/fml/common/event/FMLModIdMappingEvent.java new file mode 100644 index 000000000..80b482059 --- /dev/null +++ b/fml/src/main/java/cpw/mods/fml/common/event/FMLModIdMappingEvent.java @@ -0,0 +1,48 @@ +package cpw.mods.fml.common.event; + +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; + +public class FMLModIdMappingEvent extends FMLEvent { + public static enum RemapTarget { BLOCK, ITEM } + public class ModRemapping + { + public final int oldId; + public final int newId; + public final String tag; + public final RemapTarget remapTarget; + public ModRemapping(int oldId, int newId, String tag) + { + this.oldId = oldId; + this.newId = newId; + this.tag = tag.substring(1); + this.remapTarget = tag.charAt(0) == '\u0001' ? RemapTarget.BLOCK : RemapTarget.ITEM; + } + + } + public final ImmutableList remappedIds; + + public FMLModIdMappingEvent(Map mappings) + { + List remappings = Lists.newArrayList(); + for (Entry mapping : mappings.entrySet()) + { + remappings.add(new ModRemapping(mapping.getValue()[0], mapping.getValue()[1], mapping.getKey())); + } + + Collections.sort(remappings, new Comparator() { + @Override + public int compare(ModRemapping o1, ModRemapping o2) + { + return Integer.compare(o1.newId,o2.newId); + } + }); + remappedIds = ImmutableList.copyOf(remappings); + } +} diff --git a/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java b/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java index 6a9e33740..e195b172b 100644 --- a/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java +++ b/fml/src/main/java/cpw/mods/fml/common/registry/GameData.java @@ -16,15 +16,12 @@ import java.io.File; import java.io.IOException; import java.util.Map; import java.util.Map.Entry; -import java.util.Set; import java.util.logging.Level; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; import com.google.common.base.Charsets; import com.google.common.base.Joiner; @@ -32,7 +29,6 @@ import com.google.common.base.Joiner.MapJoiner; import com.google.common.collect.HashBasedTable; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.google.common.collect.Table; import com.google.common.io.Files; @@ -215,6 +211,7 @@ public class GameData { public static void injectWorldIDMap(Map dataList) { + Map remaps = Maps.newHashMap(); blockRegistry.beginIdSwap(); itemRegistry.beginIdSwap(); for (Entry entry : dataList.entrySet()) @@ -237,6 +234,7 @@ public class GameData { if (currId != newId) { FMLLog.info("Found %s id mismatch %s : %d %d", isBlock ? "block" : "item", itemName, currId, newId); + remaps.put(itemName, new Integer[] { currId, newId }); } if (isBlock) @@ -251,5 +249,6 @@ public class GameData { blockRegistry.completeIdSwap(); itemRegistry.completeIdSwap(); + Loader.instance().fireRemapEvent(remaps); } }