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 when the block is placed in the world.
074 */
075 public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving)
076 {
077 int var6 = par1World.getBlockMetadata(par2, par3, par4) & 3;
078 int var7 = BlockPistonBase.determineOrientation(par1World, par2, par3, par4, (EntityPlayer)par5EntityLiving);
079 byte var8 = 0;
080
081 switch (var7)
082 {
083 case 0:
084 case 1:
085 var8 = 0;
086 break;
087 case 2:
088 case 3:
089 var8 = 8;
090 break;
091 case 4:
092 case 5:
093 var8 = 4;
094 }
095
096 par1World.setBlockMetadataWithNotify(par2, par3, par4, var6 | var8);
097 }
098
099 /**
100 * From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
101 */
102 public int getBlockTextureFromSideAndMetadata(int par1, int par2)
103 {
104 int var3 = par2 & 12;
105 int var4 = par2 & 3;
106 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)))));
107 }
108
109 /**
110 * Determines the damage on the item the block drops. Used in cloth and wood.
111 */
112 protected int damageDropped(int par1)
113 {
114 return par1 & 3;
115 }
116
117 /**
118 * returns a number between 0 and 3
119 */
120 public static int limitToValidMetadata(int par0)
121 {
122 return par0 & 3;
123 }
124
125 @SideOnly(Side.CLIENT)
126
127 /**
128 * returns a list of blocks with the same ID, but different meta (eg: wood returns 4 blocks)
129 */
130 public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List par3List)
131 {
132 par3List.add(new ItemStack(par1, 1, 0));
133 par3List.add(new ItemStack(par1, 1, 1));
134 par3List.add(new ItemStack(par1, 1, 2));
135 par3List.add(new ItemStack(par1, 1, 3));
136 }
137
138 /**
139 * Returns an item stack containing a single instance of the current block type. 'i' is the block's subtype/damage
140 * and is ignored for blocks which do not support subtypes. Blocks which cannot be harvested should return null.
141 */
142 protected ItemStack createStackedBlock(int par1)
143 {
144 return new ItemStack(this.blockID, 1, limitToValidMetadata(par1));
145 }
146
147 @Override
148 public boolean canSustainLeaves(World world, int x, int y, int z)
149 {
150 return true;
151 }
152
153 @Override
154 public boolean isWood(World world, int x, int y, int z)
155 {
156 return true;
157 }
158 }