/
HerbBlock.java
106 lines (90 loc) · 2.61 KB
/
HerbBlock.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
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
package mods.natura.blocks.crops;
import java.util.Random;
import mods.natura.common.NContent;
import mods.natura.common.NaturaTab;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
public class HerbBlock extends CropBlock
{
protected HerbBlock()
{
super();
this.setTickRandomly(true);
float var3 = 0.5F;
this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, 0.25F, 0.5F + var3);
this.setCreativeTab((CreativeTabs) null);
this.setHardness(0.0F);
this.setStepSound(soundGrassFootstep);
this.disableStats();
this.setCreativeTab(NaturaTab.tab);
}
public void updateTick (World world, int x, int y, int z, Random random)
{
this.checkFlowerChange(world, x, y, z);
int light = world.getBlockLightValue(x, y, z);
if (light >= 8)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta % 4 != 3)
{
float grow = this.getGrowthRate(world, x, y, z, meta, light);
if (random.nextInt((int) (50.0F / grow) + 1) == 0)
{
meta++;
world.setBlockMetadataWithNotify(x, y, z, meta, 2);
}
}
}
}
/**
* Apply bonemeal to the crops.
*/
public void fertilize (World world, int x, int y, int z)
{
}
boolean requiresSun (int meta)
{
return false;
}
/**
* The type of render function that is called for this block
*/
public int getRenderType ()
{
return 1;
}
protected Item getCropItem (int meta)
{
return NContent.plantItem;
}
protected Item getSeedItem (int meta)
{
return NContent.seeds;
}
public int damageDropped (int meta)
{
return 0;
}
@Override
public int getPlantMetadata (World world, int x, int y, int z)
{
return world.getBlockMetadata(x, y, z);
}
@Override
public EnumPlantType getPlantType (World world, int x, int y, int z)
{
return EnumPlantType.Cave;
}
/**
* Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants.
*/
public boolean canBlockStay (World par1World, int x, int y, int z)
{
Block soil = par1World.getBlock(x, y - 1, z);
return soil != null && soil.blockMaterial == Material.rock;
}
}