Add in a remapping event for mods to consume.
This commit is contained in:
parent
985e4ceb4a
commit
4f6aabda09
3 changed files with 64 additions and 4 deletions
|
@ -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<String, Integer[]> remaps)
|
||||
{
|
||||
if (remaps.isEmpty())
|
||||
{
|
||||
FMLLog.finest("Skipping remap event - no remaps occured");
|
||||
}
|
||||
else
|
||||
{
|
||||
modController.propogateStateMessage(new FMLModIdMappingEvent(remaps));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ModRemapping> remappedIds;
|
||||
|
||||
public FMLModIdMappingEvent(Map<String, Integer[]> mappings)
|
||||
{
|
||||
List<ModRemapping> remappings = Lists.newArrayList();
|
||||
for (Entry<String, Integer[]> mapping : mappings.entrySet())
|
||||
{
|
||||
remappings.add(new ModRemapping(mapping.getValue()[0], mapping.getValue()[1], mapping.getKey()));
|
||||
}
|
||||
|
||||
Collections.sort(remappings, new Comparator<ModRemapping>() {
|
||||
@Override
|
||||
public int compare(ModRemapping o1, ModRemapping o2)
|
||||
{
|
||||
return Integer.compare(o1.newId,o2.newId);
|
||||
}
|
||||
});
|
||||
remappedIds = ImmutableList.copyOf(remappings);
|
||||
}
|
||||
}
|
|
@ -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<String, Integer> dataList)
|
||||
{
|
||||
Map<String, Integer[]> remaps = Maps.newHashMap();
|
||||
blockRegistry.beginIdSwap();
|
||||
itemRegistry.beginIdSwap();
|
||||
for (Entry<String, Integer> 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue