    001package net.minecraft.item;
    002
    003import java.util.List;
    004import net.minecraft.block.Block;
    005import net.minecraft.creativetab.CreativeTabs;
    006import net.minecraft.entity.Entity;
    007import net.minecraft.entity.item.EntityBoat;
    008import net.minecraft.entity.player.EntityPlayer;
    009import net.minecraft.util.AxisAlignedBB;
    010import net.minecraft.util.EnumMovingObjectType;
    011import net.minecraft.util.MathHelper;
    012import net.minecraft.util.MovingObjectPosition;
    013import net.minecraft.util.Vec3;
    014import net.minecraft.world.World;
    015
    016public 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 f = 1.0F;
    031        float f1 = par3EntityPlayer.prevRotationPitch + (par3EntityPlayer.rotationPitch - par3EntityPlayer.prevRotationPitch) * f;
    032        float f2 = par3EntityPlayer.prevRotationYaw + (par3EntityPlayer.rotationYaw - par3EntityPlayer.prevRotationYaw) * f;
    033        double d0 = par3EntityPlayer.prevPosX + (par3EntityPlayer.posX - par3EntityPlayer.prevPosX) * (double)f;
    034        double d1 = par3EntityPlayer.prevPosY + (par3EntityPlayer.posY - par3EntityPlayer.prevPosY) * (double)f + 1.62D - (double)par3EntityPlayer.yOffset;
    035        double d2 = par3EntityPlayer.prevPosZ + (par3EntityPlayer.posZ - par3EntityPlayer.prevPosZ) * (double)f;
    036        Vec3 vec3 = par2World.getWorldVec3Pool().getVecFromPool(d0, d1, d2);
    037        float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
    038        float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
    039        float f5 = -MathHelper.cos(-f1 * 0.017453292F);
    040        float f6 = MathHelper.sin(-f1 * 0.017453292F);
    041        float f7 = f4 * f5;
    042        float f8 = f3 * f5;
    043        double d3 = 5.0D;
    044        Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
    045        MovingObjectPosition movingobjectposition = par2World.rayTraceBlocks_do(vec3, vec31, true);
    046
    047        if (movingobjectposition == null)
    048        {
    049            return par1ItemStack;
    050        }
    051        else
    052        {
    053            Vec3 vec32 = par3EntityPlayer.getLook(f);
    054            boolean flag = false;
    055            float f9 = 1.0F;
    056            List list = par2World.getEntitiesWithinAABBExcludingEntity(par3EntityPlayer, par3EntityPlayer.boundingBox.addCoord(vec32.xCoord * d3, vec32.yCoord * d3, vec32.zCoord * d3).expand((double)f9, (double)f9, (double)f9));
    057            int i;
    058
    059            for (i = 0; i < list.size(); ++i)
    060            {
    061                Entity entity = (Entity)list.get(i);
    062
    063                if (entity.canBeCollidedWith())
    064                {
    065                    float f10 = entity.getCollisionBorderSize();
    066                    AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double)f10, (double)f10, (double)f10);
    067
    068                    if (axisalignedbb.isVecInside(vec3))
    069                    {
    070                        flag = true;
    071                    }
    072                }
    073            }
    074
    075            if (flag)
    076            {
    077                return par1ItemStack;
    078            }
    079            else
    080            {
    081                if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
    082                {
    083                    i = movingobjectposition.blockX;
    084                    int j = movingobjectposition.blockY;
    085                    int k = movingobjectposition.blockZ;
    086
    087                    if (par2World.getBlockId(i, j, k) == Block.snow.blockID)
    088                    {
    089                        --j;
    090                    }
    091
    092                    EntityBoat entityboat = new EntityBoat(par2World, (double)((float)i + 0.5F), (double)((float)j + 1.0F), (double)((float)k + 0.5F));
    093                    entityboat.rotationYaw = (float)(((MathHelper.floor_double((double)(par3EntityPlayer.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) - 1) * 90);
    094
    095                    if (!par2World.getCollidingBoundingBoxes(entityboat, entityboat.boundingBox.expand(-0.1D, -0.1D, -0.1D)).isEmpty())
    096                    {
    097                        return par1ItemStack;
    098                    }
    099
    100                    if (!par2World.isRemote)
    101                    {
    102                        par2World.spawnEntityInWorld(entityboat);
    103                    }
    104
    105                    if (!par3EntityPlayer.capabilities.isCreativeMode)
    106                    {
    107                        --par1ItemStack.stackSize;
    108                    }
    109                }
    110
    111                return par1ItemStack;
    112            }
    113        }
    114    }
    115}