Skip to content
This repository has been archived by the owner on May 26, 2018. It is now read-only.

Commit

Permalink
Finish removing marker in mapping entry names. FMLMissingMappingsEven…
Browse files Browse the repository at this point in the history
…t/FMLModIdMappingEvent should fire with correct names now.
  • Loading branch information
LexManos committed Dec 15, 2014
1 parent e3785c2 commit 5a4d362
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 35 deletions.
28 changes: 17 additions & 11 deletions src/main/java/net/minecraftforge/fml/common/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
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;
Expand Down Expand Up @@ -869,20 +870,25 @@ boolean checkRemoteModList(Map<String, String> modList, Side side)
* @param gameData GameData instance where the new map's config is to be loaded into.
* @return List with the mapping results.
*/
public List<String> fireMissingMappingEvent(LinkedHashMap<String, Integer> missing, boolean isLocalWorld, GameData gameData, Map<String, Integer[]> remaps)
public List<String> fireMissingMappingEvent(LinkedHashMap<String, Integer> missingBlocks, LinkedHashMap<String, Integer> missingItems,
boolean isLocalWorld, GameData gameData, Map<String, Integer[]> remapBlocks, Map<String, Integer[]> 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<String, MissingMapping> missingMappings = ArrayListMultimap.create();

for (Map.Entry<String, Integer> mapping : missing.entrySet())
for (Map.Entry<String, Integer> 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<String, Integer> mapping : missingItems.entrySet())
{
MissingMapping m = new MissingMapping(GameRegistry.Type.ITEM, mapping.getKey(), mapping.getValue());
missingMappings.put(m.name.substring(0, m.name.indexOf(':')), m);
}

Expand Down Expand Up @@ -925,18 +931,18 @@ public List<String> fireMissingMappingEvent(LinkedHashMap<String, Integer> missi
}
}

return GameData.processIdRematches(missingMappings.values(), isLocalWorld, gameData, remaps);
return GameData.processIdRematches(missingMappings.values(), isLocalWorld, gameData, remapBlocks, remapItems);
}

public void fireRemapEvent(Map<String, Integer[]> remaps)
public void fireRemapEvent(Map<String, Integer[]> remapBlocks, Map<String, Integer[]> 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));
}
}

Expand Down Expand Up @@ -975,4 +981,4 @@ public void runtimeDisableMod(String modId)
FMLLog.log(Level.INFO, e, "An error occurred writing the fml mod states file, your disabled change won't persist");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public static class MissingMapping {
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;
}
/**
Expand Down Expand Up @@ -191,4 +191,4 @@ public List<MissingMapping> getAll()
{
return ImmutableList.copyOf(missing.values());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ public class ModRemapping
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<ModRemapping> remappedIds;

public FMLModIdMappingEvent(Map<String, Integer[]> mappings)
public FMLModIdMappingEvent(Map<String, Integer[]> blocks, Map<String, Integer[]> items)
{
List<ModRemapping> remappings = Lists.newArrayList();
for (Entry<String, Integer[]> mapping : mappings.entrySet())
for (Entry<String, Integer[]> 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<String, Integer[]> mapping : items.entrySet())
{
remappings.add(new ModRemapping(mapping.getValue()[0], mapping.getValue()[1], mapping.getKey(), RemapTarget.ITEM));
}

Collections.sort(remappings, new Comparator<ModRemapping>() {
Expand All @@ -45,4 +49,4 @@ public int compare(ModRemapping o1, ModRemapping o2)
});
remappedIds = ImmutableList.copyOf(remappings);
}
}
}
29 changes: 16 additions & 13 deletions src/main/java/net/minecraftforge/fml/common/registry/GameData.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,10 @@ else if (availabilityMap.get(oldId)) // normal item, id is already occupied
public static List<String> 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<String, Integer[]> remaps = Maps.newHashMap();
LinkedHashMap<String, Integer> missingMappings = new LinkedHashMap<String, Integer>();
Map<String, Integer[]> remapBlocks = Maps.newHashMap();
Map<String, Integer[]> remapItems = Maps.newHashMap();
LinkedHashMap<String, Integer> missingBlocks = new LinkedHashMap<String, Integer>();
LinkedHashMap<String, Integer> missingItems = new LinkedHashMap<String, Integer>();
getMain().testConsistency();
getMain().iBlockRegistry.dump();
getMain().iItemRegistry.dump();
Expand Down Expand Up @@ -407,13 +409,13 @@ public static List<String> injectSnapshot(GameDataSnapshot snapshot, boolean inj
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
Expand All @@ -440,22 +442,23 @@ else if (currId != newId)
}
}

List<String> missedMappings = Loader.instance().fireMissingMappingEvent(missingMappings, isLocalWorld, newData, remaps);
List<String> 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<String, Integer> missingBlocks = frozen.iBlockRegistry.getEntriesNotIn(newData.iBlockRegistry);
Map<String, Integer> missingItems = frozen.iItemRegistry.getEntriesNotIn(newData.iItemRegistry);
Map<String, Integer> newBlocks = frozen.iBlockRegistry.getEntriesNotIn(newData.iBlockRegistry);
Map<String, Integer> 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<String, Integer> missing = (pass == 0) ? missingBlocks : missingItems;
Map<String, Integer> missing = (pass == 0) ? newBlocks : newItems;
Map<String, Integer[]> remaps = (isBlock ? remapBlocks : remapItems);

for (Entry<String, Integer> entry : missing.entrySet())
{
Expand Down Expand Up @@ -488,13 +491,13 @@ else if (currId != newId)

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<String> processIdRematches(Iterable<MissingMapping> missedMappings, boolean isLocalWorld, GameData gameData, Map<String, Integer[]> remaps)
public static List<String> processIdRematches(Iterable<MissingMapping> missedMappings, boolean isLocalWorld, GameData gameData, Map<String, Integer[]> remapBlocks, Map<String, Integer[]> remapItems)
{
List<String> failed = Lists.newArrayList();
List<String> ignored = Lists.newArrayList();
Expand Down Expand Up @@ -535,7 +538,7 @@ public static List<String> processIdRematches(Iterable<MissingMapping> missedMap
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
Expand Down Expand Up @@ -963,4 +966,4 @@ private void clear()
this.objectList.clear();
}
}
}
}

0 comments on commit 5a4d362

Please sign in to comment.