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