### Install @minecraft/server-net Module Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_server-net Installs the type definition for the @minecraft/server-net module using npm. This command specifies the exact version to be installed, ensuring compatibility with the project's requirements. ```bash npm i @minecraft/server-net@1.0.0-beta.1.21.130-preview.24 ``` -------------------------------- ### Install @minecraft/server Module using npm Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_server This snippet shows how to install the type definition for the @minecraft/server module using npm. It specifies the exact version to be installed, ensuring compatibility with the project's requirements. ```bash npm i @minecraft/server@2.4.0-rc.1.21.130-preview.24 ``` -------------------------------- ### @minecraft/server-ui Module Overview Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_server-ui This section provides an overview of the @minecraft/server-ui module, including its purpose, main components, and installation instructions. ```APIDOC ## Module @minecraft/server-ui - v2.0.0 The `@minecraft/server-ui` module contains types for expressing simple dialog-based user experiences. * **ActionFormData**: Used for presenting a list of buttons with captions and images to a player. * **MessageFormData**: For simple two-button message experiences (e.g., Yes/No, OK/Cancel). * **ModalFormData**: Allows for a more flexible "questionnaire-style" list of controls for input. ### Installation Install type definition for `@minecraft/server-ui` module using npm: ```bash npm i @minecraft/server-ui@2.0.0 ``` ### Dependencies * **@minecraft/common** (Optional in Manifest Details) * Requires v1.2.0 or above * **@minecraft/server** (Required in Manifest Details) * Requires v2.0.0 or above * **@minecraft/vanilla-data** (Required one of the following in Manifest Details) ### Enumerations * `FormCancelationReason` * `FormRejectReason` ### Classes * `ActionFormData` * `ActionFormResponse` * `FormRejectError` * `FormResponse` * `MessageFormData` * `MessageFormResponse` * `ModalFormData` * `ModalFormResponse` * `UIManager` ### Interfaces * `ModalFormDataDropdownOptions` * `ModalFormDataSliderOptions` * `ModalFormDataTextFieldOptions` * `ModalFormDataToggleOptions` ### Variables * `uiManager` ``` -------------------------------- ### Install @minecraft/vanilla-data using npm Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_vanilla-data This command installs the @minecraft/vanilla-data package, which provides type definitions for vanilla Minecraft content. It is useful for projects requiring up-to-date types for blocks, items, entities, and more. Ensure you have Node.js and npm installed. ```bash npm i @minecraft/vanilla-data@1.21.130-preview.24 ``` -------------------------------- ### Install @minecraft/diagnostics Module with npm Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_diagnostics This command installs the type definition for the '@minecraft/diagnostics' module. It specifies a particular beta version of the module. ```bash npm i @minecraft/diagnostics@1.0.0-beta.1.21.130-preview.24 ``` -------------------------------- ### @minecraft/server-net Module Overview Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_server-net Overview of the @minecraft/server-net module, its purpose, version, dependencies, and installation instructions. ```APIDOC ## Module @minecraft/server-net - v1.0.0-beta The `@minecraft/server-net` module contains types for executing HTTP-based requests. This module can only be used on Bedrock Dedicated Server. These APIs do not function within the Minecraft game client or within Minecraft Realms. ### Manifest Details ```json { "module_name": "@minecraft/server-net", "version": "1.0.0-beta" } ``` ### Dependencies * **@minecraft/common** (Optional) * Requires v1.2.0 or above ```json { "module_name": "@minecraft/common", "version": "1.2.0" } ``` * **@minecraft/server** (Required) * Requires v1.17.0 up to, but not including, v2.0.0 OR v2.0.0 up to, but not including, v3.0.0 ```json { "module_name": "@minecraft/server", "version": "1.17.0" } ``` ```json { "module_name": "@minecraft/server", "version": "2.0.0" } ``` * **@minecraft/vanilla-data** (Required) * **@minecraft/server-admin** (Required) * Requires v1.0.0-beta or above ```json { "module_name": "@minecraft/server-admin", "version": "1.0.0-beta" } ``` ### Installation Install type definition for `@minecraft/server-net` module using npm: ```bash npm i @minecraft/server-net@1.0.0-beta.1.21.130-preview.24 ``` ## Enumerations * `HttpRequestMethod` * `PacketId` ## Classes * `HttpClient` * `HttpHeader` * `HttpRequest` * `HttpResponse` * `InternalHttpRequestError` * `MalformedHttpRequestError` * `NetworkBeforeEvents` * `PacketReceiveBeforeEventSignal` * `PacketReceivedBeforeEvent` * `PacketSendBeforeEvent` * `PacketSendBeforeEventSignal` ## Interfaces * `PacketEventOptions` ## Variables * `beforeEvents` * `http` ``` -------------------------------- ### @minecraft/server-ui Module Documentation Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_server-ui-1 This section details the @minecraft/server-ui module, including its purpose, version, dependencies, and installation instructions. It also lists available enumerations, classes, interfaces, and variables. ```APIDOC ## Module @minecraft/server-ui - v2.1.0-beta ### Description The `@minecraft/server-ui` module contains types for expressing simple dialog-based user experiences. It includes classes for `ActionFormData`, `MessageFormData`, and `ModalFormData` to present options, messages, and questionnaires to players. ### Manifest Details ```json { "module_name": "@minecraft/server-ui", "version": "2.1.0-beta" } ``` ### Dependencies * **@minecraft/common** (Optional) * Requires v1.2.0 or above. ```json { "module_name": "@minecraft/common", "version": "1.2.0" } ``` * **@minecraft/server** (Required) * Requires v2.0.0 up to, but not including, v3.0.0. * OR requires v2.5.0-beta up to, but not including, v3.0.0. ```json { "module_name": "@minecraft/server", "version": "2.0.0" } ``` ```json { "module_name": "@minecraft/server", "version": "2.5.0-beta" } ``` * **@minecraft/vanilla-data** (Required) ### Installation Install the type definition for the `@minecraft/server-ui` module using npm: ```bash npm install @minecraft/server-ui@2.1.0-beta.1.21.130-preview.24 ``` ### Enumerations * `FormCancelationReason` * `FormRejectReason` ### Classes * `ActionFormData` * `ActionFormResponse` * `FormRejectError` * `FormResponse` * `MessageFormData` * `MessageFormResponse` * `ModalFormData` * `ModalFormResponse` * `UIManager` ### Interfaces * `ModalFormDataDropdownOptions` * `ModalFormDataSliderOptions` * `ModalFormDataTextFieldOptions` * `ModalFormDataToggleOptions` ### Variables * `uiManager` ``` -------------------------------- ### Get Entity Components with @minecraft/server Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This example retrieves all components of entities in the overworld and logs the number of components and their type IDs to the console. ```javascript import { world } from "@minecraft/server"; for (const entity of world.getDimension("overworld").getEntities()) { const components = entity.getComponents(); console.log(`Number of components: ${components.length}: ${components.map((component) => component.typeId)}`); } ``` -------------------------------- ### Install @minecraft/common Module - npm command Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_common Installs the type definition for the @minecraft/common module version 1.2.0 using npm. This command ensures that the necessary development tools and libraries are available for projects using this module. ```bash npm i @minecraft/common@1.2.0 ``` -------------------------------- ### Install @minecraft/server-admin Module with npm Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_server-admin Installs the type definition for the '@minecraft/server-admin' module using npm. This command is used to add the server administration capabilities to your project. ```bash npm i @minecraft/server-admin@1.0.0-beta.1.21.130-preview.24 ``` -------------------------------- ### Player Class Overview Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This section provides an overview of the Player class, its inheritance, and common usage examples. ```APIDOC ## Class Player Represents a player within the world. #### Example: ```javascript import { world } from "@minecraft/server"; for (const player of world.getAllPlayers()) { player.sendMessage(`Hello, ${player.name}!`); } ``` #### Hierarchy * Entity * Player * SimulatedPlayer ##### Index ### Constructors constructor ### Properties camera clientSystemInfo commandPermissionLevel dimension graphicsMode id inputInfo inputPermissions isClimbing isEmoting isFalling isFlying isGliding isInWater isJumping isOnGround isSleeping isSneaking isSprinting isSwimming isValid level localizationKey location name nameTag onScreenDisplay playerPermissionLevel scoreboardIdentity? selectedSlotIndex totalXpNeededForNextLevel typeId xpEarnedAtCurrentLevel ### Methods addEffect addExperience addLevels addTag applyDamage applyImpulse applyKnockback clearDynamicProperties clearPropertyOverridesForEntity clearVelocity extinguishFire getAABB getAllBlocksStandingOn getBlockFromViewDirection getBlockStandingOn getComponent getComponents getControlScheme getDynamicProperty getDynamicPropertyIds getDynamicPropertyTotalByteCount getEffect getEffects getEntitiesFromViewDirection getGameMode getHeadLocation getItemCooldown getProperty getRotation getSpawnPoint getTags getTotalXp getVelocity getViewDirection hasComponent hasTag kill lookAt matches playAnimation playMusic playSound queueMusic remove removeEffect removePropertyOverrideForEntity removeTag resetLevel resetProperty runCommand sendMessage setControlScheme setDynamicProperties setDynamicProperty setGameMode setOnFire setProperty setPropertyOverrideForEntity setRotation setSpawnPoint spawnParticle startItemCooldown stopMusic teleport triggerEvent tryTeleport ``` -------------------------------- ### Get Block from View Direction - JavaScript Examples Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server Provides two JavaScript examples demonstrating how to use the `getBlockFromViewDirection` method. The first example iterates through entities to log the block they are looking at, its face, and face location. The second example spawns a fox and attempts to change the block it's looking at to bedrock. ```javascript import { world } from "@minecraft/server"; for (const entity of world.getDimension("overworld").getEntities()) { const blockHit = entity.getBlockFromViewDirection(); if (blockHit) { console.log("Block Hit:"); console.log("Block:", blockHit.block); console.log("Face:", blockHit.face); console.log("Face Location:", JSON.stringify(blockHit.faceLocation)); } else { console.log("No block in view direction."); } } ``` ```javascript import { BlockPermutation, world } from "@minecraft/server"; const entity = world.getDimension("overworld").spawnEntity("minecraft:fox", { x: 0, y: 0, z: 0 }); const blockHit = entity.getBlockFromViewDirection(); if (blockHit) { blockHit.block.setPermutation(BlockPermutation.resolve("minecraft:bedrock")); } else { console.log("No block in view direction."); } ``` -------------------------------- ### setHorizonBlendStart Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-graphics Configures the starting blend value for horizon scattering, influencing the transition of scattering effects across the sky. This setting is biome-specific. ```APIDOC ## setHorizonBlendStart ### Description Sets the horizon blend start for atmospheric scattering in Vibrant Visuals. ### Method `setHorizonBlendStart` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **blendStart** (number | Record) - Required - Either a number (range [0,1]) or a set of keyframes. The keyframes are composed of key value pairs. The key is a number (range [0,1]) to signify a time of day (0.0 and 1.0 are noon, 0.25 is sunset, 0.5 is midnight, and 0.75 is sunrise). The value is also a number (range [0,1]). * **biomeIdentifier** (BiomeType) - Required - Biome Identifier. The horizon blend start will be set for the specified biome. ### Request Example ```json { "blendStart": 0.3, "biomeIdentifier": "DESERT" } ``` ### Response #### Success Response (void) This function does not return a value. #### Response Example None #### Remarks This function can't be called in read-only mode. #### Throws * `minecraftcommon.InvalidArgumentError` ``` -------------------------------- ### Play Music and Sounds in Minecraft with TypeScript Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This TypeScript example demonstrates how to play music and various sounds in Minecraft using the Script API. It includes options for music looping, fading, volume, and sound pitch, and shows how to play sounds at specific locations or for individual players. Requires @minecraft/server module. ```typescript import { world, MusicOptions, WorldSoundOptions, PlayerSoundOptions, DimensionLocation } from "@minecraft/server"; function playMusicAndSound(targetLocation: DimensionLocation) { const players = world.getPlayers(); const musicOptions: MusicOptions = { fade: 0.5, loop: true, volume: 1.0, }; world.playMusic("music.menu", musicOptions); const worldSoundOptions: WorldSoundOptions = { pitch: 0.5, volume: 4.0, }; world.playSound("ambient.weather.thunder", targetLocation, worldSoundOptions); const playerSoundOptions: PlayerSoundOptions = { pitch: 1.0, volume: 1.0, }; players[0].playSound("bucket.fill_water", playerSoundOptions); } ``` -------------------------------- ### setHorizonBlendMieStart API Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-graphics Sets the horizon blend mie start for atmospheric scattering in Vibrant Visuals for a specified biome. This value can be a single number or a set of keyframes representing different times of day. ```APIDOC ## POST /setHorizonBlendMieStart ### Description Sets the horizon blend mie start for atmospheric scattering in Vibrant Visuals for a specified biome. This value can be a single number or a set of keyframes representing different times of day. ### Method POST ### Endpoint /setHorizonBlendMieStart ### Parameters #### Query Parameters - **blendMieStart** (number | Record) - Required - Either a number (range [0,1.2]) or a set of keyframes. The keyframes are composed of key value pairs. The key is a number (range [0,1]) to signify a time of day (0.0 and 1.0 are noon, 0.25 is sunset, 0.5 is midnight, and 0.75 is sunrise). The value is also a number (range [0,1.2]). - **biomeIdentifier** (BiomeType) - Required - The identifier of the biome to modify. ### Request Example ```json { "blendMieStart": 0.5, "biomeIdentifier": "minecraft:plains" } ``` ### Response #### Success Response (200) - **void** (void) - This function does not return a value upon success. #### Response Example (No response body for void functions) #### Throws - minecraftcommon.InvalidArgumentError: This function can throw errors if the provided arguments are invalid. ``` -------------------------------- ### Entity Properties API Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server Functions for getting and setting entity properties. ```APIDOC ## POST /api/entities/{entityId}/properties/{propertyId} ### Description Sets an Entity Property to the provided value. This property change is not applied until the next tick. ### Method POST ### Endpoint /api/entities/{entityId}/properties/{propertyId} ### Parameters #### Path Parameters - **entityId** (string) - Required - The identifier of the entity. - **propertyId** (string) - Required - The Entity Property identifier. #### Query Parameters - **value** (string | number | boolean) - Required - The property value. The provided type must be compatible with the type specified in the entity's definition. ### Request Body ```json { "value": "string | number | boolean" } ``` ### Response #### Success Response (200) - **void** (void) - Indicates the operation was successful. #### Response Example (No specific response body for void return type) ``` ```APIDOC ## POST /api/entities/{targetEntityId}/overrides/{propertyId} ### Description For this player, overrides an Entity Property on the target Entity to the provided value. This property must be client synced. This change is not applied until the next tick and will not apply to other players. ### Method POST ### Endpoint /api/entities/{targetEntityId}/overrides/{propertyId} ### Parameters #### Path Parameters - **targetEntityId** (string) - Required - The identifier of the target entity. - **propertyId** (string) - Required - The Entity Property identifier. #### Query Parameters - **value** (string | number | boolean) - Required - The override value. The provided type must be compatible with the type specified in the entity's definition. ### Request Body ```json { "value": "string | number | boolean" } ``` ### Response #### Success Response (200) - **void** (void) - Indicates the operation was successful. #### Response Example (No specific response body for void return type) ``` -------------------------------- ### Apply Wither Damage (JavaScript) Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server Applies 1000 damage to the first player in the world, with the damage cause set to 'wither'. This is a direct damage application example. ```javascript import { world, EntityDamageCause } from "@minecraft/server"; const player = world.getAllPlayers()[0]; player.applyDamage(1000, { cause: EntityDamageCause.wither, }); ``` -------------------------------- ### Send Basic Message to First Player Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server Retrieves all players and sends a simple 'Hello World!' message to the first player in the list. This function is part of the sendMessage examples. ```typescript import { world, DimensionLocation } from "@minecraft/server"; function sendBasicMessage(targetLocation: DimensionLocation) { const players = world.getPlayers(); players[0].sendMessage("Hello World!"); } ``` -------------------------------- ### TypeScript: Simple Mob Game Test with Gametest Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-gametest An example demonstrating how to use the ScriptAPI gametest module in TypeScript to spawn entities, assert their presence, and define a success condition. It utilizes imports from '@minecraft/server-gametest' and '@minecraft/vanilla-data'. ```typescript import { Test, register } from "@minecraft/server-gametest"; import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; function simpleMobGameTest(test: Test) { const attackerId = MinecraftEntityTypes.Fox; const victimId = MinecraftEntityTypes.Chicken; test.spawn(attackerId, { x: 5, y: 2, z: 5 }); test.spawn(victimId, { x: 2, y: 2, z: 2 }); test.assertEntityPresentInArea(victimId, true); test.succeedWhen(() => { test.assertEntityPresentInArea(victimId, false); }); } register("StarterTests", "simpleMobTest", simpleMobGameTest).maxTicks(400).structureName("gametests:mediumglass"); ``` -------------------------------- ### List All Player Effects (JavaScript) Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This JavaScript example iterates through all players and lists their active effects. For each player, it uses `getEffects()` to retrieve an array of `Effect` objects. It then sends a message to the player displaying the effect's display name, duration, and amplifier. Dependencies include '@minecraft/server'. ```javascript import { world } from "@minecraft/server"; for (const player of world.getAllPlayers()) { for (const effect of player.getEffects()) { player.sendMessage( `Effect: ${effect.displayName} | Duration: ${effect.duration} | Amplifier: ${effect.amplifier}` ); } } ``` -------------------------------- ### Display Player Game Mode (JavaScript) Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This JavaScript example iterates through all players and displays their current game mode. For each player, it calls `getGameMode()` and sends a message to the player indicating their game mode. Dependencies include '@minecraft/server'. ```javascript import { world } from "@minecraft/server"; for (const player of world.getAllPlayers()) { const gameMode = player.getGameMode(); player.sendMessage(`Your game mode is ${gameMode}`); } ``` -------------------------------- ### Get Entity Rotation with JavaScript Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server Provides an example of how to get an entity's rotation using JavaScript. It returns a Vector2 containing the entity's rotation in degrees. This function can throw errors and cannot be called in early-execution mode. ```javascript import { world } from "@minecraft/server"; world.beforeEvents.chatSend.subscribe((event) => { const message = event.message; const player = event.sender; if (message === "rotation get") { event.cancel = true; const rotation = player.getRotation(); player.sendMessage(`Spawn point location: ${rotation.x} ${rotation.y}`); } }); ``` -------------------------------- ### Get Entity Velocity with JavaScript Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server An example of how to retrieve an entity's current velocity vector using JavaScript. It returns a Vector3 object representing the velocity. This function can throw errors and is not accessible during early-execution mode. ```javascript import { world } from "@minecraft/server"; // Example usage would typically involve getting an entity first, e.g.: // const entity = world.getDimension("overworld").getEntities()[0]; // if (entity) { // const velocity = entity.getVelocity(); // console.log(`Entity velocity: ${velocity.x}, ${velocity.y}, ${velocity.z}`); // } ``` -------------------------------- ### Remove Admin Tag from Players in TypeScript Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This TypeScript example iterates through all players in the world and removes the tag 'admin' from each of them. It utilizes the `world.getAllPlayers()` method to get a list of players and the `removeTag()` method to remove the specified tag. This script depends on the `@minecraft/server` module. ```typescript import { world } from "@minecraft/server"; for (const player of world.getAllPlayers()) { player.removeTag("admin"); } ``` -------------------------------- ### startSequence Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-gametest Creates a new GameTestSequence, which allows for chaining methods to define a series of steps that will play out sequentially within a GameTest. ```APIDOC ## POST /gameTest/startSequence ### Description Creates a new GameTestSequence. ### Method POST ### Endpoint `/gameTest/startSequence` ### Parameters None ### Response #### Success Response (200) - **sequence** (GameTestSequence) - A new GameTestSequence object. #### Response Example ```json { "sequence": { "id": "sequence-123" } } ``` ``` -------------------------------- ### Display Dynamic Properties Byte Count (TypeScript) Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This TypeScript example demonstrates how to get the total byte count of dynamic properties for an entity. It subscribes to script events, checks for a specific event ID ('dp:size'), and retrieves the byte count using `getDynamicPropertyTotalByteCount()`. The result is sent back to the player who triggered the event. Dependencies include '@minecraft/server'. ```typescript import { Player, system } from "@minecraft/server"; system.afterEvents.scriptEventReceive.subscribe((event) => { // Type /scriptevent dp:size to see this message if (event.id === "dp:size" && event.sourceEntity instanceof Player) { // Returns the total size, in bytes, of all the dynamic properties that are currently stored for this entity. const byteCount = event.sourceEntity.getDynamicPropertyTotalByteCount(); // Send the byte count to the player event.sourceEntity.sendMessage(`Dynamic Properties Byte Count: ${byteCount}`); } }); ``` -------------------------------- ### Get Entities in View Direction (TypeScript) Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This TypeScript example demonstrates how to find entities within an entity's view using `getEntitiesFromViewDirection()`. It allows for optional `EntityRaycastOptions` to configure parameters like `maxDistance`. The code iterates through all entities in the overworld dimension and logs information about any entities hit by the raycast, including their distance and entity details. Dependencies include '@minecraft/server'. ```typescript import type { EntityRaycastOptions } from "@minecraft/server"; import { world } from "@minecraft/server"; // Optional: Configure ray cast options const raycastOptions: EntityRaycastOptions = { maxDistance: 10, // Set your desired maximum distance }; // Perform the ray cast for (const entity of world.getDimension("overworld").getEntities()) { const entitiesInView = entity.getEntitiesFromViewDirection(raycastOptions); // Log the results entitiesInView.forEach((hit) => { console.log(`Entity hit at distance ${hit.distance} blocks.`); console.log("Entity details:", hit.entity); // You can access properties/methods of the hit entity }); } ``` -------------------------------- ### Display Title and Subtitle Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This TypeScript code displays a "Hello World" title and a "Welcome to the server!" subtitle to all players. It requires the '@minecraft/server' module. ```typescript import { world } from "@minecraft/server"; for (const player of world.getAllPlayers()) { player.onScreenDisplay.setTitle("Hello World"); player.onScreenDisplay.updateSubtitle("Welcome to the server!"); } ``` -------------------------------- ### Testing and Assertion API Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-gametest Provides functions for setting up tests, asserting conditions, and handling test failures. ```APIDOC ## POST /assertRedstonePower ### Description Tests if the Redstone power at a given block location matches the expected power level. Throws an error if the condition is not met. ### Method POST ### Endpoint /assertRedstonePower ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **blockLocation** (Vector3) - Required - The location to test Redstone power. - **power** (number) - Required - The expected Redstone power level. ### Request Example ```json { "blockLocation": {"x": 1, "y": 2, "z": 3}, "power": 15 } ``` ### Response #### Success Response (200) - **void** (void) - This function does not return any value upon success. #### Response Example (No response body for void return type) ``` ```APIDOC ## POST /fail ### Description Marks the current test as a failure case with a specified error message. ### Method POST ### Endpoint /fail ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **errorMessage** (string) - Required - A message describing the reason for the failure. ### Request Example ```json { "errorMessage": "Test failed due to unexpected condition." } ``` ### Response #### Success Response (200) - **void** (void) - This function does not return any value upon success. #### Response Example (No response body for void return type) ``` ```APIDOC ## POST /failIf ### Description Executes a callback function. If the callback completes without throwing an error, the test is marked as a failure. ### Method POST ### Endpoint /failIf ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **callback** (function) - Required - The function to execute. Expected to contain assertion calls. ### Request Example ```json { "callback": "() => {\n assertBlockState(new Vector3(1, 2, 3), { \"powered\": true });\n}" } ``` ### Response #### Success Response (200) - **void** (void) - This function does not return any value upon success. #### Response Example (No response body for void return type) ``` -------------------------------- ### Get Entity Tags with JavaScript Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server Shows how to get all tags associated with an entity using JavaScript. It returns an array of strings, where each string is a tag. This function can throw errors and is not available in early-execution mode. ```javascript import { world } from "@minecraft/server"; for (const entity of world.getDimension("overworld").getEntities()) { const tags = entity.getTags(); const jaylyTag = tags.find((tag) => tag.startsWith("jayly:")); if (jaylyTag) { world.sendMessage(`${entity.id}: ${jaylyTag}`); } } ``` -------------------------------- ### WidgetCreateOptions Interface Source: https://jaylydev.github.io/scriptapi-docs/preview/interfaces/_minecraft_server-editor This interface defines the configuration options for creating a widget. ```APIDOC ## Interface WidgetCreateOptions ### Description Defines the configuration options for creating a widget. ### Properties #### `Optional` bindPositionToBlockCursor - **Type**: boolean - **Description**: Whether to bind the widget's position to the block cursor. #### `Optional` collisionOffset - **Type**: Vector3 - **Description**: An offset for the widget's collision. #### `Optional` collisionRadius - **Type**: number - **Description**: The radius for the widget's collision. #### `Optional` collisionType - **Type**: WidgetCollisionType - **Description**: The type of collision for the widget. #### `Optional` lockToSurface - **Type**: boolean - **Description**: Whether to lock the widget to a surface. #### `Optional` selectable - **Type**: boolean - **Description**: Whether the widget is selectable. #### `Optional` snapToBlockLocation - **Type**: boolean - **Description**: Whether the widget should snap to block locations. #### `Optional` stateChangeEvent - **Type**: (arg0: WidgetStateChangeEventData) => void - **Description**: A callback function for widget state change events. #### `Optional` visible - **Type**: boolean - **Description**: Whether the widget is visible. #### `Optional` widgetName - **Type**: string - **Description**: The name of the widget. #### `Optional` worldBoundsMax - **Type**: Vector3 - **Description**: The maximum world bounds for the widget. #### `Optional` worldBoundsMin - **Type**: Vector3 - **Description**: The minimum world bounds for the widget. ``` -------------------------------- ### TypeScript: Example of using succeedWhen for entity presence checks Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-gametest This example demonstrates how to use the `succeedWhen` function to test for the presence or absence of entities within a GameTest. It spawns entities and asserts their presence before and after a condition is met, marking the test as successful when the condition is satisfied. ```typescript import { Test, register } from "@minecraft/server-gametest"; import { MinecraftEntityTypes } from "@minecraft/vanilla-data"; function simpleMobGameTest(test: Test) { const attackerId = MinecraftEntityTypes.Fox; const victimId = MinecraftEntityTypes.Chicken; test.spawn(attackerId, { x: 5, y: 2, z: 5 }); test.spawn(victimId, { x: 2, y: 2, z: 2 }); test.assertEntityPresentInArea(victimId, true); test.succeedWhen(() => { test.assertEntityPresentInArea(victimId, false); }); } register("StarterTests", "simpleMobTest", simpleMobGameTest).maxTicks(400).structureName("gametests:mediumglass"); ``` -------------------------------- ### WidgetGroup Class API Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-editor Provides details on the constructors, properties, and methods available for the WidgetGroup class. ```APIDOC ## Class WidgetGroup This class is used for managing a group of widgets. ### Constructors #### `Private` constructor * `new WidgetGroup()`: WidgetGroup Initializes a new instance of the `WidgetGroup` class. * **Returns**: `WidgetGroup` - A new WidgetGroup instance. ### Properties #### `Readonly` selectedWidgetCount * `selectedWidgetCount`: `number` The number of currently selected widgets in the group. * **Throws**: `InvalidWidgetGroupError` - If the property is accessed in an invalid state. * **World Ready**: Cannot be read in early-execution mode. #### visible * `visible`: `boolean` Indicates whether the widget group is currently visible. * **Remarks**: Can be edited unless in read-only mode. * **World Ready**: Cannot be read in early-execution mode. #### visibleBounds * `visibleBounds`: `boolean` Indicates whether the bounding box for the widget group is visible. * **Remarks**: Can be edited unless in read-only mode. * **World Ready**: Cannot be read in early-execution mode. ### Methods #### createWidget * `createWidget(location: Vector3, options?: WidgetCreateOptions)`: `Widget` Creates a new widget within the group at the specified location. * **Parameters**: * `location` (Vector3) - The world coordinates where the widget will be created. * `options` (WidgetCreateOptions, Optional) - Configuration options for the new widget. * **Returns**: `Widget` - The newly created widget. * **Write Privilege**: Cannot be called in read-only mode. * **Throws**: Can throw errors during widget creation. * **World Ready**: Cannot be called in early-execution mode. #### delete * `delete()`: `void` Deletes the entire widget group. * **Write Privilege**: Cannot be called in read-only mode. * **World Ready**: Cannot be called in early-execution mode. #### deleteWidget * `deleteWidget(widgetToDelete: Widget)`: `void` Deletes a specific widget from the group. * **Parameters**: * `widgetToDelete` (Widget) - The widget instance to remove from the group. * **Write Privilege**: Cannot be called in read-only mode. * **Throws**: Can throw errors if the widget is not found or deletion fails. * **World Ready**: Cannot be called in early-execution mode. #### deselectAllWidgets * `deselectAllWidgets()`: `void` Deselects all currently selected widgets within the group. * **Write Privilege**: Cannot be called in read-only mode. * **Throws**: `InvalidWidgetGroupError` - If the operation cannot be performed. * **World Ready**: Cannot be called in early-execution mode. #### selectAllWidgets * `selectAllWidgets()`: `void` Selects all widgets within the group. * **Write Privilege**: Cannot be called in read-only mode. * **Throws**: `InvalidWidgetGroupError` - If the operation cannot be performed. * **World Ready**: Cannot be called in early-execution mode. ``` -------------------------------- ### Set and Get Entity Property with JavaScript Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server Illustrates how to set and get entity properties using JavaScript. It requires an entity identifier and a value to set, and returns the property's current value. Note that properties set in the same tick are reflected in the next tick. ```javascript import { world } from "@minecraft/server"; const entity = world.getDimension("overworld").getEntities({ type: "create:dummy" })[0]; entity.setProperty("create:rotation_offset", 1); console.warn(entity.getProperty("create:rotation_offset")); ``` -------------------------------- ### Display "Hello World" in Action Bar Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This TypeScript snippet iterates through all players on the server and uses the onScreenDisplay.setActionBar method to display "Hello World" in the action bar. It requires the '@minecraft/server' module. ```typescript import { world } from "@minecraft/server"; for (const player of world.getAllPlayers()) { player.onScreenDisplay.setActionBar("Hello World"); } ``` -------------------------------- ### GameTest Class Documentation Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-gametest Provides detailed information about the GameTest class, including its constructors and methods, parameters, return types, and usage remarks. ```APIDOC ## Class Test Main class for GameTest functions, with helpers and data for manipulating the respective test. Note that all methods of this class expect BlockLocations and Locations relative to the GameTest structure block. ### Constructors * constructor ### Methods * assert * assertBlockPresent * assertBlockState * assertCanReachLocation * assertContainerContains * assertContainerEmpty * assertEntityHasArmor * assertEntityHasComponent * assertEntityInstancePresent * assertEntityInstancePresentInArea * assertEntityPresent * assertEntityPresentInArea * assertEntityState * assertEntityTouching * assertIsWaterlogged * assertItemEntityCountIs * assertItemEntityPresent * assertRedstonePower * destroyBlock * fail * failIf * getBlock * getDimension * getFenceConnectivity * getSculkSpreader * getTestDirection * idle * isCleaningUp * isCompleted * killAllEntities * onPlayerJump * pressButton * print * pullLever * pulseRedstone * relativeBlockLocation * relativeLocation * removeSimulatedPlayer * rotateDirection * rotateVector * runAfterDelay * runAtTickTime * runOnFinish * setBlockPermutation * setBlockType * setFluidContainer * setTntFuse * spawn * spawnAtLocation * spawnItem * spawnSimulatedPlayer * spawnWithoutBehaviors * spawnWithoutBehaviorsAtLocation * spreadFromFaceTowardDirection * startSequence * succeed * succeedIf * succeedOnTick * succeedOnTickWhen * succeedWhen * succeedWhenBlockPresent * succeedWhenEntityHasComponent * succeedWhenEntityPresent * triggerInternalBlockEvent * until * walkTo * walkToLocation * worldBlockLocation * worldLocation ## Constructors ### `Private` constructor * new Test(): Test #### Returns Test ## Methods ### assert * assert(condition: boolean, message: string): void #### Parameters * condition: boolean - Expression of the condition to evaluate. * message: string - Message that is passed if the _condition_ does not evaluate to true. #### Returns void #### Remarks Tests that the condition specified in _condition_ is true. If not, an error with the specified _message_ is thrown. #### Throws This function can throw errors. * GameTestCompletedError * GameTestError #### World Ready This function can't be called in early-execution mode. ### assertBlockPresent * assertBlockPresent( blockType: string | BlockType, blockLocation: Vector3, isPresent?: boolean, ): void #### Parameters * blockType: string | BlockType - Expected block type. * blockLocation: Vector3 - Location of the block to test at. * `Optional`isPresent: boolean - If true, this function tests whether a block of the specified type is at the location. If false, tests that a block of the specified type is not present. Defaults to: true #### Returns void #### Remarks Tests that a block of the specified type is present at the specified location. If it is not, an exception is thrown. #### Throws This function can throw errors. * GameTestCompletedError * GameTestError #### World Ready This function can't be called in early-execution mode. ``` -------------------------------- ### Spawn Simulated Player API Source: https://jaylydev.github.io/scriptapi-docs/preview/functions/_minecraft_server-gametest Provides details on spawning and managing simulated players within the game environment using the Script API. ```APIDOC ## POST /scriptapi/gametest/spawnSimulatedPlayer ### Description Spawns a simulated player in the specified location, with a given name and game mode. This player is not tied to a specific test and can be removed using `SimulatedPlayer.remove()`. ### Method POST ### Endpoint /scriptapi/gametest/spawnSimulatedPlayer ### Parameters #### Query Parameters - **location** (DimensionLocation) - Required - The location in which to spawn the player. - **name** (string) - Required - The name for the player. - **gameMode** (GameMode) - Required - The game mode for the player. ### Request Body This endpoint does not require a request body. ### Response #### Success Response (200) - **SimulatedPlayer** (object) - The spawned simulated player object. #### Response Example ```json { "player_id": "123e4567-e89b-12d3-a456-426614174000" } ``` ### Remarks This function can't be called in read-only mode or early-execution mode. ### Throws - **minecraftcommon.EngineError**: This function can throw errors related to engine execution. ``` -------------------------------- ### World Interaction API Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-gametest Provides functions to get information about the current game dimension and world state. ```APIDOC ## GET /getDimension ### Description Retrieves the current game dimension in which the test is running. ### Method GET ### Endpoint /getDimension ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example (No request body for GET request) ### Response #### Success Response (200) - **Dimension** (Dimension) - An object representing the current dimension. #### Response Example ```json { "id": "minecraft:overworld" } ``` ``` ```APIDOC ## GET /getFenceConnectivity ### Description If the block at the specified location is a fence, this function returns a helper object detailing its connections. ### Method GET ### Endpoint /getFenceConnectivity ### Parameters #### Path Parameters None #### Query Parameters - **blockLocation** (Vector3) - Required - The location of the block to check. ### Request Example ```json { "blockLocation": {"x": 1, "y": 2, "z": 3} } ``` ### Response #### Success Response (200) - **FenceConnectivity** (FenceConnectivity) - An object describing the fence's connections if it is a fence, otherwise behavior is undefined. #### Response Example ```json { "north": true, "south": false, "east": true, "west": false } ``` ``` ```APIDOC ## GET /getSculkSpreader ### Description Retrieves a SculkSpreader object from a block location, which can be used to manage Sculk growth. ### Method GET ### Endpoint /getSculkSpreader ### Parameters #### Path Parameters None #### Query Parameters - **blockLocation** (Vector3) - Required - The location to retrieve the SculkSpreader from. ### Request Example ```json { "blockLocation": {"x": 1, "y": 2, "z": 3} } ``` ### Response #### Success Response (200) - **SculkSpreader** (SculkSpreader) - The SculkSpreader object, or undefined if none is present. #### Response Example ```json { "id": "sculk_spreader_01", "location": {"x": 1, "y": 2, "z": 3} } ``` ``` ```APIDOC ## GET /getTestDirection ### Description Returns the direction in which the current test is oriented. ### Method GET ### Endpoint /getTestDirection ### Parameters #### Path Parameters None #### Query Parameters None ### Request Example (No request body for GET request) ### Response #### Success Response (200) - **Direction** (Direction) - The direction of the test (e.g., north, east, south, west). #### Response Example ```json { "value": 2 } ``` ``` -------------------------------- ### print Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server-gametest Displays a message to all players in the game. ```APIDOC ## print ### Description Displays the specified message to all players. ### Method N/A (Function Call) ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **text** (string) - Required - The message to display to players. ### Request Example ```javascript world.print("Hello, players!"); ``` ### Response #### Success Response (void) - No return value. #### Response Example ```json null ``` #### Error Handling - Can throw `GameTestCompletedError` or `GameTestError`. ``` -------------------------------- ### Entity Components API Source: https://jaylydev.github.io/scriptapi-docs/preview/classes/_minecraft_server This section details how to interact with entity components, retrieve all available components, and access their properties. ```APIDOC ## GET /entities/{entityId}/components ### Description Retrieves all components attached to an entity that are supported by the API. ### Method GET ### Endpoint `/entities/{entityId}/components` ### Parameters #### Path Parameters - **entityId** (string) - Required - The unique identifier of the entity. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **components** (EntityComponent[]) - An array of entity components. #### Response Example ```json { "components": [ { "typeId": "health" }, { "typeId": "inventory" } ] } ``` ``` -------------------------------- ### Manifest Details for @minecraft/server-admin Module Source: https://jaylydev.github.io/scriptapi-docs/preview/modules/_minecraft_server-admin Provides the manifest details for the '@minecraft/server-admin' module, including its name and version. This is crucial for identifying the specific module and its version in a project. ```json { "module_name": "@minecraft/server-admin", "version": "1.0.0-beta" } ```