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 BlockReed extends Block 008 { 009 protected BlockReed(int par1, int par2) 010 { 011 super(par1, Material.plants); 012 this.blockIndexInTexture = par2; 013 float var3 = 0.375F; 014 this.setBlockBounds(0.5F - var3, 0.0F, 0.5F - var3, 0.5F + var3, 1.0F, 0.5F + var3); 015 this.setTickRandomly(true); 016 } 017 018 /** 019 * Ticks the block if it's been scheduled 020 */ 021 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) 022 { 023 if (par1World.isAirBlock(par2, par3 + 1, par4)) 024 { 025 int var6; 026 027 for (var6 = 1; par1World.getBlockId(par2, par3 - var6, par4) == this.blockID; ++var6) 028 { 029 ; 030 } 031 032 if (var6 < 3) 033 { 034 int var7 = par1World.getBlockMetadata(par2, par3, par4); 035 036 if (var7 == 15) 037 { 038 par1World.setBlockWithNotify(par2, par3 + 1, par4, this.blockID); 039 par1World.setBlockMetadataWithNotify(par2, par3, par4, 0); 040 } 041 else 042 { 043 par1World.setBlockMetadataWithNotify(par2, par3, par4, var7 + 1); 044 } 045 } 046 } 047 } 048 049 /** 050 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z 051 */ 052 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) 053 { 054 int var5 = par1World.getBlockId(par2, par3 - 1, par4); 055 return var5 == this.blockID ? true : (var5 != Block.grass.blockID && var5 != Block.dirt.blockID && var5 != Block.sand.blockID ? false : (par1World.getBlockMaterial(par2 - 1, par3 - 1, par4) == Material.water ? true : (par1World.getBlockMaterial(par2 + 1, par3 - 1, par4) == Material.water ? true : (par1World.getBlockMaterial(par2, par3 - 1, par4 - 1) == Material.water ? true : par1World.getBlockMaterial(par2, par3 - 1, par4 + 1) == Material.water)))); 056 } 057 058 /** 059 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 060 * their own) Args: x, y, z, neighbor blockID 061 */ 062 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 063 { 064 this.checkBlockCoordValid(par1World, par2, par3, par4); 065 } 066 067 /** 068 * Checks if current block pos is valid, if not, breaks the block as dropable item. Used for reed and cactus. 069 */ 070 protected final void checkBlockCoordValid(World par1World, int par2, int par3, int par4) 071 { 072 if (!this.canBlockStay(par1World, par2, par3, par4)) 073 { 074 this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0); 075 par1World.setBlockWithNotify(par2, par3, par4, 0); 076 } 077 } 078 079 /** 080 * Can this block stay at this position. Similar to canPlaceBlockAt except gets checked often with plants. 081 */ 082 public boolean canBlockStay(World par1World, int par2, int par3, int par4) 083 { 084 return this.canPlaceBlockAt(par1World, par2, par3, par4); 085 } 086 087 /** 088 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been 089 * cleared to be reused) 090 */ 091 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) 092 { 093 return null; 094 } 095 096 /** 097 * Returns the ID of the items to drop on destruction. 098 */ 099 public int idDropped(int par1, Random par2Random, int par3) 100 { 101 return Item.reed.shiftedIndex; 102 } 103 104 /** 105 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 106 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 107 */ 108 public boolean isOpaqueCube() 109 { 110 return false; 111 } 112 113 /** 114 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 115 */ 116 public boolean renderAsNormalBlock() 117 { 118 return false; 119 } 120 121 /** 122 * The type of render function that is called for this block 123 */ 124 public int getRenderType() 125 { 126 return 1; 127 } 128 129 @SideOnly(Side.CLIENT) 130 131 /** 132 * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) 133 */ 134 public int idPicked(World par1World, int par2, int par3, int par4) 135 { 136 return Item.reed.shiftedIndex; 137 } 138 }