Added messy, but functional, remapper

This commit is contained in:
Ellpeck 2016-11-19 21:54:43 +01:00
parent ec8c642099
commit 07b97ada87
3 changed files with 52 additions and 17 deletions

View file

@ -43,6 +43,7 @@ import de.ellpeck.actuallyadditions.mod.recipe.HairyBallHandler;
import de.ellpeck.actuallyadditions.mod.recipe.TreasureChestHandler; import de.ellpeck.actuallyadditions.mod.recipe.TreasureChestHandler;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.update.UpdateChecker; import de.ellpeck.actuallyadditions.mod.update.UpdateChecker;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Loader;
@ -55,8 +56,6 @@ import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import java.util.Locale;
// So that BuildCraft Oil always gets used // So that BuildCraft Oil always gets used
@Mod(modid = ModUtil.MOD_ID, name = ModUtil.NAME, version = ModUtil.VERSION, dependencies = "after:BuildCraft|Energy", guiFactory = "de.ellpeck.actuallyadditions.mod.config.GuiFactory") @Mod(modid = ModUtil.MOD_ID, name = ModUtil.NAME, version = ModUtil.VERSION, dependencies = "after:BuildCraft|Energy", guiFactory = "de.ellpeck.actuallyadditions.mod.config.GuiFactory")
public class ActuallyAdditions{ public class ActuallyAdditions{
@ -147,16 +146,19 @@ public class ActuallyAdditions{
@EventHandler @EventHandler
public void missingMapping(FMLMissingMappingsEvent event){ public void missingMapping(FMLMissingMappingsEvent event){
int totalRemaps = 0;
int workedRemaps = 0;
for(FMLMissingMappingsEvent.MissingMapping mapping : event.getAll()){ for(FMLMissingMappingsEvent.MissingMapping mapping : event.getAll()){
if(mapping.name != null){ totalRemaps++;
String name = mapping.name.toLowerCase(Locale.ROOT);
if(name.startsWith(ModUtil.MOD_ID+":")){ if(ItemUtil.remapName(mapping)){
if(name.contains("paxel") || name.contains("itemspecial") || name.contains("blockbookstand") || name.contains("rarmor") || name.contains("bucket") || name.contains("modulereconstructor") || name.contains("stand")){ workedRemaps++;
mapping.ignore(); }
ModUtil.LOGGER.info("Missing Mapping "+mapping.name+" is getting ignored. This is intentional."); }
}
} if(totalRemaps > 0){
} ModUtil.LOGGER.info("Successfully remapped "+workedRemaps+" out of "+totalRemaps+" blocks and items to match the 1.11 naming conventions.");
} }
} }
} }

View file

@ -197,11 +197,11 @@ public final class InitItems{
public static void init(){ public static void init(){
ModUtil.LOGGER.info("Initializing Items..."); ModUtil.LOGGER.info("Initializing Items...");
itemFillingWand = new ItemFillingWand("itemFillingWand"); itemFillingWand = new ItemFillingWand("item_filling_wand");
itemBag = new ItemBag("itemBag", false); itemBag = new ItemBag("item_bag", false);
itemVoidBag = new ItemBag("itemVoidBag", true); itemVoidBag = new ItemBag("item_void_bag", true);
itemWorm = new ItemWorm("itemWorm"); itemWorm = new ItemWorm("item_worm");
itemPlayerProbe = new ItemPlayerProbe("itemPlayerProbe"); itemPlayerProbe = new ItemPlayerProbe("item_player_probe");
itemFilter = new ItemFilter("itemFilter"); itemFilter = new ItemFilter("itemFilter");
itemWaterBowl = new ItemWaterBowl("itemWaterBowl"); itemWaterBowl = new ItemWaterBowl("itemWaterBowl");
itemSpawnerChanger = new ItemSpawnerChanger("itemSpawnerChanger"); itemSpawnerChanger = new ItemSpawnerChanger("itemSpawnerChanger");

View file

@ -19,14 +19,17 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import java.util.Arrays; import java.util.*;
import java.util.List;
//TODO Remove the whole registry name mapping thing once the 1.11 fading phase is over
public final class ItemUtil{ public final class ItemUtil{
private static final Map<String, String> UNDERSCORELESS_TO_UNDERSCORED_NAMES = new HashMap<String, String>();
public static Item getItemFromName(String name){ public static Item getItemFromName(String name){
ResourceLocation resLoc = new ResourceLocation(name); ResourceLocation resLoc = new ResourceLocation(name);
if(Item.REGISTRY.containsKey(resLoc)){ if(Item.REGISTRY.containsKey(resLoc)){
@ -45,6 +48,8 @@ public final class ItemUtil{
GameRegistry.register(itemBlock); GameRegistry.register(itemBlock);
block.setCreativeTab(addTab ? CreativeTab.INSTANCE : null); block.setCreativeTab(addTab ? CreativeTab.INSTANCE : null);
addUnderscoreNameToMapUnderscorelessName(name);
} }
public static void registerItem(Item item, String name, boolean addTab){ public static void registerItem(Item item, String name, boolean addTab){
@ -58,6 +63,34 @@ public final class ItemUtil{
if(item instanceof IColorProvidingItem){ if(item instanceof IColorProvidingItem){
ActuallyAdditions.proxy.addColoredItem(item); ActuallyAdditions.proxy.addColoredItem(item);
} }
addUnderscoreNameToMapUnderscorelessName(name);
}
private static void addUnderscoreNameToMapUnderscorelessName(String name){
String nameId = ModUtil.MOD_ID+":"+name;
String underscoreless = nameId.replaceAll("_", "");
UNDERSCORELESS_TO_UNDERSCORED_NAMES.put(underscoreless, nameId);
}
public static boolean remapName(FMLMissingMappingsEvent.MissingMapping mapping){
if(mapping != null && mapping.name != null){
if(UNDERSCORELESS_TO_UNDERSCORED_NAMES.containsKey(mapping.name)){
String newName = UNDERSCORELESS_TO_UNDERSCORED_NAMES.get(mapping.name);
ResourceLocation newResLoc = new ResourceLocation(newName);
if(Block.REGISTRY.containsKey(newResLoc)){
mapping.remap(Block.REGISTRY.getObject(newResLoc));
return true;
}
else if(Item.REGISTRY.containsKey(newResLoc)){
mapping.remap(Item.REGISTRY.getObject(newResLoc));
return true;
}
}
}
return false;
} }
/** /**