Add compatibility with Blood Magic

Closes #538
This commit is contained in:
Ellpeck 2016-12-28 15:57:15 +01:00
parent 7e6935f646
commit 13bf8978cf
2 changed files with 27 additions and 5 deletions

View file

@ -166,13 +166,13 @@ public final class InitBlocks{
blockOilGenerator = new BlockOilGenerator("block_oil_generator");
blockFermentingBarrel = new BlockFermentingBarrel("block_fermenting_barrel");
blockRice = new BlockPlant("block_rice", 1, 2);
CompatUtil.registerMFRPlant(blockRice);
CompatUtil.registerPlant(blockRice);
blockCanola = new BlockPlant("block_canola", 2, 3);
CompatUtil.registerMFRPlant(blockCanola);
CompatUtil.registerPlant(blockCanola);
blockFlax = new BlockPlant("block_flax", 2, 4);
CompatUtil.registerMFRPlant(blockFlax);
CompatUtil.registerPlant(blockFlax);
blockCoffee = new BlockPlant("block_coffee", 2, 2);
CompatUtil.registerMFRPlant(blockCoffee);
CompatUtil.registerPlant(blockCoffee);
blockCompost = new BlockCompost("block_compost");
blockMisc = new BlockMisc("block_misc");
blockFeeder = new BlockFeeder("block_feeder");

View file

@ -10,15 +10,25 @@
package de.ellpeck.actuallyadditions.mod.util.compat;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import java.lang.reflect.Method;
public final class CompatUtil{
public static void registerMFRPlant(Block block){
public static void registerPlant(Block block){
registerMFRPlant(block);
registerBloodMagicPlant(block);
}
private static void registerMFRPlant(Block block){
FMLInterModComms.sendMessage("MineFactoryReloaded", "registerHarvestable_Crop", new ItemStack(block, 1, 7));
NBTTagCompound compound = new NBTTagCompound();
@ -33,4 +43,16 @@ public final class CompatUtil{
FMLInterModComms.sendMessage("MineFactoryReloaded", "registerPlantable_Crop", compound);
}
private static void registerBloodMagicPlant(Block block){
if(Loader.isModLoaded("bloodmagic")){
try{
Class regClass = Class.forName("WayofTime.bloodmagic.api.registry.HarvestRegistry");
Method regMethod = regClass.getDeclaredMethod("registerStandardCrop", Block.class, int.class);
regMethod.invoke(null, block, ((BlockCrops)block).getMaxAge());
}
catch(Exception e){
ModUtil.LOGGER.error("Failed to add farming compatibility for Blood Magic!", e);
}
}
}
}