    001    package net.minecraft.src;
    002
    003    import net.minecraftforge.common.MinecraftForge;
    004    import net.minecraftforge.event.entity.player.FillBucketEvent;
    005
    006    public class ItemBucket extends Item
    007    {
    008        /** field for checking if the bucket has been filled. */
    009        private int isFull;
    010
    011        public ItemBucket(int par1, int par2)
    012        {
    013            super(par1);
    014            this.maxStackSize = 1;
    015            this.isFull = par2;
    016            this.setCreativeTab(CreativeTabs.tabMisc);
    017        }
    018
    019        /**
    020         * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
    021         */
    022        public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    023        {
    024            float var4 = 1.0F;
    025            double var5 = par3EntityPlayer.prevPosX + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * (double)var4;
    026            double var7 = par3EntityPlayer.prevPosY + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par3EntityPlayer.yOffset;
    027            double var9 = par3EntityPlayer.prevPosZ + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * (double)var4;
    028            boolean var11 = this.isFull == 0;
    029            MovingObjectPosition var12 = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, var11);
    030
    031            if (var12 == null)
    032            {
    033                return par1ItemStack;
    034            }
    035            else
    036            {
    037                FillBucketEvent event = new FillBucketEvent(par3EntityPlayer, par1ItemStack, par2World, var12);
    038                if (MinecraftForge.EVENT_BUS.post(event))
    039                {
    040                    return par1ItemStack;
    041                }
    042
    043                if (event.isHandeled())
    044                {
    045                    if (par3EntityPlayer.capabilities.isCreativeMode)
    046                    {
    047                        return par1ItemStack;
    048                    }
    049
    050                    if (--par1ItemStack.stackSize <= 0)
    051                    {
    052                        return event.result;
    053                    }
    054
    055                    if (!par3EntityPlayer.inventory.addItemStackToInventory(event.result))
    056                    {
    057                        par3EntityPlayer.dropPlayerItem(event.result);
    058                    }
    059
    060                    return par1ItemStack;
    061                }
    062
    063                if (var12.typeOfHit == EnumMovingObjectType.TILE)
    064                {
    065                    int var13 = var12.blockX;
    066                    int var14 = var12.blockY;
    067                    int var15 = var12.blockZ;
    068
    069                    if (!par2World.canMineBlock(par3EntityPlayer, var13, var14, var15))
    070                    {
    071                        return par1ItemStack;
    072                    }
    073
    074                    if (this.isFull == 0)
    075                    {
    076                        if (!par3EntityPlayer.canPlayerEdit(var13, var14, var15))
    077                        {
    078                            return par1ItemStack;
    079                        }
    080
    081                        if (par2World.getBlockMaterial(var13, var14, var15) == Material.water && par2World.getBlockMetadata(var13, var14, var15) == 0)
    082                        {
    083                            par2World.setBlockWithNotify(var13, var14, var15, 0);
    084
    085                            if (par3EntityPlayer.capabilities.isCreativeMode)
    086                            {
    087                                return par1ItemStack;
    088                            }
    089
    090                            if (--par1ItemStack.stackSize <= 0)
    091                            {
    092                                return new ItemStack(Item.bucketWater);
    093                            }
    094
    095                            if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketWater)))
    096                            {
    097                                par3EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketWater.shiftedIndex, 1, 0));
    098                            }
    099
    100                            return par1ItemStack;
    101                        }
    102
    103                        if (par2World.getBlockMaterial(var13, var14, var15) == Material.lava && par2World.getBlockMetadata(var13, var14, var15) == 0)
    104                        {
    105                            par2World.setBlockWithNotify(var13, var14, var15, 0);
    106
    107                            if (par3EntityPlayer.capabilities.isCreativeMode)
    108                            {
    109                                return par1ItemStack;
    110                            }
    111
    112                            if (--par1ItemStack.stackSize <= 0)
    113                            {
    114                                return new ItemStack(Item.bucketLava);
    115                            }
    116
    117                            if (!par3EntityPlayer.inventory.addItemStackToInventory(new ItemStack(Item.bucketLava)))
    118                            {
    119                                par3EntityPlayer.dropPlayerItem(new ItemStack(Item.bucketLava.shiftedIndex, 1, 0));
    120                            }
    121
    122                            return par1ItemStack;
    123                        }
    124                    }
    125                    else
    126                    {
    127                        if (this.isFull < 0)
    128                        {
    129                            return new ItemStack(Item.bucketEmpty);
    130                        }
    131
    132                        if (var12.sideHit == 0)
    133                        {
    134                            --var14;
    135                        }
    136
    137                        if (var12.sideHit == 1)
    138                        {
    139                            ++var14;
    140                        }
    141
    142                        if (var12.sideHit == 2)
    143                        {
    144                            --var15;
    145                        }
    146
    147                        if (var12.sideHit == 3)
    148                        {
    149                            ++var15;
    150                        }
    151
    152                        if (var12.sideHit == 4)
    153                        {
    154                            --var13;
    155                        }
    156
    157                        if (var12.sideHit == 5)
    158                        {
    159                            ++var13;
    160                        }
    161
    162                        if (!par3EntityPlayer.canPlayerEdit(var13, var14, var15))
    163                        {
    164                            return par1ItemStack;
    165                        }
    166
    167                        if (this.func_77875_a(par2World, var5, var7, var9, var13, var14, var15) && !par3EntityPlayer.capabilities.isCreativeMode)
    168                        {
    169                            return new ItemStack(Item.bucketEmpty);
    170                        }
    171                    }
    172                }
    173                else if (this.isFull == 0 && var12.entityHit instanceof EntityCow)
    174                {
    175                    return new ItemStack(Item.bucketMilk);
    176                }
    177
    178                return par1ItemStack;
    179            }
    180        }
    181
    182        public boolean func_77875_a(World par1World, double par2, double par4, double par6, int par8, int par9, int par10)
    183        {
    184            if (this.isFull <= 0)
    185            {
    186                return false;
    187            }
    188            else if (!par1World.isAirBlock(par8, par9, par10) && par1World.getBlockMaterial(par8, par9, par10).isSolid())
    189            {
    190                return false;
    191            }
    192            else
    193            {
    194                if (par1World.provider.isHellWorld && this.isFull == Block.waterMoving.blockID)
    195                {
    196                    par1World.playSoundEffect(par2 + 0.5D, par4 + 0.5D, par6 + 0.5D, "random.fizz", 0.5F, 2.6F + (par1World.rand.nextFloat() - par1World.rand.nextFloat()) * 0.8F);
    197
    198                    for (int var11 = 0; var11 < 8; ++var11)
    199                    {
    200                        par1World.spawnParticle("largesmoke", (double)par8 + Math.random(), (double)par9 + Math.random(), (double)par10 + Math.random(), 0.0D, 0.0D, 0.0D);
    201                    }
    202                }
    203                else
    204                {
    205                    par1World.setBlockAndMetadataWithNotify(par8, par9, par10, this.isFull, 0);
    206                }
    207
    208                return true;
    209            }
    210        }
    211    }