Created
April 17, 2016 07:51
-
-
Save LexManos/c698aca98c433683a2a9916c9ba2e548 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package net.minecraftforge.test; | |
| import net.minecraft.block.Block; | |
| import net.minecraft.block.BlockPrismarine; | |
| import net.minecraft.client.renderer.block.model.ModelResourceLocation; | |
| import net.minecraft.creativetab.CreativeTabs; | |
| import net.minecraft.init.Blocks; | |
| import net.minecraft.item.Item; | |
| import net.minecraft.item.ItemColored; | |
| import net.minecraft.util.ResourceLocation; | |
| import net.minecraftforge.client.model.ModelLoader; | |
| import net.minecraftforge.fml.common.Mod; | |
| import net.minecraftforge.fml.common.ModContainer; | |
| import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent; | |
| import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; | |
| import net.minecraftforge.fml.common.registry.GameRegistry; | |
| import org.apache.logging.log4j.LogManager; | |
| import org.apache.logging.log4j.Logger; | |
| import java.lang.reflect.Field; | |
| import java.util.List; | |
| @Mod(modid = RegistryRemapTest.MODID) | |
| public class RegistryRemapTest | |
| { | |
| static final String MODID = "registry_remap_test"; | |
| private final Logger logger = LogManager.getLogger(MODID); | |
| private static final ResourceLocation REG_NAME = new ResourceLocation(MODID, "remaptest"); | |
| // Make a world, place the blocks, then set this to false | |
| private static final Boolean REGISTER_THINGS = false; | |
| @Mod.EventHandler | |
| public void preInit(FMLPreInitializationEvent evt) | |
| { | |
| if (REGISTER_THINGS) | |
| { | |
| Block b = (new BlockPrismarine()).setCreativeTab(CreativeTabs.tabBlock).setRegistryName(REG_NAME); | |
| Item i = new ItemColored(b, true).setRegistryName(REG_NAME); | |
| GameRegistry.register(b); | |
| GameRegistry.register(i); | |
| ModelLoader.setCustomModelResourceLocation(i, 0, new ModelResourceLocation("minecraft:prismarine", "inventory")); | |
| ModelLoader.setCustomModelResourceLocation(i, 1, new ModelResourceLocation("minecraft:prismarine_bricks", "inventory")); | |
| ModelLoader.setCustomModelResourceLocation(i, 2, new ModelResourceLocation("minecraft:dark_prismarine", "inventory")); | |
| } | |
| } | |
| @Mod.EventHandler | |
| public void onRemap(FMLMissingMappingsEvent evt) throws Exception | |
| { | |
| Field active = FMLMissingMappingsEvent.class.getDeclaredField("activeContainer"); | |
| active.setAccessible(true); | |
| ModContainer mod = (ModContainer)active.get(evt); | |
| logger.info("Received missing mappings event"); | |
| logger.info(" Mod Container: " + mod.getModId()); | |
| logger.info(" Expected: " + MODID); | |
| List<FMLMissingMappingsEvent.MissingMapping> get = evt.get(); | |
| logger.info("GET():"); | |
| for (FMLMissingMappingsEvent.MissingMapping m : get) | |
| { | |
| logger.info("\t" + m.type + " " + m.name); | |
| } | |
| List<FMLMissingMappingsEvent.MissingMapping> getAll = evt.getAll(); | |
| logger.info("GETALL():"); | |
| for (FMLMissingMappingsEvent.MissingMapping m : getAll) | |
| { | |
| logger.info("\t" + m.type + " " + m.name); | |
| } | |
| for (FMLMissingMappingsEvent.MissingMapping m : getAll) | |
| { | |
| // Remap our block into vanilla prismarine? | |
| if (REG_NAME.toString().equals(m.name)) | |
| { | |
| if (m.type == GameRegistry.Type.BLOCK) | |
| { | |
| logger.info("Remapping Block " + REG_NAME + " -> " + Blocks.prismarine); | |
| m.remap(Blocks.prismarine); | |
| } | |
| else if (m.type == GameRegistry.Type.ITEM) | |
| { | |
| logger.info("Remapping Item " + REG_NAME + " -> " + Item.getItemFromBlock(Blocks.prismarine)); | |
| m.remap(Item.getItemFromBlock(Blocks.prismarine)); | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment