Finish removing marker in mapping entry names. FMLMissingMappingsEvent/FMLModIdMappingEvent should fire with correct names now.
This commit is contained in:
parent
e9dbc71362
commit
2096bcb5ab
4 changed files with 48 additions and 35 deletions
|
@ -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<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);
|
||||
}
|
||||
|
||||
|
@ -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<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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -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<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>() {
|
||||
|
|
|
@ -336,8 +336,10 @@ public class GameData {
|
|||
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();
|
||||
|
@ -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<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())
|
||||
{
|
||||
|
@ -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<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();
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue