/
PlantableStandard.java
76 lines (66 loc) · 2.28 KB
/
PlantableStandard.java
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
package mods.natura.plugins.minefactoryreloaded.plantables;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.IPlantable;
import powercrystals.minefactoryreloaded.api.IFactoryPlantable;
/*
* 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
{
protected int _sourceId;
protected int _plantedBlockId;
public PlantableStandard(int sourceId, int plantedBlockId)
{
if (plantedBlockId >= Block.blocksList.length)
{
throw new IllegalArgumentException("Passed an Item ID to FactoryPlantableStandard's planted block argument");
}
this._sourceId = sourceId;
this._plantedBlockId = plantedBlockId;
}
@Override
public boolean canBePlantedHere (World world, int x, int y, int z, ItemStack stack)
{
int groundId = world.getBlockId(x, y - 1, z);
if (!world.isAirBlock(x, y, z))
{
return false;
}
return (Block.blocksList[_plantedBlockId].canPlaceBlockAt(world, x, y, z) && Block.blocksList[_plantedBlockId].canBlockStay(world, x, y, z))
|| (Block.blocksList[_plantedBlockId] instanceof IPlantable && Block.blocksList[groundId] != null && Block.blocksList[groundId].canSustainPlant(world, x, y, z, ForgeDirection.UP,
((IPlantable) Block.blocksList[_plantedBlockId])));
}
@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 int getPlantedBlockId (World world, int x, int y, int z, ItemStack stack)
{
if (stack.itemID != _sourceId)
{
return -1;
}
return _plantedBlockId;
}
@Override
public int getPlantedBlockMetadata (World world, int x, int y, int z, ItemStack stack)
{
return stack.getItemDamage();
}
@Override
public int getSeedId ()
{
return _sourceId;
}
}