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.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.update.UpdateChecker;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraftforge.fluids.FluidRegistry;
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.FMLPreInitializationEvent;
import java.util.Locale;
// 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")
public class ActuallyAdditions{
@ -147,16 +146,19 @@ public class ActuallyAdditions{
@EventHandler
public void missingMapping(FMLMissingMappingsEvent event){
int totalRemaps = 0;
int workedRemaps = 0;
for(FMLMissingMappingsEvent.MissingMapping mapping : event.getAll()){
if(mapping.name != null){
String name = mapping.name.toLowerCase(Locale.ROOT);
if(name.startsWith(ModUtil.MOD_ID+":")){
if(name.contains("paxel") || name.contains("itemspecial") || name.contains("blockbookstand") || name.contains("rarmor") || name.contains("bucket") || name.contains("modulereconstructor") || name.contains("stand")){
mapping.ignore();
ModUtil.LOGGER.info("Missing Mapping "+mapping.name+" is getting ignored. This is intentional.");
}
}
}
totalRemaps++;
if(ItemUtil.remapName(mapping)){
workedRemaps++;
}
}
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(){
ModUtil.LOGGER.info("Initializing Items...");
itemFillingWand = new ItemFillingWand("itemFillingWand");
itemBag = new ItemBag("itemBag", false);
itemVoidBag = new ItemBag("itemVoidBag", true);
itemWorm = new ItemWorm("itemWorm");
itemPlayerProbe = new ItemPlayerProbe("itemPlayerProbe");
itemFillingWand = new ItemFillingWand("item_filling_wand");
itemBag = new ItemBag("item_bag", false);
itemVoidBag = new ItemBag("item_void_bag", true);
itemWorm = new ItemWorm("item_worm");
itemPlayerProbe = new ItemPlayerProbe("item_player_probe");
itemFilter = new ItemFilter("itemFilter");
itemWaterBowl = new ItemWaterBowl("itemWaterBowl");
itemSpawnerChanger = new ItemSpawnerChanger("itemSpawnerChanger");

View file

@ -19,14 +19,17 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;
import java.util.Arrays;
import java.util.List;
import java.util.*;
//TODO Remove the whole registry name mapping thing once the 1.11 fading phase is over
public final class ItemUtil{
private static final Map<String, String> UNDERSCORELESS_TO_UNDERSCORED_NAMES = new HashMap<String, String>();
public static Item getItemFromName(String name){
ResourceLocation resLoc = new ResourceLocation(name);
if(Item.REGISTRY.containsKey(resLoc)){
@ -45,6 +48,8 @@ public final class ItemUtil{
GameRegistry.register(itemBlock);
block.setCreativeTab(addTab ? CreativeTab.INSTANCE : null);
addUnderscoreNameToMapUnderscorelessName(name);
}
public static void registerItem(Item item, String name, boolean addTab){
@ -58,6 +63,34 @@ public final class ItemUtil{
if(item instanceof IColorProvidingItem){
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;
}
/**