harvester support
skaviouz opened this issue ยท 1 comments
code below isn't needed now, Mine Tweaker can do this. code below isn't worth impl.
So right now to collect more flowers, I use a sprinkler and harvester (to chop away grass and vanilla flowers), and once every 30 minutes, i have 8x8 9x9 area of sticky pistons move the grass up then back down, and use vacuum hoppers/item collector (open blocks/random things) to collect them, well if you could add harvester support from mfr that would be great ;D, anyways here is some snippet code.
I wrote this before actually testing it out.... l edited the compile error, it should work
here is an example for some code: (atleast as of 1.6.4, for 2.7.9 mfr)
/*
* This code is released in the Public Domain as well as under:
* http://creativecommons.org/publicdomain/zero/1.0/
*
* There is no warranty. You're free to re-use this code or adapt it as you like.
*
* Known bugs:
* *) If MFR or Botania is not installed,
* minecraft will likely crash during startup
*/
package vazkii.botania.common;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import powercrystals.minefactoryreloaded.api.FactoryRegistry;
import powercrystals.minefactoryreloaded.api.FarmingRegistry;
import powercrystals.minefactoryreloaded.api.IFactoryHarvestable;
import powercrystals.minefactoryreloaded.api.IFactoryPlantable;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraftforge.common.IPlantable;
import cpw.mods.fml.common.FMLLog;
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.FMLLoadEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid="BotaniaFlowersMfrHarvester", name="Botania Flowers for MFR", version="1.0")
@NetworkMod(clientSideRequired=false, serverSideRequired=false)
public class MfrHackBotania {
@Instance(value = "BotaniaFlowerzMfrHack")
public static MfrHackBotania instance;
private static final Logger _log;
static {
//Init the logger
_log = Logger.getLogger("vazkii.botania.common.MfrHackBotania");
_log.setParent(FMLLog.getLogger());
}
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
instance = this;
}
private void registerMfr() throws Exception {
//Registering materials
String cropName = "botania:flower";
Constructor harvestconstructor = null;
//Yes, it is wasteful to do this reflection once for each type, but it should only really
//add miliseconds. (but we are only doing 1 crop)
try {
Class harvestClass = Class.forName("powercrystals.minefactoryreloaded.farmables.harvestables.HarvestableCropPlant");
Constructor[] harvestAllConstructors = harvestClass.getDeclaredConstructors();
for (Constructor ctor : harvestAllConstructors) {
Class<?>[] pType = ctor.getParameterTypes();
if( pType.length != 2 || pType[0] != int.class || pType[1] != int.class ) {
continue;
}
harvestconstructor = ctor;
}
} catch (ClassNotFoundException e) {
throw new RuntimeException("Failed to init mfrHarvester classes",e);
}
//Base class of the MC mod
Class cropsModClass = Class.forName("vazkii.botania.common.Botania");
//Crop(s) go here... there is only one for botania though ;D
Block crop = (Block)cropsModClass.getField(cropName).get(null);
if( crop == null) {
_log.warning("Unable to find crop "+cropName+" by reflection. Maybe that crop is disabled or something?");
continue;
}
//What does the seven(7) mean??? lol... It was meta code
IFactoryHarvestable harvestable = (IFactoryHarvestable) harvestconstructor.newInstance(crop.blockID,0);
FactoryRegistry.registerHarvestable(harvestable);
_log.finer("Registered crop "+cropName+" with the MFR harvester.");
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
try
{
_log.log(Level.INFO, "Loading Botania Flowers for MFR");
//Doing this in post-init to minimize problems with Botania
//not having finished init yet.
registerMfr();
}
catch(Exception e)
{
//Catch-all to allow exceptions during init to be thrown, and
//"crash" minecraft during startup if something goes really wrong.
throw new RuntimeException("Failed to init Botania Flowers for MFR",e);
}
}
}