| 1 | package net.minecraft.item;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.creativetab.CreativeTabs;
|
| 5 | import net.minecraft.entity.Entity;
|
| 6 | import net.minecraft.entity.item.EntityBoat;
|
| 7 | import net.minecraft.entity.player.EntityPlayer;
|
| 8 | import net.minecraft.init.Blocks;
|
| 9 | import net.minecraft.stats.StatList;
|
| 10 | import net.minecraft.util.AxisAlignedBB;
|
| 11 | import net.minecraft.util.BlockPos;
|
| 12 | import net.minecraft.util.MathHelper;
|
| 13 | import net.minecraft.util.MovingObjectPosition;
|
| 14 | import net.minecraft.util.Vec3;
|
| 15 | import net.minecraft.world.World;
|
| 16 |
|
| 17 | public class ItemBoat extends Item
|
| 18 | {
|
| 19 | public ItemBoat()
|
| 20 | {
|
| 21 | this.maxStackSize = 1;
|
| 22 | this.setCreativeTab(CreativeTabs.tabTransport);
|
| 23 | }
|
| 24 |
|
| 25 | /**
|
| 26 | * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
| 27 | */
|
| 28 | public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
|
| 29 | {
|
| 30 | float f = 1.0F;
|
| 31 | float f1 = playerIn.prevRotationPitch + (playerIn.rotationPitch - playerIn.prevRotationPitch) * f;
|
| 32 | float f2 = playerIn.prevRotationYaw + (playerIn.rotationYaw - playerIn.prevRotationYaw) * f;
|
| 33 | double d0 = playerIn.prevPosX + (playerIn.posX - playerIn.prevPosX) * (double)f;
|
| 34 | double d1 = playerIn.prevPosY + (playerIn.posY - playerIn.prevPosY) * (double)f + (double)playerIn.getEyeHeight();
|
| 35 | double d2 = playerIn.prevPosZ + (playerIn.posZ - playerIn.prevPosZ) * (double)f;
|
| 36 | Vec3 vec3 = new Vec3(d0, d1, d2);
|
| 37 | float f3 = MathHelper.cos(-f2 * 0.017453292F - (float)Math.PI);
|
| 38 | float f4 = MathHelper.sin(-f2 * 0.017453292F - (float)Math.PI);
|
| 39 | float f5 = -MathHelper.cos(-f1 * 0.017453292F);
|
| 40 | float f6 = MathHelper.sin(-f1 * 0.017453292F);
|
| 41 | float f7 = f4 * f5;
|
| 42 | float f8 = f3 * f5;
|
| 43 | double d3 = 5.0D;
|
| 44 | Vec3 vec31 = vec3.addVector((double)f7 * d3, (double)f6 * d3, (double)f8 * d3);
|
| 45 | MovingObjectPosition movingobjectposition = worldIn.rayTraceBlocks(vec3, vec31, true);
|
| 46 |
|
| 47 | if (movingobjectposition == null)
|
| 48 | {
|
| 49 | return itemStackIn;
|
| 50 | }
|
| 51 | else
|
| 52 | {
|
| 53 | Vec3 vec32 = playerIn.getLook(f);
|
| 54 | boolean flag = false;
|
| 55 | float f9 = 1.0F;
|
| 56 | List<Entity> list = worldIn.getEntitiesWithinAABBExcludingEntity(playerIn, playerIn.getEntityBoundingBox().addCoord(vec32.xCoord * d3, vec32.yCoord * d3, vec32.zCoord * d3).expand((double)f9, (double)f9, (double)f9));
|
| 57 |
|
| 58 | for (int i = 0; i < list.size(); ++i)
|
| 59 | {
|
| 60 | Entity entity = (Entity)list.get(i);
|
| 61 |
|
| 62 | if (entity.canBeCollidedWith())
|
| 63 | {
|
| 64 | float f10 = entity.getCollisionBorderSize();
|
| 65 | AxisAlignedBB axisalignedbb = entity.getEntityBoundingBox().expand((double)f10, (double)f10, (double)f10);
|
| 66 |
|
| 67 | if (axisalignedbb.isVecInside(vec3))
|
| 68 | {
|
| 69 | flag = true;
|
| 70 | }
|
| 71 | }
|
| 72 | }
|
| 73 |
|
| 74 | if (flag)
|
| 75 | {
|
| 76 | return itemStackIn;
|
| 77 | }
|
| 78 | else
|
| 79 | {
|
| 80 | if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
|
| 81 | {
|
| 82 | BlockPos blockpos = movingobjectposition.getBlockPos();
|
| 83 |
|
| 84 | if (worldIn.getBlockState(blockpos).getBlock() == Blocks.snow_layer)
|
| 85 | {
|
| 86 | blockpos = blockpos.down();
|
| 87 | }
|
| 88 |
|
| 89 | EntityBoat entityboat = new EntityBoat(worldIn, (double)((float)blockpos.getX() + 0.5F), (double)((float)blockpos.getY() + 1.0F), (double)((float)blockpos.getZ() + 0.5F));
|
| 90 | entityboat.rotationYaw = (float)(((MathHelper.floor_double((double)(playerIn.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) - 1) * 90);
|
| 91 |
|
| 92 | if (!worldIn.getCollidingBoundingBoxes(entityboat, entityboat.getEntityBoundingBox().expand(-0.1D, -0.1D, -0.1D)).isEmpty())
|
| 93 | {
|
| 94 | return itemStackIn;
|
| 95 | }
|
| 96 |
|
| 97 | if (!worldIn.isRemote)
|
| 98 | {
|
| 99 | worldIn.spawnEntityInWorld(entityboat);
|
| 100 | }
|
| 101 |
|
| 102 | if (!playerIn.capabilities.isCreativeMode)
|
| 103 | {
|
| 104 | --itemStackIn.stackSize;
|
| 105 | }
|
| 106 |
|
| 107 | playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
|
| 108 | }
|
| 109 |
|
| 110 | return itemStackIn;
|
| 111 | }
|
| 112 | }
|
| 113 | }
|
| 114 | }
|
| 115 |
|