### Entity Timer Setup and Execution Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/scoreboard-timers.md This example sets up a timer for individual entities named 'wiki:station'. It increments a 'wiki:ticks' score for each entity and executes various commands based on the timer's progress. ```yaml ## Running the Timer scoreboard players add @e[name="wiki:station",scores={wiki:ticks=0..}] wiki:ticks 1 # Executing Commands While Timer Is Running execute as @e[name="wiki:station",scores={wiki:ticks=0..}] at @s run particle minecraft:shulker_bullet ~~~ # Executing Commands Within a Timeframe execute as @e[name="wiki:station",scores={wiki:ticks=0..200}] at @s run particle minecraft:basic_flame_particle ~~~ # Executing Commands at Precise Intervals execute as @e[name="wiki:station",scores={wiki:ticks=3600}] at @s run playsound note.pling @a[r=10] # Stopping the Timer execute as @e[name="wiki:station"] at @s if entity @e[family=pacified,r=10,c=1] run scoreboard players set @s ticks -1 # Looping the Timer execute as @e[name="wiki:station",scores={wiki:ticks=6000}] at @s if entity @e[family=monster,r=10,c=1] run scoreboard players set @s ticks 0 # End of Timer kill @e[name="wiki:station",scores={wiki:ticks=6000}] ``` -------------------------------- ### Install Dependencies Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/README.md Run this command to install the necessary project dependencies. ```bash npm install ``` -------------------------------- ### Install Script API Modules Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/typescript.md Installs the necessary Script API modules for Minecraft development. Beta versions are used in this example. ```bash npm install @minecraft/server@beta npm install @minecraft/server-ui@beta npm install @minecraft/server-gametest@beta npm install @minecraft/server-admin@beta npm install @minecraft/server-net@beta ``` -------------------------------- ### Install Dependencies for Wiki Development Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/contribute-style.md Run this command once to install all necessary packages for local wiki development. Ensure it completes successfully before proceeding. ```bash npm install ``` -------------------------------- ### Focus Container Configuration Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/json-ui/json-ui-documentation.md Example of setting a UI element as a focus container. This enables focus management features for the element and its children. ```json { "other_panel": { ... "focus_container": true, "controls": [ ... ] } } ``` -------------------------------- ### Install Beta API Modules (Bash) Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/scripting-intro.md Commands to install the latest beta versions of various Minecraft Script API modules using npm. ```bash npm i @minecraft/server@2.3.0-beta.1.21.114-stable npm i @minecraft/server-ui@2.1.0-beta.1.21.114-stable npm i @minecraft/server-gametest@1.0.0-beta.1.21.114-stable npm i @minecraft/server-admin@1.0.0-beta.1.21.114-stable npm i @minecraft/server-net@1.0.0-beta.1.21.114-stable npm i @minecraft/debug-utilities@1.0.0-beta.1.21.114-stable ``` -------------------------------- ### Example Folder Structure for Recipes Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/loot/recipes.md This example shows a possible folder hierarchy for organizing recipe files within a behavior pack. The paths are arbitrary and can be structured as desired. ```text BP/recipes/brewing/negative/paralysis.json BP/recipes/crafting/weapons/cold_steel_sword.json BP/recipes/decorations/knobs/brass.json BP/recipes/magic/magic_ash.json BP/recipes/covered_arch.json BP/recipes/illumination_potion.json ``` -------------------------------- ### Brewing Container Recipe Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/loot/recipes.md An example of a brewing container recipe for creating an illumination potion. Data values are passed from input to output in this recipe type. ```json { "format_version": "1.17.41", "minecraft:recipe_brewing_container": { "description": { "identifier": "wiki:illumination_potion" }, "tags": ["brewing_stand"], "input": "minecraft:potion", "reagent": "wiki:radiant_berries", "output": "wiki:illumination_potion" } } ``` -------------------------------- ### Full Animation Controller File Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/guide/custom-entity.md A complete example of a Minecraft resource pack animation controller file, combining attack and walk controllers. ```json { "format_version": "1.10.0", "animation_controllers": { "controller.animation.ghost.attack": { "states": { "default": { "transitions": [ { "attacking": "q.is_delayed_attacking" } ] }, "attacking": { "animations": ["animation.ghost.attack"], "transitions": [ { "default": "!q.is_delayed_attacking" } ], "blend_transition": 0.1 } } }, "controller.animation.ghost.walk": { "initial_state": "walk", "states": { "walk": { "transitions": [ { "idle": "q.modified_move_speed" } ] }, "idle": { "animations": ["animation.ghost.idle"], "transitions": [ { "walk": "q.modified_move_speed" } ] } } } } } ``` -------------------------------- ### NOT Gate Example with Say Command (Method 1) Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/logic-gates.md Example of a NOT gate using /execute as, running 'say success' if the player does not have the 'red' tag. ```minecraft /execute as @p[tag=!red] run say success ``` -------------------------------- ### Run Development Server Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/README.md Use this command to start the VitePress development server for local testing. ```bash npm run dev ``` -------------------------------- ### Example MCFunction File Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/mcfunctions.md This example demonstrates applying effects to players based on their tags. Commands in a function file are executed sequentially within the same tick. ```mcfunction # These effects are for the spawn effect @a[tag=wiki:at_spawn] regeneration 12 255 true effect @a[tag=wiki:at_spawn] saturation 12 255 true effect @a[tag=wiki:at_spawn] weakness 12 255 true # These effects are for the nether effect @a[tag=wiki:in_nether] fire_resistance 12 255 true ``` -------------------------------- ### Complete Item Definition Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/guide/custom-item.md This example shows a fully defined custom item, including its format version, identifier, creative inventory category, and maximum stack size. ```json { "format_version": "1.26.30", "minecraft:item": { "description": { "identifier": "wiki:ectoplasm", "menu_category": { "category": "items" } }, "components": { "minecraft:max_stack_size": 16 } } } ``` -------------------------------- ### AND Gate Example with Say Command Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/logic-gates.md Example of an AND gate using the /execute as command to make a player say 'success' if they have both 'red' and 'green' tags. ```minecraft /execute as @p[tag=red,tag=green] run say success ``` -------------------------------- ### Complete Modal Form Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/server-forms.md An example demonstrating the integration of all modal form components: title, text field, dropdown, slider, and toggle. ```javascript let form = new ModalFormData(); let effectList = ["Regeneration", "Protection", "Poison", "Wither"]; form.title("Effect Generator"); form.textField("Target", "Target of Effect"); form.dropdown("Effect Type", effectList); form.slider("Effect Level", 0, 255, { defaultValue: 1, }); form.toggle("Hide Effect Particle", { defaultValue: true, }); ``` -------------------------------- ### Example Commands for Sneak States Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/detect-movements.md These are example commands demonstrating how to use the 'wiki:q.is_sneaking' score to trigger actions based on the player's sneak state. Modify these for your specific needs. ```minecraft ## Your Commands Here (Examples) execute as @a[scores={wiki:q.is_sneaking=0}] run say I'm not sneaking execute as @a[scores={wiki:q.is_sneaking=1}] run say I started sneaking execute as @a[scores={wiki:q.is_sneaking=1..}] run say I'm still sneaking ``` -------------------------------- ### MCFunction Comments and Structure Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/mcfunctions.md This example demonstrates the recommended comment style for organizing MCFunction files, including header levels and spacing conventions. It shows how to structure commands for player effects, particle emission, and timers. ```yaml # ON PLAYER ITEM DROP ## Give Effects ### Fire resistance execute at @e[type=item,name="Fire Trail Ability"] run effect @p[r=3] fire_resistance 10 255 ### Speed execute at @e[type=item,name="Fire Trail Ability"] run effect @p[r=3] speed 10 1 true ## Add Particle Time (10s) execute at @e[type=item,name="Fire Trail Ability"] run scoreboard players set @p[r=3] abilities.fire_trail 200 ## Delete Item kill @e[type=item,name="Fire Trail Ability"] # ENTITY TIMER ## Emit Particle Trail execute at @a[scores={wiki:ability.fire_trail=1..}] run particle minecraft:basic_flame_particle ~~~ ## Countdown Timer scoreboard players remove @a [scores={wiki:ability.fire_trail=1..}] wiki:ability.fire_trail 1 ``` -------------------------------- ### Execute Command - Example with Dimension and Position Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/new-execute.md An example demonstrating how to execute a command in a specific dimension and at a particular position, targeting players who are in the End dimension. ```minecraft-commands /execute in the_end positioned 0 -100 0 as @a[rm=1] run say I'm in the End dimension ``` -------------------------------- ### Coordinate Distribution Examples Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/world-generation/feature-types.md Illustrates various methods for distributing coordinates (x, z, y) in feature placement. ```json "x": { "distribution": "fixed_grid", "extent": [0, 15] } ``` ```json "z": { "distribution": "fixed_grid", "extent": [0, 15] } ``` ```json "y": 0 ``` ```json "x": 0 ``` ```json "x": "math.random_integer(0, v.surface_grass.spread - 1)" ``` ```json "x": { "distribution": "uniform", "extent": [0, 16] } ``` -------------------------------- ### Example Trade Table File Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/loot/trade-tables.md This is an example of a trade table file, which defines the trades an entity can offer. It includes item stacks, prices, and potential trades. ```json { "trades": { "minecraft:trades": [ { "min_uses": 1, "max_uses": 3, "reward_exp": true, "trades": [ { "input_item": { "item": "bedrock:emerald", "count": 10 }, "output_item": { "item": "bedrock:diamond", "count": 1 }, "price_multiplier": 0.05, "xp_reward": 1 }, { "input_item": { "item": "bedrock:diamond", "count": 1 }, "output_item": { "item": "bedrock:emerald", "count": 10 }, "price_multiplier": 0.05, "xp_reward": 1 } ] } ] } } ``` -------------------------------- ### Example Bedrock Animation File Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/guide/blockbench.md This is an example of a .animations.json file for a Bedrock Edition entity. It defines the keyframes and transformations for animations, such as a 'move' animation. ```json { "format_version": "1.8.0", "animations": { "animations.ghost.move": { "loop_animation": true, "animation_length": 0.5, "bones": { "bone": { "rotation": [ 0, 0, 0 ], "position": [ 0, 0, 0 ] } } } } } ``` -------------------------------- ### Entity Components Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/entities/entity-intro-bp.md This example shows how to add components to an entity's definition to grant it specific behaviors like a type family, collision box, and the ability to climb. ```json "components": { "minecraft:type_family": { "family": [ "player" ] }, "minecraft:collision_box": { "width": 0.6, "height": 1.8 }, "minecraft:can_climb": {} } ``` -------------------------------- ### Example Commands for Player States Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/detect-movements.md Provides example commands to react to player states. These can be modified to trigger specific actions based on whether a player is swimming, crawling, or gliding. ```minecraft execute as @a[scores={wiki:q.is_swimming=0}] run say I'm not swimming execute as @a[scores={wiki:q.is_crawling=1}] run say I started crawling execute as @a[scores={wiki:q.is_gliding=1..}] run say I'm still gliding ``` -------------------------------- ### Brewing Mix Recipe Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/loot/recipes.md An example of a brewing mix recipe for creating a paralysis brew. Note that assigned data values are generally broken for brewing mix recipes. ```json { "format_version": "1.17.41", "minecraft:recipe_brewing_mix": { "description": { "identifier": "wiki:paralysis_brew" }, "tags": ["brewing_stand"], "input": "wiki:amberglass_flask", "reagent": "wiki:viporfly_poison", "output": "wiki:paralysis_brew" } } ``` -------------------------------- ### Example Biome Definition JSON Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/world-generation/biomes.md This is a complete example of a biome definition file. It includes surface parameters, height noise, climate settings, and generation rules. ```json { "format_version": "1.13.0", "minecraft:biome": { "description": { "identifier": "pumpkin_pastures" }, "components": { "minecraft:surface_parameters": { "foundation_material": "minecraft:stone", "top_material": "minecraft:grass", "mid_material": "minecraft:dirt", "sea_floor_depth": 4, "sea_material": "minecraft:water", "sea_floor_material": "minecraft:sand" }, "minecraft:overworld_height": { "noise_params": [0.125, 0.0625] }, "minecraft:climate": { "temperature": 0.375, "downfall": 0.25, "snow_accumulation": [0, 0.5] }, "minecraft:overworld_generation_rules": { "generate_for_climates": [["cold", 1]], "hills_transformation": "pumpkin_pastures_hills", "shore_transformation": "pumpkin_pastures" }, "overworld": {}, "pumpkin_pastures": {}, "animal": {}, "monster": {} } } } ``` -------------------------------- ### Page Frontmatter Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/contribute-style.md This is an example of the frontmatter and content structure for a wiki page. It includes essential fields like title and description, along with optional fields. ```yaml --- title: A Wonderful Page Title description: Make your first contribution! license: true mentions: - username --- Lots and lots of content! ``` -------------------------------- ### Mob Navigation Properties Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/entities/vuc-full.md Configuration for mob navigation, specifying movement and environmental interaction rules. ```json "minecraft:navigation.walk": { "can_path_over_water": true, "avoid_water": true, "avoid_damage_blocks": true, "can_sink": false } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "avoid_water": true } ``` ```json "minecraft:navigation.walk": {} ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true } ``` ```json "minecraft:navigation.walk": { "is_amphibious": true, "avoid_sun": true, "avoid_water": true } ``` ```json "minecraft:navigation.walk": { "is_amphibious": true, "avoid_water": true } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "avoid_water": true, "avoid_damage_blocks": true } ``` ```json "minecraft:navigation.walk": { "avoid_water": true } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "can_sink": false } ``` ```json "minecraft:navigation.walk": { "can_path_over_lava": true, "avoid_water": true, "can_sink": false, "can_walk_in_lava": true } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "can_pass_doors": true, "can_open_doors": true, "can_walk": true, "avoid_water": true } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "can_pass_doors": true, "can_open_doors": true, "avoid_water": true } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "can_pass_doors": true, "can_break_doors": true } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "can_pass_doors": true, "can_open_doors": false, "avoid_water": true } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "can_path_over_lava": true, "avoid_damage_blocks": true } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "avoid_water": false } ``` ```json "minecraft:navigation.walk": { "can_path_over_water": true, "avoid_water": true } ``` ```json "minecraft:navigation.walk": { "is_amphibious": true, "can_path_over_water": false, "avoid_water": true, "avoid_damage_blocks": true } ``` ```json "minecraft:navigation.walk": { "is_amphibious": true, "can_pass_doors": true, "can_walk": true, "can_break_doors": true } ``` ```json "minecraft:navigation.walk": { "is_amphibious": true, "can_pass_doors": true, "can_open_doors": true, "avoid_water": true, "avoid_portals": true } ``` ```json "minecraft:navigation.walk": { "is_amphibious": true, "can_pass_doors": true, "can_break_doors": false, "avoid_sun": false } ``` ```json "minecraft:navigation.walk": { "is_amphibious": true, "can_pass_doors": true, "can_open_doors": true, "avoid_water": true, "avoid_sun": true } ``` ```json "minecraft:navigation.walk": { "is_amphibious": true, "can_pass_doors": true, "can_break_doors": true, "avoid_sun": false } ``` ```json "minecraft:navigation.walk": { "is_amphibious": true, "can_pass_doors": true, "can_open_doors": true, "avoid_water": true, "avoid_sun": true } ``` -------------------------------- ### Example Commands for Crawling States Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/detect-movements.md These are example commands that can be used to trigger actions based on the player's crawling state. Modify these to suit your needs. The `scores` selector argument is crucial for targeting specific states. ```minecraft execute as @a[scores={wiki:q.is_crawling=0}] run say I'm not crawling ``` ```minecraft execute as @a[scores={wiki:q.is_crawling=1}] run say I started crawling ``` ```minecraft execute as @a[scores={wiki:q.is_crawling=1..}] run say I'm still crawling ``` -------------------------------- ### Build for Production Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/README.md Execute this command to create a production-ready build of the wiki. ```bash npm run build ``` -------------------------------- ### Example Sine Wave Animation Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/visuals/bedrock-modeling.md An example of the sine wave formula applied to create a specific animation. This function is used for position or rotation adjustments. The parameters control the animation's behavior, such as its starting point, frequency, and amplitude. ```Molang Math.sin((q.life_time+0.5)*150)*15 ``` -------------------------------- ### Column-Major Transform Chain Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/entities/coordinate-space-conversion.md Shows a typical sequence of transformations in column-major order, starting from a point and applying successive parent transforms to reach world space. ```text Entity * RootBone * Pelvis * Spine0 .. SpineN * RShoulder * RightElbow * RightHand * point; ``` -------------------------------- ### XOR Gate Example with Say Command Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/logic-gates.md Example of an XOR gate using /execute unless entity twice, running 'say success' if the player has exactly one of the 'red' or 'green' tags. ```minecraft /execute as @p unless entity @s[tag=!red,tag=!green] unless entity @s[tag=red,tag=green] run say success ``` -------------------------------- ### Define Vertical Halves of a Block Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/blocks/precise-interaction.md Example of creating a SelectionBoxes instance to divide a block into its top and bottom vertical halves. This setup can be used with player interaction events. ```javascript import { world } from "@minecraft/server"; import SelectionBoxes from "../utilities/selection_boxes"; const verticalHalves = new SelectionBoxes( { origin: [-8, 8, -8], size: [16, 8, 16], name: "top" }, { origin: [-8, 0, -8], size: [16, 8, 16], name: "bottom" } ); ``` -------------------------------- ### Iteration Count Examples Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/world-generation/feature-types.md Shows how to specify the number of placement attempts for a scatter feature. ```json "iterations": 12 ``` -------------------------------- ### Run Local Wiki Development Server Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/contribute-style.md Starts a local development server that automatically updates as you make changes. Access the wiki via the provided localhost URL. ```bash npm run dev ``` -------------------------------- ### Example Trade Table Configuration Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/loot/trade-tables.md This JSON defines a trade table with multiple tiers and trades. It includes examples of item wants with quantity ranges and price multipliers, as well as items given with specific enchantments. ```json { "tiers": [ { "groups": [ { "num_to_select": 1, "trades": [ { "wants": [ { "item": "wiki:blessing_glyph", "quantity": { "min": 2, "max": 4 }, "price_multiplier": 0.5 }, { "item": "minecraft:book" } ], "gives": [ { "item": "minecraft:enchanted_book", "functions": [ { "function": "enchant_book_for_trading", "base_cost": 4, "base_random_cost": 12, "per_level_cost": 4, "per_level_random_cost": 8 } ] } ], "max_uses": 7, "trader_exp": 3 }, { "wants": [ { "item": "wiki:crystalline_spiritite", "quantity": 32, "price_multiplier": 0.125 } ], "gives": [ { "item": "wiki:exalted_blade", "functions": [ { "function": "enchant_with_levels", "treasure": true, "levels": { "min": 15, "max": 25 } } ] } ], "max_uses": 2, "reward_exp": false, "trader_exp": 8 } ] } ] }, { "total_exp_required": 28, "trades": [ { "wants": [ { "choice": [ { "item": "wiki:sacred_stones", "quantity": { "min": 4, "max": 6 }, "price_multiplier": 0.5 }, { "item": "wiki:blessed_beads", "quantity": { "min": 16, "max": 24 }, "price_multiplier": 0.5 } ] } ], "gives": [ { "item": "wiki:aeleon_jewels", "quantity": { "min": 4, "max": 6 } } ], "max_uses": 2 } ] } ] } ``` -------------------------------- ### Preview Built Wiki Locally Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/contribute-style.md Serves the compiled static site locally after a build process. Use this to preview the final output before deployment. ```bash npm run preview ``` -------------------------------- ### Simple HTTP GET Request Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/script-net.md Performs a simple HTTP GET request. This is a convenience method for GET requests without bodies. ```APIDOC ## http.get(url) ### Description Performs a simple HTTP GET request. ### Parameters #### Path Parameters - **url** (string) - Required - The URL to send the GET request to. ### Returns - `Promise` - A promise that resolves with the HTTP response. ### Example ```js import { http } from "@minecraft/server-net"; http.get("http://example.com/").then((response) => { const body = response.body; }); ``` ``` -------------------------------- ### Install TypeScript Globally Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/typescript.md Installs the TypeScript compiler globally on your system. ```bash npm install -g typescript ``` -------------------------------- ### Old /execute Syntax Examples Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/new-execute.md Demonstrates the previous syntax for the /execute command, including basic execution and conditional block detection. ```minecraft-commands /execute /execute detect ``` -------------------------------- ### Perform a Simple HTTP GET Request Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/script-net.md Use http.get for straightforward GET requests. It automatically sets the request method to GET and returns a Promise resolving to an HttpResponse object. ```javascript import { http } from "@minecraft/server-net"; http.get("http://example.com/").then((response) => { // Body content of the HTTP response. // Type: string const body = response.body; }); ``` -------------------------------- ### Initialize npm Project Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/typescript.md Creates a package.json file in the current directory to manage project dependencies. ```bash npm init -y ``` -------------------------------- ### Minecraft Color2 Component Examples Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/entities/vanilla-usage-components.md Examples of the 'minecraft:color2' component for tropical fish patterns. ```json "minecraft:color2": { "value": 0 } ``` ```json "minecraft:color2": { "value": 1 } ``` ```json "minecraft:color2": { "value": 2 } ``` -------------------------------- ### Biome Components Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/world-generation/biomes.md An example of biome components, including urban, city, metro, and rare tags. ```json "components": { … "urban": {}, "city": {}, "metro": {}, "rare": {} } ``` -------------------------------- ### Initialize a Git Repository Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/meta/version-control.md Run this command in your project's root folder to create a new, empty Git repository. Ensure Git Bash is installed and accessible. ```bash git init ``` -------------------------------- ### Villager Material Inheritance Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/visuals/materials.md This example shows a material 'villager_v2_masked' inheriting from 'entity_multitexture_masked', with specific depth function settings. ```json "villager_v2_masked:entity_multitexture_masked": { "depthFunc": "LessEqual" } ``` -------------------------------- ### JSON Item Formatting Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/contribute-style.md Demonstrates how to format JSON for item definitions, including comments for descriptions and component explanations. Use CodeHeader for file paths. ```json { "format_version": "1.26.30", "minecraft:item": { "description": { // Describing an object with components. "identifier": "wiki:copper_coin", "menu_category": { "category": "construction" } }, "components": { "minecraft:max_stack_size": 64, // Short description of a value/component. // Make notes about a group of specific components (icon and glint in our case) used below this way. "minecraft:icon": "wiki:copper_coin", "minecraft:glint": 3.5 } } } ``` -------------------------------- ### Example Furnace Recipe Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/loot/recipes.md This is an example of a furnace recipe that transforms bone fragments into magic ash using a soul campfire. ```json { "format_version": "1.17.41", "minecraft:recipe_furnace": { "description": { "identifier": "wiki:magic_ash" }, "tags": ["soul_campfire"], "input": "wiki:bone_fragments", "output": { "item": "wiki:magic_ash", "count": 4 } } } ``` -------------------------------- ### Constant Start Height Configuration Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/world-generation/jigsaw-structures.md Sets a fixed Y-level for the start of the jigsaw structure generation relative to the heightmap projection. ```json "start_height": { "type": "constant", "value": { "absolute": 10 } } ``` -------------------------------- ### Environment Sensor: Start Transforming Underwater Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/entities/vuc-full.md Configures the environment sensor to trigger a 'start transforming' event when the subject is underwater. ```json "minecraft:environment_sensor": { "triggers": { "filters": { "test": "is_underwater", "subject": "self", "operator": "==", "value": true }, "event": "minecraft:start_transforming" } } ``` -------------------------------- ### Example Format Version Declaration Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/guide/format-version.md This is how a format version is declared at the top of a file. Ensure this matches the expected version for the specific file type. ```json "format_version": "1.21.0" ``` -------------------------------- ### Set HTTP Method to GET Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/script-net.md Sets the HTTP request method to GET using the HttpRequestMethod enum. This is used for retrieving data. ```javascript import { HttpRequestMethod } from "@minecraft/server-net"; request.method = HttpRequestMethod.Get; ``` -------------------------------- ### Item with Components Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/items/items-intro.md This example adds components to a custom item, configuring its damage, durability, and hand equipping behavior. Ensure the item's menu category is set appropriately. ```json { "format_version": "1.26.30", "minecraft:item": { "description": { "identifier": "wiki:custom_item", "menu_category": { "category": "construction" } }, "components": { "minecraft:damage": 10, "minecraft:durability": { "max_durability": 36 }, "minecraft:hand_equipped": true } } } ``` -------------------------------- ### Titleraw Template Example 4 Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/dynamic-displays.md This snippet presents the final example of the Titleraw template, with text content pertaining to Shelf 8. ```json { "rawtext": [ { "translate": "%%%%s", "with": { "rawtext": [ { "score": { "name": "*", "objective": "wiki:element" } }, { "text": "Shelf: 8, Book: 1" }, { "text": "Shelf: 8, Book: 2" }, { "text": "Shelf: 8, Book: 3" }, { "text": "Shelf: 8, Book: 4" }, { "text": "Shelf: 8, Book: 5" }, { "text": "Shelf: 8, Book: 6" }, { "text": "Shelf: 8, Book: 7" }, { "text": "Shelf: 8, Book: 8" }, { "text": "Shelf: 8, Book: 9" } ] } } ] } ``` -------------------------------- ### Using Proxy Constructor Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/api-environment.md Shows how to create a proxy object using the standard `Proxy` constructor. ```javascript new Proxy({}, {}) ``` -------------------------------- ### Timer Component for Event Triggering Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/animation-controllers/entity-commands.md Repeatedly triggers the 'example_command' event every 10 seconds. ```json "minecraft:timer": { "looping": true, "time": 10, "time_down_event": { "event": "example_command" } } ``` -------------------------------- ### Minecraft Color Component Examples Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/entities/vanilla-usage-components.md Examples of the 'minecraft:color' component for different entities like cats, sheep, tropical fish, and wolves. ```json "minecraft:color": { "value": 14 } ``` ```json "minecraft:color": { "value": 0 } ``` ```json "minecraft:color": { "value": 12 } ``` ```json "minecraft:color": { "value": 15 } ``` ```json "minecraft:color": { "value": 0 } ``` ```json "minecraft:color": { "value": 1 } ``` ```json "minecraft:color": { "value": 2 } ``` ```json "minecraft:color": { "value": 14 } ``` -------------------------------- ### Wearable Component Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/items/item-components.md This snippet demonstrates how to configure the 'wearable' component for an item, specifying its protection value and the equipment slot it occupies. ```json "minecraft:wearable": { "protection": 10, "slot": "slot.armor.chest" } ``` -------------------------------- ### Example Grouped Animation Files Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/meta/style-guide.md Group animation files within the 'animations' object for better organization. This example shows animations for a dragon. ```json { "format_version": "1.8.0", "animations": { "animation.dragon.sit": { ... }, "animation.dragon.fly": { ... }, "animation.dragon.roar": { ... }, } } ``` -------------------------------- ### Material Configuration with Shader Defines Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/documentation/material-config-description.md An example of a material configuration including shader paths, vertex fields, and shader macro definitions. ```json "entity_for_skeleton": { "vertexShader": "shaders/entity.vertex", "vrGeometryShader": "shaders/entity.geometry", "fragmentShader": "shaders/entity.fragment", "+defines": [ "USE_SKINNING", "USE_OVERLAY", "NETEASE_SKINNING" ], "vertexFields": [ { "field": "Position" }, { "field": "Normal" }, { "field": "BoneId0" }, { "field": "UV0" } ], "msaaSupport": "Both", "+samplerStates": [ { "samplerIndex": 0, "textureFilter": "Point" } ] } ``` -------------------------------- ### Example Folder Structure for Functions Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/detect-movements.md Illustrates a common folder structure for organizing Minecraft functions, particularly for detection-related commands. ```text BP BP/functions BP/manifest.json BP/pack_icon.png BP/functions/wiki BP/functions/wiki/main.mcfunction BP/functions/wiki/detect BP/functions/wiki/detect/player BP/functions/wiki/detect/player/is_sleeping.mcfunction BP/functions/wiki/detect/player/is_crawling.mcfunction tick.json ``` -------------------------------- ### Install Stable API Modules (Bash) Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/scripting-intro.md Commands to install the latest stable versions of core Minecraft Script API modules using npm. ```bash npm i @minecraft/server npm i @minecraft/server-ui ``` -------------------------------- ### Molang Syntax Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/test.md Provides a comprehensive list of Molang syntax elements, including boolean values, numbers, strings, control flow statements, operators, function calls, and variable access. Useful as a reference for Molang syntax. ```molang false true 0 0.0 0.0f -0 -0.0 -0.0f 2.5e2 2.5e+2 2.5e-2 'string' this break continue return ! = < > != == <= >= ? : * / + - && || ?? -> loop() for_each() c.my_value context.my_value q.my_value query.my_value query.my_value() math.my_value math.my_value() t.my_value temp.my_value v.my_value variable.my_value array.my_value array.textures[v.texture_index] geometry.my_value material.my_value texture.my_value , ; ``` -------------------------------- ### Example Bedrock Model Geometry Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/guide/blockbench.md This is an example of a .geo.json file for a Bedrock Edition entity model. It defines the structure, bones, and cubes that make up the model. ```json { "format_version": "1.16.0", "minecraft:client_entity": { "description": { "identifier": "wiki:ghost", "materials": { "default": "entity/wiki/ghost" }, "textures": { "default": "textures/entity/wiki/ghost.png" }, "geometry": { "default": "geometry.ghost" }, "animations": { "move": "animations.ghost.move" }, "scripts": { "animate": [ "move" ] }, "render_controllers": [ "controller.render.default" ] } } } ``` -------------------------------- ### Bad Usage Example: Incorrect Animation Transition (Variant) Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/playanimation.md Another example of incorrect animation transition, specifically affecting head rotation while sneaking. ```command /playanimation @a attack.positions animation.ender_dragon.neck_head_movement 0 "v.head_position_y=0;v.head_rotation_y=q.target_y_rotation;return q.is_sneaking;" wiki:head ``` -------------------------------- ### Corner Transition Biome Configuration Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/world-generation/biomes.md Shows the configuration for a transition biome in a corner transition scenario. It uses values close to the extreme targets of the desired biome. ```json { "target_temperature": 0.8, "target_humidity": -0.8 } ``` -------------------------------- ### Bad Usage Example: Incorrect Animation Transition Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/playanimation.md This example demonstrates a potential issue where an animation is incorrectly transitioned, leading to unintended behavior when sneaking. ```command /playanimation @a animation.ender_dragon.neck_head_movement attack.positions 0 "v.head_position_y=0;v.head_rotation_y=q.life_time*1000;return !q.is_sneaking;" wiki:head ``` -------------------------------- ### Create a Label Element Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/json-ui/json-ui-intro.md Defines a UI element of type 'label' that will render the text 'Hello World'. ```json { "test_element": { "type": "label", "text": "Hello World" } } ``` -------------------------------- ### Applying Identifier-Based Configurations via Command Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/meta/deferred-qna.md This command syntax demonstrates how to apply a specific lighting configuration identified by its unique identifier. This is intended for use in scripting or command blocks to dynamically alter the game's lighting. ```shell /renderer lighting set bao:world_destroyer_event ``` -------------------------------- ### Manifest with Script Module and Dependencies Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/scripting-intro.md A complete behavior pack manifest.json including header, script module with entry point, and dependency on the '@minecraft/server' module. ```json { "format_version": 2, "header": { "name": "Bedrock Add-ons", "description": "Script API Template", "uuid": "", "version": "1.0.0", "min_engine_version": [1, 21, 114] }, "modules": [ { "uuid": "", "version": "1.0.0", "type": "script", "language": "javascript", // Your entry file; where Minecraft will read your code from. "entry": "scripts/main.js" } ], // Uncomment to use eval() and Function() inside your code (unrecommended), remove if not necessary // "capabilities": ["script_eval"], "dependencies": [ { // Enables the use of @minecraft/server module, with a version of 2.7.0 (the latest stable version available). "module_name": "@minecraft/server", "version": "2.7.0" } ] } ``` -------------------------------- ### Initialize World and Add Objectives Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/rearrange-positions.md Sets up the world by adding all required scoreboard objectives and marking the world as initialized. This function should be run once on world initialization. ```minecraft ## Add Objectives function wiki/scoreboard/objectives/add_all ## Initialization ### Add objective scoreboard objectives add wiki:q.is_initialised dummy ### Mark as Initialized scoreboard players set .World wiki:q.is_initialised 1 ``` -------------------------------- ### Synchronized Interval Timer Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/scoreboard-timers.md This snippet demonstrates how to run commands at regular intervals, such as applying an effect every 30 seconds and particles every tick. It shows how to manage timer occurrences and conditions. ```yaml ## Speed Effect (every 30s) + Particle (every tick) scoreboard players operation .SpeedEffect wiki:events %= .30s wiki:ticks execute if score .SpeedEffect wiki:occurrences matches 1.. as @a at @s run particle minecraft:shulker_bullet ~~~ execute if score .SpeedEffect wiki:events matches 0 if score .SpeedEffect wiki:occurrences matches 1.. run effect @a speed 10 2 true execute if score .SpeedEffect wiki:events matches 0 if score .SpeedEffect wiki:occurrences matches 1.. run scoreboard players remove .SpeedEffect wiki:occurrences 1 ``` -------------------------------- ### JavaScript Stack Trace Example Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/scripting/troubleshooting.md A stack trace lists the functions in order that led to a breakpoint, helping to identify the cause of a problem. This example shows a SyntaxError. ```javascript [Scripting][error]-SyntaxError: unexpected character at (index.js:16) at parse (native) at r (bundle.js) at (bundle.js) ``` -------------------------------- ### Adding Commands to Animation Timeline Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/items/equipped-item-commands.md Example of adding a command to the timeline of a server animation. This specific example adds an effect command that runs at the 0.0 keyframe. ```json { "0.0": ["/effect @s speed 1 0"] } ``` -------------------------------- ### Generic Mark Variant Examples Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/entities/vuc-full.md These examples show various mark variants that can be applied to entities. The specific entity type will determine the valid range of values. ```json "minecraft:mark_variant": { "value": 1 } ``` ```json "minecraft:mark_variant": { "value": 0 } ``` ```json "minecraft:mark_variant": { "value": 1 } ``` ```json "minecraft:mark_variant": { "value": 4 } ``` ```json "minecraft:mark_variant": { "value": 1 } ``` ```json "minecraft:mark_variant": { "value": 0 } ``` ```json "minecraft:mark_variant": { "value": 5 } ``` ```json "minecraft:mark_variant": { "value": 3 } ``` ```json "minecraft:mark_variant": { "value": 5 } ``` ```json "minecraft:mark_variant": { "value": 5 } ``` ```json "minecraft:mark_variant": { "value": 2 } ``` ```json "minecraft:mark_variant": { "value": 5 } ``` ```json "minecraft:mark_variant": { "value": 3 } ``` ```json "minecraft:mark_variant": { "value": 4 } ``` ```json "minecraft:mark_variant": { "value": 4 } ``` ```json "minecraft:mark_variant": { "value": 2 } ``` ```json "minecraft:mark_variant": { "value": 3 } ``` ```json "minecraft:mark_variant": { "value": 0 } ``` ```json "minecraft:mark_variant": { "value": 1 } ``` ```json "minecraft:mark_variant": { "value": 1 } ``` ```json "minecraft:mark_variant": { "value": 1 } ``` ```json "minecraft:mark_variant": { "value": 3 } ``` -------------------------------- ### Basic Instancing with Player Selector Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/commands/execution-forking.md This command demonstrates basic instancing. If there are 5 players online, the `at @a` subcommand forks the execution, running the particle command 5 separate times, once at the location of each player. ```minecraft_commands execute at @a run particle minecraft:basic_flame_particle ~ ~ ~ ``` -------------------------------- ### Example Vanilla Math-Based Animation Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/visuals/math-based-animations.md This is an example of a complex Molang expression used for animating entity geometry in vanilla Minecraft. It demonstrates the intricate nature of math-based animations. ```json "leftarm" : { "rotation" : [ "((-0.2 + 1.5 * (math.abs(math.mod(q.modified_distance_moved, 13) - 6.5) - 3.25) / 3.25) * q.modified_move_speed) * 57.3 - v.agent.armxrotationfactor", 0.0, "-v.agent.armzrotation" ] } ``` -------------------------------- ### Run Commands on Step Source: https://github.com/bedrock-oss/bedrock-wiki/blob/wiki/docs/blocks/block-event-migration.md Executes two chat commands: 'say Hello there!' and 'say Welcome to my world!' when an entity steps on the block. ```javascript onStepOn({ dimension }) { dimension.runCommand("say Hello there!"); dimension.runCommand("say Welcome to my world!"); } ```