### Install Dependencies and Run Dev Server
Source: https://context7.com/datapack-hub/wiki/llms.txt
Install project dependencies and start the local development server. The server auto-reloads on file changes. Also includes commands for type-checking, linting, and building for production.
```bash
# Install dependencies
npm install
# Run dev server (auto-reloads on file changes)
npm run dev
# Type-check and lint
npm run check
# Production build
npm run build
```
--------------------------------
### Install Project Dependencies
Source: https://github.com/datapack-hub/wiki/blob/main/CONTRIBUTING.md
Run this command to install all necessary project dependencies using npm.
```bash
$ npm install
```
--------------------------------
### Define Example Array
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/nbt-and-scores/array-iteration/+page.svx
This command initializes an example array in the storage. Ensure your scoreboard objective is created in your load function.
```mcfunction
data modify storage minecraft:example ExampleArray set value ["Array Item 1", "Array Item 2", "Array Item 3"]
```
--------------------------------
### Example Output
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/nbt-and-scores/array-iteration/+page.svx
Demonstrates the expected chat output and the final state of the example array after the iteration process is complete.
```mcfunction
Array Item 1
Array Item 2
Array Item 3
# /data get storage minecraft:example ExampleArray
Output: ["Iterated", "Iterated", "Iterated"]
```
--------------------------------
### Run Development Server
Source: https://github.com/datapack-hub/wiki/blob/main/CONTRIBUTING.md
Start the local development server to view changes in real-time. Open the provided URL in your browser.
```bash
$ npm run dev
```
--------------------------------
### Create a Wiki Page with Frontmatter and Markdown
Source: https://context7.com/datapack-hub/wiki/llms.txt
Example of a SvelteKit page file (.svx) for a Minecraft datapack wiki entry. It includes YAML frontmatter for metadata and Markdown content with a specific command example.
```markdown
---
title: /say
description: "The say command broadcasts a message to all online players."
version: 26.1.2
tags: command, chat
---
# /say command
The `/say` command broadcasts a plain-text message to all online players.
## Syntax
```mcfunction
say
```
## Example
```mcfunction
# Announce a message to all players
say Welcome to the server!
```
:::info
The message is prefixed with the executor's name in square brackets, e.g. `[ServerName] Welcome to the server!`
:::
```
--------------------------------
### Datapack Function File Example
Source: https://context7.com/datapack-hub/wiki/llms.txt
Functions are plain-text files containing Minecraft commands, one per line. Lines starting with `#` are comments. Place them in `data//function/`.
```mcfunction
# data/example/function/loop.mcfunction
# Runs every tick via the minecraft:tick function tag
# Select all arrows that have landed and explode them
execute as @e[type=arrow,nbt={inGround:1b}] at @s run summon tnt ~ ~ ~ {fuse:0}
kill @e[type=arrow,nbt={inGround:1b}]
```
--------------------------------
### Example Action on COAS Right Click
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/right-click/coas/+page.svx
This is an example of what can be placed in the `rc_run.mcfunction` file to perform an action when a COAS is right-clicked. This example makes the player say 'Used COAS'.
```mcfunction
say Used COAS
```
--------------------------------
### Basic Function Example
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/files/functions/+page.svx
This function gives every player an apple and then displays a message to them. Lines starting with '#' are comments and are ignored by the game.
```mcfunction
# Give a player the apple
give @a minecraft:apple
# Tell them to enjoy the apple
say Enjoy the apple!
```
--------------------------------
### Example of Forking with /execute
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/command/execute/+page.svx
Demonstrates how the /execute command forks execution when targeting multiple entities, with each branch executing independently.
```mcfunction
say first command
say second command
```
--------------------------------
### Shaped Crafting Recipe Example
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/files/recipes/+page.svx
Example of a shaped crafting recipe for bedrock using beds and stone. This recipe can be placed in the `data//recipe` folder.
```json
{
"type": "minecraft:crafting_shaped",
"pattern": [
"___",
" X ",
"___"
],
"key": {
"_": "#minecraft:beds",
"X": "minecraft:stone"
},
"result": {
"id": "minecraft:bedrock"
}
}
```
--------------------------------
### Handle Legacy Guide URL Redirect
Source: https://context7.com/datapack-hub/wiki/llms.txt
This route provides a permanent (308) redirect from the old `/guides/` URL prefix to the canonical `/guide/` prefix.
```bash
curl -I https://datapack.wiki/guides/getting-started
# HTTP/2 308
# Location: /guide/getting-started
```
--------------------------------
### Info Admonition Example
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/contribute/formatting/+page.svx
Demonstrates how to create an informational admonition block using markdown syntax. This is useful for displaying important tips or notes.
```markdown
:::info
This is an example of an info box.
:::
```
--------------------------------
### Example Resource Location for a Function
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/concepts/resource-locations/+page.svx
Use this format to reference a specific function within a datapack. The 'function' folder is implied by the '/function' command.
```mcfunction
/function my_namespace:some_folder/my_function
```
--------------------------------
### Highlighting Component Example
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/contribute/formatting/+page.svx
Shows how to use the Highlight component to add colored emphasis to text within the wiki. Specify the color using a hex code.
```svelte
Highlighted Text
```
--------------------------------
### Execute Minecraft functions
Source: https://context7.com/datapack-hub/wiki/llms.txt
Demonstrates how to run `.mcfunction` files using the `/function` command. Includes examples for running plain functions, macro functions with NBT arguments, and sourcing arguments from storage.
```mcfunction
# Run a plain function
function example:setup
# Run a macro function, passing arguments as a NBT compound
function example:give_items {count: 5, item: "diamond"}
# Run a macro function sourcing arguments from storage
data modify storage example:args item set value "emerald"
function example:give_items with storage example:args
```
--------------------------------
### Fetch Datapack Sitemap
Source: https://context7.com/datapack-hub/wiki/llms.txt
Retrieve the auto-generated sitemap for all wiki and guide pages. Excludes internal JSON/XML routes.
```bash
curl https://datapack.wiki/sitemap.xml
# Returns a standard XML sitemap with all wiki and guide page URLs,
# changefreq: weekly, origin: https://datapack.wiki
```
--------------------------------
### Example: Text Component with Click Event
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/concepts/text/+page.svx
This JSON object demonstrates how to create a text component that, when clicked, executes a command. Ensure the player has the necessary permissions to run the specified command.
```json
{
"text": "Click me",
"click_event": { "action": "run_command", "command": "/say Hello" }
}
```
--------------------------------
### Markdown Content Example
Source: https://github.com/datapack-hub/wiki/blob/main/CONTRIBUTING.md
Write the main content of your page using Markdown. Supports custom info, warning, and tip boxes.
```markdown
# /function command
This command runs any `.mcfunction` file when called. You can also pass in a NBT
compound or NBT source path.
:::info
I am a very important piece of information. Please dont ignore me. I'm
only smol.
:::
:::warning
The stuff in this box is probably very important.
:::
:::tip
You can do this really cool thing. It'll make your life a lot better!
:::
```
--------------------------------
### NBT Path Examples
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/nbt-scoreboards/nbt/+page.svx
Demonstrates various NBT path syntaxes for accessing data within a nested NBT structure, including direct keys, array indices, and object value matching.
```javascript
{
root: {
version: 1,
title: "Targets",
people: [
{name: "Silabear", age: 102},
{name: "Aandeel", age: 100}
]
}
}
```
```plaintext
root.version
```
```plaintext
root.title
```
```plaintext
root.people[0]
```
```plaintext
root.people[0].name
```
```plaintext
root.people[{name:"Aandeel"}]
```
```plaintext
root.people[{name:"Aandeel"}].age
```
--------------------------------
### Example: tellraw command with target selector
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/concepts/target-selectors/+page.svx
Demonstrates using a target selector with the tellraw command to send a message to players within a specific range.
```minecraft-commands
tellraw @a[distance=..10] "You're within 10 blocks of me"
```
--------------------------------
### JavaScript Function Example
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/contribute/formatting/+page.svx
A basic JavaScript function example. This snippet is intended to showcase code block formatting with a title and syntax highlighting.
```js:example.js
function example() {
console.log("Hello World!");
}
```
--------------------------------
### Use predicates in Minecraft commands
Source: https://context7.com/datapack-hub/wiki/llms.txt
These examples show how to use a defined predicate in Minecraft commands. The first example uses it with `execute as` to target players holding a sword, and the second shows its use with `execute if`.
```mcfunction
# Use the predicate in a command
execute as @a[predicate=example:holding_sword] run say I am holding a sword!
# Use in execute if
execute if predicate example:holding_sword run ...
```
--------------------------------
### Execute Command on Ground Arrows
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/getting-started/+page.svx
This example demonstrates using `execute as` with a target selector to run a command on specific entities. It selects arrows in the ground and makes them say a message.
```mcfunction
execute as @e[type=arrow,nbt={inGround:1b}] run say I'm an arrow, I'm in the ground!
```
--------------------------------
### Execute commands with context and conditions
Source: https://context7.com/datapack-hub/wiki/llms.txt
This section provides examples of the powerful `/execute` command in Minecraft. It demonstrates running commands as specific entities, at their positions, conditionally, storing results, chaining commands, and using predicates.
```mcfunction
# Run a function as every cow, at the cow's position
execute as @e[type=minecraft:cow] at @s run function example:cow_tick
# Conditional: only run if a block is present
execute if block ~ ~-1 ~ minecraft:grass_block run say I'm standing on grass!
# Store the result of a command into a scoreboard
execute store result score @s my_score run data get entity @s Health
# Chain: teleport every player above Y=300 to safety
execute as @a if entity @s[y=300,dy=500,distance=..500] run teleport @s ~ 64 ~
# Check a predicate, then run at the entity's feet
execute as @e[type=minecraft:zombie] at @s if predicate example:is_near_player run function example:zombie_aggro
# positioned over heightmap — place above terrain
execute positioned as @s positioned over world_surface run summon minecraft:lightning_bolt ~ ~ ~
```
--------------------------------
### SNBT Integer Examples
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/nbt-scoreboards/nbt/+page.svx
Examples of representing whole numbers using different integer types and suffixes in SNBT. Numbers are stored as integers by default.
```plaintext
count:1234s
```
```plaintext
bigNumber:1200000
```
```plaintext
reallyBigNumber:12123023687234L
```
```plaintext
byte:112b
```
--------------------------------
### Example JSON Structure
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/info/json/+page.svx
Demonstrates a typical JSON object with various data types including strings, integers, booleans, lists, and nested dictionaries.
```json
{
"name": "Aron Aronson",
"age": 83,
"alive": true,
"family_members": ["James Aronson", "Catherine Aronson"],
"login_details": {
"email": "aron.aronson@gmail.com",
"password": "MyNameIsAron12345"
}
}
```
--------------------------------
### Example Minecraft Ore Placement Configuration
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/worldgen/custom-worldgen/+page.svx
This JSON defines the placement configuration for an ore feature, specifying its size, discard chance on air exposure, and the types of blocks it can replace.
```json
{
"type": "minecraft:ore",
"config": {
"discard_chance_on_air_exposure": 0.0,
"size": 10,
"targets": [
{
"state": {
"Name": "minecraft:copper_ore"
},
"target": {
"predicate_type": "minecraft:tag_match",
"tag": "minecraft:stone_ore_replaceables"
}
},
{
"state": {
"Name": "minecraft:deepslate_copper_ore"
},
"target": {
"predicate_type": "minecraft:tag_match",
"tag": "minecraft:deepslate_ore_replaceables"
}
}
]
}
}
```
--------------------------------
### SNBT Example Structure
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/nbt-scoreboards/nbt/+page.svx
Illustrates the basic structure of SNBT, a human-readable format for NBT data, using key/value pairs within compounds and arrays.
```plaintext
{name:"Silabear",age:102,friends:["Flynecraft","Aandeel","Cobblestone"],socials:{discord:"silabear"}}
```
--------------------------------
### Give Command with Item Name Component
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/adding-new-features/custom-items/intro/+page.svx
Example of using the `item_name` component to set a custom name for an item in a give command.
```mcfunction
/give @s flint[minecraft:item_name="Sharp Rock"]
```
--------------------------------
### Apply Styles to Text Component
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/concepts/text/+page.svx
This example shows how to apply multiple style properties to a text component. Use 'true' or 'false' for boolean styles and valid color names or hex codes for color.
```json
{ "text": "Hello World", "color": "red", "bold": true, "strikethrough": true }
```
--------------------------------
### Using the Svelte Component
Source: https://context7.com/datapack-hub/wiki/llms.txt
Example of importing and using the `` Svelte component in a .svx page. It displays a banner indicating if the page's declared version is up-to-date with the latest Minecraft release.
```svelte
---
title: Functions
version: 26.1.2
---
# Functions
Functions are `.mcfunction` files containing a list of commands...
```
--------------------------------
### Summon and Initialize Slowcast Projectile
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/misc/slowcasts/+page.svx
Summons a marker entity and runs the setup function as that entity to initialize it as a slowcast projectile. This is typically executed at the player's position.
```mcfunction
execute anchored eyes positioned ^ ^ ^.3 summon minecraft:marker run function :setup
```
--------------------------------
### Setup Slowcast Projectile Properties
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/misc/slowcasts/+page.svx
Tags the entity as a slowcast projectile and sets its initial scores by copying from temporary scoreboards. It then calls the main ticking function.
```mcfunction
tag @s add slowcast
scoreboard players operation @s slowcast.steps = maxSteps temp
scoreboard players operation @s slowcast.duration = duration temp
function :temp_tick
```
--------------------------------
### Using the Svelte Component
Source: https://context7.com/datapack-hub/wiki/llms.txt
Example of using the `` Svelte component for inline text highlighting. It accepts a CSS-compatible color prop to customize the highlight color.
```svelte
The execute command is the most powerful command in datapacks.
The function command runs an `.mcfunction` file.
```
--------------------------------
### Read and modify NBT data
Source: https://context7.com/datapack-hub/wiki/llms.txt
Examples for the `/data` command, which allows reading, merging, modifying, copying, appending, and removing NBT data from entities, block entities, and storages. It also shows how to use `execute store` with `/data`.
```mcfunction
# Get the item in a player's main hand
data get entity @s SelectedItem.id
# Merge NBT onto a creeper (short fuse, big explosion)
data merge entity @e[type=creeper,limit=1,sort=nearest] {Fuse: 5s, ExplosionRadius: 8b}
# Set a value in named storage
data modify storage example:globals currentPhase set value "attack"
# Copy a value from storage to an entity
data modify entity @s CustomName set from storage example:globals playerName
# Append to a list in storage
data modify storage example:log entries append value "Player joined at noon"
# Remove a path from storage
data remove storage example:temp scratch
# Use with execute store to convert NBT to a scoreboard value (scaled ×1)
execute store result score @s health_score run data get entity @s Health 1
```
--------------------------------
### Start Raycast Function
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/misc/raycasts/+page.svx
This function initiates the raycast. It tags the caster, sets the maximum raycast distance, and calls the main raycast function from the player's eye position.
```mcfunction
# Tag the raycaster
tag @s add raycaster
# Set the maximum distance
scoreboard players set .raycastLimit raycast 1000
# Begin the raycast function
execute at @s anchored eyes positioned ^ ^ ^.1 run function :raycast
# Remove the tag from the raycaster
tag @s remove raycaster
```
--------------------------------
### Summon with Tags and Execute Function
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/command/summon/+page.svx
This mcfunction example demonstrates summoning an entity, tagging it, executing a function as that entity, and then removing the tag. This is an alternative to 'execute summon' when NBT data is required.
```mcfunction
summon minecraft:cow ~ ~ ~ {Tags:["newly_summoned_cow"]}
execute as @n[type=cow,tag=newly_summoned_cow] at @s run function custom_function
tag @n[type=cow,tag=newly_summoned_cow] remove newly_summoned_cow
```
--------------------------------
### Example Biome Entry for Dimension File
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/worldgen/custom-worldgen/+page.svx
This JSON structure defines a single biome entry within a dimension's biome source configuration. It specifies the biome's namespaced ID and a set of parameters that control its placement based on noise maps. Ensure all listed parameters are included, and they can be either a single value or a min/max range.
```json
{
"biome": "minecraft:plains",
"parameters": {
"temperature": [-0.45, -0.15],
"humidity": [-1, -0.35],
"continentalness": [-0.11, 0.3],
"erosion": [-0.7799, -0.375],
"weirdness": [-1, -0.9333],
"depth": 0,
"offset": 0
}
}
```
--------------------------------
### Start Array Iteration
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/nbt-and-scores/array-iteration/+page.svx
This function gets the length of the array and stores it in a score. It then calls the loop function if the array has at least one element. Replace `` with your actual scoreboard objective name.
```mcfunction
# Get the length of the array, and store it in a fake player in a scoreboard
# (we assume you already have created a scoreboard - do this in your load function)
execute store result $length run data get storage minecraft:example ExampleArray
# If the length is at least 1, run the loop function
execute if score $length matches 1.. run function :array_loop
```
--------------------------------
### SNBT Decimal Number Examples
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/nbt-scoreboards/nbt/+page.svx
Examples of representing decimal numbers using Float and Double types in SNBT. Doubles are used by default.
```plaintext
pi:3.1415926535d
```
```plaintext
e:2.718281828459045d
```
```plaintext
phi:1.6180f
```
--------------------------------
### SNBT Boolean Examples
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/nbt-scoreboards/nbt/+page.svx
Examples of representing booleans in SNBT. Historically, booleans were represented by bytes (0b for false, 1b for true), but dedicated boolean types are now recommended for readability.
```plaintext
0b
```
```plaintext
1b
```
--------------------------------
### data get
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/command/data/+page.svx
Gets NBT data from a specified source and path, optionally multiplying by a scale factor. The result is printed in SNBT format and can be used with 'execute store' or 'return run'.
```APIDOC
## data get [path] [scale]
### Description
Gets the data from a data source, and a `path`, if specified. Multiplies the resulting value by `scale`, if specified. `source` is a [data source], `path` is an [nbt path] and `scale` is a number. If `scale` is set, and the data at that path it not a number, the command fails.
After fetching the NBT at the path, if it exists, it prints the data in [SNBT] format in the chat. Therefore, its main use is manually inspecting NBT data. However, it also returns the integer representation of the fetched data, so it can be used in combination with `execute store` or `return run` to convert NBT into an integer.
### Parameters
#### Source
- `source` (data source) - Required - The data source to fetch from.
- `path` (nbt path) - Optional - The NBT path to the data.
- `scale` (number) - Optional - A number to multiply the fetched value by.
### Examples
```
data get entity @s SelectedItem.id
data get block ~ ~ ~ Items
```
```
--------------------------------
### Initialize Scoreboards for Slowcasting
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/misc/slowcasts/+page.svx
Sets up the necessary scoreboards for tracking slowcast steps and duration. This should be run once on world load.
```mcfunction
scoreboard objectives add temp dummy
scoreboard objectives add slowcast.steps dummy
scoreboard objectives add slowcast.duration dummy
```
--------------------------------
### SNBT List and Number Array Examples
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/nbt-scoreboards/nbt/+page.svx
Examples of defining lists and number arrays in SNBT. Lists can store mixed types, while number arrays are type-specific and can be prefixed with the type and a semicolon (e.g., [B;]).
```plaintext
["Silabear", 15, true, 242]
```
```plaintext
[B;1b,2B,true,false]
```
```plaintext
["Kanokarob", "LadyEternal", "lionlance", "thederdiscohund", "theblackswitch"]
```
```plaintext
[L;1l,2l,3l,4l,5l]
```
--------------------------------
### Initialize and Modify NBT Storage
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/nbt-scoreboards/nbt/+page.svx
Shows how to initialize and modify an NBT storage using `/data` commands. Storages are global and do not require pre-initialization.
```mcfunction
data merge storage example:main {number: 1, message: "Hello!"}
```
```mcfunction
data modify storage example:main other_number set from storage example:main number
```
```mcfunction
data modify storage example:main compound.array append value 42
```
--------------------------------
### Get Block Inventory
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/command/data/+page.svx
Retrieves the inventory data of a block at the current coordinates.
```minecraft
data get block ~ ~ ~ Items
```
--------------------------------
### Get Entity Item ID
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/command/data/+page.svx
Fetches the ID of the item currently held by an entity.
```minecraft
data get entity @s SelectedItem.id
```
--------------------------------
### Customizable Info/Warning/Tip Boxes
Source: https://github.com/datapack-hub/wiki/blob/main/CONTRIBUTING.md
Create distinct informational, warning, or tip boxes within your Markdown content using the ::: syntax.
```markdown
:::info
This is an info box!
:::
:::warning
This is a warning box!
:::
:::tip
This is a tip box!
:::
```
--------------------------------
### MCFunction Variables: Scoreboards, Macros, and Storages
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/mcf-vs-code/+page.svx
Demonstrates the creation and manipulation of variables using scoreboards, macros for templating, and storages for NBT data in MCFunction.
```mcfunction
# Scoreboards
# creates a new table called storage
# (dummy means it does not track any statistic)
scoreboard objectives add storage dummy
# adds a fake player named "$steps" to storage (using prefix "$" to avoid collisions with real players, good practice)
scoreboard players set $steps storage 41
# sets the value of a player to 42
scoreboard players set Cbble_ storage 42
# Macros
# Run cool function with a macro
function dph:cool_function with block ~ ~ ~ Items
function dph:cool_function with entity @e[type=minecraft:squid,limit=1,sort=nearest] CustomName
function dph:cool_function {Potato:true}
# Usage with entity NBT:
execute as @p run dph:cool_function with entity @s SelectedItem
# this is in the dph:cool_function function
$say The player running this function is holding $(count) items with ID $(id)!
# Storages
data merge storage example:main {number: 1, message: "Hello!"}
data modify storage example:main other_number set from storage example:main number
data modify storage example:main compound.array append value 42
```
--------------------------------
### Create Datapack Command
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/getting-started/+page.svx
Use this command in-game to create a new datapack with a specified ID and description. This automatically generates the necessary folder structure and pack.mcmeta file.
```minecraft
/datapack create example_datapack "This is an example datapack"
```
--------------------------------
### Datapack Function Tag for Load Execution
Source: https://context7.com/datapack-hub/wiki/llms.txt
JSON files in `data/minecraft/tags/function/` schedule functions to run automatically. This example schedules a function to run once on `/reload`.
```json
// data/minecraft/tags/function/load.json — runs once on /reload
{
"values": ["example:setup"]
}
```
--------------------------------
### Front Matter Example
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/contribute/formatting/+page.svx
Front matter is required for page metadata like title, description, and version. It is denoted by triple hyphens at the top of the page.
```markdown
title: "Site Development" description: "This page is meant to be an introduction
to formatting a page for the wiki. In it is multiple examples which you can
examine raw in the [site source code](https://github.com/Datapack-Hub/wiki)."
version: 1.21.5
```
--------------------------------
### Initialize and Search Datapack Index with Node.js
Source: https://context7.com/datapack-hub/wiki/llms.txt
Use `createSearchIndex` once on page load after fetching search data, then use `search` for user input. Supports full-text and tag-based searches.
```typescript
import { createSearchIndex, search } from "$lib/search";
// 1. Initialize index (done once at app startup)
const pages = await fetch("/search.json").then(r => r.json());
createSearchIndex(pages);
// 2. Full-text search — returns up to 1 highlighted snippet per result
const results = search("execute as");
// => [{ title: "...execute ...", url: "/wiki/command/execute", content: ["...run execute as @a..."] }]
// 3. Tag-based search using the tag: prefix
const tagResults = search("tag:beginner");
// => [{ title: "How to Make a Minecraft Datapack", url: "/guide/getting-started", content: [""] }]
```
--------------------------------
### execute run
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/command/execute/+page.svx
Executes a specified command with the current context. This command takes no further subcommands and is typically used after other 'execute' subcommands.
```APIDOC
## execute run
### Description
Runs the specified command with the current context. Takes no further subcommands. This is useless by itself, and should always be preceded by other subcommands.
### Parameters
#### Path Parameters
- **command** (string) - Required - The command to execute.
### Request Example
```
execute run say hi
execute at @e[type=sheep] run setblock ~ ~ ~ stone
```
```
--------------------------------
### Hello World mcfunction
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/getting-started/+page.svx
A basic function file that displays 'Hello World!' to the player's screen and gives them a diamond. Commands within .mcfunction files should not include the leading slash.
```mcfunction
# Show the player Hello World on their screen
title @s title "Hello World!"
# Give the player a diamond
give @s diamond
```
--------------------------------
### Datapack Function Tag for Tick Execution
Source: https://context7.com/datapack-hub/wiki/llms.txt
JSON files in `data/minecraft/tags/function/` schedule functions to run automatically. This example schedules a function to run every game tick.
```json
// data/minecraft/tags/function/tick.json — runs every game tick (20/sec)
{
"values": ["example:loop"]
}
```
--------------------------------
### Define Custom Trim Material - matexample.json
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/adding-new-features/smithing-trims/+page.svx
This JSON file defines a new smithing trim material, including its asset name and a descriptive text component with a specific color. This file should be placed in `data//trim_material/`.
```json
{
"asset_name": "matexample",
"description": {
"text": "Example Material",
"color": "#00e09d"
}
}
```
--------------------------------
### Select Entities by NBT Data
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/getting-started/+page.svx
Use the `nbt` criteria to select entities based on their internal data (NBT). For example, `nbt={inGround:1b}` selects entities that are in the ground.
```mcfunction
[nbt={key:value}]
```
```mcfunction
@e[type=arrow,nbt={inGround:1b}]
```
--------------------------------
### Manage Global State with Svelte 5 Stores
Source: https://context7.com/datapack-hub/wiki/llms.txt
Utilize Svelte 5 '$state' stores for shared global state. 'windowInfo' tracks UI state like sidebar visibility, while 'latestMCData' holds Minecraft version information fetched server-side.
```typescript
import { latestMCData, windowInfo } from "$lib/stores.svelte";
// windowInfo: tracks sidebar open/closed state and viewport width
windowInfo.isNavOpen = false; // collapse sidebar
console.log(windowInfo.width); // current window width (default 1920)
// latestMCData: populated at layout load time from the mcmeta API
// defaults: { packFormat: 57, gameVersion: "1.21.1", changed: false }
console.log(latestMCData.gameVersion); // e.g. "1.21.11"
console.log(latestMCData.packFormat); // e.g. 94
```
--------------------------------
### Limit Selection Size
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/getting-started/+page.svx
Use the `limit` criteria to specify the maximum number of entities to select. Often used with `sort=nearest` to get a specific number of closest entities.
```mcfunction
[limit=2]
```
```mcfunction
[sort=nearest,limit=1]
```
--------------------------------
### Implement Version Picker for Sidebar Navigation
Source: https://context7.com/datapack-hub/wiki/llms.txt
Create a VersionPicker component to allow users to switch between different sidebar navigation sets based on Minecraft version. It dynamically imports the correct Svelte module.
```svelte
{#await import(`./${version}/WikiPages.svelte`)}
Loading...
{:then WPage}
{/await}
```
--------------------------------
### Fetch Datapack Search Metadata
Source: https://context7.com/datapack-hub/wiki/llms.txt
Retrieve the pre-built array of page metadata for populating the search index. This endpoint is prerendered at build time.
```bash
curl https://datapack.wiki/search.json
# Response (truncated):
# [{"title":"Home","content":"Welcome to the Datapack Wiki...","url":"/","tags":[]}, ...]
```
--------------------------------
### Remove NBT Data from Storage
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/command/data/+page.svx
Removes NBT data from a specified storage at a given path. This example demonstrates removing multiple keys by targeting a common parent path.
```mcfunction
data modify storage example:main temp.a set value 1
data modify storage example:main temp.b set value 2
# Removes both keys
data remove storage example:main temp
```
--------------------------------
### Select Entities by Type
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/getting-started/+page.svx
Use the `type` criteria within square brackets to filter selections by entity type. For example, `[type=minecraft:cow]` selects only cows. This is recommended for performance.
```mcfunction
@e[type=minecraft:cow]
```
--------------------------------
### Render Collapsible File Tree with TreeRoot and TreeEntry
Source: https://context7.com/datapack-hub/wiki/llms.txt
Use TreeRoot and TreeEntry components to display an interactive, collapsible file tree structure. No specific imports are needed beyond the components themselves.
```svelte
pack.mcmetadata/function/hello_world.mcfunctionloop.mcfunction
```
--------------------------------
### SNBT String Formatting
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/nbt-scoreboards/nbt/+page.svx
Demonstrates the formatting rules for strings in SNBT, which can be enclosed in double quotes, single quotes, or optionally have no quotes if they start with a letter and contain only allowed characters.
```plaintext
name:"Silabear"
```
```plaintext
name:'Cobblestone'
```
```plaintext
name:Aandeel
```
--------------------------------
### Calling Functions in MCFunction
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/mcf-vs-code/+page.svx
Illustrates the basic syntax for calling other functions within your datapack using the `function` command.
```mcfunction
function [...]
```
--------------------------------
### Page Metadata Configuration
Source: https://github.com/datapack-hub/wiki/blob/main/CONTRIBUTING.md
Define the title and description for your wiki page using YAML front matter at the top of the .svx file.
```yaml
---
title: Page title
description: "Here is a short description!"
---
```
--------------------------------
### Create a Repeating Function
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/guide/getting-started/+page.svx
Use a `tick.json` file to specify functions that should run every game tick. Ensure the `values` array contains valid function references.
```mcfunction
say Hi
```
--------------------------------
### Example Item Tag JSON
Source: https://github.com/datapack-hub/wiki/blob/main/src/routes/wiki/files/tags/+page.svx
This JSON structure defines an item tag. The 'replace' field determines if the tag overwrites existing ones. 'values' lists the items or other tags to include.
```json
{
"replace": true,
"values": [
"#minecraft:logs",
"#minecraft:planks",
"minecraft:chest",
"minecraft:stick"
]
}
```