/
SaguaroBlock.java
292 lines (262 loc) · 9.17 KB
/
SaguaroBlock.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
package mods.natura.blocks.trees;
import java.util.Random;
import mods.natura.client.SaguaroRenderer;
import mods.natura.common.NContent;
import mods.natura.common.NaturaTab;
import mods.natura.worldgen.SaguaroGen;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.IPlantable;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class SaguaroBlock extends Block implements IPlantable
{
public SaguaroBlock()
{
super(Material.cactus);
this.setCreativeTab(NaturaTab.tab);
setStepSound(soundTypeCloth);
this.setHardness(0.3f);
this.setTickRandomly(true);
}
@Override
public void updateTick (World world, int x, int y, int z, Random random)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0 && world.getWorldInfo().isRaining() && random.nextInt(20) == 0 && world.getBlock(x, y + 1, z) == Blocks.air)
{
switch (random.nextInt(4))
{
case 0:
if (world.getBlock(x + 1, y, z) == Blocks.air)
world.setBlock(x + 1, y, z, this, 5, 3);
break;
case 1:
if (world.getBlock(x, y, z + 1) == Blocks.air)
world.setBlock(x, y, z + 1, this, 6, 3);
break;
case 2:
if (world.getBlock(x - 1, y, z) == Blocks.air)
world.setBlock(x - 1, y, z, this, 3, 3);
break;
case 3:
if (world.getBlock(x, y, z - 1) == Blocks.air)
world.setBlock(x, y, z - 1, this, 4, 3);
break;
}
}
else if (meta == 2 && random.nextInt(200) == 0)
{
SaguaroGen gen = new SaguaroGen(NContent.saguaro, 0, true);
gen.generate(world, random, x, y, z);
}
else if (meta == 1 && random.nextInt(200) == 0)
{
world.setBlockMetadataWithNotify(x, y, z, 2, 3);
}
//Fruit shouldn't do a thing
}
public AxisAlignedBB getCollisionBoundingBoxFromPool (World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0)
{
float offset = 0.125F;
return AxisAlignedBB.getBoundingBox((float) x + offset, y, (float) z + offset, (float) (x + 1) - offset, (float) (y + 1) - offset, (float) (z + 1) - offset);
}
else if (meta == 1 || meta == 2)
{
float offset = 0.325F;
return AxisAlignedBB.getBoundingBox((float) x + offset, y, (float) z + offset, (float) (x + 1) - offset, (float) (y + 1) - offset, (float) (z + 1) - offset);
}
else if (meta == 3)
{
float offset = 0.25F;
return AxisAlignedBB.getBoundingBox((float) x + 0.625f, y + 0.1875, (float) z + offset, x + 1.125f, y + 0.75, (float) (z + 1) - offset);
}
else if (meta == 4)
{
float offset = 0.25F;
return AxisAlignedBB.getBoundingBox((float) x + offset, y + 0.1875, (float) z + 0.625f, (float) (x + 1) - offset, y + 0.75, (float) z + 1.125f);
}
else if (meta == 5)
{
float offset = 0.25F;
return AxisAlignedBB.getBoundingBox((float) x - 0.125f, y + 0.1875, (float) z + offset, (float) x + 0.375f, y + 0.75, (float) (z + 1) - offset);
}
else if (meta == 6)
{
float offset = 0.25F;
return AxisAlignedBB.getBoundingBox((float) x + offset, y + 0.1875, (float) z - 0.125f, (float) (x + 1) - offset, y + 0.75, (float) z + 0.375f);
}
return null;
}
public AxisAlignedBB getSelectedBoundingBoxFromPool (World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if (meta == 0)
{
float offset = 0.125F;
float height = 0.125F;
float base = 0F;
if (world.getBlock(x, y + 1, z) == this)
height = 0F;
Block block = world.getBlock(x, y - 1, z);
if (block != null && !block.isOpaqueCube())
base = 0.125F;
return AxisAlignedBB.getBoundingBox((float) x + offset, y, (float) z + offset, (float) (x + 1) - offset, (float) (y + 1) - height, (float) (z + 1) - offset);
}
else if (meta == 1 || meta == 2)
{
float offset = 0.325F;
return AxisAlignedBB.getBoundingBox((float) x + offset, y, (float) z + offset, (float) (x + 1) - offset, y + 0.5, (float) (z + 1) - offset);
}
else if (meta == 3)
{
float offset = 0.25F;
return AxisAlignedBB.getBoundingBox((float) x + 0.625f, y + 0.1875, (float) z + offset, x + 1.125f, y + 0.75, (float) (z + 1) - offset);
}
else if (meta == 4)
{
float offset = 0.25F;
return AxisAlignedBB.getBoundingBox((float) x + offset, y + 0.1875, (float) z + 0.625f, (float) (x + 1) - offset, y + 0.75, (float) z + 1.125f);
}
else if (meta == 5)
{
float offset = 0.25F;
return AxisAlignedBB.getBoundingBox((float) x - 0.125f, y + 0.1875, (float) z + offset, (float) x + 0.375f, y + 0.75, (float) (z + 1) - offset);
}
else if (meta == 6)
{
float offset = 0.25F;
return AxisAlignedBB.getBoundingBox((float) x + offset, y + 0.1875, (float) z - 0.125f, (float) (x + 1) - offset, y + 0.75, (float) z + 0.375f);
}
return null;
}
public int getRenderType ()
{
return SaguaroRenderer.model;
}
public static int func_72219_c (int par0)
{
return (par0 & 12) >> 2;
}
public static int getRotation (int meta)
{
return meta - 3;
}
public Item itemDropped (int meta, Random random, int fortune)
{
if (meta == 0)
return new ItemStack(this).getItem();
else
return NContent.seedFood;
}
public IIcon[] icons;
public String[] textureNames = new String[] { "saguaro_bottom", "saguaro_top", "saguaro_side", "saguaro_fruit" };
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons (IIconRegister iconRegister)
{
this.icons = new IIcon[textureNames.length];
for (int i = 0; i < this.icons.length; ++i)
{
this.icons[i] = iconRegister.registerIcon("natura:" + textureNames[i]);
}
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon (int side, int meta)
{
if (meta == 0)
{
if (side < 2)
return icons[side];
else
return icons[2];
}
else if (meta == 1 || meta == 2)
{
return icons[1];
}
else
{
return icons[3];
}
}
public boolean renderAsNormalBlock ()
{
return false;
}
public boolean isOpaqueCube ()
{
return false;
}
public boolean canPlaceBlockAt (World world, int i, int j, int k)
{
if (!super.canPlaceBlockAt(world, i, j, k))
{
return false;
}
else
{
return canBlockStay(world, i, j, k);
}
}
public void onNeighborBlockChange (World world, int i, int j, int k, int l)
{
if (!canBlockStay(world, i, j, k))
{
dropBlockAsItem(world, i, j, k, world.getBlockMetadata(i, j, k), 0);
world.setBlockToAir(i, j, k);
}
}
public boolean canBlockStay (World world, int x, int y, int z)
{
Block blockID = world.getBlock(x, y - 1, z);
return blockID == this || blockID == Blocks.sand || blockID == null;
}
public void onEntityCollidedWithBlock (World world, int i, int j, int k, Entity entity)
{
if (!(entity instanceof EntityItem))
entity.attackEntityFrom(DamageSource.cactus, 1);
}
public boolean canConnectSuguaroTo (IBlockAccess world, int x, int y, int z)
{
if (world.getBlock(x, y, z) == this && world.getBlockMetadata(x, y, z) == 0)
return true;
return false;
}
@Override
public EnumPlantType getPlantType (IBlockAccess world, int x, int y, int z)
{
return EnumPlantType.Desert;
}
@Override
public Block getPlant (IBlockAccess world, int x, int y, int z)
{
return this;
}
@Override
public int getPlantMetadata (IBlockAccess world, int x, int y, int z)
{
return 1;
}
/*public void getSubBlocks (int par1, CreativeTabs par2CreativeTabs, List list)
{
for (int i = 0; i < 7; i++)
list.add(new ItemStack(par1, 1, i));
}*/
}