Added an AgriCraft Harvest Handler for their crops (uses reflection, so will be pulled as soon as the official one is made on their side)

Added the checks required for Strength to affect the damage of the Tool Paradigms.
This commit is contained in:
WayofTime 2015-04-21 12:33:20 -04:00
parent 201c70a766
commit 34f779563e
11 changed files with 136 additions and 34 deletions

View file

@ -0,0 +1,83 @@
package WayofTime.alchemicalWizardry.common.harvest;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.api.harvest.IHarvestHandler;
import cpw.mods.fml.common.registry.GameRegistry;
public class AgriCraftCropHarvestHandler implements IHarvestHandler
{
public Block harvestBlock;
public Method isMature;
public Method harvest;
public AgriCraftCropHarvestHandler()
{
this.harvestBlock = getBlockForString("AgriCraft:crops");
if(this.harvestBlock != null)
{
try {
Class clazz = Class.forName("com.InfinityRaider.AgriCraft.blocks.BlockCrop");
if(clazz != null)
{
isMature = clazz.getMethod("isMature", World.class, int.class, int.class, int.class);
harvest = clazz.getMethod("harvest", World.class, int.class, int.class, int.class);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public boolean isHarvesterValid()
{
return harvestBlock != null && isMature != null && harvest != null;
}
public static Block getBlockForString(String str)
{
String[] parts = str.split(":");
String modId = parts[0];
String name = parts[1];
return GameRegistry.findBlock(modId, name);
}
public boolean canHandleBlock(Block block)
{
return block == harvestBlock;
}
@Override
public boolean harvestAndPlant(World world, int xCoord, int yCoord, int zCoord, Block block, int meta)
{
if (!this.canHandleBlock(block))
{
return false;
}
try {
return (Boolean)(isMature.invoke(block, world, xCoord, yCoord, zCoord)) && (Boolean)(harvest.invoke(block, world, xCoord, yCoord, zCoord));
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
}

View file

@ -1,7 +1,9 @@
package WayofTime.alchemicalWizardry.common.harvest;
import WayofTime.alchemicalWizardry.api.harvest.IHarvestHandler;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCrops;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
@ -9,8 +11,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
import java.util.List;
import WayofTime.alchemicalWizardry.api.harvest.IHarvestHandler;
public class BloodMagicHarvestHandler implements IHarvestHandler
{
@ -21,6 +22,10 @@ public class BloodMagicHarvestHandler implements IHarvestHandler
public int getHarvestMeta(Block block)
{
if(block instanceof BlockCrops)
{
}
if (block == Blocks.wheat)
{
return 7;