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.List;
006 import java.util.Random;
007
008 public class BlockLog extends Block
009 {
010 /** The type of tree this log came from. */
011 public static final String[] woodType = new String[] {"oak", "spruce", "birch", "jungle"};
012
013 protected BlockLog(int par1)
014 {
015 super(par1, Material.wood);
016 this.blockIndexInTexture = 20;
017 this.setCreativeTab(CreativeTabs.tabBlock);
018 }
019
020 /**
021 * The type of render function that is called for this block
022 */
023 public int getRenderType()
024 {
025 return 31;
026 }
027
028 /**
029 * Returns the quantity of items to drop on block destruction.
030 */
031 public int quantityDropped(Random par1Random)
032 {
033 return 1;
034 }
035
036 /**
037 * Returns the ID of the items to drop on destruction.
038 */
039 public int idDropped(int par1, Random par2Random, int par3)
040 {
041 return Block.wood.blockID;
042 }
043
044 /**
045 * ejects contained items into the world, and notifies neighbours of an update, as appropriate
046 */
047 public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
048 {
049 byte var7 = 4;
050 int var8 = var7 + 1;
051
052 if (par1World.checkChunksExist(par2 - var8, par3 - var8, par4 - var8, par2 + var8, par3 + var8, par4 + var8))
053 {
054 for (int var9 = -var7; var9 <= var7; ++var9)
055 {
056 for (int var10 = -var7; var10 <= var7; ++var10)
057 {
058 for (int var11 = -var7; var11 <= var7; ++var11)
059 {
060 int var12 = par1World.getBlockId(par2 + var9, par3 + var10, par4 + var11);
061
062 if (Block.blocksList[var12] != null)
063 {
064 Block.blocksList[var12].beginLeavesDecay(par1World, par2 + var9, par3 + var10, par4 + var11);
065 }
066 }
067 }
068 }
069 }
070 }
071
072 /**
073 * called before onBlockPlacedBy by ItemBlock and ItemReed
074 */
075 public void updateBlockMetadata(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8)
076 {
077 int var9 = par1World.getBlockMetadata(par2, par3, par4) & 3;
078 byte var10 = 0;
079
080 switch (par5)
081 {
082 case 0:
083 case 1:
084 var10 = 0;
085 break;
086 case 2:
087 case 3:
088 var10 = 8;
089 break;
090 case 4:
091 case 5:
092 var10 = 4;
093 }
094
095 par1World.setBlockMetadataWithNotify(par2, par3, par4, var9 | var10);
096 }
097
098 /**
099 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
100 */
101 public int getBlockTextureFromSideAndMetadata(int par1, int par2)
102 {
103 int var3 = par2 & 12;
104 int var4 = par2 & 3;
105 return var3 == 0 && (par1 == 1 || par1 == 0) ? 21 : (var3 == 4 && (par1 == 5 || par1 == 4) ? 21 : (var3 == 8 && (par1 == 2 || par1 == 3) ? 21 : (var4 == 1 ? 116 : (var4 == 2 ? 117 : (var4 == 3 ? 153 : 20)))));
106 }
107
108 /**
109 * Determines the damage on the item the block drops. Used in cloth and wood.
110 */
111 public int damageDropped(int par1)
112 {
113 return par1 & 3;
114 }
115
116 /**
117 * returns a number between 0 and 3
118 */
119 public static int limitToValidMetadata(int par0)
120 {
121 return par0 & 3;
122 }
123
124 @SideOnly(Side.CLIENT)
125
126 /**
127 * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
128 */
129 public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
130 {
131 par3List.add(new ItemStack(par1, 1, 0));
132 par3List.add(new ItemStack(par1, 1, 1));
133 par3List.add(new ItemStack(par1, 1, 2));
134 par3List.add(new ItemStack(par1, 1, 3));
135 }
136
137 /**
138 * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
139 * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
140 */
141 protected ItemStack createStackedBlock(int par1)
142 {
143 return new ItemStack(this.blockID, 1, limitToValidMetadata(par1));
144 }
145
146 @Override
147 public boolean canSustainLeaves(World world, int x, int y, int z)
148 {
149 return true;
150 }
151
152 @Override
153 public boolean isWood(World world, int x, int y, int z)
154 {
155 return true;
156 }
157 }