    001    package net.minecraft.item;
    002
    003    import java.util.List;
    004    import net.minecraft.block.Block;
    005    import net.minecraft.creativetab.CreativeTabs;
    006    import net.minecraft.entity.Entity;
    007    import net.minecraft.entity.item.EntityBoat;
    008    import net.minecraft.entity.player.EntityPlayer;
    009    import net.minecraft.util.AxisAlignedBB;
    010    import net.minecraft.util.EnumMovingObjectType;
    011    import net.minecraft.util.MathHelper;
    012    import net.minecraft.util.MovingObjectPosition;
    013    import net.minecraft.util.Vec3;
    014    import net.minecraft.world.World;
    015
    016    public class ItemBoat extends Item
    017    {
    018        public ItemBoat(int par1)
    019        {
    020            super(par1);
    021            this.maxStackSize = 1;
    022            this.setCreativeTab(CreativeTabs.tabTransport);
    023        }
    024
    025        /**
    026         * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
    027         */
    028        public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    029        {
    030            float var4 = 1.0F;
    031            float var5 = par3EntityPlayer.prevRotationPitch + (par3EntityPlayer.rotationPitch - par3EntityPlayer.prevRotationPitch) * var4;
    032            float var6 = par3EntityPlayer.prevRotationYaw + (par3EntityPlayer.rotationYaw - par3EntityPlayer.prevRotationYaw) * var4;
    033            double var7 = par3EntityPlayer.prevPosX + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * (double)var4;
    034            double var9 = par3EntityPlayer.prevPosY + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * (double)var4 + 1.62D - (double)par3EntityPlayer.yOffset;
    035            double var11 = par3EntityPlayer.prevPosZ + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * (double)var4;
    036            Vec3 var13 = par2World.getWorldVec3Pool().getVecFromPool(var7, var9, var11);
    037            float var14 = MathHelper.cos(-var6 * 0.017453292F - (float)Math.PI);
    038            float var15 = MathHelper.sin(-var6 * 0.017453292F - (float)Math.PI);
    039            float var16 = -MathHelper.cos(-var5 * 0.017453292F);
    040            float var17 = MathHelper.sin(-var5 * 0.017453292F);
    041            float var18 = var15 * var16;
    042            float var20 = var14 * var16;
    043            double var21 = 5.0D;
    044            Vec3 var23 = var13.addVector((double)var18 * var21, (double)var17 * var21, (double)var20 * var21);
    045            MovingObjectPosition var24 = par2World.rayTraceBlocks_do(var13, var23, true);
    046
    047            if (var24 == null)
    048            {
    049                return par1ItemStack;
    050            }
    051            else
    052            {
    053                Vec3 var25 = par3EntityPlayer.getLook(var4);
    054                boolean var26 = false;
    055                float var27 = 1.0F;
    056                List var28 = par2World.getEntitiesWithinAABBExcludingEntity(par3EntityPlayer, par3EntityPlayer.boundingBox.addCoord(var25.xCoord * var21, var25.yCoord * var21, var25.zCoord * var21).expand((double)var27, (double)var27, (double)var27));
    057                int var29;
    058
    059                for (var29 = 0; var29 < var28.size(); ++var29)
    060                {
    061                    Entity var30 = (Entity)var28.get(var29);
    062
    063                    if (var30.canBeCollidedWith())
    064                    {
    065                        float var31 = var30.getCollisionBorderSize();
    066                        AxisAlignedBB var32 = var30.boundingBox.expand((double)var31, (double)var31, (double)var31);
    067
    068                        if (var32.isVecInside(var13))
    069                        {
    070                            var26 = true;
    071                        }
    072                    }
    073                }
    074
    075                if (var26)
    076                {
    077                    return par1ItemStack;
    078                }
    079                else
    080                {
    081                    if (var24.typeOfHit == EnumMovingObjectType.TILE)
    082                    {
    083                        var29 = var24.blockX;
    084                        int var33 = var24.blockY;
    085                        int var34 = var24.blockZ;
    086
    087                        if (par2World.getBlockId(var29, var33, var34) == Block.snow.blockID)
    088                        {
    089                            --var33;
    090                        }
    091
    092                        EntityBoat var35 = new EntityBoat(par2World, (double)((float)var29 + 0.5F), (double)((float)var33 + 1.0F), (double)((float)var34 + 0.5F));
    093
    094                        if (!par2World.getCollidingBoundingBoxes(var35, var35.boundingBox.expand(-0.1D, -0.1D, -0.1D)).isEmpty())
    095                        {
    096                            return par1ItemStack;
    097                        }
    098
    099                        if (!par2World.isRemote)
    100                        {
    101                            par2World.spawnEntityInWorld(var35);
    102                        }
    103
    104                        if (!par3EntityPlayer.capabilities.isCreativeMode)
    105                        {
    106                            --par1ItemStack.stackSize;
    107                        }
    108                    }
    109
    110                    return par1ItemStack;
    111                }
    112            }
    113        }
    114    }