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 BlockFarmland extends Block 008 { 009 protected BlockFarmland(int par1) 010 { 011 super(par1, Material.ground); 012 this.blockIndexInTexture = 87; 013 this.setTickRandomly(true); 014 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.9375F, 1.0F); 015 this.setLightOpacity(255); 016 } 017 018 /** 019 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been 020 * cleared to be reused) 021 */ 022 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) 023 { 024 return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)(par2 + 0), (double)(par3 + 0), (double)(par4 + 0), (double)(par2 + 1), (double)(par3 + 1), (double)(par4 + 1)); 025 } 026 027 /** 028 * Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the shared face of two 029 * adjacent blocks and also whether the player can attach torches, redstone wire, etc to this block. 030 */ 031 public boolean isOpaqueCube() 032 { 033 return false; 034 } 035 036 /** 037 * If this block doesn't render as an ordinary block it will return False (examples: signs, buttons, stairs, etc) 038 */ 039 public boolean renderAsNormalBlock() 040 { 041 return false; 042 } 043 044 /** 045 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata 046 */ 047 public int getBlockTextureFromSideAndMetadata(int par1, int par2) 048 { 049 return par1 == 1 && par2 > 0 ? this.blockIndexInTexture - 1 : (par1 == 1 ? this.blockIndexInTexture : 2); 050 } 051 052 /** 053 * Ticks the block if it's been scheduled 054 */ 055 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) 056 { 057 if (!this.isWaterNearby(par1World, par2, par3, par4) && !par1World.canLightningStrikeAt(par2, par3 + 1, par4)) 058 { 059 int var6 = par1World.getBlockMetadata(par2, par3, par4); 060 061 if (var6 > 0) 062 { 063 par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 - 1); 064 } 065 else if (!this.isCropsNearby(par1World, par2, par3, par4)) 066 { 067 par1World.setBlockWithNotify(par2, par3, par4, Block.dirt.blockID); 068 } 069 } 070 else 071 { 072 par1World.setBlockMetadataWithNotify(par2, par3, par4, 7); 073 } 074 } 075 076 /** 077 * Block's chance to react to an entity falling on it. 078 */ 079 public void onFallenUpon(World par1World, int par2, int par3, int par4, Entity par5Entity, float par6) 080 { 081 if (!par1World.isRemote && par1World.rand.nextFloat() < par6 - 0.5F) 082 { 083 par1World.setBlockWithNotify(par2, par3, par4, Block.dirt.blockID); 084 } 085 } 086 087 /** 088 * returns true if there is at least one cropblock nearby (x-1 to x+1, y+1, z-1 to z+1) 089 */ 090 private boolean isCropsNearby(World par1World, int par2, int par3, int par4) 091 { 092 byte var5 = 0; 093 094 for (int var6 = par2 - var5; var6 <= par2 + var5; ++var6) 095 { 096 for (int var7 = par4 - var5; var7 <= par4 + var5; ++var7) 097 { 098 int var8 = par1World.getBlockId(var6, par3 + 1, var7); 099 100 if (var8 == Block.crops.blockID || var8 == Block.melonStem.blockID || var8 == Block.pumpkinStem.blockID) 101 { 102 return true; 103 } 104 } 105 } 106 107 return false; 108 } 109 110 /** 111 * returns true if there's water nearby (x-4 to x+4, y to y+1, k-4 to k+4) 112 */ 113 private boolean isWaterNearby(World par1World, int par2, int par3, int par4) 114 { 115 for (int var5 = par2 - 4; var5 <= par2 + 4; ++var5) 116 { 117 for (int var6 = par3; var6 <= par3 + 1; ++var6) 118 { 119 for (int var7 = par4 - 4; var7 <= par4 + 4; ++var7) 120 { 121 if (par1World.getBlockMaterial(var5, var6, var7) == Material.water) 122 { 123 return true; 124 } 125 } 126 } 127 } 128 129 return false; 130 } 131 132 /** 133 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 134 * their own) Args: x, y, z, neighbor blockID 135 */ 136 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 137 { 138 super.onNeighborBlockChange(par1World, par2, par3, par4, par5); 139 Material var6 = par1World.getBlockMaterial(par2, par3 + 1, par4); 140 141 if (var6.isSolid()) 142 { 143 par1World.setBlockWithNotify(par2, par3, par4, Block.dirt.blockID); 144 } 145 } 146 147 /** 148 * Returns the ID of the items to drop on destruction. 149 */ 150 public int idDropped(int par1, Random par2Random, int par3) 151 { 152 return Block.dirt.idDropped(0, par2Random, par3); 153 } 154 155 @SideOnly(Side.CLIENT) 156 157 /** 158 * only called by clickMiddleMouseButton , and passed to inventory.setCurrentItem (along with isCreative) 159 */ 160 public int idPicked(World par1World, int par2, int par3, int par4) 161 { 162 return Block.dirt.blockID; 163 } 164 }