aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/forestry/trees/ForestrySapling.java
blob: 7c81ea09286bc4d6ce057cd1c0c17997c6b18038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package gtPlusPlus.xmod.forestry.trees;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import powercrystals.minefactoryreloaded.api.ReplacementBlock;
import powercrystals.minefactoryreloaded.farmables.plantables.PlantableStandard;
import forestry.api.arboriculture.ITreeRoot;
import forestry.api.genetics.AlleleManager;

public class ForestrySapling extends PlantableStandard
{
	private ITreeRoot root;

	public ForestrySapling(Item item, Block block)
	{
		super(item, block, WILDCARD, null);
		root = (ITreeRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees");
		_plantedBlock = new ReplacementBlock((Block)null) {
			@Override
			public boolean replaceBlock(World world, int x, int y, int z, ItemStack stack) {
				return root.plantSapling(world, root.getMember(stack), null, x, y, z);
			}
		};
	}

	public Block getPlant()
	{
		return _block;
	}

	@Override
	public boolean canBePlantedHere(World world, int x, int y, int z, ItemStack stack)
	{
		if (!world.isAirBlock(x, y, z))
			return false;

		return root.getMember(stack).canStay(world, x, y, z);
	}

	public boolean canFertilize(World world, int x, int y, int z)
	{
		return true;
	}

	public boolean fertilize(World world, Random rand, int x, int y, int z)
	{
		Block block = world.getBlock(x, y, z);
		root.getTree(world, x, y, z).getTreeGenerator(world, x, y, z, true).generate(world, rand, x, y, z);
		return world.getBlock(x, y, z) != block;
	}
}