001 package net.minecraft.src;
002
003 import cpw.mods.fml.common.Side;
004 import cpw.mods.fml.common.asm.SideOnly;
005 import java.util.Random;
006
007 import net.minecraftforge.common.EnumPlantType;
008 import net.minecraftforge.common.ForgeDirection;
009 import net.minecraftforge.common.IPlantable;
010
011 public class BlockCactus extends Block implements IPlantable
012 {
013 protected BlockCactus(int par1, int par2)
014 {
015 super(par1, par2, Material.cactus);
016 this.setTickRandomly(true);
017 this.setCreativeTab(CreativeTabs.tabDecorations);
018 }
019
020 /**
021 * Ticks the block if it's been scheduled
022 */
023 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
024 {
025 if (par1World.isAirBlock(par2, par3 + 1, par4))
026 {
027 int var6;
028
029 for (var6 = 1; par1World.getBlockId(par2, par3 - var6, par4) == this.blockID; ++var6)
030 {
031 ;
032 }
033
034 if (var6 < 3)
035 {
036 int var7 = par1World.getBlockMetadata(par2, par3, par4);
037
038 if (var7 == 15)
039 {
040 par1World.setBlockWithNotify(par2, par3 + 1, par4, this.blockID);
041 par1World.setBlockMetadataWithNotify(par2, par3, par4, 0);
042 }
043 else
044 {
045 par1World.setBlockMetadataWithNotify(par2, par3, par4, var7 + 1);
046 }
047 }
048 }
049 }
050
051 /**
052 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
053 * cleared to be reused)
054 */
055 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
056 {
057 float var5 = 0.0625F;
058 return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var5), (double)par3, (double)((float)par4 + var5), (double)((float)(par2 + 1) - var5), (double)((float)(par3 + 1) - var5), (double)((float)(par4 + 1) - var5));
059 }
060
061 @SideOnly(Side.CLIENT)
062
063 /**
064 * Returns the bounding box of the wired rectangular prism to render.
065 */
066 public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
067 {
068 float var5 = 0.0625F;
069 return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)par2 + var5), (double)par3, (double)((float)par4 + var5), (double)((float)(par2 + 1) - var5), (double)(par3 + 1), (double)((float)(par4 + 1) - var5));
070 }
071
072 /**
073 * Returns the block texture based on the side being looked at. Args: side
074 */
075 public int getBlockTextureFromSide(int par1)
076 {
077 return par1 == 1 ? this.blockIndexInTexture - 1 : (par1 == 0 ? this.blockIndexInTexture + 1 : this.blockIndexInTexture);
078 }
079
080 /**
081 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
082 */
083 public boolean renderAsNormalBlock()
084 {
085 return false;
086 }
087
088 /**
089 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
090 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
091 */
092 public boolean isOpaqueCube()
093 {
094 return false;
095 }
096
097 /**
098 * The type of render function that is called for this block
099 */
100 public int getRenderType()
101 {
102 return 13;
103 }
104
105 /**
106 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z
107 */
108 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4)
109 {
110 return !super.canPlaceBlockAt(par1World, par2, par3, par4) ? false : this.canBlockStay(par1World, par2, par3, par4);
111 }
112
113 /**
114 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
115 * their own) Args: x, y, z, neighbor blockID
116 */
117 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
118 {
119 if (!this.canBlockStay(par1World, par2, par3, par4))
120 {
121 this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
122 par1World.setBlockWithNotify(par2, par3, par4, 0);
123 }
124 }
125
126 /**
127 * Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants.
128 */
129 public boolean canBlockStay(World par1World, int par2, int par3, int par4)
130 {
131 if (par1World.getBlockMaterial(par2 - 1, par3, par4).isSolid())
132 {
133 return false;
134 }
135 else if (par1World.getBlockMaterial(par2 + 1, par3, par4).isSolid())
136 {
137 return false;
138 }
139 else if (par1World.getBlockMaterial(par2, par3, par4 - 1).isSolid())
140 {
141 return false;
142 }
143 else if (par1World.getBlockMaterial(par2, par3, par4 + 1).isSolid())
144 {
145 return false;
146 }
147 else
148 {
149 int var5 = par1World.getBlockId(par2, par3 - 1, par4);
150 return blocksList[var5] != null && blocksList[var5].canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this);
151 }
152 }
153
154 /**
155 * Triggered whenever an entity collides with this block (enters into the block). Args: world, x, y, z, entity
156 */
157 public void onEntityCollidedWithBlock(World par1World, int par2, int par3, int par4, Entity par5Entity)
158 {
159 par5Entity.attackEntityFrom(DamageSource.cactus, 1);
160 }
161
162 @Override
163 public EnumPlantType getPlantType(World world, int x, int y, int z)
164 {
165 return EnumPlantType.Desert;
166 }
167
168 @Override
169 public int getPlantID(World world, int x, int y, int z)
170 {
171 return blockID;
172 }
173
174 @Override
175 public int getPlantMetadata(World world, int x, int y, int z)
176 {
177 return -1;
178 }
179 }