| 1 | package net.minecraft.item;
|
| 2 |
|
| 3 | import net.minecraft.block.Block;
|
| 4 | import net.minecraft.block.BlockSnow;
|
| 5 | import net.minecraft.block.state.IBlockState;
|
| 6 | import net.minecraft.entity.Entity;
|
| 7 | import net.minecraft.entity.player.EntityPlayer;
|
| 8 | import net.minecraft.init.Blocks;
|
| 9 | import net.minecraft.util.BlockPos;
|
| 10 | import net.minecraft.util.EnumFacing;
|
| 11 | import net.minecraft.world.World;
|
| 12 |
|
| 13 | public class ItemReed extends Item
|
| 14 | {
|
| 15 | private Block block;
|
| 16 |
|
| 17 | public ItemReed(Block block)
|
| 18 | {
|
| 19 | this.block = block;
|
| 20 | }
|
| 21 |
|
| 22 | /**
|
| 23 | * Called when a Block is right-clicked with this Item
|
| 24 | */
|
| 25 | public boolean onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ)
|
| 26 | {
|
| 27 | IBlockState iblockstate = worldIn.getBlockState(pos);
|
| 28 | Block block = iblockstate.getBlock();
|
| 29 |
|
| 30 | if (block == Blocks.snow_layer && ((Integer)iblockstate.getValue(BlockSnow.LAYERS)).intValue() < 1)
|
| 31 | {
|
| 32 | side = EnumFacing.UP;
|
| 33 | }
|
| 34 | else if (!block.isReplaceable(worldIn, pos))
|
| 35 | {
|
| 36 | pos = pos.offset(side);
|
| 37 | }
|
| 38 |
|
| 39 | if (!playerIn.canPlayerEdit(pos, side, stack))
|
| 40 | {
|
| 41 | return false;
|
| 42 | }
|
| 43 | else if (stack.stackSize == 0)
|
| 44 | {
|
| 45 | return false;
|
| 46 | }
|
| 47 | else
|
| 48 | {
|
| 49 | if (worldIn.canBlockBePlaced(this.block, pos, false, side, (Entity)null, stack))
|
| 50 | {
|
| 51 | IBlockState iblockstate1 = this.block.onBlockPlaced(worldIn, pos, side, hitX, hitY, hitZ, 0, playerIn);
|
| 52 |
|
| 53 | if (worldIn.setBlockState(pos, iblockstate1, 3))
|
| 54 | {
|
| 55 | iblockstate1 = worldIn.getBlockState(pos);
|
| 56 |
|
| 57 | if (iblockstate1.getBlock() == this.block)
|
| 58 | {
|
| 59 | ItemBlock.setTileEntityNBT(worldIn, playerIn, pos, stack);
|
| 60 | iblockstate1.getBlock().onBlockPlacedBy(worldIn, pos, iblockstate1, playerIn, stack);
|
| 61 | }
|
| 62 |
|
| 63 | worldIn.playSoundEffect((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), this.block.stepSound.getPlaceSound(), (this.block.stepSound.getVolume() + 1.0F) / 2.0F, this.block.stepSound.getFrequency() * 0.8F);
|
| 64 | --stack.stackSize;
|
| 65 | return true;
|
| 66 | }
|
| 67 | }
|
| 68 |
|
| 69 | return false;
|
| 70 | }
|
| 71 | }
|
| 72 | }
|
| 73 |
|