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
007 public class ItemBlock extends Item
008 {
009 /** The block ID of the Block associated with this ItemBlock */
010 private int blockID;
011
012 public ItemBlock(int par1)
013 {
014 super(par1);
015 this.blockID = par1 + 256;
016 this.setIconIndex(Block.blocksList[par1 + 256].getBlockTextureFromSide(2));
017 isDefaultTexture = Block.blocksList[par1 + 256].isDefaultTexture;
018 }
019
020 /**
021 * Returns the blockID for this Item
022 */
023 public int getBlockID()
024 {
025 return this.blockID;
026 }
027
028 /**
029 * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
030 * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
031 */
032 public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
033 {
034 int var11 = par3World.getBlockId(par4, par5, par6);
035
036 if (var11 == Block.snow.blockID)
037 {
038 par7 = 1;
039 }
040 else if (var11 != Block.vine.blockID && var11 != Block.tallGrass.blockID && var11 != Block.deadBush.blockID
041 && (Block.blocksList[var11] == null || !Block.blocksList[var11].isBlockReplaceable(par3World, par4, par5, par6)))
042 {
043 if (par7 == 0)
044 {
045 --par5;
046 }
047
048 if (par7 == 1)
049 {
050 ++par5;
051 }
052
053 if (par7 == 2)
054 {
055 --par6;
056 }
057
058 if (par7 == 3)
059 {
060 ++par6;
061 }
062
063 if (par7 == 4)
064 {
065 --par4;
066 }
067
068 if (par7 == 5)
069 {
070 ++par4;
071 }
072 }
073
074 if (par1ItemStack.stackSize == 0)
075 {
076 return false;
077 }
078 else if (!par2EntityPlayer.func_82247_a(par4, par5, par6, par7, par1ItemStack))
079 {
080 return false;
081 }
082 else if (par5 == 255 && Block.blocksList[this.blockID].blockMaterial.isSolid())
083 {
084 return false;
085 }
086 else if (par3World.canPlaceEntityOnSide(this.blockID, par4, par5, par6, false, par7, par2EntityPlayer))
087 {
088 Block var12 = Block.blocksList[this.blockID];
089 int var13 = this.getMetadata(par1ItemStack.getItemDamage());
090 int var14 = Block.blocksList[this.blockID].func_85104_a(par3World, par4, par5, par6, par7, par8, par9, par10, var13);
091
092 if (placeBlockAt(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10, var14))
093 {
094 par3World.playSoundEffect((double)((float)par4 + 0.5F), (double)((float)par5 + 0.5F), (double)((float)par6 + 0.5F), var12.stepSound.getPlaceSound(), (var12.stepSound.getVolume() + 1.0F) / 2.0F, var12.stepSound.getPitch() * 0.8F);
095 --par1ItemStack.stackSize;
096 }
097
098 return true;
099 }
100 else
101 {
102 return false;
103 }
104 }
105
106 @SideOnly(Side.CLIENT)
107
108 /**
109 * Returns true if the given ItemBlock can be placed on the given side of the given block position.
110 */
111 public boolean canPlaceItemBlockOnSide(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer, ItemStack par7ItemStack)
112 {
113 int var8 = par1World.getBlockId(par2, par3, par4);
114
115 if (var8 == Block.snow.blockID)
116 {
117 par5 = 1;
118 }
119 else if (var8 != Block.vine.blockID && var8 != Block.tallGrass.blockID && var8 != Block.deadBush.blockID
120 && (Block.blocksList[var8] == null || !Block.blocksList[var8].isBlockReplaceable(par1World, par2, par3, par4)))
121 {
122 if (par5 == 0)
123 {
124 --par3;
125 }
126
127 if (par5 == 1)
128 {
129 ++par3;
130 }
131
132 if (par5 == 2)
133 {
134 --par4;
135 }
136
137 if (par5 == 3)
138 {
139 ++par4;
140 }
141
142 if (par5 == 4)
143 {
144 --par2;
145 }
146
147 if (par5 == 5)
148 {
149 ++par2;
150 }
151 }
152
153 return par1World.canPlaceEntityOnSide(this.getBlockID(), par2, par3, par4, false, par5, (Entity)null);
154 }
155
156 public String getItemNameIS(ItemStack par1ItemStack)
157 {
158 return Block.blocksList[this.blockID].getBlockName();
159 }
160
161 public String getItemName()
162 {
163 return Block.blocksList[this.blockID].getBlockName();
164 }
165
166 @SideOnly(Side.CLIENT)
167
168 /**
169 * gets the CreativeTab this item is displayed on
170 */
171 public CreativeTabs getCreativeTab()
172 {
173 return Block.blocksList[this.blockID].getCreativeTabToDisplayOn();
174 }
175
176 @SideOnly(Side.CLIENT)
177
178 /**
179 * returns a list of items with the same ID, but different meta (eg: dye returns 16 items)
180 */
181 public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List)
182 {
183 Block.blocksList[this.blockID].getSubBlocks(par1, par2CreativeTabs, par3List);
184 }
185
186 /**
187 * Called to actually place the block, after the location is determined
188 * and all permission checks have been made.
189 *
190 * @param stack The item stack that was used to place the block. This can be changed inside the method.
191 * @param player The player who is placing the block. Can be null if the block is not being placed by a player.
192 * @param side The side the player (or machine) right-clicked on.
193 */
194 public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
195 {
196 if (!world.setBlockAndMetadataWithNotify(x, y, z, this.blockID, metadata))
197 {
198 return false;
199 }
200
201 if (world.getBlockId(x, y, z) == this.blockID)
202 {
203 Block.blocksList[this.blockID].onBlockPlacedBy(world, x, y, z, player);
204 Block.blocksList[this.blockID].func_85105_g(world, x, y, z, metadata);
205 }
206
207 return true;
208 }
209 }