Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package mechaet.mfr.compat.magicalcrops;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import net.minecraft.block.Block;
- import net.minecraft.item.Item;
- import net.minecraftforge.common.IPlantable;
- import powercrystals.minefactoryreloaded.MFRRegistry;
- import powercrystals.minefactoryreloaded.farmables.plantables.PlantableCropPlant;
- import powercrystals.minefactoryreloaded.farmables.harvestables.HarvestableCropPlant;
- import cpw.mods.fml.common.Mod;
- import cpw.mods.fml.common.Mod.EventHandler;
- import cpw.mods.fml.common.Mod.Instance;
- import cpw.mods.fml.common.event.FMLInitializationEvent;
- import cpw.mods.fml.common.event.FMLPostInitializationEvent;
- import cpw.mods.fml.common.event.FMLPreInitializationEvent;
- import cpw.mods.fml.common.network.NetworkMod;
- @Mod(modid = MFRCompatMagicalCrops._ID, name = MFRCompatMagicalCrops._NAME, version = MFRCompatMagicalCrops._VERSION, dependencies = MFRCompatMagicalCrops._DEPENDENCIES)
- @NetworkMod(clientSideRequired = false, serverSideRequired = false)
- public class MFRCompatMagicalCrops
- {
- public static final String _ID = "MineFactoryReloaded|MFRCompatMagicalCrops";
- public static final String _NAME = "MFR Compat: MagicalCrops";
- public static final String _VERSION = "0.1a";
- public static final String _DEPENDENCIES = "after:MineFactoryReloaded;after:magicalcrops";
- @Instance(_ID)
- public static MFRCompatMagicalCrops instance;
- private Logger _log;
- @EventHandler
- public void preInit(FMLPreInitializationEvent event)
- {
- _log = event.getModLog();
- }
- private void registerMFR() throws Exception
- {
- // Registering materials
- String[] mMaterials =
- {
- "Alumin",
- "Blaze",
- "Coal",
- "Copper",
- "Diamond",
- "Dye",
- "Emerald",
- "Ender",
- "Essence",
- "Glowstone",
- "Gold",
- "Iron",
- "Lapis",
- "Lead",
- "Nether",
- "Obsidian",
- "Peridot",
- "Quartz",
- "Redstone",
- "Ruby",
- "Sapphire",
- "Silver",
- "Tin",
- "XP",
- };
- registerMFR(mMaterials, "m");
- // Registering elements
- String[] nMaterials =
- {
- "Bberry",
- "Chil",
- "Cucum",
- "Grape",
- "Rberry",
- "Sberry",
- "Sweetcorn",
- "Tomato",
- };
- registerMFR(nMaterials, "");
- // Registering elements
- String[] eMaterials =
- {
- "Water",
- "Fire",
- "Earth",
- "Air",
- };
- registerMFR(eMaterials, "e");
- // Registering your soul
- String[] soulMaterials =
- {
- "Cow",
- "Creeper",
- "Ghast",
- "Magma",
- "Skeleton",
- "Slime",
- "Spider",
- };
- registerMFR(soulMaterials, "soul");
- }
- private void registerMFR(String[] materials, String prefix) throws Exception
- {
- // Base class of the MC mod
- Class cropsModClass = Class.forName("magicalcrops.mod_mCrops");
- // Loop through all the crops that were passed in and add them to the
- // list.
- for (String material : materials)
- {
- // Shared
- String cropName;
- String seedName;
- if (prefix.isEmpty())
- {
- cropName = "crop" + material;
- seedName = "seed" + material;
- }
- else
- {
- cropName = prefix + "Crop" + material;
- seedName = prefix.charAt(0) + "Seeds" + material;
- }
- Block crop = (Block) cropsModClass.getField(cropName).get(null);
- Item seed = (Item) cropsModClass.getField(seedName).get(null);
- if (crop == null || seed == null)
- {
- _log.warning("Unable to find crop " + cropName + " by reflection. Maybe that crop is disabled or something?");
- continue;
- }
- // Planter
- if (!(seed instanceof IPlantable))
- {
- throw new IllegalArgumentException("Seed " + seed.getUnlocalizedName() + " is not IPlantable. Type is " + seed.getClass());
- }
- // Using MFR code to register for Planter
- MFRRegistry.registerPlantable(new PlantableCropPlant(seed.itemID, crop.blockID));
- // Using MFR code to register for Harvester
- MFRRegistry.registerHarvestable(new HarvestableCropPlant(crop.blockID, 7));
- _log.finer("Registered crop " + cropName + " with the MFR planter and harvester.");
- }
- }
- @EventHandler
- public void init(FMLInitializationEvent event) {
- try
- {
- _log.log(Level.INFO, "Loading MFR Compatibility for Magical Crops");
- // Doing this in post-init to minimize problems with Magical Crops
- // not having finished init yet.
- registerMFR();
- _log.log(Level.INFO, "MFR Compatibility for Magical Crops successfully initialized");
- } catch (Exception exception)
- {
- exception.printStackTrace();
- }
- }
- @EventHandler
- public static void postInit(FMLPostInitializationEvent event)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement