搬运一批Bedrock wiki内容,完善翻译

This commit is contained in:
boybook
2025-03-20 00:13:44 +08:00
parent ead7392a76
commit 4896c1a4f2
163 changed files with 33930 additions and 1464 deletions

View File

@@ -0,0 +1,173 @@
---
title: MBE - Max's Block Entity
category: Techniques
mention:
- BedrockCommands
- zheaEvyline
tags:
- system
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
This method, developed by Reddit user [u/Maxed_Out10](https://www.reddit.com/user/Maxed_Out10/) allows you to create near-perfect entity replications of any Minecraft block using armour stands and some sequential `/playanimation` commands.
To preserve credits to the creator, the community termed this method as "Max's Block Entity" or MBE for short.
### Points to Note
1. This method uses 1 armour stand per block entity. Therefore, too many armour stands (like any entity) can contribute to server lag.
2. Players will still be able to pass through them as well as interact with them if not restricted.
3. While the block entity may appear in one spot, it's actual hitbox will have a slight offset.
## Video Demonstration
<YouTubeEmbed
id="kb8rz9ItE_M"
/>
## Setup
*To be typed in chat:*
1. `/summon armor_stand Grumm`
- It is necessary to name it 'Grumm' to avoid inverted block textures.
2. `/execute as @e [type= armor_stand, name=Grumm, c=1] at @s run tp @s ~~~ 260`
- This will align the MBE to the normal Minecraft block grid.
:::tip
- Crouch & right-click (on mcpe: long press) the armor stand 6 times to place it in Pose 7
- Doing this negates the need to use the 2nd command in the system.
- **Only use this if you wish to reduce one command from the system.**
:::
## System
> Note: adding a delay of 100-200 ticks is recommended.
<CodeHeader>mcfunction</CodeHeader>
```yaml
/effect @e [type= armor_stand, name=Grumm] invisibility 999999 1 true
/playanimation @e [type= armor_stand, name=Grumm] animation.armor_stand.entertain_pose null 0 "0" align.arms
/playanimation @e [type= armor_stand, name=Grumm] animation.player.move.arms.zombie null 0 "0" size.mini_block
/playanimation @e [type= armor_stand, name=Grumm] animation.ghast.scale null 0 "0" size.full_block
/playanimation @e [type= armor_stand, name=Grumm] animation.fireworks_rocket.move null 0 "0" align.full_block
/execute as @e [type= armor_stand, name=Grumm] at @s run tp ~~~
```
![commandBlockChain6](/assets/images/commands/commandBlockChain/6.png)
### Purpose Of Each Command
1. Hides the armour stand body.
2. Automatically sets the armour stand pose to 7 for arms alignment. Skip this command you prefer to do it manually.
3. __Required command__. Increases size to present as mini-block.
4. *Optional command.* Increases size to present as full-block.
5. *Optional command.* Aligns the full-block size MBE properly.
- Skip 4 & 5 if you do not need full-block size MBE.
6. Locks in place to prevent fall in case block underneath is removed.
## Rotations & Alignments
> Note: These rotation commands are to be executed only once through a command block.
<Spoiler title="Full MBE">
```yaml
# Face North
/tp @e [type=armor_stand, name=Grumm, c=1] ~-1.1245 ~0.2260 ~-0.097 81
# Face South
/tp @e [type=armor_stand, name=Grumm, c=1] ~1.1245 ~0.2260 ~0.097 260
# Face East
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.097 ~0.2260 ~-1.1245 171
# Face West
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.097 ~0.2260 ~1.1245 350
```
</Spoiler>
<Spoiler title="Mini MBE">
```yaml
# Face North
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.417~-0.5 ~-0.035 81
# Face South
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.417 ~-0.5 ~0.035 260
# Face East
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.035 ~-0.5 ~-0.417 171
# Face West
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.035 ~-0.5 ~0.417 350
```
</Spoiler>
<Spoiler title="Stair MBE">
```yaml
# Face North
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.097 ~0.2325 ~1.1245 350
# Face South
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.097 ~0.2325 ~-1.1245 171
# Face East
/tp @e [type=armor_stand, name=Grumm, c=1] ~-1.1245 ~0.2325 ~-0.097 81
# Face West
/tp @e [type=armor_stand, name=Grumm, c=1] ~1.1245 ~0.2325 ~0.097 260
```
</Spoiler>
<Spoiler title="Bottom Slab MBE">
```yaml
# Face North
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.097 ~0.2325 ~1.1245 350
# Face South
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.097 ~0.2325 ~-1.1245 171
# Face East
/tp @e [type=armor_stand, name=Grumm, c=1] ~-1.1245 ~0.2325 ~-0.097 81
# Face West
/tp @e [type=armor_stand, name=Grumm, c=1] ~1.1245 ~0.2325 ~0.097 260
```
</Spoiler>
<Spoiler title="Top Slab MBE">
```yaml
# Face North
/tp @e [type=armor_stand, name=Grumm, c=1] ~-1.1245 ~0.484 ~-0.097 81
# Face South
/tp @e [type=armor_stand, name=Grumm, c=1] ~1.1245 ~0.484 ~0.097 260
# Face East
/tp @e [type=armor_stand, name=Grumm, c=1] ~0.097 ~0.484 ~-1.1245 171
# Face West
/tp @e [type=armor_stand, name=Grumm, c=1] ~-0.097 ~0.484 ~1.1245 350
```
</Spoiler>
## Saving & Loading MBE
1. To save run:
- `/execute as @e [type=armor_stand, name=Grumm, c=1] at @s run structure save MBE ~~~ ~~~`
2. To load run:
- `/structure load MBE <coordinates>`
> Note: structure name `MBE` can be changed to your preference.

View File

@@ -0,0 +1,118 @@
---
title: Block States
category: General
mentions:
- BedrockCommands
- zheaEvyline
- SmokeyStack
- ThomasOrs
tags:
- info
---
## Introduction
[Sourced by Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
Block States or Block Properties are additional data that defines how the block appears or behaves. Such as the direction it is facing, it's color, it's variant, whether it is powered or unpowered and so on.
This is used in a multitude of commands such as `/clone`, `/execute`, `/fill`, `/setblock` and `/testforblock`
In Bedrock Edition we used Aux values (also known as Metadata) to define a block. However; as of 1.19.70 and beyond this is no longer supported and have been fully replaced with Block States instead.
<CodeHeader>example</CodeHeader>
```yaml
#Aux Value Example:
/setblock ~ ~ ~ wool 1
#It's Block State equivalent:
/setblock ~ ~ ~ wool ["color"="orange"]
```
- Any command block using aux values will continue to function as it is however block states will need to be adopted when updating them.
- Similarly any commands using aux values in behaviour or function packs with `min_engine_version` 1.19.63 or below will also continue to function however block states must be adopted if the `min_engine_version` is updated to 1.19.70 or above.
## Block State Examples & Syntax
<CodeHeader>Examples</CodeHeader>
```yaml
/setblock ~ ~ ~ wool ["color"="white"]
/setblock ~ ~ ~ wheat ["growth"=0]
/setblock ~ ~ ~ wood ["wood_type"="birch","stripped_bit"=true]
/setblock ~ ~ ~ wool []
```
- Block states are enclosed in square brackets ` [ ] `
- When specifying multiple block states a comma ` , ` is used to separate them.
- Quotation marks ` " " ` are used around strings such as `"birch", "spruce" etc..`
- Integer values `0, 1, 2..` and boolean values `true/false` do not use quotation marks.
- Leaving the brackets blank is also a correct syntax, it will simply default to 0.
- `wool 0` is white wool hence you may simply write it as `wool []` instead of `wool ["color"="white"]`
### Notes For Beginners
- **Integers** are whole numbers. They are used to define a block from a 'range' of values.
- Example: Redstone power 1 to 15
- `["redstone_power"=10]`
- **Boolean** is a programming term which refers to `true/false` values. You can simply understand it as yes or no questions.
- Is this piston powered? `yes/no`
- Is this button pressed? `yes/no`
- Is this log stripped? `yes/no`
- `["stripped_bit"=true]`
- **Strings** are unique 'text' inputs. You can simply understand it as multiple choice questions.
- What color is this wool? `"white"`, `"orange"`, `"brown"` etc..
- What wood type is this log? `"spruce"`, `"birch"`, `"acacia"` etc..
- `["wood_type"="spruce"]`
## Block States List
A list of all the block states currently available within Bedrock can be found at:
https://learn.microsoft.com/en-us/minecraft/creator/reference/content/blockreference/examples/blockstateslist
Note: In the site block states may be written as one word but make sure to separate them with underscores `_` when typing in commands.
Example: `buttonPressedBit``"button_pressed_bit"`
## Converting Aux Values to Block States
For your convenience; download any of the excel sheet below to find the full list of block IDs, their aux values and equivalent block states in Bedrock. *Shared by kayla@Mojang*
<BButton
link="https://github.com/BedrockCommands/bedrockcommands.github.io/files/10987839/Aux-Value_to_Block-States_Map.xlsx"
color=white
>Download Sheet 1</BButton>
Note: the above sheet was quickly generated and contains some minor errors. Boolean values `0` should be replaced with `false` and `1` should be replaced with `true` since the game doesn't recognize the syntax otherwise.
Alternate sheet: *Shared by @ItsRichHeart*
<BButton
link="https://github.com/BedrockCommands/bedrockcommands.github.io/files/11069804/All.Block-Item.List.Bedrock.pdf"
color=white
>Download Sheet 2</BButton>
You may also use this [Lookup Table](https://auxval-to-blockstates.netlify.app/) instead not needing to download any files.
## Known Issue
Detecting blocks using commands such as `/execute` or `/testforblock` requires __all__ or __none__ of the block states specified else the command returns an error.
Example; detecting a pressed stone button on ground facing up:
<CodeHeader></CodeHeader>
```yaml
#✅ Accepted:
/execute if block ~~~ stone_button [“button_pressed_bit”=true,”facing_direction”=1] run say success
/execute if block ~~~ stone_button run say success
# ❌ Not Accepted:
/execute if block ~~~ stone_button [“button_pressed_bit”=true] run say success
/execute if block ~~~ stone_button [“facing_direction”=1] run say success
```
Though block states have replaced aux values, we still cannot detect blocks based on specific filters yet like we do with selector arguments.
### Related Bug Reports
- [MCPE-133360](https://bugs.mojang.com/browse/MCPE-133360)
- [MCPE-168391](https://bugs.mojang.com/browse/MCPE-168391)

View File

@@ -0,0 +1,96 @@
---
title: Damage
category: Commands
tags:
- info
mentions:
- BedrockCommands
- cda94581
- jordanparki7
- zheaEvyline
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
Introduced in Minecraft Release `1.18.10`, the /damage command deals precise damage to specified entities. With this change, the clunky methods like using `/effect` command to damage entities are rendered obsolete, making maps and other creations more powerful.
## Syntax
- There are two ways the damage command can be used:
- `/damage <Target> <Amount> [Cause]`
- `/damage <Target> <Amount> <Cause> entity <Damager>`
## Arguments
- Phrases not contained in angle <> or square [] brackets instruct you to type it as-is.
- Phrases contained within brackets are variables, these need to be replaced:
- **` <> `** Angle brackets mean the variable is required.
- **` [] `** Square brackets mean the variable is optional.
## Variables
- **` Target `** This is your typical entity selector, such as `@s` , `@e` , or `"cda94581"` . Multiple entities may be selected at a time to deal the damage to multiple targets.
- **` Amount `** This is a whole number, which specifies the amount of damage to deal to the targets. The minimum value is `0` and the maximum value is `2147483647`, or the signed 32-bit integer limit.
- **` Cause `** This specifies the "reason" the damage was dealt. This cause will appear in death messages (`X hit the ground too hard for cause: fall`) be used in damage calculation with armor (`the value dealt in Amount may be different depending on the worn armor`), and used in a large variety of other things, such as in Behavior Pack/Add-ons. A full list of all the damage causes can be found [below](/commands/damage#damage-cause-list)
- **` Damager `** If Cause was something to do with entities `(such as entity_attack)`, this specifies where the damage came from `(the entity that dealt the attack)`. This is limited to only 1 target. An error will be thrown if multiple targets are found from the selector.
> Note: the `<Cause> entity <Damager>` is only required when the Cause has to do with another entity `(entity_attack)`. Otherwise, follow the first syntax.
## Examples
<CodeHeader>mcfunction</CodeHeader>
```yaml
#Deal 4 damage to all players
/damage @a 4
#Deal 3 'fire' damage to all entities of type 'sheep'
/damage @e [type=sheep] 3 fire
#Deal 40 'entity attack' damage from a random player to all entities of type 'sheep'
/damage @a 40 entity_attack entity @r [type=sheep]
```
## Damage Cause List
Listed below are all the 'damage sources' in MCBE for the `/damage` command currently available:
```
anvil
attack
block_explosion
charging
contact
drowning
entity_attack
entity_explosion
fall
falling_block
fatal
fire
fire_tick
fireworks
fly_into_wall
freezing
lava
lightning
magic
magma
none
override
piston
projectile
sonic_boom
stalactite
stalagmite
starve
suffocation
suicide
temperature
thorns
void
wither
```

View File

@@ -0,0 +1,89 @@
---
title: Entity Counter
category: Scoreboard Systems
mentions:
- BedrockCommands
- zheaEvyline
nav_order: 3
tags:
- system
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
This system allows you to track how many players/entities are there on your world and run your desired commands based on the values obtained.
> Note: you cannot track entities in unloaded chunks though players can still be tracked regardless.
## Setup
*To be typed in Chat:*
`/scoreboard objectives add total dummy`
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
## System
<CodeHeader>BP/functions/entity_counter.mcfunction</CodeHeader>
```yaml
scoreboard players set onlinePlayers total 0
execute as @e [type=player] run scoreboard players add onlinePlayers total 1
#Your Commands Here (examples)
execute if score onlinePlayers total matches 4.. run title @a actionbar Enough players to start game.
execute if score onlinePlayers total matches ..3 run title @a actionbar Not enough players.
```
![commandBlockChain3](/assets/images/commands/commandBlockChain/3.png)
Here we have used a FakePlayer name `onlinePlayers` and targeting `@e [type=player]` to track how many players are currently on the world. However you may use any FakePlayer name and target any entity you might need. Such as `@e [type=creeper]`
Similarly we're running a `/title` command as an example:
- a) when there are 4 or more players `4..`
- b) when there are 3 players or less `..3`
You can edit this as well to suit your need.
## Explanation
- The first two commands in the system sets the FakePlayer name's score to 0 (here `onlinePlayers`) and from each loaded entity we want to track (here `type=player`) it will add a score to the specified FakePlayer name (here `onlinePlayers`)
Now based on the values obtained we can use the `/execute if score` command to run our desired commands when certain values are met.
- **` n `** any number n
- **` n.. `** any number n and above
- **` ..n `** any number n and below
- **` n1..n2 `** any number n1 to any number n2.
## Tick JSON
If you are using functions instead of command blocks, the ` entity_counter ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
<CodeHeader>BP/functions/tick.json</CodeHeader>
```json
{
"values": [
"entity_counter"
]
}
```
If using functions, your pack folder structure will be be as follows:
<FolderView
:paths="[
'BP',
'BP/functions',
'BP/pack_icon.png',
'BP/manifest.json',
'BP/functions/entity_counter.mcfunction',
'BP/functions/tick.json'
]"
></FolderView>
> **Note:** the scoreboard names (in this case: 'total') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
> - ` total_0fe678 `
> - ` entity_counter_0fe678.mcfunction `

View File

@@ -0,0 +1,14 @@
---
title: Commands
categories:
- title: General
color: green
- title: Commands
color: green
- title: On Event Systems
color: blue
- title: Scoreboard Systems
color: blue
- title: Techniques
color: orange
---

View File

@@ -0,0 +1,141 @@
---
title: Intro to Command Blocks
category: General
mentions:
- BedrockCommands
- zheaEvyline
- jordanparki7
nav_order: 1
tags:
- info
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
Command Blocks are special blocks in Minecraft. The same commands (cheats) you type in chat can be run automatically using command blocks and it can be reused without needing to type all over again.
They can only be placed or destroyed by a player with the Operator permission level in gamemode Creative.
## Obtaining
1. Open your world settings.
2. Under Cheats, toggle "Activate Cheats" setting ON.
3. Run `/give @s command_block` command in chat.
## Command Block UI
![commandBlockUI](/assets/images/commands/commandBlockUI.png)
## Command Block Types
![impulseCommandBlock](/assets/images/commands/impulseCommandBlock.png) **Impulse** runs the command __once__ each time it is powered.
![chainCommandBlock](/assets/images/commands/chainCommandBlock.png) **Chain** runs the command in a sequence, ie. only after the previous command block it is connecting from was run.
![repeatingCommandBlock](/assets/images/commands/repeatingCommandBlock.png) **Repeat** runs the command every game tick. There are approximately 20 ticks per second. A delay can be applied to adjust how often the command is executed, explained [below](/commands/intro-to-command-blocks#command-block-tick-delay).
## Command Block Conditions
**Conditional** command blocks will run the command only if the previous command block it was connecting from had an output that was `true` (successful)
> Conditional command block states are shown by a small indent into the command block's texture, as shown below:
> - ![pasteCommandButton](/assets/images/commands/impulseConditionalCommandBlock.png) Impulse Conditional Command Block
> - ![chainConditionalCommandBlock](/assets/images/commands/chainConditionalCommandBlock.png) Chain Conditional Command Block
> - ![repeatingConditionalCommandBlock](/assets/images/commands/repeatingConditionalCommandBlock.png) Repeating Conditional Command Block
**Unconditional** command blocks will run the command regardless. Whether the previous command block it was connecting from had an output that was `true` (succesful), `false` (failed) or even if it came with a syntax error the command block will still run the command.
## Command Block Redstone States
**Needs Redstone** command block can only be activated with redstone power. Using buttons, levers, redstone torch etc..
**Always Active** command block will be activated as soon as you close the command block UI.
## Command Block Tick Delay
In this option you may specify how much delay you want there to be before the command block runs the command.
The ticks refer to Minecraft game ticks. A **tick** is simply a unit of measure for time in games. 1 second in real life is approximately 20 game ticks in Minecraft.
:::tip
![gametick.png](/assets/images/commands/gametick.png)
:::
## Command Block Hover Note
This option allows you to put a hovering text on your command blocks. It's useful for giving short-names for easy identification when working with many command blocks.
When a command is run, the hover note will be displayed with the output in chat if gamerule `commandblockoutput` is enabled.
![hover_note](/assets/images/commands/hover_note.png)
## Paste Button
![pasteCommandButton](/assets/images/commands/pasteCommandButton.png)
The paste button allows you to paste commands from your clipboard to the 'Command Input' box.
## Command Block Output
- Toggle the 'Previous Output' button in the command block UI to see command output and block details.
- The ` / ` you type before the whole command is not required in a command block but doing so won't cause any errors.
- A redstone comparator can read command blocks outputs. If output is true, it will send anywhere from 1 to 15 redstone signals depending on the output value.
- You can check if a command output is `true`/`false` by running it in chat. A red output will be a `false` output or a syntax error. A white output means command was run successfully.
- You can also tell if a command was `true`/`false` by checking whether action was performed or not.
- An output with a value of `0` is usually a false output.
### Disabling Command Messages In Chat
Run in Chat:
- `/gamerule commandblockoutput false` to disable command block messages in chat.
- `/gamerule sendcommandfeedback false` to disable feedback from commands entered in chat.
## Command Block Placement
When placing command blocks in a line (arranged to work together) for any system, make sure the consecutive command blocks connect/start from the head of the arrow.
The arrow/facing direction can be observed from the command block texture.
**✅ Correct Placement**
![correctCommandBlockPlacement](/assets/images/commands/correctCommandBlockPlacement.png)
**❌ Incorrect Placement**
![incorrectCommandBlockPlacement](/assets/images/commands/incorrectCommandBlockPlacement.png)
## Troubleshooting Command Blocks
- In world settings, under **Cheats**, make sure command blocks have not been disabled.
- Make sure gamerule `maxcommandchainlength` is **not** set to 0
- Make sure there are no unwanted redstone power that is interfering with the command block. It can be from redstone dust, lever, redstone torch etc..
- Try switching between Always Active & Needs Redstone.
- Double check the block type, condition & the command syntax. Check 'Previous Output' after powering it once again.
- Just like redstone, command blocks must also be in loaded chunks for them to work. You can use a tickingarea to keep them loaded when players are not nearby. Refer to [/tickingarea](https://learn.microsoft.com/en-us/minecraft/creator/documents/tickingareacommand) command documentation for more info.
If nothing seems to work simply break and place that command block again.
## What you have learned
:::tip What you have learned:
- How to obtain a command block in game.
- How the different types of command blocks behave and what they look like.
- What the different command block options are (including conditional, state and delay.)
- How command blocks output data by redstone and chat messages.
- How to properly place command block chains.
- How to resolve 'command block not working'
:::
To put what you have learned into practice, try making this simple [Entity Counter](/commands/entity-counter) system.
> Note: when setting up command block systems, always the first command will be ![repeatingCommandBlock](/assets/images/commands/repeatingCommandBlock.png) **`Unconditional Always Active`** and the rest will be ![chainCommandBlock](/assets/images/commands/chainCommandBlock.png) **`Unconditional Always Active`** (all 0 ticks delay) *unless specified otherwise.*
>
> ![commandBlockChain4](/assets/images/commands/commandBlockChain/4.png)
**(Recommended) Read Next: [Understanding Selectors](/commands/selectors)**

View File

@@ -0,0 +1,158 @@
---
title: Functions
category: General
mentions:
- Bedrock Commands
- cda94581
- zheaEvyline
- jordanparki7
nav_order: 3
tags:
- info
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
Functions are `.mcfunction` files which contain multiple lines of commands. They are run with the `/function` command in-game.
Functions are created in a **Behavior Pack**, nested within the **functions** folder. A function pack creates a system using solely function files.
Functions are useful in many ways to reduce the time spent going from command block to command block debugging a system. They also help with packaging systems for use in multiple worlds and provide many functions that can change how everything works.
## Function Pack Folder Structure
<FolderView
:paths="[
'BP',
'BP/functions',
'BP/functions/this_code.mcfunction',
'BP/functions/more_of_this_code.mcfunction',
'BP/functions/tick.json',
'BP/functions/nested',
'BP/functions/nested/this_code_is_nested.mcfunction',
]"
></FolderView>
## Notes For Beginners
<CodeHeader>mcfunction</CodeHeader>
```yaml
#Spawn Effects
effect @a [tag=atSpawn] regeneration 12 255 true
effect @a [tag=atSpawn] saturation 12 255 true
effect @a [tag=atSpawn] weakness 12 255 true
```
- Each new line in a function file represents a new command. You may start a line with # to add comments. Commands in a function do not need to begin with a slash `/`, however doing so will not cause any errors.
- All commands in a function are run in the *same tick*. Because of this, a function which causes large changes may cause a sudden lag spike and it is helpful to delegate some commands across multiple ticks, if possible.
Commands in a function are still run in the same order, however.
- Minecraft can **not** run more than 10,000 lines of commands in one function file. This includes any other function files that are executed inside of the original file.
- It is not possible to run conditional commands. Those will still need to utilize command blocks in some way, or could utilize the 1.19.50 execute syntax.
- Running commands with a specified delay in a function would involve using scoreboard timers to incrementally count up every tick (to a certain point), and executing at certain scores along the file. You may refer to [Scoreboard Timers](/commands/scoreboard-timers) system to learn how to set it up.
## Creating a Function
1. Locate the `📁 com.mojang` folder and navigate to `📁 development_behavior_packs`
- The development folders are used for quick reloading of packs, as the packs aren't cached to the world files.
2. Create a folder (of any name) for the function pack. This will be referred to as Behavior Pack or BP.
3. Create a `📄 manifest.json` file and a `🖼 pack_icon.png` file (optional) within the BP folder.
- A manifest file contains all the information needed to register a pack, while a pack icon displays visually in the pack menu. A pack icon is typically a 128x128 or a 256x256 image, though any power-of-2 resolution will do, they will be upscaled and downscaled accordingly.
<Spoiler title="Sample 📄 manifest.json">
<CodeHeader>BP/manifest.json</CodeHeader>
```json
{
"format_version": 2,
"header": {
"description": "Write Your Pack Description Here",
"name": "Write Your Pack Name Here",
"uuid": "00000000-0000-0000-0000-000000000000",
"version": [ 1, 0, 0 ],
"min_engine_version": [ 1, 19, 73 ]
},
"modules": [
{
"description": "§r",
"type": "data",
"uuid": "00000000-0000-0000-0000-000000000000",
"version": [1, 0, 0 ]
}
]
}
```
Note that the uuid field needs to be replaced with an actual uuid, and the two generated must be different from one another. You can generate a uuid at https://uuidgenerator.net/
</Spoiler>
<Spoiler title="Sample 🖼 pack_icon.png">
Sample A:
![pack_icon.png](/assets/images/commands/pack_icon.png)
Sample B:
![pack_icon.png](/assets/images/guide/project-setup/pack_icon.png)
</Spoiler>
4. Create a `📁 functions` folder. Any file within this folder that ends with **.mcfunction** will be registered as a function in-game, which can be run with `/function <function_name>`.
- Nested functions are allowed, simply list the file path in relation to the functions folder as shown in the function pack folder structure.
5. Apply the behavior pack in-game and try out the functions. Function file changes can be reflected in the world by running `/reload` or by simply relogging.
:::tip NOTE
Functions are versioned; therefore, they will run in the version listed in the `📄 manifest.json`, such as:
- `min_engine_version` 1.19.50 or above will adopt the new execute syntax.
- `min_engine_version` 1.19.70 or above will require aux values be replaced with block states.
:::
## Execution
Functions can be executed in-game by typing `/function name_of_function`. This will execute all the commands in the function file, all in a single tick.
Nested functions, for example `BP/functions/lobby/items/1.mcfunction` can be run using the nested folder path, in this case `/function lobby/items/1`
## tick.json
The final file within a function is the **tick.json** file. This specifies functions to run server-side on every game tick, (similar to a repeating command block.) It is located in the `BP/functions` folder. By default, functions running in this file execute at origin `0, 0, 0` in the overworld.
<CodeHeader>BP/functions/tick.json</CodeHeader>
```json
{
"values": [
"function_1",
"function_2"
]
}
```
> Note: functions in this file are run as soon as the world is *initialized*, regardless of whether or not the player has been *loaded*. This may cause unintended behavior if used incorrectly.
## Sample Function Pack
<CardLink
imgsrcLight="assets/images/commands/BClogo.png"
title="Download Sample Function Pack"
link="https://github.com/Bedrock-OSS/wiki-addon/releases/download/download/functions_sample.mcpack"
/>
## Troubleshooting Functions
Your functions may not appear within the command suggestions when using `/function`. This is normally due to an error with one or more commands in the function.
Enabling the [Content Log](/guide/troubleshooting#content-log) in creator settings will allow you to see if there are any errors in your function pack, in which function the error is in, at which line and exactly what the syntax error for that command is.
The list of errors will be generated every time you load a world or run `/reload` to reflect changes after editing files. The list can be viewed on-screen for a few seconds as well as in the content log history in settings.
![contentLogToggles](/assets/images/commands/contentLogToggles.png)
![contentLogHistory](/assets/images/commands/contentLogHistory.png)

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,247 @@
---
title: New Execute
category: Commands
tags:
- easy
mentions:
- JaylyDev
- Sprunkles137
- Hatchibombotar
- TheItsNameless
- SmokeyStack
- zheaEvyline
---
## Introduction
With the release of 1.19.50, the `/execute` command was given a syntax overhaul. While the syntax is now more verbose and longer to write, it allows much finer control over the contextual components of commands and adds support for conditions to commands, superseding the use of commands like `/testfor`, `/testforblock`, and `/testforblocks`.
Before we dive into the syntax and how to write it, we need to understand how the old `/execute` command worked, and what changed and why. This will make explaining the concepts found in the syntax easier.
## Understanding Execution Context
For both beginners to commands and those well versed in how old `/execute` behaved, it may be a good idea to review the concept of a command's **execution context**.
In short, these are the parameters that affects how a command runs. Who the command will run as, also known as its executor; where the command will run, and in which dimension; and the rotation applied to the command are all parameters that can be changed.
Every command has this context applied to it, and this context changes depending on how the command runs. Commands fired from command blocks do not have an executor, and the position is set to that command block; commands ran from chat define the executor as the player, and it runs at the player's position.
## Execute, and Why it Changed
The `/execute` command executes a command on behalf of one or more entities. The old syntax used to be this:
```
/execute <target> <position> <command>
/execute <target> <position> detect <position> <block> <data value> <command>
```
You specified a target to execute as, then the command's context would change to run as that target, and at that target. Any position changes were then always relative to that target.
While this is useful in most cases, it also forces the fact that a command's target and its position are always tied together (unless you were to manually insert world coordinates in place of `<position>`). It is also not very malleable in regards to making conditional statements, as you have to execute as an entity every time.
Back in the Summer of 2017 during the Update Aquatic's development, the developers of Minecraft: Java Edition were getting feedback from the community on how they can improve the `/execute` command's syntax, and the basic concept that was conceived is this: `/execute` takes an unlimited number of **subcommands** that manipulate certain aspects of the command in the order you specify, then a "run" subcommand is placed at the end to fire a command.
This allows for much greater control for what `/execute` can do to a command, and allows splitting up the executor and the command's position.
## New Syntax
Now, let us review the new `/execute` syntax. They are as follows:
### `/execute as`
Changes the executor of the command, or what the target selector `@s` will select.
```
/execute as <origin: target> -> execute
```
This does not change the position, rotation, or dimension context of the command.
If multiple targets are specified then a command is ran once for each target, where `@s` selects each entity in turn.
### `/execute at`
Changes where the command runs, setting the command's position, rotation, and dimension context to the entity.
```
/execute at <origin: target> -> execute
```
This does not change the executor of the command, so `@s` will remain as whoever was targeted last.
If multiple targets are specified then a command is ran once for each target, setting the position, rotation, and dimension context to each target.
### `/execute in`
Sets the dimension in which the command should run.
```
/execute in <dimension: string> -> execute
```
Currently accepted values are `overworld`, `nether`, and `the_end`.
This change in dimension will respect that dimension's scale; going from the Overworld to The Nether will apply a scale of x0.125 to the position, and vice versa will apply a x8 scale to the position.
### `/execute positioned`
Directly sets the position context of the command.
```
/execute positioned <position: x y z> -> execute
```
Sets the position of the command to specific values. [Relative and local coordinates](/commands/relative-coordinates) are based around the current position of the command.
```
/execute positioned as <origin: target> -> execute
```
Sets the position of the command to a target's location. This is similar to how `/execute at` works, but it only sets the command's position and not its rotation or dimension.
If multiple targets are specified then a command is ran once for each target, setting the position context to the target's position.
### `/execute align`
Aligns the current position of the command to the block grid.
```
/execute align <axes: swizzle> -> execute
```
Aligning a position will floor it. This subcommand accepts any non-repeating combination of the letters "x", "y", and "z", and will floor the position along each axis specified.
### `/execute anchored`
Sets the anchor of the command to the executor's feet or eyes. Changing the anchor will affect the position where local coordinates will start at.
```
/execute anchored (eyes|feet) -> execute
```
The default anchor when executing at a target is their feet.
When the anchor is set to `eyes`, the command's local position is offset by some amount corresponding to the "eye height" of the current executor.
This offset should only apply to local coordinates, but it currently affects relative coordinates due to a bug: [MCPE-162681](https://bugs.mojang.com/browse/MCPE-162681).
### `/execute rotated`
Directly sets the rotation context of the command.
```
/execute rotated <yaw: value> <pitch: value> -> execute
```
Sets the rotation of the command to specific values. Relative and local coordinates are based around the current rotation of the command. This defaults to 0 for both pitch and yaw, unless the rotation was changed prior.
```
/execute rotated as <origin: target> -> execute
```
Sets the rotation of the command to a target's rotation.
If multiple targets are specified then a command is ran once for each target, setting the rotation context to the target's rotation.
### `/execute facing`
Sets the rotation of the command to face some position. This rotation is calculated based on the current position of the command.
```
/execute facing <position: x y z> -> execute
```
Sets the rotation to face a block position. Relative and local coordinates are based around the current position of the command.
```
/execute facing entity <origin: target> (eyes|feet) -> execute
```
Sets the rotation to face a target's position. Setting the anchor to `feet` will aim the rotation to face where they are currently standing, while setting the anchor to `eyes` will aim the command up at the "eye position" of that target (see [`/execute anchored`](/commands/new-execute#execute-anchored)).
If multiple targets are specified then a command is ran once for each target, setting the rotation context to face that target.
### `/execute (if|unless)`
Prevents running a command based on a condition. If the condition is true then the command will continue, or stop otherwise.
`/execute unless` acts as the opposite, testing if the condition is false in order to continue.
```
/execute if entity <target: target> -> execute
```
Acts like `/testfor`. Returns true if the targets exist.
```
/execute if block <position: x y z> <block: string> -> execute
```
Acts like `/testforblock`. Returns true if the block at the specified location exists.
A data value or block state may additionally be specified, otherwise it ignores block states (acts as if it were set to `-1`).
```
/execute if blocks <begin: x y z> <end: x y z> <destination: x y z> (all|masked) -> execute
```
Acts like `/testforblocks`. It constructs a volume between the beginning and end positions, and returns true if the volume at the destination matches the original volume.
The parameter `all` tests that all blocks must match, while `masked` will ignore air blocks.
```
/execute if score <target: target> <objective: string> matches <range: integer range> -> execute
```
Tests if a specified score is a certain value. This uses the integer range syntax.
```
/execute if score <target: target> <objective: string> (=|<|<=|>|>=) <source: target> <objective: string> -> execute
```
Tests if a specified score matches some logical comparison to another score. Operators are equals (`=`), greater than (`>`), greater than or equal to (`>=`), less than (`<`), and less than or equal to (`<=`).
### `/execute run`
```
/execute run <command: command>
```
Runs a command using all of the currently applied context modifications. This subcommand always goes last in one `/execute` command.
This subcommand is not always required however; an `/execute` command ending with an `if` or `unless` subcommand is valid too, and will return the success of the test it performed.
## Examples and Upgrading Old Commands
Since subcommands can be chained limitlessly, there really is a nearly infinite combination of arguments for an `/execute` command and they cannot all be listed. Instead, listed here are some common examples of commands.
The old functionality of `/execute` can be replicated with `as <target> at @s`. If you need a positional offset relative to the entity, add `positioned`. If you want to detect if a block is present, add `if block`. Here are some equivalents:
```
# Teleport with an offset
/execute @p ~ ~1.62 ~ teleport @s ^ ^ ^3
/execute as @p at @s positioned ~ ~1.62 ~ run teleport @s ^ ^ ^3
```
```
# Chaining multiple '/execute's
/execute @e[type=sheep] ~ ~ ~ execute @e[type=item,r=5] ~ ~ ~ detect ~ ~-1 ~ stone 0 kill @s
/execute at @e[type=sheep] as @e[type=item,r=5] at @s if block ~ ~-1 ~ stone 0 run kill @s
```
(Note that we do not use `as @e[type=sheep] at @s` because we do not need to execute as the sheep; only the position here is required.)
Now for some examples of things that were not possible to do in one command, or were more difficult to perform before the new syntax was introduced.
```
# Testing a fake player's score
/execute if score game_settings var matches 3.. run say [Game] Difficulty set to Hard.
# Comparing if two scores are equal
/execute as @a if score @s x = @s y run say My X is equal to my Y.
# Test for an entity without targeting it
/execute as @a at @s if entity @e[type=armor_stand,r=10] run gamemode survival @s
```

View File

@@ -0,0 +1,73 @@
---
title: On First Join
category: On Event Systems
mentions:
- BedrockCommands
- zheaEvyline
- SmokeyStack
nav_order: 1
tags:
- system
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
This system will run your desired commands on the event that a player joins the world for the first time.
## System
<CodeHeader>BP/functions/on_first_join.mcfunction</CodeHeader>
```yaml
#Your Commands Here (examples)
give @a [tag=!joined] stone_pickaxe
give @a [tag=!joined] bread 16 1
tag @a [tag=!joined] add joined
```
![commandBlockChain3](/assets/images/commands/commandBlockChain/3.png)
Here we have used 2 `give` commands as example but you can use any command you prefer and as many as you require.
Just make sure to follow the given order and properly add the selector argument ` tag=!joined ` as shown for your desired commands.
## Explanation
When the player joins the world for the first time, they will not have the joined tag.
Once we run our desired commands for players without the tag, they will be given the tag immediately and the commands will not repeat for them again unless we remove their tag with:
`tag <player> remove joined`
## Tick JSON
If you are using functions instead of command blocks, the ` on_first_join ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
<CodeHeader>BP/functions/tick.json</CodeHeader>
```json
{
"values": [
"on_first_join"
]
}
```
If using functions, your pack folder structure will be be as follows:
<FolderView
:paths="[
'BP',
'BP/functions',
'BP/pack_icon.png',
'BP/manifest.json',
'BP/functions/on_first_join.mcfunction',
'BP/functions/tick.json'
]"
></FolderView>
> **Note:** the tag names (in this case: 'joined') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
> - ` joined_0fe678 `
> - ` on_first_join_0fe678.mcfunction `

View File

@@ -0,0 +1,78 @@
---
title: On First World Load
category: On Event Systems
mentions:
- BedrockCommands
- zheaEvyline
- SmokeyStack
- cda94581
nav_order: 6
tags:
- system
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
This system will run your desired commands on the event that the world is loaded for the first time.
> **Note:** a [Function](/commands/mcfunctions) Pack is required to achieve this system since it is the `tick.json` file which allows us to run commands as soon as the world is initialised.
## Tick Json
<CodeHeader>BP/functions/tick.json</CodeHeader>
```json
{
"values": [
"initialise"
]
}
```
## System
<CodeHeader>BP/functions/initialise.mcfunction</CodeHeader>
```yaml
scoreboard objectives add world dummy
scoreboard players add initialised world 0
#Your Commands Here (example)
execute if score initialised world matches 0 run say New world created!
scoreboard players set initialised world 1
```
Here we have used an `execute - say` command as an example but you can use any command you prefer and as many as you require.
Just make sure to follow the given order and properly use the `execute if score` command as shown to run the commands you need.
## Explanation
- **` initialised=0 `** this means the world has just initialised and we are yet to run the initlisation commands.
- **` initialised=1 `** this means the world has been initialised and we have already run the initialisation commands.
An objective of the name `world` is added for us to save scores to it so that we can track whether the world has been initialised or not. This also allows us to structure our commands to only execute at world initialisation.
Following the creation of the objective, a score of `0` is added to the FakePlayer name `initialised`. This will register it to the objective and enable us to use the `execute if score` command structure to run our desired commands.
Finally the score for `initialised` is set to 1 after all the commands are run in order to prevent it from executing more than once.
## Folder Structure
<FolderView
:paths="[
'BP',
'BP/functions',
'BP/pack_icon.png',
'BP/manifest.json',
'BP/functions/initialise.mcfunction',
'BP/functions/tick.json'
]"
></FolderView>
> **Note:** the scoreboard names (in this case: 'world') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
> - ` world_0fe678 `
> - ` initialise_0fe678.mcfunction `

View File

@@ -0,0 +1,95 @@
---
title: On Player Death
category: On Event Systems
mentions:
- BedrockCommands
- zheaEvyline
nav_order: 4
tags:
- system
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
This system will run your desired commands on the event that a player dies.
## Setup
*To be typed in Chat:*
`/scoreboard objectives add alive dummy`
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
## System
<CodeHeader>BP/functions/on_player_death.mcfunction</CodeHeader>
```yaml
scoreboard players set @a [scores={alive=!2}] alive 0
scoreboard players set @e [type=player] alive 1
#Your Commands Here (example)
execute as @a [scores={alive=0}] run say I died
scoreboard players set @a [scores={alive=0}] alive 2
```
![commandBlockChain4](/assets/images/commands/commandBlockChain/4.png)
Here we have used an `/execute - say` command as an example but you can use any command you prefer and as many as you require.
Just make sure to follow the given order and properly add the selector argument ` scores={alive=0} ` as shown for your desired commands.
## Explanation
- **` alive=0 `** this means player is dead.
- **` alive=1 `** this means player is alive.
- **` alive=2 `** this means player is dead and we have run our desired commands on/from them.
- **` @a `** selector will target all players alive/dead so we use it to mark everyone as 0 'dead.'
- Note: we will ignore 2 or it will end up making the commands execute on dead players again. We only want our commands to execute once.
- **` @e `** selector on the other hand will only target players who are alive, so we can use this to mark all alive players 1 'alive.'
- Now that dead players are 0 and alive players are 1 we can use this knowledge to run our desired commands on the dead players.
- Keep in mind we need to set their score to 2 after or otherwise the commands will keep executing till they respawn.
## Tick JSON
If you are using functions instead of command blocks, the ` on_player_death ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
<CodeHeader>BP/functions/tick.json</CodeHeader>
```json
{
"values": [
"on_player_death"
]
}
```
If using functions, your pack folder structure will be be as follows:
<FolderView
:paths="[
'BP',
'BP/functions',
'BP/pack_icon.png',
'BP/manifest.json',
'BP/functions/on_player_death.mcfunction',
'BP/functions/tick.json'
]"
></FolderView>
> **Note:** the scoreboard names (in this case: 'alive') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
> - ` alive_0fe678 `
> - ` on_player_death_0fe678.mcfunction `

View File

@@ -0,0 +1,86 @@
---
title: On Player Join
category: On Event Systems
mentions:
- BedrockCommands
- zheaEvyline
nav_order: 2
tags:
- system
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
This system will run your desired commands on the event that a players joins the world.
## Setup
*To be typed in Chat:*
`/scoreboard objectives add joined dummy`
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
## System
<CodeHeader>BP/functions/on_player_join.mcfunction</CodeHeader>
```yaml
scoreboard players add @a joined 0
#Your Commands Here (example)
tp @a[scores={joined=0}] 0 65 0
scoreboard players reset * joined
scoreboard players set @a joined 1
```
![commandBlockChain4](/assets/images/commands/commandBlockChain/4.png)
Here we have used a `tp` command as an example but you can use any command you prefer and as many as you require.
Just make sure to follow the given order and properly add the selector argument ` scores={joined=0} ` as shown for your desired commands.
## Explanation
When the player joins, a 0 is added to their objective, this allows us to run commands from them using the 'scores' selector argument.
Immediately after the commands are run, we reset all the scores on the objective using wildcard **` * `** and only players who stayed online will have their score set to 1.
And this way, since our commands only target players with the score 0, the commands won't repeat again for the players who stayed unless they leave and rejoin or if we run:
`/scoreboard players set <player> joined 0`
## Tick JSON
If you are using functions instead of command blocks, the ` on_player_join ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
<CodeHeader>BP/functions/tick.json</CodeHeader>
```json
{
"values": [
"on_player_join"
]
}
```
If using functions, your pack folder structure will be be as follows:
<FolderView
:paths="[
'BP',
'BP/functions',
'BP/pack_icon.png',
'BP/manifest.json',
'BP/functions/on_player_join.mcfunction',
'BP/functions/tick.json'
]"
></FolderView>
> **Note:** the scoreboard names (in this case: 'joined') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
> - ` joined_0fe678 `
> - ` on_player_join_0fe678.mcfunction `

View File

@@ -0,0 +1,107 @@
---
title: On Player Leave
category: On Event Systems
mentions:
- BedrockCommands
- zheaEvyline
nav_order: 3
tags:
- system
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
This system will run your desired commands on the event that a player leaves the world.
> **Note:** you cannot execute commands on the *players* that leave using selectors. However; you may use the [On Player Join](/commands/on-player-join) system to execute when they join back.
## Setup
*To be typed in Chat:*
`/scoreboard objectives add total dummy`
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
## System
<CodeHeader>BP/functions/on_player_leave.mcfunction</CodeHeader>
```yaml
scoreboard players reset new total
execute as @a run scoreboard players add new total 1
scoreboard players operation new total -= old total
#Your Commands Here (example)
execute if score new total matches ..-1 run say a player has left the world
scoreboard players reset old total
execute as @a run scoreboard players add old total 1
```
![commandBlockChain6](/assets/images/commands/commandBlockChain/6.png)
Here we have used a **`/say`** command as an example but you can use any command you prefer and as many as you require.
Just make sure to follow the given order and properly use the `/execute if score` command as shown to run the commands you need.
## Explanation
- **` new `** this FakePlayer name means the total number of players on the world in the current game tick.
- **` old `** this FakePlayer name means the total number of players that were on the world in the previous game tick but also saves the values to be used in the *next* game tick.
These values are obtained using the [Entity Counter](/commands/entity-counter) system. It may be beneficial to refer to that doc for better understanding this one.
By subtracting 'old' total from 'new' total we will be able to identify if player count has:
- decreased ` ..-1 `
- increased ` 1.. `
- or if it's unchanged ` 0 `
If it has decreased; we know that 1 or more players have left the game.
With this knowledge we can run our desired commands from 'new' if it's score is -1 or less.
- ie, if there were 10 players and someone leaves:
- that is ` new - old `
- which is ` 9 - 10 = -1 `
- hence we will detect by ` ..-1 `
- The 'new' total value is obtained first, subtraction is performed after that to run your desired commands and lastly the 'old' total value is obtained to be used in the next game tick.
:::tip
All commands involved in a command-block-chain or function will only run in a sequence one after the other but it all still happens in the same tick regardless of the number of commands involved. We are able to achieve this system due to the fact that commands run along the end of a game tick after all events such as player log in, log out, death etc.. occur.
![gametick](/assets/images/commands/gametick.png)
:::
## Tick JSON
If you are using functions instead of command blocks, the ` on_player_leave ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
<CodeHeader>BP/functions/tick.json</CodeHeader>
```json
{
"values": [
"on_player_leave"
]
}
```
If using functions, your pack folder structure will be be as follows:
<FolderView
:paths="[
'BP',
'BP/functions',
'BP/pack_icon.png',
'BP/manifest.json',
'BP/functions/on_player_leave.mcfunction',
'BP/functions/tick.json'
]"
></FolderView>
> **Note:** the scoreboard names (in this case: 'total') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
> - ` total_0fe678 `
> - ` on_player_leave_0fe678.mcfunction `

View File

@@ -0,0 +1,86 @@
---
title: On Player Respawn
category: On Event Systems
mentions:
- BedrockCommands
- zheaEvyline
nav_order: 5
tags:
- system
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
This system will run your desired commands on the event that a player respawns from death state.
## Setup
*To be typed in Chat:*
`/scoreboard objectives add respawn dummy`
If you prefer to have the objective added automatically on world initialisation, follow the process outlined in [On First World Load.](/commands/on-first-world-load)
## System
<CodeHeader>on_player_respawn.mcfunction</CodeHeader>
```yaml
#Your Commands Here (example)
execute as @e [scores={respawn=1}] run say I died and respawned.
scoreboard players set @a respawn 1
scoreboard players set @e [type=player] respawn 0
```
![commandBlockChain3](/assets/images/commands/commandBlockChain/3.png)
Here we have used an `/execute - say` command as an example but you can use any command you prefer and as many as you require.
Just make sure to follow the given order and properly use the selector argument ` @e [scores={respawn=1}] ` as shown for your desired commands.
## Explanation
- **` respawn=0 `** this means the player is alive or had already respawned.
- **` respawn=1 `** this means the player died and is now respawning, ie. respawned *just now*, in the current gametick.
- **` @a `** selector will target all players alive/dead so we use it to mark everyone as 1 'respawning'
- **` @e `** selector on the other hand will only target players who are alive, so we can use this to mark all alive players 0 'respawned'
Now that *respawning* players are 1 and *respawned* players are 0 we can use this knowledge to run our desired commands on the players respawning.
In the system, your desired commands must come before the other 2 commands because players change from death state to alive state along the start of the gametick before commands are run.
Hence; if we were to put them at the end then the other 2 commands would set respawning players score to 0 first and then the commands you want to run won't be able to select those players as our selector argument is ` @e [scores={respawn=1}] ` not 0. Using 0 would not work as then it would repeat endlessly even on players who have already respawned.
## Tick JSON
If you are using functions instead of command blocks, the ` on_player_respawn ` function must be added to the ` tick.json ` in order to loop and run it continuously. Multiple files can be added to the ` tick.json ` by placing a comma after each string. Refer to [Functions](/commands/mcfunctions#tick-json) documentation for further info.
<CodeHeader>BP/functions/tick.json</CodeHeader>
```json
{
"values": [
"on_player_respawn"
]
}
```
If using functions, your pack folder structure will be be as follows:
<FolderView
:paths="[
'BP',
'BP/functions',
'BP/pack_icon.png',
'BP/manifest.json',
'BP/functions/on_player_respawn.mcfunction',
'BP/functions/tick.json'
]"
></FolderView>
> **Note:** the scoreboard names (in this case: 'respawn') may end up being used by other people. Appending ` _ ` and a set of randomly generated characters after would be a choice that reduces the probability of collisions. Similar technique can be employed for the ` .mcfunction ` filenames. Ex:
> - ` respawn_0fe678 `
> - ` on_player_respawn_0fe678.mcfunction `

View File

@@ -0,0 +1,79 @@
---
title: Playsound
category: Commands
mentions:
- BedrockCommands
- zheaEvyline
- jordanparki7
tags:
- info
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
You can use the `/playsound` command to play sound effects to players present anywhere in the world whenever you like.
## Syntax
`/playsound <sound> [player] [position] [volume] [pitch] [minimumVolume]`
## Definitions
### Sound
- It is the sound effect you wish to play.
- You can find the list of sound IDs currently available at:
- https://www.digminecraft.com/lists/sound_list_pe.php
### Player
- This is an optional argument.
- It refers to your typical target selectors (whom you want to play the sound to) ` @a `, ` @r `, ` @p `, ` Technoblade `, etc..
### Position
- This is an optional argument.
- It refers to the `x y z` position from where the sound will be played, ie. the center of the playsound radius.
### Volume
- This is an optional argument.
- It determines the size of the sphere in which the sound effect can be heard.
- ` 0.0 ` is the minimum size.
- Sound & audible sphere size increases as `volume` value is increased.
- Playaound volume of `1` is equal to an audible sphere of radius 16 blocks.
- Similarly; volume of `4` would be equal to 64 blocks.
### Pitch
- This is an optional aegument.
- It determines the pitch for the sound effect.
- It can be a value between ` 0.0 ` and ` 256.0 `
- The higher the value, the higher the pitch.
- Values less than or equal to `0.0` makes the sound inaudible.
> Note: pitch affects the speed at which the audio is played. For example, a pitch of `0.5` would mean the audio is played at ` 0.5× ` speed.
### Minimum Volume
- This is an optional argument.
- It determines the minimum volume at which the sound will be heard outside of the audible sphere.
- It can be a value between ` 0.0 ` and ` 1.0 `
## Examples
<CodeHeader>mcfunction</CodeHeader>
```yaml
#Play a random explosion sound effect to closest player.
/playsound random.explode @p
#Play a random orb sound effect to all players at their relative position with a volume of 10000
/execute as @a at @s playsound random.orb @s ~ ~ ~ 10000
```
Note: since the playsound command is positonal, it is helpful to use an execute command structure as shown in the second example to prevent the sound effect from cutting off in special cases such as playing a sound effect following a `/tp` command. You may increase volume when covering large distances to reduce failures.
**(Recommended) Read Next: [Sounds](/concepts/sounds)**

View File

@@ -0,0 +1,46 @@
---
title: Coordinate System
category: General
mentions:
- MedicalJewel105
- Sprunkles137
- 7dev7urandom
- Hatchibombotar
- TheItsNameless
---
## The Coordinate System
Minecraft stores the locations of blocks and entities in the world using a system of three-dimensional coordinates, each representing a value in a one-dimensional axis. They are stored in the format of X, then Y, and lastly Z. Whether you are placing structures and blocks, or teleporting and summoning entities, you can, and are sometimes required to, put in coordinates. They don't need to always be real values however; you can substitute world coordinates for relative values, either based in world space or local space.
![image](https://user-images.githubusercontent.com/64864915/134789891-85644dd7-e30f-4e02-966c-df2bf17a7879.png)
_You may already be familiar with coordinates if you've enabled the Show Coordinates world option!_
## Relative Coordinates (~)
Relative coordinates are represented using tildes in place of real coordinates, and represent a position that is relative to the world coordinates its located at. You may insert numbers after a tilde to add an offset to the current position. These can be mixed with world coordinates, but cannot be mixed with local coordinates.
Examples:
- `~ ~ ~`: Current position with no changes.
- `~5 ~-2 ~`: Current position with a 5-block X offset and a negative 2-block Y offset.
### Rotations
Relative coordinates can also be used in the context of rotations, where they represent a rotation that is relative to the current rotation it inherits from. These may also accept numbers after the tilde to add an offset to the current rotation.
Example: `~90 ~` will add 90° to the current yaw (y-rotation) value.
## Local Coordinates (^)
Local coordinates are similar to relative coordinates, but represent a position in local space, where the axes are based off of rotation. They take the form `^left ^up ^forward`; you can think of this as `~x ~y ~z` if both your yaw and pitch rotations are 0 (facing straight ahead, due south).
Like relative coordinates, you can insert numbers to produce an offset of the current position, in local space. If there is no entity to copy rotation from, the x- and y-rotations are assumed to be 0.
Examples:
- `^10 ^ ^`: Current position with a 10-block offset to the left.
- `^ ^1.5 ^1`: Current position with a 1.5-block offset upward and a 1-block offset forward.
## Additional Notes
- The player's eye level is 1.62 blocks above their feet. (~ ~1.62 ~)

View File

@@ -0,0 +1,135 @@
---
title: Scoreboard Operations
category: General
mentions:
- Sprunkles137
- Luthorius
- MedicalJewel105
- Hatchibombotar
---
Scoreboards can be used to perform complex operations, similar to [Molang](/concepts/molang). Operations come in two flavors: mathematical, and logical.
## Overview
Operations are performed using the `/scoreboard players operation` command. The full syntax is laid out below:
```
/scoreboard players operation <targetScore> <objective> <operation> <sourceScore> <objective>
```
The command consists of two score holders: The target score, and the source score. The target score is the value being operated on, and the source score is the value affecting the operation. The result of the operation is written into the target score, and the source score's value is not touched, save for [one operation](/commands/scoreboard-operations#swap-operator).
## Mathematical Operators
Mathematical operators use arithmetic to affect the target score. There are five mathematical operations available: addition, subtraction, multiplication, floor division, and floor modulo division.
For each of the following examples below, assume that score holder `A var` equals 25, and `B var` equals 10.
### Addition
Operator: **+=**
This operation adds the target score and source scores together, then stores the sum into the target score.
```
/scoreboard players operation A var += B var
```
`A = A + B`, and as such `25 + 10 = 35`.
### Subtraction
Operator: **-=**
This operation subtracts the target score by the source score, then stores the difference into the target score.
```
/scoreboard players operation A var -= B var
```
`A = A - B`, and as such `25 - 10 = 15`.
### Multiplication
Operator: **\*=**
This operation multiplies the target score by the source score, then stores the product into the target score.
```
/scoreboard players operation A var *= B var
```
`A = A * B`, and as such `25 * 10 = 250`.
### Floored Division
Operator: **/=**
This operation divides the target score by the source score, then stores the quotient into the target score. Because score values can only be integers, the value is floored, or rounded down.
```
/scoreboard players operation A var /= B var
```
`A = floor(A / B)`, and as such `floor(25 / 10) = 2`.
### Floored Modulo Division
Operator: **%=**
This operation also divides the target score by the source score, but instead returns the remainder after the division into the target score. This is also floored.
```
/scoreboard players operation A var %= B var
```
`A = floor(mod(A, B))`, and as such `floor(mod(25, 10)) = 5`.
## Logical Operators
Logical operations use logic gates and assignments to affect the target score. There are four logical operations available: assignment, less than, greater than, and swap.
Similar to the above, assume that score holder `A var` equals 25, and `B var` equals 10.
### Assignment Operator
Operator: **=**
This operation sets the target score equal to the source score.
```
/scoreboard players operation A var = B var
```
`A = B`, and as such the result is `10`.
### Minimum Operator
Operator: **<**
This operation returns the smallest of the input scores, and stores it into the target score.
```
/scoreboard players operation A var < B var
```
`A = min(A, B)`, and as such `min(25, 10) = 10`.
### Maximum Operator
Operator: **>**
This operation returns the largest of the input scores, and stores it into the target score.
```
/scoreboard players operation A var > B var
```
`A = max(A, B)`, and as such `max(25, 10) = 25`.
### Swap Operator
Operator: **><**
This operation swaps the target score and source scores with each other. This is the only operation that affects the source score.
```
/scoreboard players operation A var >< B var
```
The above command would swap the values of A and B e.g.
Before: A = 10; B = 25;
After: A = 25; B = 10;
This can be seen as three operations: `temp = A; A = B; B = temp;`, and as such `A var = 10` and `B var = 25`.
## Useful Creations
#### Check If Values are Equal
If you want to check in scoreboard, whether one value equals another value, you can copy first value to temporary value, subtract the other and compare temporary value to zero. Given values A and B:
<CodeHeader></CodeHeader>
```
scoreboard objectives add temp dummy
scoreboard players operation @e temp = @s A
scoreboard players operation @e temp -= @s B
execute @e[scores={temp=0}] ~~~ say A equals B
scoreboard objectives remove temp
```
#### Scoreboard Initialization
If you want to initialize a scoreboard value to 0, but only if it doesn't exists, you can use `scoreboard players add <selector> <name> 0`. It will set the value to 0, if it doesn't exist on the entity and do nothing, if it already exist.

View File

@@ -0,0 +1,200 @@
---
title: Scoreboard Timers
category: Scoreboard Systems
mentions:
- BedrockCommands
- zheaEvyline
nav_order: 5
tags:
- system
---
## Introduction
[Sourced By Bedrock Commands Community Discord](https://discord.gg/SYstTYx5G5)
This system allows you to run your desired commands at specific intervals with any amount of delay that you wish to add.
- **Some Examples:**
- Sending a message in chat every 2 hours.
- Running a 'lag clear' function every 10 minutes.
- Effecting players with 'speed' every 30 seconds.
This system is especially useful when you need to set up multiple timers on your world. When working with command blocks, you may use the [Tick Delay](/commands/intro-to-command-blocks#command-block-tick-delay) option to delay the time taken for your commands to run. However, when working with functions you will need to use a system like this.
It is recommended to use this system while working with command blocks, as well if you wish to run all your timers in sync with one another, ie. with the same start time.
## Setup
*To be typed in chat:*
<CodeHeader></CodeHeader>
```yaml
scoreboard objectives add ticks dummy
scoreboard objectives add events dummy
```
Once you have created these two objectives, you will need to define the interval for each repeating event you need on your world in the `ticks` objective.
To do that, first you must know that **1 second is approximately 20 game ticks in Minecraft**. Based on this knowledge, you will need to do some basic calculations to obtain the ticks equivalent for each interval you want to define.
<CodeHeader></CodeHeader>
```yaml
# 2h = 20(t) × 60(s) × 60(m) × 2(h) = 144000t
scoreboard players set 2h ticks 144000
#10m = 20(t) × 60(s) × 10(m) = 12000t
scoreboard players set 10m ticks 12000
#30s = 20(t) × 30(s) = 600t
scoreboard players set 30s ticks 600
```
We will now use this scoreboard data to make our timers function.
## System
<CodeHeader>mcfunction</CodeHeader>
```yaml
scoreboard players add timer ticks 1
scoreboard players operation * events = timer ticks
#Chat Message (every 2h)
scoreboard players operation chatMessage events %= 2h ticks
execute if score chatMessage events matches 0 run say Technoblade never dies!
#Lag Clear (every 10m)
scoreboard players operation lagClear events %= 10m ticks
execute if score lagClear events matches 0 run function clear_lag
#Speed Effect (every 30s)
scoreboard players operation speedEffect events %= 30s ticks
execute if score speedEffect events matches 0 run effect @a speed 10 2 true
```
![commandBlockChain8](/assets/images/commands/commandBlockChain/8.png)
Here we have taken 3 examples to give you an idea on how to do it, but you can add any timer you need and as many as you require.
Just make sure to follow the given order and properly use the `/execute if score` command as shown to run the commands you need.
## Explanation
- **` events `** on this objective we label all the repeating events we want on our world.
- `chatMessage`
- `lagClear`
- `speedEffect`
- **` ticks `** on this objective we define all the intervals for our events and also run our scoreboard timer.
- ` 2h` interval (static score 144000)
- `10m` interval (static score 12000)
- `30s` interval (static score 600)
- `timer` clock (variable score n+1)
- **Command 1:** this command adds +1 score every tick to FakePlayer name `timer` indicating a tick has passed in the game. This is basically our scoreboard timer/clock which we will use for all the repeating events on our world.
- **Command 2:** here we copy `timer` score to all our events using the ` * ` wildcard selector. This will allow us to perform operations to determine if the interval has been reached to run the commands for that particular event. Example:
- If `timer` score is 1200 that means 1200 game ticks have passed.
- And this command makes it so all our events FakePlayer names: `chatMessage`, `lagClear`, `speedEffect` scores are also 1200.
- **Command 3:** we will use the ` %= ` modulo operation to check if our event score is divisible by it's corresponding interval. A number is said to be divisible when the remainder is 0.
- Chat Message: `1200/144000` Q=0, R=1200, *hence interval not reached.*
- Lag Clear: `1200/12000` Q=0, R=1200, *hence interval not reached.*
- Speed Effect: `1200/600` Q=2, R=0, *hence interval has reached and event commands can be executed.*
Here we can note that the first 2 events are yet to happen but the 3rd event is happening for the second time.
:::tip
In Minecraft; scoreboard division is only calculated up to whole numbers and decimal values are ignored.
![longDivision](/assets/images/commands/longDivision.png)
:::
- **Command 4:** the remainder value obtained from the calculation is applied to the corresponding event FakePlayer name. Based on this knowledge we can run our command if it's score is equal to 0.
The rest of the commands are identical in structure and only the event labels and interval values are changed.
## Defining Events With Limited Intervals
To limit how many times an event occurs, you will need to create a new objective called `intervals` and define how many times the event should occur like so:
<CodeHeader></CodeHeader>
```yaml
scoreboard objectives set chatMessage intervals 5
scoreboard objectives set speedEffect intervals 10
```
Once you have done that, modify your system from above like so:
<CodeHeader>mcfunction</CodeHeader>
```yaml
scoreboard players add timer ticks 1
scoreboard players operation * events = timer ticks
#Chat Message (every 10m)
scoreboard players operation chatMessage events %= 2h ticks
execute if score chatMessage events matches 0 if score chatMessage intervals matches 1.. run say Technoblade never dies!
execute if score chatMessage events matches 0 if score chatMessage intervals matches 1.. run scoreboard players remove chatMessage intervals 1
#Speed Effect (every 30s)
scoreboard players operation speedEffect events %= 30s ticks
execute if score speedEffect events matches 0 if score speedEffect intervals matches 1.. run effect @a speed 10 2 true
execute if score speedEffect events matches 0 if score speedEffect intervals matches 1.. run scoreboard players remove speedEffect intervals 1
```
![commandBlockChain8](/assets/images/commands/commandBlockChain/8.png)
## Executing Commands During Timeframe
To run commands during the timeframe between intervals for a particular system you may do something like this:
<CodeHeader>mcfunction</CodeHeader>
```yaml
#Speed Effect (every 30s) + Particle (every tick)
scoreboard players operation speedEffect events %= 30s ticks
execute if score speedEffect intervals matches 1.. as @a at @s run particle minecraft:shulker_bullet ~~~
execute if score speedEffect events matches 0 if score speedEffect intervals matches 1.. run effect @a speed 10 2 true
execute if score speedEffect events matches 0 if score speedEffect intervals matches 1.. run scoreboard players remove speedEffect intervals 1
```
As shown in line 3; to run commands while the timer is running, all you need to do is remove the "if score" testing if the interval has been reached. And instead, only test if *any* interval is left, to run our commands.
Let's say we had set the intervals for this event to 10, then that means players would also have particle trails for 300 seconds since `10*30s=300s`
## Entity Timers
In some cases such as an entity despawn event you will need to run timers for each entity individually rather than a synchronised timer which could cause the event to trigger too soon. In such cases an Async Timer can be helpful.
Let's say we want to:
- kill all entities named "station" 5 minutes after they've been summoned.
- play a shulker particle around them during that timeframe.
- play a flame particle around them in the first 10 seconds.
- play a pling sound to nearby players when the timer reaches half way.
- stop the timer if a passive mob is nearby.
- loop the timer if a hostile mob is nearby.
<CodeHeader>mcfunction</CodeHeader>
```yaml
#Clock
scoreboard players add @e [name=station, scores={ticks=0..}] ticks 1
#Executing Commands while timer is running
execute as @e [name=station, scores={ticks=0..}] at @s run particle minecraft:shulker_bullet ~~~
#Executing commands within a timeframe
execute as @e [name=station, scores={ticks=0..200}] at @s run particle minecraft:basic_flame_particle ~~~
#Executing commands at specific intervals
execute as @e [name=station, scores={ticks=3600}] at @s run playsound note.pling @a [r=10]
#Stopping the timer
execute as @e [name=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=station, scores={ticks=6000}] at @s if entity @e [family=monster, r=10, c=1] run scoreboard players set @s ticks 0
#End
kill @e [name=station, scores={ticks=6000}]
```
![commandBlockChain7](/assets/images/commands/commandBlockChain/7.png)
As shown; setting the score to 0 when it completes the timeframe will loop the timer and setting the score to -1 will stop/disable it. You can still set the score to 0 to start the timer again.

View File

@@ -0,0 +1,217 @@
---
title: Understanding Selectors
category: General
mentions:
- Science-geek42
- Brougud
- MedicalJewel105
- SmokeyStack
- Sprunkles137
- Hatchibombotar
---
Target selectors are used in commands to target who you want to execute a command on without explicitly setting a target, such as a player's name. A target selector is comprised of a selector variable, and optionally a list of selector arguments.
## Selector Variables
The selector variable defines the broad list of entities to select. There are six selector variables to choose from:
- `@a` - Target all players
- `@p` - Target the nearest player
- `@r` - Target a random player
- `@e` - Target all entities
- `@s` - Target the executor
- `@initiator` - Target the player interacting with an NPC
## Selector Arguments
Selector arguments can narrow down a list of target candidates to those who meet certain conditions. In order to use selector arguments, you must first have a selector variable. To start with selector arguments you must add square brackets `[]` to the end of the chosen target selector like this: `kill @e[]`. Multiple selector arguments can be used by separating them with commas.
### Type
Limits the selection of targets by their identifier. Negating the argument selects entities without that identifier. This argument cannot be repeated unless negated, since a given entity can only have one identifier. This argument can be used with the selector `@r` to select entities randomly.
- `type=<identifier>`—Include only entities with the given identifier.
- `type=!<identifier>`—Exclude any entities with the given identifier.
Examples:
Affect all pigs with levitation:
- `/effect @e[type=pig] levitation`
Kill all entities that are not arrows and snowballs:
- `/kill @e[type=!arrow,type=!snowball]`
### Count
Limits the number of selected entities, following selector sorting rules.
The selectors `@a`, `@p`, and `@e` sort by increasing distance, while `@r` sorts randomly. For the variables `@p` and `@r`, this argument defaults to 1. Negating this argument reverses the sorting order; random sorting cannot be negated.
- `c=<count>`—Select up to `<count>` entities.
Examples:
Clear stone from the closest five players:
- `/clear @a[c=5] stone`
Damage the furthest two skeletons:
- `/damage @e[type=skeleton,c=-2] 2`
### Position
Changes the position a selector starts its search at. It also modifies where the distance and volume arguments are positioned. Leaving any undefined defaults to the command's current position.
[Relative coordinates](/commands/relative-coordinates#relative-coordinates) can be used to define a relative offset from the command's position.
- `x=<value>`, `y=<value>`, and `z=<value>`—Defines a position for the target selector.
Examples:
Teleport the closest player to (140, 64, -200) ten blocks up:
- `/teleport @p[x=140, y=64, z=-200] ~ ~10 ~`
### Distance
Limits the selection of targets by their spherical distance from the selector. This selects entities by their feet.
- `rm=<value>` and `r=<value>`—Selects entities between the minimum and maximum number of blocks away, inclusive and respectively.
Examples:
Kill all chickens between two and six blocks away:
- `/kill @e[type=chicken, rm=2, r=6]`
Enchant the held item with Sharpness for all players within one block of (0, 100, 0):
- `/enchant @a[x=0, y=100, z=0, r=1] sharpness`
### Volume
Limits the selection of targets to those inside of a cuboid volume aligned to the block grid. There are three arguments, each determining the size of the box along their respective axes. If at least one argument is defined, any remaining arguments left undefined are assumed to be 0. This selects entities by their feet.
The general formula for calculating the volume between two positions can be viewed as: `dx = x2 - x1; dy = y2 - y1; dz = z2 - z1`.
- `dx=<value>`, `dy=<value>`, and `dz=<value>`—Selects entities inside the given bounding box.
Examples:
List all entities within a 12x30x2 box:
- `/say @e[dx=12, dz=30, dy=2]`
Add the "lobby" tag to all players between (-400, 0, -350) and (-150, 256, 50):
- `/tag @a[x=-400, y=0, z=-350, dx=250, dy=256, dz=400] add lobby`
### Scores
Limits the selection of targets by their score value. This argument is represented as an object, with key-value pairs for a scoreboard objective and a value. The value can represent a range of numbers, using the range syntax. The value of a score can be negated to test if the entity does not have a score value within that range.
- `scores={<objective>=<value>}`—Selects entities whose score under the given objective matches the given value.
The range syntax works as follows:
- `N..` is any number greater than or equal to N.
- `..N` is any number less than or equal to N.
- `N..M` is any number between N and M, inclusive.
Examples:
Set the "points" score for all players with a "points" score of ten to 0:
- `/scoreboard players set @p[scores={points=10}] points 0`
Add the "start" tag to armor stands with both a "started" score of one, and a "timer" score of 20 or less:
- `/tag @e[type=armor_stand, scores={started=1, timer=..20}] add start`
### Name
Limits the selection of targets by name. Negating the argument selects entities whose name does not match.
- `name=<name>`—Include only entities with the given name.
- `name=!<name>`—Exclude any entities with the given name.
Examples:
List all zombies named Shadow:
- `/say @e[type=zombie, name=Shadow]`
Give one level to players both not named Steve and not named Alex:
- `/xp 1L @a[name=!Steve, name=!Alex]`
### Tag
Limits the selection of targets by their tags. This argument can be repeated to test for multiple tags, and all filters must pass for an entity to be selected. Negating this argument selects entities without that tag.
- `tag=<tag>`—Include only entities with the given tag.
- `tag=!<tag>`—Exclude any entities with the given tag.
Examples:
Kill all mobs with the tag "marked", and without the tag "exempt":
- `/kill @e[tag=marked, tag=!exempt]`
### Family
Limits the selection of targets by type family. This argument can be repeated to test for multiple families, and all filters must pass for an entity to be selected. Negating this argument selects entities whose type family does not match.
- `family=<family>`—Include only entities with the given type family.
- `family=!<family>`—Exclude any entities with the given type family.
Examples:
Affect all entities in the "monster" family with Regeneration:
- `/effect @e[family=monster] regeneration`
### Rotation
Limits the selection of targets by their rotation. There are two types of rotation: x-rotation, which is vertical rotation around the x-axis; and y-rotation, which is horizontal rotation around the y-axis. X-rotation ranges between -90 and 90 (180° total), going from looking up to down; and y-rotation ranges between -180 and 180 (360° total), starting and ending at North, wrapping around clockwise.
- `rxm=<value>` and `rx=<value>`—Selects entities whose x-rotation is between the minimum and maximum values, inclusive and respectively.
- `rym=<value>` and `ry=<value>`—Selects entities whose y-rotation is between the minimum and maximum values, inclusive and respectively.
Examples:
Affect all players looking at or above the horizon with Blindness for one second:
- `/effect @a[rx=0] blindness 1` (0 or less)
Damage all players facing generally south:
- `/damage @a[rym=-45, ry=45] 1`
### Level
Limits the selection of targets by experience levels. Only players can have EXP, so this filters out non-player targets.
- `lm=<amount>` and `l=<amount>`—Selects players whose EXP levels are between the minimum and maximum values specified, inclusive and respectively.
Examples:
Give all players who have between three and eight levels a diamond:
- `/give @a[lm=3, l=8] diamond`
### Game mode
Limits the selection of targets by game mode. Only players can use game mode, so this filters out non-player targets. Negating the argument selects targets whose game mode does not match.
- `m=<gamemode>`—Selects players by their game mode.
Possible values include:
* `0`, `s`, or `survival` for Survival mode
* `1`, `c`, or `creative` for Creative mode
* `2`, `a`, or `adventure` for Adventure mode
* `spectator` for Spectator mode
* `d` or `default` for the default game mode
Examples:
List all players in Creative mode:
- `/say @a[m=creative]`
Set the game mode to Creative mode for players both not in Survival mode, and not in Adventure mode:
- `/gamemode creative @a[m=!survival, m=!adventure]`
### Items
Limits the selection of targets by what items they have in their inventory. This argument is represented as an object, or an array of objects, with up to one each of the following parameters:
- `item=<string>`—The identifier of the item to test for, and the only required argument. This can accept custom identifiers too.
- `quantity=<int>`—The amount of the item to test for. Accepts a [range](/commands/selectors#scores) for a value. This argument can also be negated.
- `data=<int>`—The data value of the item to test for. Defaults to -1. **Currently not functional:** [MCPE-151920](https://bugs.mojang.com/browse/MCPE-151920)
- `location=<string>`—The slot the item should be located in. Accepts the same arguments as the slotType argument in the `/replaceitem` command.
- `slot=<int>`—The index of the slot used in the "location" argument, and can only be used with "location". Accepts a range for a value. This argument can be negated.
Examples:
Checks for players who have a netherite sword in their inventory:
- `/testfor @a[hasitem={item=netherite_sword}]`
Clears 2 apples for players that have four or more apples:
- `/clear @a[hasitem={item=apple,quantity=4..}] apple 2`
Checks for players who have two sticks and two diamonds:
- `/testfor @a[hasitem=[{item=diamond,quantity=2},{item=stick,quantity=2}]]`
Checks for players who doesn't have a stick:
- `/testfor @a[hasitem=[{item=stick,quantity=0}]`

View File

@@ -0,0 +1,132 @@
---
title: Tellraw
category: Commands
mentions:
- SirLich
- Dreamedc2015
- MedicalJewel105
- Luthorius
- Fabrimat
- Sprunkles137
- ThomasOrs
- zheaEvyline
- SmokeyStack
---
tellraw sends a JSON message to selected or all players being useful for sending plain messages to players ingame
**The titleraw command follows the same theme**
![](/assets/images/documentation/tellrawshow.png)
## Format
this is how the tell raw command is formatted
```
tellraw <target: target> <raw json message: json>
```
- ` <target: target>`: The target is expressed as a playername or player groups such as `@a` `@r` `@s` `@p`
- `<raw json message: json>`: This is a json schema that tells how the message is structured or constructed. expressed with for example:
`{"rawtext":[{"text":""}]}`
## Examples
This sends the words in the last set of quotes
<CodeHeader></CodeHeader>
```json
/tellraw @a {"rawtext":[{"text":"Hello"}]}
```
## Escaping Characters
To use quotations in a tellraw message place a backslash to the left side of the quotation mark.
<CodeHeader></CodeHeader>
```json
/tellraw @a {"rawtext":[{"text":"Quote me: \"I am here\"."}]}
```
## Line breaks
To insert a line break use `\n`
<CodeHeader></CodeHeader>
```json
/tellraw @a { "rawtext": [ { "text":"I am line one\nI am line two" } ] }
```
## Displaying entities / player
You can use the following to use selector to display names.
<CodeHeader></CodeHeader>
```json
/tellraw @a {"rawtext": [{"text": "§6The winner is: §a"}, {"selector": "@a[r=5,c=1]"}]}
```
## Displaying scores
You can use the following to use selector to display names.
<CodeHeader></CodeHeader>
```json
/tellraw @a {"rawtext": [{"text": "§6The winner is: §a"}, {"selector": "@a[r=5,c=1]"}, {"text": "§6With a score of: "}, {"score":{"name": "@s","objective": "value"}}]}
```
## Translate text
To have a language dependant text you can use the translate component and [translation keys](/concepts/text-and-translations). please note you will need relevant information in each of the desired .lang files for this to work.
<CodeHeader>RP/texts/en_US.lang</CodeHeader>
```
example.langcode.1=I am line one
```
<CodeHeader>RP/texts/de_DE.lang</CodeHeader>
```
example.langcode.1=Ich bin Zeile eins
```
The command:
<CodeHeader></CodeHeader>
```json
/tellraw @a { "rawtext": [ { "translate": "example.langcode.1" } ] }
```
## Translate text with selectors/scores
language files:
<CodeHeader></CodeHeader>
```
example.langcode.2=The winner is: %s. With a score of %s
```
<CodeHeader></CodeHeader>
```json
/tellraw @a {"rawtext":[{"translate":"example.langcode.2","with":{"rawtext":[{"selector":"@a[r=5,c=1]"},{"text":"§6With a score of: "},{"score":{"name":"@s","objective":"value"}}]}}]}
```