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