Skip to content

Commit f159fdc

Browse files
committed
add Forestry sapling compat
1 parent 86016a3 commit f159fdc

2 files changed

Lines changed: 73 additions & 0 deletions

File tree

common/buildcraft/compat/CompatModuleForestry.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package buildcraft.compat;
22

3+
import buildcraft.api.crops.CropManager;
4+
import buildcraft.compat.forestry.CropHandlerForestry;
35
import net.minecraft.item.Item;
46
import net.minecraft.item.ItemStack;
57
import cpw.mods.fml.common.FMLCommonHandler;
@@ -48,11 +50,18 @@ public void preInit() {
4850

4951
@Override
5052
public void init() {
53+
CropManager.registerHandler(new CropHandlerForestry());
54+
5155
if (Loader.isModLoaded("BuildCraft|Builders")) {
5256
initBuilders();
5357
}
5458
}
5559

60+
@Override
61+
public void postInit() {
62+
CropHandlerForestry.postInit();
63+
}
64+
5665
@Optional.Method(modid = "BuildCraft|Transport")
5766
private void preInitTransport() {
5867
IAlleleRegistry alleleRegistry = AlleleManager.alleleRegistry;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)