-
Notifications
You must be signed in to change notification settings - Fork 753
/
SlimeSapling.java
130 lines (110 loc) · 3.66 KB
/
SlimeSapling.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package tconstruct.blocks.slime;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockSapling;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;
import tconstruct.common.TContent;
import tconstruct.common.TRepo;
import tconstruct.library.TConstructRegistry;
import tconstruct.worldgen.SlimeTreeGen;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class SlimeSapling extends BlockSapling
{
public IIcon[] icons;
public String[] textureNames = new String[] { "blue" };
public SlimeSapling()
{
super();
float f = 0.4F;
setBlockBounds(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
this.func_149711_c(0.0F);
this.setStepSound(Block.soundGrassFootstep);
this.func_149647_a(TConstructRegistry.blockTab);
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons (IIconRegister iconRegister)
{
this.icons = new IIcon[textureNames.length];
for (int i = 0; i < this.icons.length; ++i)
{
this.icons[i] = iconRegister.registerIcon("tinker:slimesapling_" + textureNames[i]);
}
}
public boolean canThisPlantGrowOnThisBlockID (Block b)
{
return b == Blocks.grass || b == Blocks.dirt || b == TRepo.slimeGrass || b == TRepo.craftedSoil;
}
public void func_149674_a (World world, int x, int y, int z, Random random)
{
if (world.isRemote)
{
return;
}
super.func_149674_a(world, x, y, z, random);
int md = world.getBlockMetadata(x, y, z);
if (random.nextInt(10) == 0 && world.getBlockLightValue(x, y + 1, z) >= 9)
{
if ((md & 8) == 0)
world.setBlockMetadataWithNotify(x, y, z, md | 8, 4);
else
growTree(world, x, y, z, random);
}
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon (int side, int meta)
{
return icons[meta % 8];
}
@Override
public void markOrGrowMarked (World world, int x, int y, int z, Random random)
{
boneFertilize(world, x, y, z, random, null);
}
public boolean boneFertilize (World world, int x, int y, int z, Random random, EntityPlayer player)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta % 8 == 0 && (player == null || !player.capabilities.isCreativeMode))
return false;
if ((meta & 8) == 0)
{
world.setBlockMetadataWithNotify(x, y, z, meta | 8, 4);
}
else
{
this.growTree(world, x, y, z, random);
}
return true;
}
public void growTree (World world, int x, int y, int z, Random random)
{
int md = world.getBlockMetadata(x, y, z) % 8;
world.setBlock(x, y, z, Blocks.air);
WorldGenerator obj = null;
obj = new SlimeTreeGen(true, 5, 4, 1, 0);
if (!(obj.generate(world, random, x, y, z)))
world.setBlock(x, y, z, Blocks.air, md + 8, 3);
}
public int damageDropped (int i)
{
return i % 8;
}
@SideOnly(Side.CLIENT)
@Override
public void getSubBlocks (Item b, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < 1; i++)
par3List.add(new ItemStack(b, 1, i));
}
}