From 07b97ada87a579372995b8b0a6f160bc6cc62746 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sat, 19 Nov 2016 21:54:43 +0100 Subject: [PATCH] Added messy, but functional, remapper --- .../mod/ActuallyAdditions.java | 22 ++++++----- .../mod/items/InitItems.java | 10 ++--- .../actuallyadditions/mod/util/ItemUtil.java | 37 ++++++++++++++++++- 3 files changed, 52 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index d183c4c09..7c916c594 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -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."); + } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java index 8ff4e8687..7e4316f0d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/InitItems.java @@ -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"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java index f9d6cd90e..4c4118a8f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/ItemUtil.java @@ -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 UNDERSCORELESS_TO_UNDERSCORED_NAMES = new HashMap(); + 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; } /**