|
| 1 | +package buildcraft.compat.forestry; |
| 2 | + |
| 3 | +import buildcraft.api.core.BuildCraftAPI; |
| 4 | +import buildcraft.api.crops.ICropHandler; |
| 5 | +import forestry.api.arboriculture.EnumGermlingType; |
| 6 | +import forestry.api.arboriculture.ITree; |
| 7 | +import forestry.api.arboriculture.ITreeRoot; |
| 8 | +import forestry.api.genetics.AlleleManager; |
| 9 | +import net.minecraft.block.Block; |
| 10 | +import net.minecraft.entity.player.EntityPlayer; |
| 11 | +import net.minecraft.item.ItemStack; |
| 12 | +import net.minecraft.world.IBlockAccess; |
| 13 | +import net.minecraft.world.World; |
| 14 | + |
| 15 | +import java.util.List; |
| 16 | + |
| 17 | +public class CropHandlerForestry implements ICropHandler { |
| 18 | + private static ITreeRoot treeRoot; |
| 19 | + |
| 20 | + public static void postInit() { |
| 21 | + treeRoot = (ITreeRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees"); |
| 22 | + } |
| 23 | + |
| 24 | + @Override |
| 25 | + public boolean isSeed(ItemStack itemStack) { |
| 26 | + if (treeRoot.getType(itemStack) != EnumGermlingType.SAPLING) { |
| 27 | + return false; |
| 28 | + } |
| 29 | + ITree tree = treeRoot.getMember(itemStack); |
| 30 | + return tree != null; |
| 31 | + } |
| 32 | + |
| 33 | + @Override |
| 34 | + public boolean canSustainPlant(World world, ItemStack itemStack, int x, int y, int z) { |
| 35 | + if (world.isAirBlock(x, y, z) && isSeed(itemStack)) { |
| 36 | + ITree tree = treeRoot.getMember(itemStack); |
| 37 | + return tree != null && tree.canStay(world, x, y, z); |
| 38 | + } else { |
| 39 | + return false; |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public boolean plantCrop(World world, EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z) { |
| 45 | + if (world.isAirBlock(x, y, z) && isSeed(itemStack)) { |
| 46 | + if (treeRoot.plantSapling(world, treeRoot.getMember(itemStack), null, x, y, z)) { |
| 47 | + itemStack.stackSize--; |
| 48 | + return true; |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + return false; |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public boolean isMature(IBlockAccess iBlockAccess, Block block, int i, int i1, int i2, int i3) { |
| 57 | + return false; |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public boolean harvestCrop(World world, int i, int i1, int i2, List<ItemStack> list) { |
| 62 | + return false; |
| 63 | + } |
| 64 | +} |
0 commit comments