For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /server/classes/LocatorBar.md.

Class: LocatorBar

Beta

管理玩家定位栏上显示的路径点集合。允许添加、移除和查询路径点,具有最大容量限制。

定位栏中的无效路径点将在下一个游戏刻自动移除。这包括与已从世界中移除的实体绑定的路径点。

注意:你可以使用 playerWaypoints GameRule 控制是否自动将玩家路径点添加到定位栏。接受的值有 off(玩家不显示在定位栏上)和 everyone(所有玩家在定位栏上可见)。

注意:你只能修改、移除或查询由此包添加的路径点。

Manages the collection of waypoints displayed on a player's locator bar. Allows adding, removing, and querying waypoints with a maximum capacity limit.

Invalid waypoints in the locator bar will be automatically removed in the next tick. This includes waypoints tied to entities that have been removed from the world.

Note: You can control whether vanilla player waypoints are automatically added to the locator bar using the playerWaypoints GameRule. Accepted values are off (players are not shown on the locator bar) and everyone (all players are visible on the locator bar).

Note: You can only modify, remove, or query waypoints that were added by this pack.

Example

sharedWaypoint.ts

/*
import { world, LocationWaypoint, WaypointTextureSelector, WaypointTexture } from "@minecraft/server"

function sharedWaypoint() {
  const players = world.getAllPlayers();

  if (players.length < 2) {
    console.warn("Need at least 2 players for this example.");
    return;
  }

  const playerA = players[0];
  const playerB = players[1];

  // Create a single waypoint at a specific location
  const textureSelector: WaypointTextureSelector = {
    textureBoundsList: [
      { lowerBound: 0, texture: WaypointTexture.Circle }
    ]
  };

  const waypoint = new LocationWaypoint(
    { dimension: playerA.dimension, x: 100, y: 64, z: 100 },
    textureSelector,
    { red: 1, green: 0, blue: 0 } // Initially red
  );

  // Add the same waypoint to both players' locator bars
  playerA.locatorBar.addWaypoint(waypoint);
  playerB.locatorBar.addWaypoint(waypoint);

  // Change the color - this affects both players
  waypoint.color = { red: 0, green: 1, blue: 0 }; // Now green for both players
}
*/

Properties

count

readonly count: number

Beta

Remarks

定位栏中当前的路径点数量。

The current number of waypoints in the locator bar.


maxCount

readonly maxCount: number

Beta

Remarks

可以添加到定位栏的最大路径点数量。

The maximum number of waypoints that can be added to the locator bar.

Methods

addWaypoint()

addWaypoint(waypoint): void

World Mutation Beta

Parameters

waypoint

Waypoint

要添加到定位栏的 Waypoint

The Waypoint to add to the locator bar.

Returns

void

Remarks

将路径点添加到定位栏。如果路径点已存在、已达到最大路径点限制或路径点无效,则抛出错误。

Adds a waypoint to the locator bar. Throws an error if the waypoint already exists, the maximum waypoint limit has been reached, or the waypoint is invalid.

Throws

This function can throw errors.

EngineError

InvalidWaypointError

LocatorBarError


getAllWaypoints()

getAllWaypoints(): Waypoint[]

World Mutation Beta

Returns

Waypoint[]

Remarks

返回当前定位栏中所有路径点的数组。

Returns an array of all waypoints currently in the locator bar.


hasWaypoint()

hasWaypoint(waypoint): boolean

World Mutation Beta

Parameters

waypoint

Waypoint

要检查的 Waypoint

The Waypoint to check for.

Returns

boolean

Remarks

检查指定的路径点是否存在于定位栏中。

Checks whether the specified waypoint exists in the locator bar.


removeAllWaypoints()

removeAllWaypoints(): void

World Mutation Beta

Returns

void

Remarks

从定位栏中移除所有路径点,将其完全清空。

Removes all waypoints from the locator bar, clearing it completely.

Throws

This function can throw errors.

EngineError


removeWaypoint()

removeWaypoint(waypoint): void

World Mutation Beta

Parameters

waypoint

Waypoint

要从定位栏中移除的 Waypoint

The Waypoint to remove from the locator bar.

Returns

void

Remarks

从定位栏中移除指定路径点。如果路径点不存在于定位栏中,则返回错误。

Removes a specific waypoint from the locator bar. Returns an error if the waypoint does not exist in the locator bar.

Throws

This function can throw errors.

EngineError

LocatorBarError