aboutsummaryrefslogtreecommitdiff
path: root/src/Java/powercrystals/minefactoryreloaded/farmables/plantables/PlantableStandard.java
blob: 022d947150233ac3cb6b2cf8714e8bf4d349781f (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package powercrystals.minefactoryreloaded.farmables.plantables;

import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import powercrystals.minefactoryreloaded.api.IFactoryPlantable;
import powercrystals.minefactoryreloaded.api.ReplacementBlock;

/*
 * Used for directly placing blocks (ie saplings) and items (ie sugarcane). Pass in source ID to constructor,
 * so one instance per source ID.
 */

public class PlantableStandard implements IFactoryPlantable
{
	public static final int WILDCARD = OreDictionary.WILDCARD_VALUE;

	protected Item _seed;
	protected Block _block;
	protected ReplacementBlock _plantedBlock;
	protected int _validMeta;

	public PlantableStandard(Block block)
	{
		this(Item.getItemFromBlock(block), block);
	}

	public PlantableStandard(Block block, Block plantedBlock)
	{
		this(Item.getItemFromBlock(block), plantedBlock);
	}

	public PlantableStandard(Item block, Block plantedBlock)
	{
		this(block, plantedBlock, WILDCARD);
	}

	public PlantableStandard(Block block, int meta)
	{
		this(Item.getItemFromBlock(block), block, meta);
	}

	public PlantableStandard(Block block, Block plantedBlock, int meta)
	{
		this(Item.getItemFromBlock(block), plantedBlock, meta);
	}

	public PlantableStandard(Item block, Block plantedBlock, int validMeta)
	{
		this(block, plantedBlock, validMeta, new ReplacementBlock(plantedBlock));
	}

	public PlantableStandard(Item block, Block plantedBlock, int validMeta, int plantedMeta)
	{
		this(block, plantedBlock, validMeta, new ReplacementBlock(plantedBlock).setMeta(plantedMeta));
	}

	public PlantableStandard(Item block, Block plantedBlock, int validMeta, boolean useItemMeta)
	{
		this(block, plantedBlock, validMeta, new ReplacementBlock(plantedBlock).setMeta(useItemMeta));
	}

	public PlantableStandard(Item block, Block plantedBlock, int validMeta, ReplacementBlock repl)
	{
		_seed = block;
		_block = plantedBlock;
		_validMeta = validMeta;
		_plantedBlock = repl;
	}

	@Override
	public boolean canBePlanted(ItemStack stack, boolean forFermenting)
	{
		return _validMeta == WILDCARD || stack.getItemDamage() == _validMeta;
	}

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

		Block groundId = world.getBlock(x, y - 1, z);
		return (_block.canPlaceBlockAt(world, x, y, z) && _block.canReplace(world, x, y, z, 0, stack)) ||
				(_block instanceof IPlantable && groundId != null &&
				groundId.canSustainPlant(world, x, y, z, ForgeDirection.UP, (IPlantable)_block));
	}

	@Override
	public void prePlant(World world, int x, int y, int z, ItemStack stack)
	{
		return;
	}

	@Override
	public void postPlant(World world, int x, int y, int z, ItemStack stack)
	{
		return;
	}

	@Override
	public ReplacementBlock getPlantedBlock(World world, int x, int y, int z, ItemStack stack)
	{
		return _plantedBlock;
	}

	@Override
	public Item getSeed()
	{
		return _seed;
	}
}