### Example Datapack Function Source: https://datapack.wiki/wiki/files/functions This example demonstrates a basic Minecraft function that gives all players an apple and then displays a message. It includes comments, which 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! ``` -------------------------------- ### JavaScript Code Block Example Source: https://datapack.wiki/contribute/formatting A basic JavaScript function example, demonstrating how to format code snippets within wiki pages. This snippet includes a title for the code block, improving clarity when presenting code samples. ```javascript function example() { console.log("Hello World!"); } ``` -------------------------------- ### Minecraft: Example function for execute command Source: https://datapack.wiki/wiki/command/execute A sample function that might be executed by the /execute command. It shows basic commands that would run within a modified context. ```minecraft say first command say second command ``` -------------------------------- ### NBT Path Examples Source: https://datapack.wiki/wiki/nbt-scoreboards/nbt Examples of NBT paths used to navigate and access specific data within an NBT structure. Paths use dot notation for nested compounds and square brackets for array indices or object matching. ```NBT Path root.version root.title root.people[0] root.people[0].name root.people[{name:"Aandeel"}] root.people[{name:"Aandeel"}].age ``` -------------------------------- ### Example Command: Using a Predicate Source: https://datapack.wiki/wiki/files/predicates This command demonstrates how to use a previously defined predicate (`namespace:my_predicate`) to select players who meet the specified conditions and execute a command for them. It uses the 'execute as @a[predicate=...]' syntax. ```minecraft_command execute as @a[predicate=namespace:my_predicate] run say I am holding beef in a desert village :D ``` -------------------------------- ### Example JSON Structure Source: https://datapack.wiki/wiki/info/json Demonstrates a typical JSON object structure with various data types including strings, integers, booleans, lists, and nested dictionaries. This serves as a foundational example for understanding JSON organization. ```json { "name": "Aron Aronson", "age": 83, "alive": true, "family_members": ["James Aronson", "Catherine Aronson"], "login_details": { "email": "aron.aronson@gmail.com", "password": "MyNameIsAron12345" } } ``` -------------------------------- ### Markdown Admonition Example Source: https://datapack.wiki/contribute/formatting This shows how to create an 'info' admonition box within Markdown content. Admonitions are used to highlight important information such as warnings, tips, or general info, improving page readability. ```markdown :::info This is an example of an info box. ::: ``` -------------------------------- ### NBT Storage Data Example Source: https://datapack.wiki/wiki/nbt-scoreboards/nbt The resulting NBT data structure within a storage after executing the initialization and modification commands. This demonstrates how data is organized in storages. ```NBT {number: 1,message: "Hello!",other_number: 1,compound: {array: [42]}} ``` -------------------------------- ### Markdown Frontmatter Example Source: https://datapack.wiki/contribute/formatting This snippet demonstrates the structure of front matter, which includes metadata like title, description, and version for a wiki page. Front matter is enclosed by triple hyphens and is crucial for SEO and proper page rendering. ```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 --- ``` -------------------------------- ### SNBT Structure Example Source: https://datapack.wiki/wiki/nbt-scoreboards/nbt An example of the SNBT (Stringified Named Binary Tags) format, which is a human-readable representation of NBT data used in Minecraft datapacks. It demonstrates key/value pairs, compounds, and arrays. ```SNBT {name:"Silabear",age:102,friends:["Flynecraft","Aandeel","Cobblestone"],socials:{discord:"silabear"}} ``` -------------------------------- ### Minecraft Text Component: Styled Text Source: https://datapack.wiki/wiki/concepts/text Shows an example of a styled text component in Minecraft, making the text 'Hello World' appear in red, bold, and strikethrough. This illustrates the use of color and boolean style properties. ```json { "text": "Hello World", "color": "red", "bold": true, "strikethrough": true } ``` -------------------------------- ### NBT Storage Initialization and Modification Source: https://datapack.wiki/wiki/nbt-scoreboards/nbt Examples of Minecraft commands to initialize and modify NBT storages. Storages allow global data storage per world, accessed via the /data command. ```Minecraft Commands 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 ``` -------------------------------- ### Calling Macro Functions with Arguments Source: https://datapack.wiki/wiki/files/functions This example illustrates how to invoke a macro function with dynamic arguments. It shows two methods: directly passing NBT data with the 'function' command and using a storage to hold the macro values before calling the function. ```mcfunction function example:macro {count: 7} # This also works data modify storage example:storage count set value 12 function example:macro with storage example:storage ``` -------------------------------- ### Get NBT Data with /data get Source: https://datapack.wiki/wiki/command/data Retrieves NBT data from a specified source and path, optionally scaling the result. Used for inspecting NBT or converting it to an integer for use with 'execute store'. Fails if the path does not contain a number when a scale is applied. ```minecraft-commands data get entity @s SelectedItem.id ``` ```minecraft-commands data get block ~ ~ ~ Items ``` -------------------------------- ### Macro Function Example for Giving Diamonds Source: https://datapack.wiki/wiki/files/functions This snippet shows a macro function that dynamically gives a player a specified number of diamonds. The $(count) placeholder is replaced with a numerical value when the function is called, allowing for variable output. ```mcfunction # When called, $(count) will be replaced with some number, producing a valid command $give @s diamond $(count) ``` -------------------------------- ### Execute Command with Context Change Source: https://datapack.wiki/wiki/concepts/commands Demonstrates the usage of the '/execute' command in Minecraft to alter the context for a subsequent command. This specific example changes the executor to a player named 'Silabear' and sets the command's position to '123 456 789' before running the 'say Hello!' command. ```minecraft-commands execute as Silabear positioned 123 456 789 run say Hello! ``` -------------------------------- ### Minecraft: Execute align axes Source: https://datapack.wiki/wiki/command/execute Shows examples of the 'execute align' subcommand, which rounds down coordinates to the nearest integer along specified axes (x, y, z). ```minecraft execute align xz ``` ```minecraft execute align yxz ``` -------------------------------- ### Specify Selection Area with Coordinates in Minecraft Source: https://datapack.wiki/wiki/concepts/target-selectors Arguments `x`, `y`, `z` define a starting point for selection, affecting `distance` and `dx`/`dy`/`dz`. `dx`, `dy`, `dz` define a cuboid selection area. If not set, they default to 0. ```minecraft_commands @e[x=10,y=9,z=-5,distance=..5] @e[x=10,y=13,z=87,dx=10,dy=20,dz=5] ``` -------------------------------- ### Shaped Crafting Recipe for Bedrock (JSON) Source: https://datapack.wiki/wiki/files/recipes An example of a shaped crafting recipe in JSON format for creating bedrock. This recipe utilizes item tags and specific items as keys within the crafting grid. It is typically placed in the data//recipe folder. ```json { "type": "minecraft:crafting_shaped", "pattern": [ "___", " X ", "___" ], "key": { "_": "#minecraft:beds", "X": "minecraft:stone" }, "result": { "id": "minecraft:bedrock" } } ``` -------------------------------- ### Define Selection Cuboid with Position Arguments Source: https://datapack.wiki/wiki/concepts/target-selectors Specifies a starting position (x, y, z) and dimensions (dx, dy, dz) to create a cuboid for entity selection. Any entity intersecting this cuboid is selected. ```minecraft-commands @e[x=10,y=9,z=-5,distance=..5] @e[x=10,y=13,z=87,dx=10,dy=20,dz=5] @e[x=7,y=3,z=9,dx=0,dy=0,dz=0] ``` -------------------------------- ### Minecraft: Execute on relation Source: https://datapack.wiki/wiki/command/execute Provides examples of the 'execute on' subcommand, which changes the executor based on a specified relation to the current entity (e.g., attacker, passengers, target). ```minecraft execute on passengers ``` ```minecraft execute on target ``` -------------------------------- ### Example of Entity Attribute NBT Change (1.21) Source: https://datapack.wiki/wiki/info/breaking-changes Demonstrates the transformation of the entity attribute NBT structure from older versions to the format used in 1.21. It highlights the renaming of keys like 'Attributes' to 'attributes' and 'Name' to 'id'. ```minecraftnbt summon ... {Attributes:[{Name:"generic.scale",Base:2,Modifiers:[{UUID:[I;1,0,0,0],Name:"example_modifier",Amount:1,Operation:0}]}]} would now look like summon ... {attributes:[{id:"generic.scale",base:2,modifiers:[{id:"tutorial:example_modifier",amount:1,operation:"add_value"}]}]} ``` -------------------------------- ### Example Predicate: Holding Beef in Desert Village Source: https://datapack.wiki/wiki/files/predicates This JSON predicate checks if an entity is holding 'minecraft:beef' in their main hand and is located within a desert village structure. It utilizes the 'entity_properties' condition. ```json { "condition": "minecraft:entity_properties", "entity": "this", "predicate": { "location": { "structures": "minecraft:village_desert" }, "equipment": { "mainhand": { "items": "minecraft:beef" } } } } ``` -------------------------------- ### Biome Feature Configuration Example (JSON) Source: https://datapack.wiki/wiki/worldgen/custom-worldgen This JSON structure represents the configuration for biome features. It is an array of arrays, where each inner array corresponds to a 'step' in the feature generation process and contains identifiers for the features to be placed in that step. Features are generally placed in order from top to bottom. ```json { "features": [ [], ["minecraft:lake_lava_underground", "minecraft:lake_lava_surface"], ["minecraft:amethyst_geode"], ["minecraft:monster_room", "minecraft:monster_room_deep"], [], [], [ "minecraft:ore_dirt", "minecraft:ore_gravel", "minecraft:ore_granite_upper", "minecraft:ore_granite_lower", "minecraft:ore_diorite_upper", "minecraft:ore_diorite_lower", "minecraft:ore_andesite_upper", "minecraft:ore_andesite_lower", "minecraft:ore_tuff", "minecraft:ore_coal_upper", "minecraft:ore_coal_lower", "minecraft:ore_iron_upper", "minecraft:ore_iron_middle", "minecraft:ore_iron_small", "minecraft:ore_gold", "minecraft:ore_gold_lower", "minecraft:ore_redstone", "minecraft:ore_redstone_lower", "minecraft:ore_diamond", "minecraft:ore_diamond_medium", "minecraft:ore_diamond_large", "minecraft:ore_diamond_buried", "minecraft:ore_lapis", "minecraft:ore_lapis_buried", "minecraft:ore_copper", "minecraft:underwater_magma", "minecraft:disk_sand", "minecraft:disk_clay", "minecraft:disk_gravel" ], [], ["minecraft:spring_water", "minecraft:spring_lava"], [ "minecraft:glow_lichen", "minecraft:patch_tall_grass_2", "minecraft:patch_bush", "minecraft:trees_plains", "minecraft:flower_plains", "minecraft:patch_grass_plain", "minecraft:brown_mushroom_normal", "minecraft:red_mushroom_normal", "minecraft:patch_pumpkin", "minecraft:patch_sugar_cane", "minecraft:patch_firefly_bush_near_water" ], ["minecraft:freeze_top_layer"] ] } ``` -------------------------------- ### Example Item Tag JSON - Minecraft Datapacks Source: https://datapack.wiki/wiki/files/tags Demonstrates the JSON format for a Minecraft item tag. This tag, when set to replace, includes all items from '#minecraft:logs' and '#minecraft:planks', along with 'minecraft:chest' and 'minecraft:stick'. It specifies whether to replace existing tags or merge with them. ```json { "replace": true, "values": [ "#minecraft:logs", "#minecraft:planks", "minecraft:chest", "minecraft:stick" ] } ``` -------------------------------- ### Get String NBT with /data modify ... string Source: https://datapack.wiki/wiki/command/data Retrieves NBT data from a source, ensuring it is treated as a string. Allows for optional truncation using start and end indices. Start is inclusive, end is exclusive. ```minecraft-commands data modify string [path] [start] [end] ``` -------------------------------- ### Run Command on Click (JSON) Source: https://datapack.wiki/wiki/concepts/text Specifies text that, when clicked, executes a chat command. This requires the player to have the necessary permissions for the command. ```json { "text": "Click me", "click_event": { "action": "run_command", "command": "/say Hello" } } ``` -------------------------------- ### Create Smithing Trim Recipe - JSON Source: https://datapack.wiki/guide/adding-new-features/smithing-trims Specifies the crafting recipe for applying a custom smithing trim pattern. This JSON file defines the type of recipe, the materials that can be used as additions and bases, the template item, and the namespace path to the custom trim pattern. ```json { "type": "minecraft:smithing_trim", "addition": "#minecraft:trim_materials", "base": "#minecraft:trimmable_armor", "template": "minecraft:diamond_block", "pattern": ":example_template" } ``` -------------------------------- ### Example of Projectile NBT Change (1.21) Source: https://datapack.wiki/wiki/info/breaking-changes Illustrates how the 'ShotFromCrossbow' NBT field for projectiles has been removed and replaced by a new 'weapon' field in version 1.21. This change affects how the projectile's origin is determined. ```minecraftnbt @e[type=arrow,nbt={ShotFromCrossbow:1b}] would now look like @e[type=arrow,nbt={weapon:{id:"minecraft:crossbow"}}] ``` -------------------------------- ### Minecraft JSON: Tick Tag Configuration Source: https://datapack.wiki/guide/getting-started This JSON file configures the 'tick.json' tag, which tells Minecraft which functions to run every game tick. It specifies a list of function references. ```json { "values": ["example:loop"] } ``` -------------------------------- ### Execute Command: Summon and Run Source: https://datapack.wiki/wiki/command/execute Summons an entity at the current position and executes a subcommand as that entity. NBT data cannot be specified for the summoned entity. The 'run' subcommand executes a single command with the current context. ```minecraft execute summon iron_golem ... execute summon marker ... execute run say hi execute at @e[type=sheep] run setblock ~ ~ ~ stone ``` -------------------------------- ### String Data Type Examples in NBT Source: https://datapack.wiki/wiki/nbt-scoreboards/nbt Illustrates how string data types are represented in NBT/SNBT format. Strings can be enclosed in double or single quotes, or sometimes left unquoted if they meet specific criteria. ```NBT/SNBT name:"Silabear" name:'Cobblestone' name:Aandeel ``` -------------------------------- ### Minecraft mcfunction: Simple Loop Source: https://datapack.wiki/guide/getting-started A basic .mcfunction file designed to be run on a loop. It simply prints 'Hi' to the chat every time it is executed. ```mcfunction say Hi ``` -------------------------------- ### Create and Enable Trigger Scoreboard Objective (Minecraft Commands) Source: https://datapack.wiki/wiki/nbt-scoreboards/scoreboards This demonstrates creating a 'trigger' scoreboard objective and enabling it for players. Trigger objectives allow players to manually set their score using the /trigger command, useful for UIs. ```minecraft scoreboard objectives add option trigger scoreboard players enable @a option ``` -------------------------------- ### Minecraft: Execute at entity Source: https://datapack.wiki/wiki/command/execute Shows how to use the 'execute at' subcommand to change the position and rotation for subsequent command execution to match that of a target entity. Forking rules apply if multiple entities are targeted. ```minecraft execute at @s ``` ```minecraft execute at @p ``` -------------------------------- ### Datapack Metadata (pack.mcmeta) Source: https://datapack.wiki/guide/getting-started The pack.mcmeta file is essential for defining a datapack. It specifies the datapack's description and the pack_format, which indicates compatibility with Minecraft versions. This is a JSON file. ```json { "pack": { "description": "DATAPACK NAME HERE", "pack_format": 81 } } ``` -------------------------------- ### Minecraft: Execute as entity and run function Source: https://datapack.wiki/wiki/command/execute Demonstrates the 'execute as' subcommand to change the executor to specified entities and then run a function. This can lead to multiple command executions if the entity selector targets more than one entity. ```minecraft execute as @e[type=marker] run function example ``` -------------------------------- ### Minecraft /summon Command Usage Source: https://datapack.wiki/wiki/command/summon Demonstrates various ways to use the Minecraft /summon command to spawn entities. It covers basic summoning, specifying coordinates, and applying NBT data for customized entity behavior. The namespace can be omitted for default Minecraft entities. ```minecraft-command summon minecraft:cow summon minecraft:ender_dragon ~ ~50 ~ summon minecraft:wither 29 372 121 summon minecraft:zombie ~ ~ ~ {NoAI:1b} ``` -------------------------------- ### Minecraft Lists and Arrays Source: https://datapack.wiki/wiki/nbt-scoreboards/nbt Shows how to define lists and number arrays in Minecraft using square brackets and commas. It includes examples of mixed-type lists and type-specific number arrays, such as byte arrays prefixed with '[B;' or long arrays prefixed with '[L;'. ```minecraft ["Silabear", 15, true, 242] [B;1b,2B,true,false] ["Kanokarob", "LadyEternal", "lionlance", "thederdiscohund", "theblackswitch"] [L;1l,2l,3l,4l,5l] ``` -------------------------------- ### Define Trim Material JSON Source: https://datapack.wiki/guide/adding-new-features/smithing-trims This JSON file defines the properties of a new trim material, including its asset name and a descriptive text with a color. The 'asset_name' is crucial for resource pack referencing, and 'description' provides a user-friendly name and color. ```json { "asset_name": "matexample", "description": { "text": "Example Material", "color": "#00e09d" } } ``` -------------------------------- ### Minecraft mcfunction: Display Title and Give Item Source: https://datapack.wiki/guide/getting-started This .mcfunction file demonstrates how to display a title message to a player and give them a diamond. It uses the 'title' and 'give' commands. ```mcfunction # Show the player Hello World on their screen title @s title "Hello World!" # Give the player a diamond give @s diamond ``` -------------------------------- ### Reference a Minecraft Function Source: https://datapack.wiki/wiki/concepts/resource-locations Demonstrates how to specify a resource location for a function within a Minecraft datapack. It shows the command syntax and the corresponding file path structure. The namespace is explicit. ```minecraft /function my_namespace:some_folder/my_function ``` -------------------------------- ### Generate Search Indexes Source: https://datapack.wiki/contribute/git-practices Scripts to regenerate the search index file (`search.json`). This is typically used to resolve conflicts when merging changes, as `search.json` should not be manually edited. It can be executed using Node.js or Bun. ```bash node run ./gen_search_indexes_node.js ``` ```bash bun ./gen_search_indexes.js ``` -------------------------------- ### Block Atlas Configuration for Trims (JSON) Source: https://datapack.wiki/guide/adding-new-features/smithing-trims Configures the block atlas to include custom trim textures. It uses 'paletted_permutations' to map different trim materials to specific color palettes, enabling the game to dynamically apply trims to items. ```json { "sources": [ { "type": "paletted_permutations", "textures": [ "trims/items/pickaxe_trim" ], "palette_key": "trims/color_palettes/trim_palette", "permutations": { "quartz": "trims/color_palettes/quartz", "iron": "trims/color_palettes/iron", "gold": "trims/color_palettes/gold", "diamond": "trims/color_palettes/diamond", "netherite": "trims/color_palettes/netherite", "redstone": "trims/color_palettes/redstone", "copper": "trims/color_palettes/copper", "emerald": "trims/color_palettes/emerald", "lapis": "trims/color_palettes/lapis", "amethyst": "trims/color_palettes/amethyst", "resin": "trims/color_palettes/resin" } } ] } ``` -------------------------------- ### Reference a Minecraft Function (Default Namespace) Source: https://datapack.wiki/wiki/concepts/resource-locations Shows how to reference a function when the namespace is omitted, defaulting to the 'minecraft' namespace. This simplifies commands when targeting default game functions. ```minecraft /function some_folder/my_function ``` -------------------------------- ### Execute Command as Ground Arrows Source: https://datapack.wiki/guide/getting-started Executes a command as every arrow entity that is in the ground. This uses the 'type' and 'nbt' criteria to filter entities. The 'at @s' clause ensures the command is run at the arrow's location. ```minecraft-function execute as @e[type=arrow,nbt={inGround:1b}] at @s run say I'm an arrow, I'm in the ground! ``` -------------------------------- ### Minecraft Text Component: NBT Storage Data Source: https://datapack.wiki/wiki/concepts/text Demonstrates how to create a text component in Minecraft that displays a value from NBT storage. It requires specifying the NBT path and the storage namespace. ```json { "nbt": "ShopData.Name", "storage": "minecraft:xyz" } ``` -------------------------------- ### Minecraft: Execute anchored Source: https://datapack.wiki/wiki/command/execute Illustrates the 'execute anchored' subcommand, which sets the anchor for local coordinates to either the entity's eyes or feet. ```minecraft execute anchored eyes ``` -------------------------------- ### Prepend NBT to List with /data modify ... prepend Source: https://datapack.wiki/wiki/command/data Prepends an NBT value to the beginning of a list or typed array within a data source. Creates the list if it does not exist. This action is equivalent to 'data modify ... insert -1 ...'. ```minecraft-commands data modify prepend value ``` -------------------------------- ### Update Trim Pattern and Trim Material Definitions Source: https://datapack.wiki/wiki/info/breaking-changes This section outlines changes to how trim pattern and trim material items are specified. Trim patterns now require an `id` in the smithing trim pattern recipe, and trim materials use the `provides_trim_material` item component instead of an `ingredient` field. ```json { "recipe": { "type": "minecraft:smithing_trim", "template": "#my_trim_pattern_id", "material": "minecraft:iron", "result": { "item": "minecraft:iron_chestplate" } } } ``` ```json { "components": { "minecraft:provides_trim_material": "minecraft:iron" } } ``` -------------------------------- ### JSON Structure: Item Matcher Source: https://datapack.wiki/wiki/files/predicates Defines how to match items, including specific item types, count ranges, and advanced component matching. Components can be matched exactly or by checking for the presence of certain data. ```json { "items": "", "count": , "components": { "": }, "predicate": { "": } } ``` -------------------------------- ### JSON Structure: Number Provider - Binomial Distribution Source: https://datapack.wiki/wiki/files/predicates Defines a number provider that generates a random number based on a binomial distribution. It requires the number of trials ('n') and the chance of success ('p') for each trial. ```json { "type": "minecraft:binomial", "n": , "p": } ```