Edit

Share via


@minecraft/server-editor Module

Caution

This module is still in pre-release. It may change or it may be removed in future releases.

Changelog

Manifest Details

{
    "module_name": "@minecraft/server-editor",
    "version": "0.1.0-beta"
}

This is version 0.x.x of this module, which is the latest as of version 1.21.100-beta.23 of Minecraft.

Available Versions

  • 0.1.0-beta

Enumerations

Type Aliases

Classes

Interfaces

Errors

Functions

deserialize

deserialize(s: string): unknown

Deserialize anything, defaults to the same behavior as JSON.parse but will use custom deserializers passed into {@link registerSerializationForType}.

Parameters

  • s: string

Returns unknown

executeLargeOperation

executeLargeOperation(volume: RelativeVolumeListBlockVolume, operation: (blockLocation: minecraftserver.Vector3) => void): Promise<void>

Executes an operation over a selection via chunks to allow splitting operation over multiple game ticks

Parameters

  • volume: RelativeVolumeListBlockVolume

  • operation: (blockLocation: minecraftserver.Vector3) => void

    the operation to apply over each block location

Returns Promise<void>

executeLargeOperationFromIterator

executeLargeOperationFromIterator(blockLocationIterator: minecraftserver.BlockLocationIterator, operation: (blockLocation: minecraftserver.Vector3) => void): Promise<void>

Executes an operation over a BlockLocationIterator via chunks to allow splitting operation over multiple game ticks

Parameters

  • blockLocationIterator: minecraftserver.BlockLocationIterator

    the selection to iterator over

  • operation: (blockLocation: minecraftserver.Vector3) => void

    the operation to apply over each block location

Returns Promise<void>

getDefaultAllowBlockList

getDefaultAllowBlockList(): string[]

Returns a string array of the default block types for editor operations. Can be used to further filter blocks. This will throw if called in early execution.

Returns string[] - Default allowed block list

getDefaultBrushShapes

getDefaultBrushShapes(excludeList: CoreBrushShapeType[]): BrushShape[]

Returns a list of default core brush shapes

Parameters

  • excludeList: CoreBrushShapeType[]

    List of shape types to exclude

Returns BrushShape[]

makeObservable

makeObservable(initialValue: T, validator: ObservableValidator<T>): IObservable<T>

Creates an observable object that stores a value state.

Parameters

  • initialValue: T

    Initial value of the observable.

  • validator: ObservableValidator<T>

    Optional validator to use for the setter.

Returns IObservable<T>

registerEditorExtension

registerEditorExtension(extensionName: string, activationFunction: ActivationFunctionType<PerPlayerStorageType>, shutdownFunction: ShutdownFunctionType<PerPlayerStorageType>, options: IRegisterExtensionOptionalParameters): Extension

Registers an editor extension into Minecraft. This function calls underlying functionality to register an extension but provides helpful and contextual wrappers for individual client lifetimes. The onActivation function is called whenever a client joins a session, while the shutdown is called when a client leaves. There may be other circumstances in which these are called as well based on client state that is an implementation detail of the system.

Parameters

  • extensionName: string
  • activationFunction: ActivationFunctionType<PerPlayerStorageType>
  • shutdownFunction: ShutdownFunctionType<PerPlayerStorageType>
  • options: IRegisterExtensionOptionalParameters

Returns Extension

registerSerializationForType

registerSerializationForType(typeConstructor: Function, name: string, serializer: (obj: T) => Record<string, unknown>, deserializer: (vals: Record<string, unknown>) => T): void

Register a type to have custom serialization/deserialization when using {@link serialize} and {@link deserialize}.

Parameters

  • typeConstructor: Function
  • name: string
  • serializer: (obj: T) => Record<string, unknown>
  • deserializer: (vals: Record<string, unknown>) => T

Returns void

registerUserDefinedTransactionHandler

registerUserDefinedTransactionHandler(transactionManager: TransactionManager, undoHandler: (payload: T) => void, redoHandler: (payload: T) => void): UserDefinedTransactionHandle<T>

Creates a strongly typed transaction handle to enforce type safety when adding user defined transactions. This function is a wrapper around the more generalized transaction manager API for script based transactions. Any Editor Extension that needs to insert data into the transaction log for undo/redo should use this function to create a handler for the specific type of data that needs to be inserted. When a transaction is undone/redone, the associated handler function will be invoked with a copy of the payload data that was inserted into the log. As a general rule, transaction data should contain 2 things:
1. The data that will be used to perform the operation we're trying to record
2. The data that will be used to restore the state of the program to what it was before the operation.
NOTE/WARNING:
The payload data is serialized to JSON before being inserted into the transaction log and the underlying implementation uses the JSON.stringify() function to serialize the data. Any non-primitive data, such as classes or minecraft native objects will not serialize to JSON properly, so you should avoid using them as payload data.

Parameters

  • transactionManager: TransactionManager

    A reference to the TransactionManager (from the extension context for your extension)

  • undoHandler: (payload: T) => void

    A function that will be invoked when the transaction is undone. The function will be passed a copy of the payload data that was inserted into the transaction log.

  • redoHandler: (payload: T) => void

    A function that will be invoked when the transaction is redone. The function will be passed a copy of the payload data that was inserted into the transaction log.

Returns UserDefinedTransactionHandle<T> - - {@link UserDefinedTransactionHandle} - A strongly typed transaction handle that can be used to add transactions to the transaction manager.

serialize

serialize(obj: unknown): string

Serialize anything, defaults to the same behavior as JSON.stringify but will use custom serializers passed into {@link registerSerializationForType}.

Parameters

  • obj: unknown

Returns string

stringFromException

stringFromException(e: unknown): string

Small utility for getting a string from an unknown exception type

Parameters

  • e: unknown

Returns string

Objects

editor

static read-only editor: MinecraftEditor;

Type: MinecraftEditor

Dependencies