diff --git a/src/main/java/com/verdantartifice/thaumicwonders/ThaumicWonders.java b/src/main/java/com/verdantartifice/thaumicwonders/ThaumicWonders.java index 14baeb3..373ff02 100644 --- a/src/main/java/com/verdantartifice/thaumicwonders/ThaumicWonders.java +++ b/src/main/java/com/verdantartifice/thaumicwonders/ThaumicWonders.java @@ -3,11 +3,15 @@ import org.apache.logging.log4j.Logger; import com.verdantartifice.thaumicwonders.common.misc.CreativeTabTW; +import com.verdantartifice.thaumicwonders.compat.datafixes.ItemDataFixer; import com.verdantartifice.thaumicwonders.proxy.IProxyTW; import com.verdantartifice.thaumicwonders.thaumicwonders.Tags; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.util.datafix.FixTypes; +import net.minecraftforge.common.util.ModFixs; import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.SidedProxy; @@ -41,6 +45,9 @@ public void preInit(FMLPreInitializationEvent event) { @EventHandler public void init(FMLInitializationEvent event) { proxy.init(event); + + ModFixs modFixer = FMLCommonHandler.instance().getDataFixer().init(ID, 1); + modFixer.registerFix(FixTypes.ITEM_INSTANCE, new ItemDataFixer()); } @EventHandler diff --git a/src/main/java/com/verdantartifice/thaumicwonders/compat/datafixes/ItemDataFixer.java b/src/main/java/com/verdantartifice/thaumicwonders/compat/datafixes/ItemDataFixer.java new file mode 100644 index 0000000..c6bd017 --- /dev/null +++ b/src/main/java/com/verdantartifice/thaumicwonders/compat/datafixes/ItemDataFixer.java @@ -0,0 +1,54 @@ +package com.verdantartifice.thaumicwonders.compat.datafixes; + +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.datafix.IFixableData; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.RegistryEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +import java.util.HashMap; +import java.util.Map; + +import com.verdantartifice.thaumicwonders.ThaumicWonders; + +public class ItemDataFixer implements IFixableData { + private static final Map ITEM_NAME_MAPPINGS = new HashMap<>(); + + static { + ITEM_NAME_MAPPINGS.put(new ResourceLocation(ThaumicWonders.MODID, "bone_bow"), new ResourceLocation("minecraft", "bow")); + + // Metadata is not fun... + ITEM_NAME_MAPPINGS.put(new ResourceLocation(ThaumicWonders.MODID, "primal_arrow"), new ResourceLocation("minecraft", "arrow")); + } + + public ItemDataFixer() { + MinecraftForge.EVENT_BUS.register(this); + } + + @Override + public int getFixVersion() { + return 1; + } + + @Override + public NBTTagCompound fixTagCompound(NBTTagCompound compound) { + return compound; + } + + @SubscribeEvent + public void missingItemMapping(RegistryEvent.MissingMappings event) { + for (RegistryEvent.MissingMappings.Mapping entry : event.getAllMappings()) { + ResourceLocation oldName = entry.key; + ResourceLocation newName = ITEM_NAME_MAPPINGS.get(oldName); + if (newName != null) { + Item newItem = ForgeRegistries.ITEMS.getValue(newName); + if (newItem != null) { + entry.remap(newItem); + } + } + } + } +}