@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
161 lines (160 loc) • 6.37 kB
TypeScript
import CreatorTools, { CreatorToolsMinecraftErrorStatus, CreatorToolsMinecraftState } from "./CreatorTools";
import { CreatorToolsServerStatus, ISlotConfig } from "./CreatorToolsAuthentication";
import IMinecraft, { IMinecraftMessage, IPrepareAndStartResult } from "./IMinecraft";
import Project from "./Project";
import MinecraftPush from "./MinecraftPush";
import GameStateManager from "../minecraft/GameStateManager";
import IFolder from "../storage/IFolder";
import IStorage from "../storage/IStorage";
import IActionSetData from "../actions/IActionSetData";
export default class RemoteMinecraft implements IMinecraft {
private _creatorTools;
state: CreatorToolsMinecraftState;
private _project;
private _lastFullPush;
private _onStateChanged;
private _gameStateManager;
private _nextPollInterval;
private _pollIntervalCount;
private _webSocket;
private _useWebSocket;
private _wsReconnectTimer;
errorStatus?: CreatorToolsMinecraftErrorStatus;
errorMessage?: string;
/**
* Configuration metadata for the slot, received once at connection time.
* Contains flags like debuggerEnabled and debuggerStreamingEnabled that
* inform the UI about what features are available.
*/
slotConfig?: ISlotConfig;
worldFolder: IFolder | undefined;
projectFolder: IFolder | undefined;
worldContentStorage: IStorage | undefined;
worldProject: Project | undefined;
/**
* Map of connected player names to their info (position, xuid, etc.)
* Updated when playerJoined/playerLeft/playerMoved events are received via WebSocket.
*/
private _connectedPlayers;
private _onPlayersChanged;
private messagesReceived;
private _onWorldStorageReady;
private _onProjectStorageReady;
private _onMessage;
private _onWorldContentChanged;
/**
* Event fired when the MCT server sends a shutdown notification.
* This indicates the entire server is shutting down (not just a BDS instance).
* Args: { reason: string, graceful: boolean }
*/
private _onServerShutdown;
get onWorldFolderReady(): import("ste-events").IEvent<IMinecraft, IFolder>;
get onProjectFolderReady(): import("ste-events").IEvent<IMinecraft, IFolder>;
get onMessage(): import("ste-events").IEvent<IMinecraft, IMinecraftMessage>;
/**
* Event fired when world content files change on the server.
* This allows the WorldView component to refresh its data.
*/
get onWorldContentChanged(): import("ste-events").IEvent<IMinecraft, {
eventName: string;
category: string;
path: string;
slot: number;
}>;
/**
* Event fired when the connected players list changes (join/leave).
* Returns array of player names currently connected.
*/
get onPlayersChanged(): import("ste-events").IEvent<IMinecraft, string[]>;
/**
* Event fired when the MCT server is shutting down.
* Subscribers should show appropriate UI feedback (e.g., banner message)
* and understand the connection will be lost.
*/
get onServerShutdown(): import("ste-events").IEvent<IMinecraft, {
reason: string;
graceful: boolean;
}>;
/**
* Get array of currently connected player names.
*/
get connectedPlayerNames(): string[];
/**
* Get detailed info for all connected players.
*/
get connectedPlayers(): Array<{
name: string;
xuid?: string;
position?: {
x: number;
y: number;
z: number;
};
dimension?: string;
}>;
get canDeployFiles(): boolean;
get activeProject(): Project | undefined;
set activeProject(newProject: Project | undefined);
get gameStateManager(): GameStateManager;
get onStateChanged(): import("ste-events").IEvent<IMinecraft, CreatorToolsMinecraftState>;
get onRefreshed(): import("ste-events").IEvent<IMinecraft, CreatorToolsMinecraftState>;
canPrepare(): boolean;
constructor(creatorTools: CreatorTools);
updateStatus(): Promise<CreatorToolsMinecraftState>;
setState(newState: CreatorToolsMinecraftState): void;
processExternalMessage(command: string, data: string): void;
prepare(force?: boolean): Promise<void>;
/**
* Initialize the worldContentStorage with an HttpStorage pointing to the server's
* /api/worldContent/{slot}/ endpoint. This provides access to the server's
* behavior_packs, resource_packs, and world folders.
*
* Also establishes a WebSocket connection for real-time file change notifications.
*/
private initWorldContentStorage;
/**
* Initialize the worldFolder from worldContentStorage for WorldDisplay rendering.
* The world folder is at /world/ within the worldContentStorage.
*/
private initWorldFolder;
/**
* Connect to the WebSocket notification endpoint for real-time status updates.
* Falls back to polling if WebSocket connection fails.
*/
private connectWebSocket;
/**
* Handle incoming WebSocket messages for status updates.
*/
private _handleWebSocketMessage;
/**
* Disconnect WebSocket and clean up.
*/
private disconnectWebSocket;
/**
* Start polling for status updates (fallback when WebSocket is unavailable).
*/
private startPolling;
/**
* Lazily create a Project wrapper for the worldContentStorage.
* This allows treating the server's world content as a Project.
*/
ensureWorldProject(): Promise<Project | undefined>;
prepareAndStart(push: MinecraftPush): Promise<IPrepareAndStartResult>;
/**
* Handle upload errors, specifically the EULA_REQUIRED 451 error.
* Returns an error result if EULA is required, otherwise returns undefined
* to let the caller re-throw the error.
*/
private _handleUploadError;
runActionSet(actionSet: IActionSetData): Promise<any>;
runCommand(command: string): Promise<string>;
getBaseApiUrl(): string;
initSession(slot: number): Promise<void>;
syncWithDeployment(): Promise<void>;
stop(): Promise<void>;
restart(): Promise<void>;
processServerStatus(newStatus: CreatorToolsServerStatus): Promise<boolean>;
resetInterval(): void;
doHeartbeat(): Promise<void>;
initialize(): Promise<void>;
}