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 BlockSnow extends Block 008 { 009 protected BlockSnow(int par1, int par2) 010 { 011 super(par1, par2, Material.snow); 012 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.125F, 1.0F); 013 this.setTickRandomly(true); 014 this.setCreativeTab(CreativeTabs.tabDecorations); 015 } 016 017 /** 018 * Returns a bounding box from the pool of bounding boxes (this means this box can change after the pool has been 019 * cleared to be reused) 020 */ 021 public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) 022 { 023 int var5 = par1World.getBlockMetadata(par2, par3, par4) & 7; 024 return var5 >= 3 ? AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)par2 + this.minX, (double)par3 + this.minY, (double)par4 + this.minZ, (double)par2 + this.maxX, (double)((float)par3 + 0.5F), (double)par4 + this.maxZ) : null; 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 * Updates the blocks bounds based on its current state. Args: world, x, y, z 046 */ 047 public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) 048 { 049 int var5 = par1IBlockAccess.getBlockMetadata(par2, par3, par4) & 7; 050 float var6 = (float)(2 * (1 + var5)) / 16.0F; 051 this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, var6, 1.0F); 052 } 053 054 /** 055 * Checks to see if its valid to put this block at the specified coordinates. Args: world, x, y, z 056 */ 057 public boolean canPlaceBlockAt(World par1World, int par2, int par3, int par4) 058 { 059 int var5 = par1World.getBlockId(par2, par3 - 1, par4); 060 Block block = Block.blocksList[var5]; 061 return block != null && (block.isLeaves(par1World, par2, par3 - 1, par4) || Block.blocksList[var5].isOpaqueCube()) ? par1World.getBlockMaterial(par2, par3 - 1, par4).blocksMovement() : false; 062 } 063 064 /** 065 * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are 066 * their own) Args: x, y, z, neighbor blockID 067 */ 068 public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) 069 { 070 this.canSnowStay(par1World, par2, par3, par4); 071 } 072 073 /** 074 * Checks if this snow block can stay at this location. 075 */ 076 private boolean canSnowStay(World par1World, int par2, int par3, int par4) 077 { 078 if (!this.canPlaceBlockAt(par1World, par2, par3, par4)) 079 { 080 par1World.setBlockWithNotify(par2, par3, par4, 0); 081 return false; 082 } 083 else 084 { 085 return true; 086 } 087 } 088 089 /** 090 * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the coordinates of the 091 * block and l is the block's subtype/damage. 092 */ 093 public void harvestBlock(World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) 094 { 095 dropBlockAsItem(par1World, par3, par4, par5, par6, 0); 096 par2EntityPlayer.addStat(StatList.mineBlockStatArray[this.blockID], 1); 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.snowball.shiftedIndex; 105 } 106 107 /** 108 * Returns the quantity of items to drop on block destruction. 109 */ 110 public int quantityDropped(Random par1Random) 111 { 112 return 1; 113 } 114 115 /** 116 * Ticks the block if it's been scheduled 117 */ 118 public void updateTick(World par1World, int par2, int par3, int par4, Random par5Random) 119 { 120 if (par1World.getSavedLightValue(EnumSkyBlock.Block, par2, par3, par4) > 11) 121 { 122 par1World.setBlockWithNotify(par2, par3, par4, 0); 123 } 124 } 125 126 @SideOnly(Side.CLIENT) 127 128 /** 129 * Returns true if the given side of this block type should be rendered, if the adjacent block is at the given 130 * coordinates. Args: blockAccess, x, y, z, side 131 */ 132 public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5) 133 { 134 return par5 == 1 ? true : super.shouldSideBeRendered(par1IBlockAccess, par2, par3, par4, par5); 135 } 136 }