org.bukkit.entity.Player#getEyeLocation ( )源码实例Demo

下面列出了org.bukkit.entity.Player#getEyeLocation ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: uSkyBlock   文件: NetherTerraFormEvents.java
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    if (event == null || !terraformEnabled) {
        return;
    }
    Block block = event.getBlock();
    Player player = event.getPlayer();
    if (!plugin.getWorldManager().isSkyNether(block.getWorld()) || !plugin.getWorldManager().isSkyNether(player.getWorld())) {
        return; // Bail out, not our problem
    }
    if (player.getGameMode() != GameMode.SURVIVAL) {
        return;
    }
    if (!plugin.playerIsOnIsland(player)) {
        return;
    }
    if (!terraFormMap.containsKey(block.getType())) {
        return; // Not a block we terra-form on.
    }
    // TODO: 10/07/2016 - R4zorax: Handle dual-wielding (would break 1.8 compatibility)
    ItemStack tool = event.getPlayer().getItemInHand();
    if (event.getBlock().getDrops(tool).isEmpty()) {
        return; // Only terra-form when stuff is mined correctly
    }
    double toolWeight = getToolWeight(tool);
    Location playerLocation = player.getEyeLocation();
    Location blockLocation = LocationUtil.centerInBlock(block.getLocation());
    Vector v = new Vector(blockLocation.getX(), blockLocation.getY(), blockLocation.getZ());
    v.subtract(new Vector(playerLocation.getX(), playerLocation.getY(), playerLocation.getZ()));
    v.normalize();
    // Disable spawning above the player... enabling the player to clear a region
    if (playerLocation.getPitch() >= minPitch && playerLocation.getPitch() <= maxPitch) {
        ProtectedCuboidRegion islandRegion = WorldGuardHandler.getIslandRegion(playerLocation);
        List<Material> yield = getYield(block.getType(), toolWeight);
        for (Material mat : yield) {
            spawnBlock(mat, blockLocation, v, islandRegion);
        }
    }
}
 
源代码2 项目: NBTEditor   文件: GenericBomb.java
@Override
public final void onLeftClick(PlayerInteractEvent event, PlayerDetails details) {
	details.consumeItem();
	Player player = event.getPlayer();
	Location loc = player.getEyeLocation();
	trigger(createItem(loc, loc.getDirection()));
	event.setCancelled(true);
}
 
源代码3 项目: AACAdditionPro   文件: VectorUtils.java
/**
 * @return an array of {@link Vector}s which represent the 3 different camera modes in minecraft, 1st person and the two
 * 3rd person views with the following indices: <br>
 * [0] = normal (eyeposition vector) <br>
 * [1] = front <br>
 * [2] = behind <br>
 */
public static Vector[] getCameraVectors(final Player player)
{
    /*
        All the vectors
        [0] = normal (eyeposition vector)
        [1] = front
        [2] = behind
    */
    final Vector[] vectors = new Vector[3];

    // Front vector : The 3rd person perspective in front of the player
    // Use THIRD_PERSON_OFFSET to get the maximum positions
    // No cloning or normalizing as a new unit-vector instance is returned.
    vectors[1] = player.getLocation().getDirection().multiply(THIRD_PERSON_OFFSET);

    // Behind vector : The 3rd person perspective behind the player
    vectors[2] = vectors[1].clone().multiply(-1);

    final Location eyeLocation = player.getEyeLocation();

    // Normal
    vectors[0] = eyeLocation.toVector();

    // Do the Cameras intersect with Blocks
    // Get the length of the first intersection or 0 if there is none

    // [0] = frontIntersection
    // [1] = behindIntersection
    final double[] intersections = new double[]{
            VectorUtils.getDistanceToFirstIntersectionWithBlock(eyeLocation, vectors[1]),
            VectorUtils.getDistanceToFirstIntersectionWithBlock(eyeLocation, vectors[2])
    };

    for (int i = 0; i < intersections.length; i++) {
        // There is an intersection
        if (intersections[i] != 0) {
            // Now we need to make sure the vectors are not inside of blocks as the method above returns.
            // The 0.05 factor makes sure that we are outside of the block and not on the edge.
            intersections[i] -= 0.05 +
                                // Calculate the distance to the middle of the block
                                (0.5 / Math.sin(vectors[i + 1].angle(vectors[i + 1].clone().setY(0))));

            // Add the correct position.
            vectors[i + 1].normalize().multiply(intersections[i]);
        }

        // Add the eye location for a correct starting point.
        vectors[i + 1].add(vectors[0]);
    }
    return vectors;
}
 
源代码4 项目: Shopkeepers   文件: Utils.java
/**
 * Determines the exact intersection point of a players view and a targeted block.
 * 
 * @param player
 *            the player
 * @param targetBlock
 *            the block the player is looking at
 * @return the intersection point of the players view and the target block,
 *         or null if no intersection was found
 */
public static Location getBlockIntersection(Player player, Block targetBlock) {
	if (player == null || targetBlock == null) return null;

	// block bounds:
	double minX = targetBlock.getX();
	double minY = targetBlock.getY();
	double minZ = targetBlock.getZ();

	double maxX = minX + 1.0D;
	double maxY = minY + 1.0D;
	double maxZ = minZ + 1.0D;

	// ray origin:
	Location origin = player.getEyeLocation();
	double originX = origin.getX();
	double originY = origin.getY();
	double originZ = origin.getZ();

	// ray direction
	Vector dir = origin.getDirection();
	double dirX = dir.getX();
	double dirY = dir.getY();
	double dirZ = dir.getZ();

	// tiny improvement to save a few divisions below:
	double divX = 1.0D / dirX;
	double divY = 1.0D / dirY;
	double divZ = 1.0D / dirZ;

	// intersection interval:
	double t0 = 0.0D;
	double t1 = Double.MAX_VALUE;

	double tmin;
	double tmax;

	double tymin;
	double tymax;

	double tzmin;
	double tzmax;

	if (dirX >= 0.0D) {
		tmin = (minX - originX) * divX;
		tmax = (maxX - originX) * divX;
	} else {
		tmin = (maxX - originX) * divX;
		tmax = (minX - originX) * divX;
	}

	if (dirY >= 0.0D) {
		tymin = (minY - originY) * divY;
		tymax = (maxY - originY) * divY;
	} else {
		tymin = (maxY - originY) * divY;
		tymax = (minY - originY) * divY;
	}

	if ((tmin > tymax) || (tymin > tmax)) {
		return null;
	}

	if (tymin > tmin) tmin = tymin;
	if (tymax < tmax) tmax = tymax;

	if (dirZ >= 0.0D) {
		tzmin = (minZ - originZ) * divZ;
		tzmax = (maxZ - originZ) * divZ;
	} else {
		tzmin = (maxZ - originZ) * divZ;
		tzmax = (minZ - originZ) * divZ;
	}

	if ((tmin > tzmax) || (tzmin > tmax)) {
		return null;
	}

	if (tzmin > tmin) tmin = tzmin;
	if (tzmax < tmax) tmax = tzmax;

	if ((tmin >= t1) || (tmax <= t0)) {
		return null;
	}

	// intersection:
	Location intersection = origin.add(dir.multiply(tmin));
	return intersection;
}
 
源代码5 项目: XSeries   文件: XParticle.java
/**
 * Draws a line from the player's looking direction.
 *
 * @param player the player to draw the line from.
 * @param length the length of the line.
 * @param rate   the rate of points of the line.
 * @see #line(Location, Location, double, ParticleDisplay)
 * @since 1.0.0
 */
public static void drawLine(Player player, double length, double rate, ParticleDisplay display) {
    Location eye = player.getEyeLocation();
    line(eye, eye.clone().add(eye.getDirection().multiply(length)), rate, display);
}