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 public class BlockCocoa extends BlockDirectional
008 {
009 public BlockCocoa(int par1)
010 {
011 super(par1, 168, Material.plants);
012 this.setTickRandomly(true);
013 }
014
015 /**
016 * Ticks the block if it's been scheduled
017 */
018 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random)
019 {
020 if (!this.canBlockStay(par1World, par2, par3, par4))
021 {
022 this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
023 par1World.setBlockWithNotify(par2, par3, par4, 0);
024 }
025 else if (par1World.rand.nextInt(5) == 0)
026 {
027 int var6 = par1World.getBlockMetadata(par2, par3, par4);
028 int var7 = func_72219_c(var6);
029
030 if (var7 < 2)
031 {
032 ++var7;
033 par1World.setBlockMetadataWithNotify(par2, par3, par4, var7 << 2 | getDirection(var6));
034 }
035 }
036 }
037
038 /**
039 * Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants.
040 */
041 public boolean canBlockStay(World par1World, int par2, int par3, int par4)
042 {
043 int var5 = getDirection(par1World.getBlockMetadata(par2, par3, par4));
044 par2 += Direction.offsetX[var5];
045 par4 += Direction.offsetZ[var5];
046 int var6 = par1World.getBlockId(par2, par3, par4);
047 return var6 == Block.wood.blockID && BlockLog.limitToValidMetadata(par1World.getBlockMetadata(par2, par3, par4)) == 3;
048 }
049
050 /**
051 * The type of render function that is called for this block
052 */
053 public int getRenderType()
054 {
055 return 28;
056 }
057
058 /**
059 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc)
060 */
061 public boolean renderAsNormalBlock()
062 {
063 return false;
064 }
065
066 /**
067 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two
068 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block.
069 */
070 public boolean isOpaqueCube()
071 {
072 return false;
073 }
074
075 /**
076 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been
077 * cleared to be reused)
078 */
079 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
080 {
081 this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
082 return super.getCollisionBoundingBoxFromPool(par1World, par2, par3, par4);
083 }
084
085 @SideOnly(Side.CLIENT)
086
087 /**
088 * Returns the bounding box of the wired rectangular prism to render.
089 */
090 public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
091 {
092 this.setBlockBoundsBasedOnState(par1World, par2, par3, par4);
093 return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4);
094 }
095
096 /**
097 * Updates the blocks bounds based on its current state. Args: world, x, y, z
098 */
099 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
100 {
101 int var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
102 int var6 = getDirection(var5);
103 int var7 = func_72219_c(var5);
104 int var8 = 4 + var7 * 2;
105 int var9 = 5 + var7 * 2;
106 float var10 = (float)var8 / 2.0F;
107
108 switch (var6)
109 {
110 case 0:
111 this.setBlockBounds((8.0F - var10) / 16.0F, (12.0F - (float)var9) / 16.0F, (15.0F - (float)var8) / 16.0F, (8.0F + var10) / 16.0F, 0.75F, 0.9375F);
112 break;
113 case 1:
114 this.setBlockBounds(0.0625F, (12.0F - (float)var9) / 16.0F, (8.0F - var10) / 16.0F, (1.0F + (float)var8) / 16.0F, 0.75F, (8.0F + var10) / 16.0F);
115 break;
116 case 2:
117 this.setBlockBounds((8.0F - var10) / 16.0F, (12.0F - (float)var9) / 16.0F, 0.0625F, (8.0F + var10) / 16.0F, 0.75F, (1.0F + (float)var8) / 16.0F);
118 break;
119 case 3:
120 this.setBlockBounds((15.0F - (float)var8) / 16.0F, (12.0F - (float)var9) / 16.0F, (8.0F - var10) / 16.0F, 0.9375F, 0.75F, (8.0F + var10) / 16.0F);
121 }
122 }
123
124 /**
125 * Called when the block is placed in the world.
126 */
127 public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
128 {
129 int var6 = ((MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) + 0) % 4;
130 par1World.setBlockMetadataWithNotify(par2, par3, par4, var6);
131 }
132
133 /**
134 * called before onBlockPlacedBy by ItemBlock and ItemReed
135 */
136 public void updateBlockMetadata(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8)
137 {
138 if (par5 == 1 || par5 == 0)
139 {
140 par5 = 2;
141 }
142
143 int var9 = Direction.footInvisibleFaceRemap[Direction.vineGrowth[par5]];
144 par1World.setBlockMetadataWithNotify(par2, par3, par4, var9);
145 }
146
147 /**
148 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
149 * their own) Args: x, y, z, neighbor blockID
150 */
151 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
152 {
153 if (!this.canBlockStay(par1World, par2, par3, par4))
154 {
155 this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
156 par1World.setBlockWithNotify(par2, par3, par4, 0);
157 }
158 }
159
160 public static int func_72219_c(int par0)
161 {
162 return (par0 & 12) >> 2;
163 }
164
165 /**
166 * Drops the block items with a specified chance of dropping the specified items
167 */
168 public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7)
169 {
170 int var8 = func_72219_c(par5);
171 byte var9 = 1;
172
173 if (var8 >= 2)
174 {
175 var9 = 3;
176 }
177
178 for (int var10 = 0; var10 < var9; ++var10)
179 {
180 this.dropBlockAsItem_do(par1World, par2, par3, par4, new ItemStack(Item.dyePowder, 1, 3));
181 }
182 }
183
184 @SideOnly(Side.CLIENT)
185
186 /**
187 * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative)
188 */
189 public int idPicked(World par1World, int par2, int par3, int par4)
190 {
191 return Item.dyePowder.shiftedIndex;
192 }
193
194 /**
195 * Get the block's damage value (for use with pick block).
196 */
197 public int getDamageValue(World par1World, int par2, int par3, int par4)
198 {
199 return 3;
200 }
201 }