| 1 | package net.minecraft.item;
|
| 2 |
|
| 3 | import net.minecraft.block.material.Material;
|
| 4 | import net.minecraft.creativetab.CreativeTabs;
|
| 5 | import net.minecraft.entity.player.EntityPlayer;
|
| 6 | import net.minecraft.init.Items;
|
| 7 | import net.minecraft.stats.StatList;
|
| 8 | import net.minecraft.util.BlockPos;
|
| 9 | import net.minecraft.util.MovingObjectPosition;
|
| 10 | import net.minecraft.world.World;
|
| 11 |
|
| 12 | public class ItemGlassBottle extends Item
|
| 13 | {
|
| 14 | public ItemGlassBottle()
|
| 15 | {
|
| 16 | this.setCreativeTab(CreativeTabs.tabBrewing);
|
| 17 | }
|
| 18 |
|
| 19 | /**
|
| 20 | * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
| 21 | */
|
| 22 | public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
|
| 23 | {
|
| 24 | MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(worldIn, playerIn, true);
|
| 25 |
|
| 26 | if (movingobjectposition == null)
|
| 27 | {
|
| 28 | return itemStackIn;
|
| 29 | }
|
| 30 | else
|
| 31 | {
|
| 32 | if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
| 33 | {
|
| 34 | BlockPos blockpos = movingobjectposition.getBlockPos();
|
| 35 |
|
| 36 | if (!worldIn.isBlockModifiable(playerIn, blockpos))
|
| 37 | {
|
| 38 | return itemStackIn;
|
| 39 | }
|
| 40 |
|
| 41 | if (!playerIn.canPlayerEdit(blockpos.offset(movingobjectposition.sideHit), movingobjectposition.sideHit, itemStackIn))
|
| 42 | {
|
| 43 | return itemStackIn;
|
| 44 | }
|
| 45 |
|
| 46 | if (worldIn.getBlockState(blockpos).getBlock().getMaterial() == Material.water)
|
| 47 | {
|
| 48 | --itemStackIn.stackSize;
|
| 49 | playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
|
| 50 |
|
| 51 | if (itemStackIn.stackSize <= 0)
|
| 52 | {
|
| 53 | return new ItemStack(Items.potionitem);
|
| 54 | }
|
| 55 |
|
| 56 | if (!playerIn.inventory.addItemStackToInventory(new ItemStack(Items.potionitem)))
|
| 57 | {
|
| 58 | playerIn.dropPlayerItemWithRandomChoice(new ItemStack(Items.potionitem, 1, 0), false);
|
| 59 | }
|
| 60 | }
|
| 61 | }
|
| 62 |
|
| 63 | return itemStackIn;
|
| 64 | }
|
| 65 | }
|
| 66 | }
|
| 67 |
|