add FML remap event support to mapping registry, should help backwards compatibility
This commit is contained in:
parent
09212f053b
commit
23ea92f93b
1 changed files with 63 additions and 3 deletions
|
@ -8,10 +8,21 @@
|
|||
*/
|
||||
package buildcraft.api.blueprints;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.google.common.collect.Multiset;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import org.apache.logging.log4j.Level;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
|
@ -22,6 +33,11 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagShort;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.FMLModContainer;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import buildcraft.api.core.BCLog;
|
||||
|
@ -285,6 +301,36 @@ public class MappingRegistry {
|
|||
nbt.setTag("entitiesMapping", entitiesMapping);
|
||||
}
|
||||
|
||||
private final Object getMissingMappingFromFML(boolean isBlock, String name, int i) {
|
||||
String modName = name.split(":")[0];
|
||||
if (Loader.isModLoaded(modName)) {
|
||||
try {
|
||||
FMLMissingMappingsEvent.MissingMapping mapping = new FMLMissingMappingsEvent.MissingMapping(
|
||||
(isBlock ? '\u0001' : '\u0020') + name, i
|
||||
);
|
||||
ListMultimap<String, FMLMissingMappingsEvent.MissingMapping> missingMapping
|
||||
= ArrayListMultimap.create();
|
||||
missingMapping.put(modName, mapping);
|
||||
FMLMissingMappingsEvent event = new FMLMissingMappingsEvent(missingMapping);
|
||||
for (ModContainer container : Loader.instance().getModList()) {
|
||||
if (container instanceof FMLModContainer) {
|
||||
event.applyModContainer(container);
|
||||
((FMLModContainer) container).handleModStateEvent(event);
|
||||
if (mapping.getAction() != FMLMissingMappingsEvent.Action.DEFAULT) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mapping.getAction() == FMLMissingMappingsEvent.Action.REMAP) {
|
||||
return mapping.getTarget();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void read (NBTTagCompound nbt) {
|
||||
NBTTagList blocksMapping = nbt.getTagList("blocksMapping",
|
||||
Constants.NBT.TAG_COMPOUND);
|
||||
|
@ -299,8 +345,15 @@ public class MappingRegistry {
|
|||
}
|
||||
String name = sub.getString("name");
|
||||
Block b = null;
|
||||
|
||||
if (!Block.blockRegistry.containsKey(name) && name.contains(":")) {
|
||||
b = (Block) getMissingMappingFromFML(true, name, i);
|
||||
if (b != null) {
|
||||
BCLog.logger.info("Remapped " + name + " to " + Block.blockRegistry.getNameForObject(b));
|
||||
}
|
||||
}
|
||||
|
||||
if (Block.blockRegistry.containsKey(name)) {
|
||||
if (b == null && Block.blockRegistry.containsKey(name)) {
|
||||
b = (Block) Block.blockRegistry.getObject(name);
|
||||
}
|
||||
|
||||
|
@ -327,8 +380,15 @@ public class MappingRegistry {
|
|||
|
||||
String name = sub.getString("name");
|
||||
Item item = null;
|
||||
|
||||
if (Item.itemRegistry.containsKey(name)) {
|
||||
|
||||
if (!Item.itemRegistry.containsKey(name) && name.contains(":")) {
|
||||
item = (Item) getMissingMappingFromFML(false, name, i);
|
||||
if (item != null) {
|
||||
BCLog.logger.info("Remapped " + name + " to " + Item.itemRegistry.getNameForObject(item));
|
||||
}
|
||||
}
|
||||
|
||||
if (item == null && Item.itemRegistry.containsKey(name)) {
|
||||
item = (Item) Item.itemRegistry.getObject(name);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue