@Override public void update(Location location) { location.setYaw(yaw); location.setPitch(pitch); }
/** * Read a Location from the "Pos" and "Rotation" children of a tag. * * <p>If "Pos" is absent or invalid, null is returned. * * <p>If "Rotation" is absent or invalid, it is skipped and a location without rotation is * returned. * * @param world The world of the location (see readWorld). * @param tag The tag to read from. * @return The location, or null. */ public static Location listTagsToLocation(World world, CompoundTag tag) { // check for position list final Location[] out = {null}; tag.readDoubleList("Pos", pos -> { if (pos.size() == 3) { Location location = new Location(world, pos.get(0), pos.get(1), pos.get(2)); // check for rotation tag.readFloatList("Rotation", rot -> { if (rot.size() == 2) { location.setYaw(rot.get(0)); location.setPitch(rot.get(1)); } }); out[0] = location; } }); return out[0]; }
@Override public void update(Location location) { location.setX(x); location.setY(y); location.setZ(z); location.setYaw(yaw); location.setPitch(pitch); }
@Override public void end(GlowLivingEntity entity) { Location location = entity.getLocation(); location.setPitch(0); location.setYaw(entity.getHeadYaw()); entity.teleport(location); target = null; }
@Override public void end(GlowLivingEntity entity) { Location location = entity.getLocation(); location.setPitch(0); location.setYaw(entity.getHeadYaw()); entity.teleport(location); target = null; }
/** * Copies this message's position and orientation to a {@link Location}. * * @param location the location to update */ public void update(Location location) { location.setX(x); location.setY(y); location.setZ(z); location.setYaw(yaw); location.setPitch(pitch); } }
/** * Copy the contents of one Location to another. * * @param source The Location to read from. * @param dest The Location to modify. May be null. * @return The dest parameter, modified if not null. */ public static Location copyLocation(Location source, Location dest) { if (dest == null) { return null; } dest.setWorld(source.getWorld()); dest.setX(source.getX()); dest.setY(source.getY()); dest.setZ(source.getZ()); dest.setPitch(source.getPitch()); dest.setYaw(source.getYaw()); return dest; }
location.setPitch(0); location.setYaw(0);
location.setPitch(0.0f);
/** * Open the sign editor interface at the specified location. * * @param loc The location to open the editor at */ public void openSignEditor(Location loc) { signLocation = loc.clone(); signLocation.setX(loc.getBlockX()); signLocation.setY(loc.getBlockY()); signLocation.setZ(loc.getBlockZ()); signLocation.setYaw(0); signLocation.setPitch(0); // Client closes inventory when sign editor is opened if (!GlowInventoryView.isDefault(getOpenInventory())) { closeInventory(); } session.send(new SignEditorMessage(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); }
destination.setPitch(entityLocation.getPitch()); destination.setYaw(entityLocation.getYaw());
private void recalculateLocation() { BlockFace rightFace = getRightFace(); double modX = rightFace.getModX() * art.getBlockWidth() / 2.0; double modY = art.getBlockHeight() / 2.0; double modZ = rightFace.getModZ() * art.getBlockWidth() / 2.0; BlockFace facing = getFacing(); if (modX == 0.0) { modX = 0.5 - facing.getModX() * 0.5 - PAINTING_DEPTH / 2; } else if (modZ == 0.0) { modZ = 0.5 - facing.getModZ() * 0.5 - PAINTING_DEPTH / 2; } Location add = getTopLeftCorner().add(modX, -modY, modZ); location.setX(add.getX()); location.setY(add.getY()); location.setZ(add.getZ()); location.setPitch(0); location.setYaw(getYaw()); }
} else { targetLocation.setYaw(target.getLocation().getYaw()); targetLocation.setPitch(target.getLocation().getPitch());
default Location faceLocation(Location from, Location at) { Vector direction = from.toVector().subtract(at.toVector()).normalize(); Location newLocation = from.clone(); newLocation.setYaw(180 - (float) Math.toDegrees(Math.atan2(direction.getX(), direction.getZ()))); newLocation.setPitch(90 - (float) Math.toDegrees(Math.acos(direction.getY()))); return newLocation; }
public Location getLocation() { Location loc = world.getSpawnLocation(); loc.setPitch(getPitch()); loc.setYaw(getYaw()); return loc; }
@Override public void execute(CommandSender sender, String label, String[] args) throws CommandException { Player player = CommandValidator.getPlayerSender(sender); NamedHologram hologram = NamedHologramManager.getHologram(args[0].toLowerCase()); CommandValidator.notNull(hologram, Strings.noSuchHologram(args[0].toLowerCase())); Location loc = hologram.getLocation(); loc.setPitch(90); player.teleport(loc, TeleportCause.PLUGIN); player.sendMessage(Colors.PRIMARY + "You were teleported to the hologram named '" + hologram.getName() + "'."); }
@EventHandler public void onPlayerInteractBlockTeleport(PlayerInteractEvent event) { Player player = event.getPlayer(); //Null check isn't necessary anymore, an empty item will have Material.AIR and getTargetBlock() now also works if no target block is found if (player.getItemInHand().getType() == Material.BONE) { Location playerLoc = player.getLocation(); //Get the player's location Location target = player.getTargetBlock((Set) null, 200).getLocation().clone().add(0, 1, 0); //Get the block location + 1 y target.setYaw(playerLoc.getYaw()); //Set the yaw of the target location to the player's yaw target.setPitch(playerLoc.getPitch()); //Set the pitch of the target location to the player's pitch player.teleport(target); //Teleport player player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 10, 1); //Play sound } }
protected void teleportTo(Entity sourceEntity, Entity targetEntity) { Location targetLocation = targetEntity.getLocation(); // Try to place you in front of the other player, and facing them BlockFace targetFacing = getFacing(targetEntity.getLocation()); Location candidate = findPlaceToStand(targetLocation.getBlock().getRelative(targetFacing).getRelative(targetFacing).getLocation(), 4, 4); if (candidate != null) { candidate.setPitch(0); candidate.setYaw(360 - targetLocation.getYaw()); targetLocation = candidate; } sourceEntity.teleport(targetLocation); }
public static void fireworkParticleShower(Player player, Color color) { Location location = player.getLocation(); location.setY(location.getY() + (player.isInsideVehicle() ? 1.0 : -1.0)); location.setPitch(-90); Firework firework = (Firework) player.getWorld().spawnEntity(location, EntityType.FIREWORK); firework.setMetadata(mcMMO.funfettiMetadataKey, new FixedMetadataValue(mcMMO.p, null)); FireworkMeta fireworkMeta = firework.getFireworkMeta(); FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(color).with((Config.getInstance().getLargeFireworks() ? Type.BALL_LARGE : Type.BALL)).trail(true).build(); fireworkMeta.addEffect(effect); fireworkMeta.addEffect(effect); fireworkMeta.setPower(0); firework.setFireworkMeta(fireworkMeta); }
public static Location lerp(Location loc1, Location loc2, double stage) { Location newloc = new Location(loc1.getWorld(), 0, 0, 0); newloc.setX(lerp(loc1.getX(), loc2.getX(), stage)); newloc.setY(lerp(loc1.getY(), loc2.getY(), stage)); newloc.setZ(lerp(loc1.getZ(), loc2.getZ(), stage)); newloc.setYaw((float) lerp(loc1.getYaw(), loc2.getYaw(), stage)); newloc.setPitch((float) lerp(loc1.getPitch(), loc2.getPitch(), stage)); return newloc; }