diff --git a/404.html b/404.html
new file mode 100644
index 000000000..129af5b6b
--- /dev/null
+++ b/404.html
@@ -0,0 +1,50 @@
+
+
+
+
+
+ 404: Page Not Found
+
+
+
+
+
404: Page Not Found
+
Go back to the Table of Contents
+
If you encounter any issues, you can create a GitHub issue .
+
+
+
\ No newline at end of file
diff --git a/_config.yml b/_config.yml
index 671640e82..d28cda254 100644
--- a/_config.yml
+++ b/_config.yml
@@ -11,4 +11,4 @@ include:
- CODE_OF_CONDUCT.md
- CONTRIBUTING.md
- ISSUE_TEMPLATE.md
- - PULL_REQUEST_TEMPLATE.md
+ - PULL_REQUEST_TEMPLATE.md
\ No newline at end of file
diff --git a/bcresources.md b/bcresources.md
index bacdda332..2abc8ac76 100644
--- a/bcresources.md
+++ b/bcresources.md
@@ -1,12 +1,13 @@
# Bedrock Codebase Resources
-This page contains a list of links to utilities and references for **Pocket Edition/Windows 10** ("Minecraft Unified") map making that you may find useful.
+This page contains a list of links to utilities and references for **Minecraft Bedrock Edition** map making that you may find useful.
Looking for resources for the normal Java PC edition? [Click here for Java/PC resources.](/wiki/resources)
-Submit a pull request or create a GitHub issue if you've found a useful tool or reference that you think would fit here.
+Submit a [pull request](https://github.com/MinecraftCommands/wiki/pulls) or create a [GitHub issue](https://github.com/MinecraftCommands/wiki/issues) if you've found a useful tool or reference that you think would fit here.
-[Online documentation](https://bedrock.dev) (TheDestruc7i0n)
+* [Online documentation](https://bedrock.dev) (TheDestruc7i0n)
+* [Online documentation](https://wiki.bedrock.dev)
## NBT
diff --git a/debugging.md b/debugging.md
index 412d5918e..d191c5570 100644
--- a/debugging.md
+++ b/debugging.md
@@ -20,26 +20,24 @@ This page details information on common problems you might have with a command,
* Watch out for `“smart quotes”` that word processors might auto-add, only `"normal quotes"` will work. You should use a plain plain text editor (Notepad, Notepad++, Sublime, Code), **not** a word processor or rich text editor (Microsoft Word, Wordpad, Textedit)
* Narrow down your problem as much as possible. Remove parts slowly (or build up your command slowly in the first place) until you have just the part that's causing the issue
* Macs add weird characters that are invisible in-game when the arrow keys are pressed. These will stop the command from working
-* Mods/plugins (especially Essentials) may overwrite vanilla commands. To avoid this you can use one of the two following methods:
- * `/minecraft:command` instead of `/command` for the vanilla implementation (e.g: `/minecraft:give`)
- * `/execute run command` instead of `/command`, this is better because it works in vanilla servers too
+* Mods/plugins (especially Essentials) may overwrite vanilla commands. To avoid this you can use`/minecraft:command` instead of `/command` for the vanilla implementation (e.g: `/minecraft:give`)
+ * `/execute run command` instead of `/command`, no longer works, as `execute` can run plugin commands
* If you have any mods, try vanilla to see if the mod is causing the problem. Even mods like Optifine can cause issues
* Make sure you don't have a mod that dissables command blocks or functions
-* Make sure command blocks are enabled in server.propieties
-* When using tutorials or [online generators](/wiki/resources) make sure that are for the correct edition (java or bedrock) and version (1.12, 1.17, 1.20)
+* Make sure command blocks are enabled in `server.properties`
+* When using tutorials or [online generators](/wiki/resources) make sure that are for the correct edition (java or bedrock) and version (1.12, 1.17, 1.20...)
* Check if the command block is in a loaded chunk, you can use the [`/forceload`](https://minecraft.wiki/w/Commands/forceload) command in Java or the [`/tickingarea`](https://minecraft.wiki/w/Commands/tickingarea) command in Bedrock to force a chunk to be always loaded
* Maybe you set the command to conditional accidentaly and it should be uncoditional, double check that
* The command block must be `always active` or have redstone powering in order for it to run the command
* Make sure to capitalize the correct leters in the command, for example `/Say` will not work but `/say` will do (in bedrock edition works different, as you can capitalize commands)
* Same goes for scoreboard values, if you capitalized it when creating it, it should be capitalized when you use it
-* The `commandModificationBlockLimit` gamerule (defaults to 32768) specifies the limit of blocks that can be selected with the `/fill`, `/fillbiome` and `/clone` commands
+* The `commandModificationBlockLimit` gamerule (defaults to `32768`) specifies the limit of blocks that can be selected with the `/fill`, `/fillbiome` and `/clone` commands
* Make sure you are **not** using per-1.13 execute in newer versions
* Or viceversa, using 1.13+ execute in pre-1.13
* The same goes for bedrock new execute
* Command blocks can only run commands of level permission of 1 or 2
* The can **not** ban, kick or deop, for example
* Make sure you are **not** using item components in pre-1.20.5 or item `nbt` in 1.20.5+
-* execute does not allow the use of commands for plugins, so the command `/execute as @a run tpa ...` will **not** work
## Functions
@@ -51,8 +49,8 @@ This page details information on common problems you might have with a command,
* Inserting from a list/array or NBT path is not allowed
* Use a plain plain text editor (Notepad, Notepad++, Sublime, Code), **not** a word processor or rich text editor (Microsoft Word, Wordpad, Textedit)
* Make sure your file's encoding is UTF-8 (without BOM) - this is not the default in many programs! ([Notepad](http://i.imgur.com/R4yFjAQ.png), [Notepad++](http://i.imgur.com/8AsDJ3F.png), [Sublime](http://i.imgur.com/63rsYOB.png), [Code](http://i.imgur.com/dmOqy0y.png))
-* The namespace folder is not optional, functions should **not** be directly inside `data/functions/`, they must be in `data//functions/`
-* Don't forget to save changes if editing directly the datapack (with programs like VScode), normaly `ctrl+s` (Windows/Lunix) or `cmd+s` (Mac)
+* The namespace folder is not optional, functions should **not** be directly inside `data/functions/`, they must be in `data//functions/` (or in `data//function/` in 1.21+)
+* Don't forget to save changes if editing directly the datapack (with programs like VScode), normally `ctrl+s` (Windows/Lunix) or `cmd+s` (Mac)
* Don't forget to use `/reload` to reload the functions after making changes
* Make sure you have the datapack enabled. You can enable the datapack by typing `/datapack enable ""`
* When edition world generation you need to leave and rejoin the world in order to save changes (or restart the server).
@@ -60,8 +58,8 @@ This page details information on common problems you might have with a command,
* Recursive/looping functions will run `maxCommandChainLength` commands in one tick, then stop, the default value of this gamerule is `65536`
* To check if a function did **not** end (so it has been cut off by this gamerule) you can set a scoreboard value of a [fakeplayer](wiki/questions/fakeplayer) to 1, run all commands and set it to 0 after that (that command should be the last one in the whole tick). In the next tick you can check if the value is 1 or 0, if its 1, the function has been cutted.
* Make sure the tick/load function tag is specifing the correct function
-* Functions can run any command that requires a higher level permission than 2.
- * You can override this if you set `function-level-permission` in `server.propieties` to a higher number
+* Functions can not run any command that requires a higher level permission than 2.
+ * You can override this if you set `function-level-permission` in `server.properties` to a higher number
* If a function has a syntax error, it will **not** show up in the autocomplete and it will flail, if you try to run it
* All commands must have a correct syntax in order to run the function
* You can start the function with a `/say` command, so you will know if the function has been executed
diff --git a/oldresources.md b/oldresources.md
new file mode 100644
index 000000000..846e00b99
--- /dev/null
+++ b/oldresources.md
@@ -0,0 +1,274 @@
+# Resources
+
+| ⚠️ Important |
+|--------------|
+|This page is outdated: some links won't work and the majority of sites are for older versions of minecraft (1.14 and older). To see rousources for newer versions see the [resources page](wiki/resources)|
+
+This page contains a list of links to utilities and references relating to commands and map making that you may find useful.
+
+Submit a [pull request](https://github.com/MinecraftCommands/wiki/pulls) or create a [GitHub issue](https://github.com/MinecraftCommands/wiki/issues) if you've found a useful tool or reference that you think would fit here.
+
+## NBT
+
+### Utilities
+
+- [NBT Studio](https://github.com/tryashtar/nbt-studio) (tryashtar)
+- [NBTExplorer](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1262665-nbtexplorer-nbt-editor-for-windows-and-mac) (jaquadro)
+- [Web NBT Editor](https://irath96.github.io/webNBT/) (irath96)
+- [NBT Workbench](https://rttv.ca) ([On GitHub](https://github.com/RealRTTV/nbtworkbench)) (RealRTTV)
+- [Tag checker](http://www.mediafire.com/file/n38fgnjnr0q113d/PCN+1.4.zip) (pca006132)
+- [Web NBT Validator](https://www.soltoder.com/NBTLint/#{Hello:%22reddit%22,Test:{Int:267,Short:345s,TooLarge:9999999999,%221.12%20Compatible%22:[I;1,2,3]}}) (AjaxGb)
+- [1.16 UUID Converter](https://www.soltoder.com/mc-uuid-converter/) (AjaxGb)
+- [UUID <--> UUIDMost/Least converter](https://minecraft.repertor.space/uuid.html) (Repertor)
+- [UUID <--> UUIDMost/Least converter](http://skylinerw.com/uuid/index.php?convert=dechex&uuidleast=1&uuidmost=1) (Skylinerw)
+
+### References
+
+- [Chunk format](http://minecraft.wiki/Chunk_format) (Wiki)
+- [Player.dat format](http://minecraft.wiki/Player.dat_format) (Wiki)
+- [Structure file format](http://minecraft.wiki/Structure_block_file_format) (Wiki)
+
+## Commands
+
+### Utilities
+
+- [Command language](http://zipkrowd.com/tools.htm#cbp) (CBP)
+- [Command language](http://commandstudio.github.io/commandstudio/) (CommandStudio)
+- [Command language](http://smelt.gnasp.com/) (Smelt)
+- [Command language](http://energyxxer.com/cpm/) (CPM)
+- [Commands from C/assembly](https://github.com/simon816/Command-Block-Assembly) (simon816)
+- [One command generator](https://mrgarretto.com/commanddump) (MrGarretto)
+- [Command editor/one command generator](https://blockbench.net/tools/clg/) (JannisX11)
+- [Selector generator](https://blockbench.net/tools/selector/) (JannisX11)
+- [Command generator](https://mcstacker.net/mcstacker1.13.php) (MCStacker)
+- [Command generator](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/2142815-1-11-1-12-minecraft-command-generator-v2) (Cubiccl)
+
+### References
+
+- [Commands list](http://minecraft.wiki/Commands) (Wiki)
+- [Statistics list](http://minecraft.wiki/Statistics) (Wiki)
+- [Full syntax tree (as JSON, useful for tools)](https://gist.github.com/Dinnerbone/7370a2846953eee2d8fc64514fb76de8) (Dinnerbone)
+
+## Loot tables (& predicates)
+
+### Utilities
+
+- [Generator](https://misode.github.io/loot-table/) (Misode)
+- [Predicate generator](https://misode.github.io/predicate) (Misode)
+- [Generator](https://jsfiddle.net/MrPingouin/125mx5r5/embedded/result/) (MrPingouin)
+- [Generator](https://amaury.carrade.eu/minecraft/loot_tables) (Amaury, based on MrPingouin's)
+- [Generator](http://minecraft.tools/en/loots.php) (Minecraft Tools) ^[Missing features]
+- [Evaluator](https://sourceblock.net/beta/tools/loot-table-evaluator) (Skylinerw)
+- [VSCode Schema](https://marketplace.visualstudio.com/items?itemName=Levertion.mcjson) (Levertion)
+
+### References
+
+- [Guide](http://minecraft.wiki/Loot_table) (Wiki)
+- [Guide](https://github.com/skylinerw/guides/blob/master/java/loot%20tables.md) (Skylinerw)
+- [New 1.14 features guide](https://gist.github.com/misode/66456e57372ce62cd9b65d1052521069) (Misode)
+
+## Functions
+
+### Utilities
+
+- [VSCode syntax highlighter](https://marketplace.visualstudio.com/items?itemName=arcensoth.language-mcfunction) (Arcensoth)
+- [VSCode language server & more](https://marketplace.visualstudio.com/items?itemName=SPGoding.datapack-language-server) (SPGoding)
+- [Sublime syntax highlighter](https://github.com/AjaxGb/Sublime-MCFunction) (AjaxGb)
+- [Sublime syntax highlighter](https://github.com/42iscool42/MCC) (42iscool42)
+- [Atom syntax highlighter](https://atom.io/packages/mcfunction) (MrYurihi)
+
+### References
+
+- [Info](http://minecraft.wiki/Function) (Wiki)
+
+## Advancements
+
+### Utilities
+
+- [Generator](http://commandcreator.com/advancements/) (Command Creator)
+- [Generator](https://advancements.thedestruc7i0n.ca/) (destruc7i0n)
+- [Generator](https://misode.github.io/advancement/) (Misode)
+- [Evaluator](https://sourceblock.net/beta/tools/advancement-evaluator) (Skylinerw)
+- [Empty vanilla advancements, for overwriting default ones](http://www.mediafire.com/file/oku6p2tje0vv9lc/Impossible%20Advancements.zip) (18w22c)
+- [VSCode Schema](https://marketplace.visualstudio.com/items?itemName=Levertion.mcjson) (Levertion)
+
+
+### References
+
+- [Guide](https://github.com/skylinerw/guides/blob/master/java/advancements.md) (Skylinerw)
+- [Format](http://minecraft.wiki/Advancements#JSON_Format) (Wiki)
+- [Biome list](https://pastebin.com/MK61Xuzf) (Skylinerw)
+- [Order of trigger activations in a tick](http://i.imgur.com/pz5mU0G.png) (Skylinerw)
+
+## Recipes
+
+### Utilities
+
+- [Generator](http://minecraft.tools/en/custom-crafting.php#) (Minecraft Tools)
+- [Generator](https://crafting.thedestruc7i0n.ca/) (destruc7i0n)
+- [Generator](http://commandcreator.com/Craft/) (Command Creator)
+- [Evaluator](https://sourceblock.net/beta/tools/recipe-evaluator) (Skylinerw)
+
+### References
+
+- [Guide](https://github.com/skylinerw/guides/blob/master/java/recipes.md) (Skylinerw)
+
+## Text formatting
+
+### Utilities
+
+- [Title](http://minecraft.tools/en/title.php) (Minecraft Tools)
+- [Title](https://minecraftcommand.science/title-generator) (Command Science)
+- [Sign](http://minecraft.tools/en/sign.php) (Minecraft Tools)
+- [Sign](https://minecraftcommand.science/command-sign-generator) (Command Science) ^[Escapes incorrectly]
+- [Sign](https://mctoolbox.cmd.science/sign/) (MCToolBox)
+- [Book](http://minecraft.tools/en/book.php) (Minecraft Tools)
+- [Tellraw](http://minecraft.tools/en/tellraw.php) (Minecraft Tools)
+- [Tellraw](https://blockbench.net/tools/tellraw/) (JannisX11)
+- [Evaluator](https://sourceblock.net/beta/tools/text-component-evaluator) (Skylinerw)
+- [§ code Texteditor](https://plagiatus.net/tools/colortext/) (Plagiatus)
+
+### References
+
+- [Guide](https://github.com/skylinerw/guides/blob/master/java/text%20component.md) (Skylinerw)
+- [§ codes](http://minecraft.wiki/Formatting_codes) (Wiki)
+- [§ codes](http://minecraft.tools/en/color-code.php) (Minecraft Tools)
+
+## Give
+
+### Utilities
+
+- [Give generator](https://mcstacker.net/mcstacker1.13.php) (MCStacker)
+- [Item](https://minecraftcommand.science/custom-item-generator) (Command Science)
+- [Tools/weapons](https://minecraftcommand.science/tool-generator) (Command Science)
+- [Potions](https://minecraftcommand.science/potion-generator) (Command Science)
+- [Armor](https://minecraftcommand.science/armor-generator) (Command Science)
+- [Firework generator](http://minecraft.tools/en/firework.php) (Minecraft Tools)
+
+### References
+
+## Entities
+
+### Utilities
+
+- [Summon generator](http://minecraft.tools/en/spawn.php) (Minecraft Tools)
+- [Summon generator](https://mcstacker.net/mcstacker1.13.php) (MCStacker)
+- [Summon generator](http://www.summon-helper.net/entitySelection.html) (Summon Helper)
+- [Spawner generator](https://mcstacker.net/mcstacker1.13.php) (MCStacker, select mob spawner in `/setblock`)
+- [Villager shop](https://minecraftcommand.science/shop-generator) (Command Science)
+- [Hologram text](https://minecraftcommand.science/hologram-generator) (Command Science)
+- [Hologram text](https://mctoolbox.cmd.science/holograms/) (MCToolBox)
+- [Mob click detection](http://mctoolbox.cmd.science/click-mobs/) (MCToolBox)
+
+### References
+
+- [Chunk format](http://minecraft.wiki/Chunk_format) (Wiki)
+
+## World editing
+
+### Utilities
+
+- [Amulet Editor](https://www.amulet-editor.com/)
+- [MCEdit Unified](http://www.mcedit-unified.net)
+- [MCEdit 2.0 beta](http://www.mcedit.net/downloads.html) ^[Beta, missing features]
+- [MCEdit filter collection](http://www.brightmoore.net/mcedit-filters-1) (Adrian Brightmoore)
+- [MCEdit filter collection](http://web.archive.org/web/20161229045538/http://elemanser.com/filters.html) (Texelelf)
+- [WorldPainter](http://worldpainter.net/) (Captain Chaos)
+- [WorldSynth](https://www.worldsynth.net) (booleanbyte)
+- [MCA Selector](https://github.com/Querz/mcaselector) (Querz)
+- [Shape planner](http://www.plotz.co.uk/) (Plotz)
+- [Template manager](https://www.youtube.com/watch?v=LjixFRcqxSs) (bananenbroek4)
+
+### References
+
+- [Data values](http://minecraft.wiki/Data_values) (Wiki)
+- [Building guides](https://www.reddit.com/r/Minecraft/comments/6eua5z/a_reminder_of_some_excellent_build_guidesbuilders/) (Adrian Brightmoore)
+- [Biome colour-map](http://i.imgur.com/05QGuPX.png) (Word_Wizzard)
+
+## World generation
+
+### Utilities
+
+- [Custom world setting generator](https://misode.github.io/worldgen/) (Misode)
+- [Superflat preset generator](http://minecraft.tools/en/flat.php) (Minecraft Tools)
+
+### References
+
+- [Custom world type format](https://minecraft.wiki/Custom)
+- [Noise settings examples](https://gist.github.com/misode/b83bfe4964e6bf53b2dd31b22ee94157) (Misode)
+- [Vanilla worldgen reference files](https://t.co/cm3pJcAHcy) (Mojang)
+
+## Resource packs
+
+### Utilities
+
+- [Model creator](https://blockbench.net/) (BlockBench)
+- [Model creator](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/2146545-opls-model-creator-free-3d-model-editor) (opl)
+- [Model creator](https://mrcrayfish.com/tools?id=mc) (MrCrayfish)
+- [Model creator](http://thejonwithnoh.github.io/SetblockWebModeler/) (thejonwithnoh)
+- [Model creator](https://cubik.studio/) (Cubik) ^[Paid]
+- [Damage predicate generator](http://accidentalgames.com/media/durabilityModels.php) (Accidental games)
+- [Upgraded damage predicate generator](https://geenium.github.io/damage-value-generator/) (Upgraded by geenium)
+- [Resource pack creator](https://minecraft.novaskin.me/resourcepacks) (Novaskin)
+- [Resource pack creator](https://mcrpw.github.io/) (MightyPork)
+- [Block designer](https://codecrafted.net/blockdesigner) (CodeCrafted, concept by Simplysarc)
+
+### References
+
+- [Model format](http://minecraft.wiki/Model) (Wiki)
+- [Sounds list](https://minecraft.wiki/Sounds.json/Java_Edition_values) (Wik)
+- [Font json format](https://discordapp.com/channels/154777837382008833/154777837382008833/468913675017912320) (AmberW)
+- [Shader `post` json format](https://discordapp.com/channels/154777837382008833/154777837382008833/490651571261014036) (Mrpingouin)
+- [Shader `program` special variables](https://discordapp.com/channels/154777837382008833/306175724942000128/491380153960628231) (Mrpingouin)
+- [Shader guide](https://docs.google.com/document/d/15TOAOVLgSNEoHGzpNlkez5cryH3hFF3awXL5Py81EMk/edit?usp=sharing) (SirBenet)
+
+## Map publishing
+
+### Utilities
+
+- [Map auto-install creator](https://github.com/mrjvs/mpm/releases) (mrjvs)
+- [Minecraft Maps](http://www.minecraftmaps.com) (Site for maps)
+- [Minecraft Forum](https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/maps) (Site for maps)
+- [Planet Minecraft](https://www.planetminecraft.com) (Site for maps)
+
+### References
+
+## Miscellaneous
+
+### Heads
+
+- [Head generator](https://minecraftcommand.science/head-generator) (Command Science)
+- [Custom heads](http://heads.freshcoal.com/maincollection.php) (Freshcoal)
+- [Mob head display sizes](https://twitter.com/samasaurus6/status/787010091094540288) (samasaurus6)
+
+### Banners/shields
+
+- [Banner designer](http://www.needcoolshoes.com/banner) (Miners Need Cool Shoes)
+- [Banner designer](http://www.planetminecraft.com/banner/) (Planet Minecraft)
+- [Banner designer](http://minecraft.tools/en/banner.php) (Minecraft Tools)
+- [Shield designer](http://minecraft.tools/en/shield.php) (Minecraft Tools)
+
+### Color
+
+- [Beacon color](http://minecraft.tools/en/beacon-color.php) (Minecraft Tools)
+- [Armor color](http://minecraft.tools/en/armor.php) (Minecraft Tools)
+- [Armor color](https://minecraftcommand.science/armor-color) (Command Science)
+- [Color picker](http://skylinerw.com/color/) (Skylinerw)
+- [Block colors](http://mrgarretto.com/blockcolors) (MrGarretto)
+- [Particle color](http://mctoolbox.cmd.science/particles/) (MCToolBox)
+- [Biome water colors](https://pastebin.com/2zYzzymu) (extracted by MrPingouin using [Fabric](https://fabricmc.net/))
+
+### Map items
+
+- [Image to map](https://mc-map.djfun.de/) (MC Map Item Tool)
+- [Image to map](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1261738-linux-windows-imagetomap-in-game-text-and-images) (ImageToMap)
+- [Image to map](https://github.com/tryashtar/image-map/raw/master/Image%20Map/bin/Debug/Image%20Map.exe) (tryashtar)
+- [NBT reference](http://minecraft.wiki/Player.dat_format#Maps) (Wiki)
+
+
+### Animation
+
+- [Animator](https://github.com/JannisX11/animator/releases/tag/v1.1.1) (Jannis)
+- [Cutscene generator](https://www.youtube.com/watch?v=ukR7126RkU4) (The Redstone Scientist)
+- [Armorstand animator](https://mrgarretto.com/armorstand/) (MrGarretto)
+- [Block model animator](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/2715476-block-models-json-model-animator) (fizzy81)
diff --git a/optimising.md b/optimising.md
index 31e0cfde1..73e929448 100644
--- a/optimising.md
+++ b/optimising.md
@@ -86,7 +86,9 @@ Selectors are used a lot in commands. To make sure you're not causing extra work
Your main aim here is to narrow down the list as much as possible before getting to the expensive distance-sorting/shuffling and especially the super expensive NBT checks. You shouldn't however unnecessarily check arguments that won't narrow down the list before distance-sorting/shuffling. For example, don't check `@e[type=zombie,tag=IsUndeadMob]` if all zombies will have that tag. You shouldn't make your selector imprecise so that it applies to more entities than it needs to, either.
-`nbt` is the least efficient target selector, as it has to do a lot of converting and comparing, and as such should be avoided at (almost) all costs, or at least limited to the absolute minimum required. [Predicates](https://minecraft.wiki/w/Predicate), in the other hand, can archive the same causing less performance impact only when not using NBT checks but built-in checks. If using NBT checks it actually performs worse.
+`nbt` is the least efficient target selector, as it has to do a lot of converting and comparing, and as such should be avoided at (almost) all costs, or at least limited to the absolute minimum required. [Predicates](https://minecraft.wiki/w/Predicate), in the other hand, can archive the same causing less performance impact only when not using NBT checks but built-in checks. If using NBT checks it actually performs worse.
+
+Use `execute if/unless items` instead of `nbt` to detect items in the player inventory. For more details see [Detect a specific item?](/wiki/questions/detectitem)
`@s` is the most efficient selector, directly grabbing the command sender. See the section on **function-specific optimisations** for how you can make use of it to cut down on use of other selectors.
@@ -98,10 +100,17 @@ Consider also whether you actually need a selector. If you're selecting the same
## Optimize entities
-Using armor stands as markers? Strongly consider switching to area effect clouds or, even better, the marker entity instead. [Here's a good video showing just how much difference this makes.](https://www.youtube.com/watch?v=RKXzWGQfIcg) You can summon an area effect cloud that acts as a marker with:
+Using armor stands as markers? Strongly consider switching to area effect clouds or, even better, the `marker` entity instead. [Here's a good video showing just how much difference this makes.](https://www.youtube.com/watch?v=RKXzWGQfIcg) You can summon an area effect cloud that acts as a marker with:
+ # 1.20.5+
+ summon area_effect_cloud ~ ~ ~ {Duration:-1}
+ # Pre-1.20.5
summon area_effect_cloud ~ ~ ~ {Duration:2147483647}
+| 📝 Note |
+|---------|
+|Starting [in 1.21.5](https://www.minecraft.net/de-de/article/minecraft-java-edition-1-21-5), setting the `Duration` to `-1` causes the area effect cloud to never expire (this is now the default, so the `Duration` field can be omitted). Before that you'd set it to `2147483647` which made the cloud expire after over 3 years of ingame time.|
+
These won't show up to spectators, which is a bonus if you don't want spectators to see your markers. If you want to see them for debugging purposes, turn on hitboxes (`F3 + B`). Armor stands should only be used where necessary, such as displaying an item (In pre-1.19.4, as you can use item displays in newer versions) or using `Motion`.
[Marker entities](https://minecraft.wiki/wiki/Marker) on the other hand are impossible to see, as they aren't even sent to the client (unless using [a mod](https://modrinth.com/mod/visiblebarriers), that needs to be on the server as well), so you'd need to resort to other options to debug them. This however means that they have a competitive advantage when it comes to performance and should be used as a marker over the other options wherever possible.
@@ -140,3 +149,5 @@ This means that instead of evaluating `@e[tag=blah]` many times, it is only eval
[/u/Wooden_chest](https://www.reddit.com/user/Wooden_chest/) created an in-depth analysis of a lot of small things that can improve your performance, like what order to put your execute subcommands into or that depending on the circumstance it might actually be faster to copy NBT you want to test to the storage first before testing it instead of testing it on the entity/player directly.
Read their full post here: https://www.reddit.com/r/MinecraftCommands/comments/w4vjs3/whenever_i_create_datapacks_i_sometimes_do/
+
+You can use [Misode's Report Inspector](https://misode.github.io/report/) to see what commands are causing lag.
\ No newline at end of file
diff --git a/questions.md b/questions.md
index 7c30e33cf..9f180a41b 100644
--- a/questions.md
+++ b/questions.md
@@ -5,11 +5,7 @@
Because in 1.19.50, the [new execute syntax](https://learn.microsoft.com/en-us/minecraft/creator/documents/commandsnewexecute) became mandatory, so you'll need to switch to that. See also [this information on bedrock.dev](https://wiki.bedrock.dev/commands/new-execute.html).
## Why is my give command broken (java)?
-In 1.20.5 a new system for storing item data has been introduced to Java Edition in [Snapshot 24w09a](https://www.minecraft.net/en-us/article/minecraft-snapshot-24w09a).
-Anything relating to items (such as /give, /item or loot tables) have a different format now.
-The gist of it is this: Unstructured NBT data attached to stacks of items (tag field) has been replaced with structured 'components' that go in [] and are comma separated.
-For example: /give @p diamond_pickaxe[damage=10,custom_model_data=7]
-For a list of how item components are structured, see [this article on the minecraft.wiki](https://minecraft.wiki/w/Item_format/1.20.5).
+In 1.20.5, unstructured NBT for item stacks (tag field) was replaced with structured "components." Learn more in [this article](https://minecraft.wiki/w/Item_format/1.20.5).
## How do I...
@@ -44,31 +40,37 @@ For a list of how item components are structured, see [this article on the minec
[Detect when a player kills an entity/other player?](/wiki/questions/playerkills)
[Detect a player joining (for the first time)?](/wiki/questions/playerjoin)
[Store a players inventory (and give it back later)?](/wiki/questions/storeinventory)
-[Detect a player looking at something (entity / position)](/wiki/questions/lookat)
+[Detect a player looking at something (entity / position)?](/wiki/questions/lookat)
-### Misc
+### Conditions
+[Do conditions with functions?](/wiki/questions/functionconditions)
[Do something if a command block *wasn't* successful?](/wiki/questions/blockinvert)
+[Check if there are exactly X players (or entities) matching a selector?](/wiki/questions/numplayers)
+
+### Entities
+
[Do something (e.g: kill) to the entity I just found with /execute if entity (testfor)?](/wiki/questions/tagentity)
-[Add a delay to a command block?](/wiki/questions/blockdelay)
-[Check if there are exactly X players matching a selector?](/wiki/questions/numplayers)
-[Do conditions with functions?](/wiki/questions/functionconditions)
-[Point a compass towards a player?](/wiki/questions/compasstoplayer)
-[Summon an entity/projectile flying in the direction the player is looking?](/wiki/questions/shootfacing)
-[Make a scoreboard ID system?](/wiki/questions/linkentity)
[Make one mob attack another mob/player?](/wiki/questions/angermob)
-[Do raycasting?](/wiki/questions/raycast)
-[Make a circle (of blocks / entities)?](/wiki/questions/makecircle)
+[Summon an entity/projectile flying in the direction the player is looking?](/wiki/questions/shootfacing)
[Detect when a mob has died](/wiki/questions/mobdeaths)
-[Make hostile mobs friendly / dissable PvP](/wiki/questions/hostilefriendly)
+[Make hostile mobs friendly / disable PvP?](/wiki/questions/hostilefriendly)
[Setup, configure and add multiple dialogues to NPCs?](/wiki/questions/npc)
+### Misc
+
+[Add a delay to a command block?](/wiki/questions/blockdelay)
+[Point a compass towards a player/location?](/wiki/questions/compasstoplayer)
+[Make a scoreboard ID system?](/wiki/questions/linkentity)
+[Do raycasting?](/wiki/questions/raycast)
+[Make a circle (of blocks / entities)?](/wiki/questions/makecircle)
+
## What is...
[a fake player?](/wiki/questions/fakeplayer)
[a range? / those two dots `..`?](/wiki/questions/range)
[command context?](/wiki/questions/commandcontext)
-
+[escaping?](/wiki/questions/escaping)
## How do I... (1.12 and below only)
@@ -77,4 +79,4 @@ For a list of how item components are structured, see [this article on the minec
## Still needed articles
-*Found something that should be added? Maybe even want to contribute an article? Submit a pull request or create a GitHub issue [here](https://github.com/MinecraftCommands/wiki).*
+*Found something that should be added? Maybe even want to contribute an article? Submit a [pull request](https://github.com/MinecraftCommands/wiki/pulls) or create a [GitHub issue](https://github.com/MinecraftCommands/wiki/issues)*
diff --git a/questions/amountitems.md b/questions/amountitems.md
index 3d6a4fd74..03030f530 100644
--- a/questions/amountitems.md
+++ b/questions/amountitems.md
@@ -1,5 +1,8 @@
# Select players with exactly X amount of items?
+* [Java](#java)
+* [Bedrock](#bedrock)
+
## Java
### Clear
@@ -7,51 +10,61 @@
Using the [`clear`](https://minecraft.wiki/Commands/clear) command with a `[]` of 0 will return the amount of items a player has, without actually clearing any of them.
That means we can use [`execute store`](https://minecraft.wiki/w/Commands/execute#Store_subcommand) to save that number somewhere and then execute depending on that:
- # Setup
- scoreboard objectives add diamonds dummy
+```mcfunction
+# Setup
+scoreboard objectives add diamonds dummy
- # Commands
- execute store result score @s diamonds run clear @s diamond 0
- execute if score @s diamonds matches 5 run say I have exactly 5 diamonds in my inventory.
- execute if score @s diamonds matches 1..4 run say I have somewhere between 1 and 4 diamonds in my inventory.
- execute if score @s diamonds matches 10.. run say I have 10 or more diamonds in my inventory.
- execute if score @s diamonds matches ..20 run say I have 20 or less diamonds in my inventory.
+# Commands
+execute store result score @s diamonds run clear @s diamond 0
+execute if score @s diamonds matches 5 run say I have exactly 5 diamonds in my inventory.
+execute if score @s diamonds matches 1..4 run say I have somewhere between 1 and 4 diamonds in my inventory.
+execute if score @s diamonds matches 10.. run say I have 10 or more diamonds in my inventory.
+execute if score @s diamonds matches ..20 run say I have 20 or less diamonds in my inventory.
+```
### Execute if items
-Since version 1.20.5 you can also use [`execute if items`](https://minecraft.wiki/w/Commands/execute#(if|unless)_items) to count the number of items.
+Since version 1.20.5, you can also use [`execute if items`](https://minecraft.wiki/w/Commands/execute#(if%7Cunless)_items) to count the number of items.
The `if items` subcommand, when executed, returns the number of items that meet the specified conditions. For a quick example, running this command will show the count of all items in the player's inventory (except for armor and left hand slots):
- # In chat
- execute if items entity @s container.* *
+```mcfunction
+# In chat
+execute if items entity @s container.* *
+```
You can find out more details on how to detect specific items here: [Detect a specific item](/wiki/questions/detectitem)
Below is an example for getting the amount of a custom item and executing some command depending on the result:
- # Example item
- give @s diamond[minecraft:custom_data={diamond:true},minecraft:item_name="'Custom Diamond'"]
-
- # Command blocks
- execute as @a store result score @s diamonds if items entity @s container.* *[custom_data~{diamond:true}]
- execute as @a[scores={diamonds=5}] run say I have exactly 5 coins.
- execute as @a[scores={diamonds=1..4}] run say I have somewhere between 1 and 4 coins.
- execute as @a[scores={diamonds=10..}] run say I have 10 or more coins.
- execute as @a[scores={diamonds=..20}] run say I have 20 or less coins.
+```mcfunction
+# Example item
+give @s diamond[minecraft:custom_data={diamond:true},minecraft:item_name="'Custom Diamond'"]
+
+# Command blocks
+execute as @a store result score @s diamonds if items entity @s container.* *[custom_data~{diamond:true}]
+execute as @a[scores={diamonds=5}] run say I have exactly 5 coins.
+execute as @a[scores={diamonds=1..4}] run say I have somewhere between 1 and 4 coins.
+execute as @a[scores={diamonds=10..}] run say I have 10 or more coins.
+execute as @a[scores={diamonds=..20}] run say I have 20 or less coins.
+```
Although you can use `/clear` on a player, `if items` can also count the number of items in a chest, shulker_box and other containers, can also count the number of items in a players ender_chest.
Here are some examples for this:
- # Counting items in chest or any container
- execute store result score #container diamonds if items block container.* *[custom_data~{diamond:true}]
-
- # Counting items in ender_chest
- execute as @a store result score @s diamonds if items entity @s enderchest.* *[custom_data~{diamond:true}]
+```mcfunction
+# Counting items in chest or any container
+execute store result score #container diamonds if items block container.* *[custom_data~{diamond:true}]
+
+# Counting items in ender_chest
+execute as @a store result score @s diamonds if items entity @s enderchest.* *[custom_data~{diamond:true}]
+```
## Bedrock
In the **1.18.20 beta** they added the [`hasitem`](https://minecraft.wiki/wiki/Target_selectors#Selecting_targets_by_items) target selector, which allows you to check for specific amounts (as [ranges](/wiki/questions/range)) of items in entities inventories. Below is an example (using 1.19.50 execute), check the link above for more information.
- execute as @a[hasitem={item=apple,quantity=5..}] run say I have 5 or more apples in my inventory
+```mcfunction
+execute as @a[hasitem={item=apple,quantity=5..}] run say I have 5 or more apples in my inventory
+```
\ No newline at end of file
diff --git a/questions/angermob.md b/questions/angermob.md
index 2dcd7f177..ea985e217 100644
--- a/questions/angermob.md
+++ b/questions/angermob.md
@@ -1,4 +1,4 @@
-# Make a mob attack another specfic entity / player
+# Make a mob attack another specific entity / player
The basic principle for this method is that a mob that can attack will get angry at whoever attacks them. _(some exceptions apply)_
@@ -6,29 +6,35 @@ The basic principle for this method is that a mob that can attack will get angry
### Using /damage
-> [!IMPORTANT]
-> In bedrock a lot of entities have a very defined set of other entities they can attack, as defined in their behavior pack. So if the below method doesn't work to anger them, make sure they're actually able to attack the target entity and change the behavior files accordingly!
+| ⚠️ Important |
+|--------------|
+|In bedrock a lot of entities have a very defined set of other entities they can attack, as defined in their behavior pack. So if the below method doesn't work to anger them, make sure they're actually able to attack the target entity and change the behavior files accordingly!|
Thanks to the introduction of the [`/damage` command](https://minecraft.wiki/wiki/Commands/damage) (in 1.18.10 Bedrock and 1.19.4 Java) we can use this command to inflict fake damage from one entity onto another with relative ease:
- # bedrock
- /damage entity_attack entity
- # java
- /damage by
+```mcfunction
+# bedrock
+/damage entity_attack entity
+# java
+/damage by
+```
so for example, to make a single wolf attack a player, you can run this command
- # bedrock
- /damage @e[type=wolf,c=1] 0 entity_attack entity @p
- # java
- /damage @e[type=wolf,limit=1,sort=nearest] 0 player_attack by @p
-
+```mcfunction
+# bedrock
+/damage @e[type=wolf,c=1] 0 entity_attack entity @p
+# java
+/damage @e[type=wolf,limit=1,sort=nearest] 0 player_attack by @p
+```
or to make all skeleton skeleton attack a zombie
- # bedrock
- /damage @e[type=skeleton] 0 entity_attack entity @e[type=zombie]
- # java
- /execute as @e[type=skeleton] run damage @s 0 player_attack by @e[type=zombie,limit=1]
+```mcfunction
+# bedrock
+/damage @e[type=skeleton] 0 entity_attack entity @e[type=zombie]
+# java
+/execute as @e[type=skeleton] run damage @s 0 player_attack by @e[type=zombie,limit=1]
+```
In this example we're using `0` as the amount of damage, as we just want to pretend to deal damage to the entity, not actually deal any damage.
@@ -39,16 +45,19 @@ In this example we're using `0` as the amount of damage, as we just want to pret
The way the game knows who got attacked by whom is by tracking the owner of a projectile through the projectiles `Owner` tag, which represents the owners UUID. We can use this to make a projectile that pretends to be from a specific entity by modifying this NBT tag.
For example you can use a snowball, as this projectile only deal damage to blazes. The snowball is summoned 2.3 blocks above the target so their hitboxes don't overlap (which would cause the snowball to ignore the target).
-> [!IMPORTANT]
-> If the player is crawnling or it has a block above them, it wont work.
-In the following example a skeleton tagged `attacker` is tricked into attacking a zombie tagged `target`.
+| ⚠️ Important |
+|--------------|
+|If the player is crawling or it has a block above them, it won't work|
- # summon the snowball
- execute at @e[type=skeleton,tag=attacker] run summon minecraft:snowball ~ ~2.3 ~ {Tags:["atk_target"]}
- # make the snowball owner the zombie
- execute as @e[type=minecraft:snowball,tag=atk_target] run data modify entity @s Owner set from entity @e[type=zombie,limit=1,tag=target] UUID
+In the following example a skeleton tagged `attacker` is tricked into attacking a zombie tagged `target`.
+```mcfunction
+# summon the snowball
+execute at @e[type=skeleton,tag=attacker] run summon minecraft:snowball ~ ~2.3 ~ {Tags:["atk_target"]}
+# make the snowball owner the zombie
+execute as @e[type=minecraft:snowball,tag=atk_target] run data modify entity @s Owner set from entity @e[type=zombie,limit=1,tag=target] UUID
+```
## Bedrock
### Using behaviors
@@ -57,44 +66,50 @@ As mentioned above, what entities can and cannot be attacked by another entity i
Here is the relevant component in the vanilla skeleton behavior file (1.17):
- "minecraft:behavior.nearest_attackable_target": {
- "priority": 2,
- "must_see": true,
- "reselect_targets": true,
- "entity_types": [
- {
- "filters": {
+
+ See skeleton behavior
+
+```json
+ "minecraft:behavior.nearest_attackable_target": {
+ "priority": 2,
+ "must_see": true,
+ "reselect_targets": true,
+ "entity_types": [
+ {
+ "filters": {
+ "test": "is_family",
+ "subject": "other",
+ "value": "player"
+ },
+ "max_dist": 16
+ },
+ {
+ "filters": {
+ "test": "is_family",
+ "subject": "other",
+ "value": "irongolem"
+ },
+ "max_dist": 16
+ },
+ {
+ "filters": {
+ "all_of": [
+ {
"test": "is_family",
"subject": "other",
- "value": "player"
+ "value": "baby_turtle"
},
- "max_dist": 16
- },
- {
- "filters": {
- "test": "is_family",
+ {
+ "test": "in_water",
"subject": "other",
- "value": "irongolem"
- },
- "max_dist": 16
- },
- {
- "filters": {
- "all_of": [
- {
- "test": "is_family",
- "subject": "other",
- "value": "baby_turtle"
- },
- {
- "test": "in_water",
- "subject": "other",
- "operator": "!=",
- "value": true
- }
- ]
- },
- "max_dist": 16
- }
- ]
- },
+ "operator": "!=",
+ "value": true
+ }
+ ]
+ },
+ "max_dist": 16
+ }
+ ]
+ },
+```
+
\ No newline at end of file
diff --git a/questions/areas.md b/questions/areas.md
index f5732f1e2..95e1a4958 100644
--- a/questions/areas.md
+++ b/questions/areas.md
@@ -1,14 +1,17 @@
# Do something if a player is in certain areas
-> [!NOTE]
-> Java Syntax, but this can be applied to Bedrock just as well by changing the selector arguments to Bedrock Syntax. Instead of `distance=..X` use `r=X`, instead of `distance=X..Y` use `r=Y,rm=X` and instead of `distance=X..` use `rm=X`.
+| 📝 Note |
+|---------|
+|Java Syntax, but this can be applied to Bedrock just as well by changing the selector arguments to Bedrock Syntax. Instead of `distance=..X` use `r=X`, instead of `distance=X..Y` use `r=Y,rm=X` and instead of `distance=X..` use `rm=X`.|
-This mostly comes up as a question to change the gamemode in a certain area (e.g. spawn, safe zones, etc.), so we will focus on that, but this can be applied to any use case. For questions to do something once a player enters a single area, [look here](/wiki/questions/runonce).
+This mostly comes up as a question to change the gamemode in a certain area (e.g., spawn, safe zones, etc.), so we will focus on that, but this can be applied to any use case. For questions to do something once a player enters a single area, [look here](/wiki/questions/runonce).
The naive approach would be to put everyone in a radius X around the worldspawn (e.g. at 0 0 0) to adventure mode and everyone outside of it to survival mode.
- gamemode adventure @a[x=0,y=0,z=0,distance=..X]
- gamemode survival @a[x=0,y=0,z=0,distance=X..]
+```mcfunction
+gamemode adventure @a[x=0,y=0,z=0,distance=..X]
+gamemode survival @a[x=0,y=0,z=0,distance=X..]
+```
This method quickly falls apart if you have a non-spherical or non-box shaped area or you want this to apply to more than one area, because a player will always be outside of the other areas, even if they are inside one, so will always end up in survival.
@@ -16,18 +19,22 @@ This method quickly falls apart if you have a non-spherical or non-box shaped ar
The best way to make sure players are in one of multiple areas without overwriting each other, is to use a tag: So instead of applying the desired effect to each area individually, you tag all players that are in one of the areas and apply the effect once to all of them (or everyone else). But this method requires a separate command block for each location. For a large number of locations, use the anchor entity method.
- # Command blocks / tick function
- tag @a remove inArea
- tag @a[x=0,y=0,z=0,distance=..X] add inArea
- tag @a[x=100,y=64,z=100,dx=70,dy=16,dz=28] add in Area
- ....
- gamemode adventure @a[tag=inArea]
- gamemode survival @a[tag=!inArea]
+```mcfunction
+# Command blocks / tick function
+tag @a remove inArea
+tag @a[x=0,y=0,z=0,distance=..X] add inArea
+tag @a[x=100,y=64,z=100,dx=70,dy=16,dz=28] add inArea
+....
+gamemode adventure @a[tag=inArea]
+gamemode survival @a[tag=!inArea]
+```
-To prevent chatspam for the players and unnecessary gamemode changes, we suggest using the gamemode selector argument on the last two commands:
+To prevent chat spam for the players and unnecessary gamemode changes, we suggest using the gamemode selector argument on the last two commands:
- gamemode adventure @a[tag=inArea,gamemode=!adventure]
- gamemode survival @a[tag=!inArea,gamemode=!survival]
+```mcfunction
+gamemode adventure @a[tag=inArea,gamemode=!adventure]
+gamemode survival @a[tag=!inArea,gamemode=!survival]
+```
If for some reason you want to keep commandBlockOutput on and don't want your output to be spammed by this system, check out [this post](https://www.reddit.com/r/MinecraftCommands/comments/mw11xm/do_something_to_players_in_multiple_specific) by [u/Afanofall23](https://www.reddit.com/u/Afanofall23).
@@ -37,24 +44,28 @@ If you need to check if the player is in one of several spherical areas, for exa
For versions before 1.17 you can use armor_stand or area_effect_cloud, but since version 1.17 it is strongly recommended to use an [marker entity](https://minecraft.wiki/w/Marker) to mark a place.
- # Summon marker
- summon marker {Tags:["adventure_area"]}
-
- # Command blocks / tick function
- execute as @a[gamemode=survival] at @s if entity @e[type=marker,tag=adventure_area,distance=..X,limit=1] run gamemode adventure
- execute as @a[gamemode=adventure] at @s unless entity @e[type=marker,tag=adventure_area,distance=..X,limit=1] run gamemode survival
-
+```mcfunction
+# Summon marker
+summon marker {Tags:["adventure_area"]}
+
+# Command blocks / tick function
+execute as @a[gamemode=survival] at @s if entity @e[type=marker,tag=adventure_area,distance=..X,limit=1] run gamemode adventure
+execute as @a[gamemode=adventure] at @s unless entity @e[type=marker,tag=adventure_area,distance=..X,limit=1] run gamemode survival
+```
+
`X - distance at which players should be switched into adventure mode.`
To make placing markers more convenient, you can give a spawn_egg containing a marker with the tag:
- # 1.17 - 1.20.4
- give @s bat_spawn_egg{EntityTag:{id:"minecraft:marker",Tags:["adventure_area"]},display:{Name:'{"text":"Adventure Area Marker","italic":false}'}}
-
- # 1.20.5+
- give @s minecraft:bat_spawn_egg[entity_data={id:"minecraft:marker",Tags:["adventure_area"]},item_name='"Adventure Area Marker"']
+```mcfunction
+# 1.17 - 1.20.4
+give @s bat_spawn_egg{EntityTag:{id:"minecraft:marker",Tags:["adventure_area"]},display:{Name:'{"text":"Adventure Area Marker","italic":false}'}}
+
+# 1.20.5+
+give @s minecraft:bat_spawn_egg[entity_data={id:"minecraft:marker",Tags:["adventure_area"]},item_name='"Adventure Area Marker"']
+```
-Because in bedrock edition we can't give a custom spawn egg (some exceptions apply, see [give custom item in Bedrock](wiki/questions/giveitembedrock)), you will need to manualy tag the entity with the `/tag` command and use `armor_stand` instead of `marker`.
+Because in bedrock edition we can't give a custom spawn egg (some exceptions apply, see [give custom item in Bedrock](wiki/questions/giveitembedrock)), you will need to manually tag the entity with the `/tag` command and use `armor_stand` instead of `marker`.
## Block layer
@@ -62,8 +73,10 @@ If you need to execute a command when a player enters a very randomly shaped are
For example, you want to create an area on your map where the player will be detected if the player is not sneaking. This example will check the red_concrete block at Y=-63 for this area:
- # Command block / tick function (1.20.5+)
- execute as @a at @s if predicate {condition:"entity_properties",entity:"this",predicate:{flags:{is_sneaking:false}}} if block ~ -63 ~ minecraft:red_concrete run say You have been found!
+```mcfunction
+# Command block / tick function (1.20.5+)
+execute as @a at @s if predicate {condition:"entity_properties",entity:"this",predicate:{flags:{is_sneaking:false}}} if block ~ -63 ~ minecraft:red_concrete run say You have been found!
+```
## Predicates
@@ -73,65 +86,71 @@ In a predicate, you can use the `minecraft:alternative` (1.14-1.19.4) or `minecr
Below is an example of a predicate for checking three cubic areas:
+
+ Example predicate
+
+```json
+{
+ "condition": "minecraft:any_of",
+ "terms": [
{
- "condition": "minecraft:any_of",
- "terms": [
- {
- "condition": "minecraft:location_check",
- "predicate": {
- "position": {
- "x": {
- "min": 10,
- "max": 20
- },
- "y": {
- "min": 64,
- "max": 70
- },
- "z": {
- "min": 30,
- "max": 40
- }
- }
+ "condition": "minecraft:location_check",
+ "predicate": {
+ "position": {
+ "x": {
+ "min": 10,
+ "max": 20
+ },
+ "y": {
+ "min": 64,
+ "max": 70
+ },
+ "z": {
+ "min": 30,
+ "max": 40
}
- },
- {
- "condition": "minecraft:location_check",
- "predicate": {
- "position": {
- "x": {
- "min": 60,
- "max": 85
- },
- "y": {
- "min": -20,
- "max": 10
- },
- "z": {
- "min": 10,
- "max": 80
- }
- }
+ }
+ }
+ },
+ {
+ "condition": "minecraft:location_check",
+ "predicate": {
+ "position": {
+ "x": {
+ "min": 60,
+ "max": 85
+ },
+ "y": {
+ "min": -20,
+ "max": 10
+ },
+ "z": {
+ "min": 10,
+ "max": 80
}
- },
- {
- "condition": "minecraft:location_check",
- "predicate": {
- "position": {
- "x": {
- "min": -80,
- "max": -20
- },
- "y": {
- "min": 125,
- "max": 155
- },
- "z": {
- "min": 55,
- "max": 78
- }
- }
+ }
+ }
+ },
+ {
+ "condition": "minecraft:location_check",
+ "predicate": {
+ "position": {
+ "x": {
+ "min": -80,
+ "max": -20
+ },
+ "y": {
+ "min": 125,
+ "max": 155
+ },
+ "z": {
+ "min": 55,
+ "max": 78
}
}
- ]
+ }
}
+ ]
+}
+```
+
\ No newline at end of file
diff --git a/questions/blockdelay.md b/questions/blockdelay.md
index 68a8a8255..5f3ff0659 100644
--- a/questions/blockdelay.md
+++ b/questions/blockdelay.md
@@ -1,9 +1,12 @@
# Add a delay to a command block
+* [Java](#java)
+* [Bedrock](#bedrock)
+
## Bedrock
-In the Bedrock edition of the game, you can just give a commandblock a delay direcly through its interface, no need for any workarounds, unless you want to make a timer for every player, see the method using a [scoreboard](#scoreboard)
+In the Bedrock edition of the game, you can just give a commandblock a delay directly through its interface, no need for any workarounds, unless you want to make a timer for every player, see the method using a [scoreboard](#scoreboard)
## Java
@@ -15,44 +18,56 @@ Area effect clouds (AECs) have a `Duration` tag and an `Age` tag. Their `Age` wi
For example, the following creates an AEC that will disappear in 100 ticks (5 seconds), as their `Age` defaults to 0:
- summon area_effect_cloud ~ ~ ~ {Duration:100}
+```mcfunction
+summon area_effect_cloud ~ ~ ~ {Duration:100}
+```
-> [!NOTE]
-> To see area_effect_cloud press `F3 + B` to show hitboxes.
+| 📝 Note |
+|---------|
+|To see area_effect_cloud press `F3 + B` to show hitboxes|
You can set the `Duration` tag as a positive value or the `Age` tag as a negative value, but then you need to set the `Particle` tag to `"block air"` (1.20.4 and below) or `{type:"block",block_state:"minecraft:air"}` (1.20.5 and above) to prevent it from creating particles.
We can also summon it with a tag to select it with later:
+```mcfunction
+# 1.20.4 and below
+summon area_effect_cloud ~ ~ ~ {Tags:["delay"],Age:-100,Particle:"block air"}
- # 1.20.4 and below
- summon area_effect_cloud ~ ~ ~ {Tags:["delay"],Age:-100,Particle:"block air"}
-
- # 1.20.5 and above
- summon area_effect_cloud ~ ~ ~ {Tags:["delay"],Age:-100,Particle:{type:"block",block_state:"minecraft:air"}}
+# 1.20.5 and above
+summon area_effect_cloud ~ ~ ~ {Tags:["delay"],Age:-100,Particle:{type:"block",block_state:"minecraft:air"}}
+```
The following 3 commands, in this order on a repeating-chain clock, will tag any AEC that's reached `Age:-1` with `delayActivating`, then make them activate (by turning on/off) an impulse command block at their position:
- tag @e[type=area_effect_cloud,tag=delay,nbt={Age:-1}] add delayActivating
- execute at @e[type=area_effect_cloud,tag=delayActivating] run data merge block ~ ~ ~ {auto:true}
- execute at @e[type=area_effect_cloud,tag=delayActivating] run data merge block ~ ~ ~ {auto:false}
+```mcfunction
+tag @e[type=area_effect_cloud,tag=delay,nbt={Age:-1}] add delayActivating
+execute at @e[type=area_effect_cloud,tag=delayActivating] run data merge block ~ ~ ~ {auto:true}
+execute at @e[type=area_effect_cloud,tag=delayActivating] run data merge block ~ ~ ~ {auto:false}
+```
That means that if you have those 3 commands repeating somewhere in your world, the command `/summon area_effect_cloud X Y Z {Tags:[delay],Age:-##,Particle:{type:"block",block_state:"minecraft:air"}}` can be used to activate the command block at (X, Y, Z) in ## ticks. An example, that'll activate the block at (10, 64, 30) in 70 ticks:
- summon area_effect_cloud 10 64 30 {Tags:["delay"],Age:-70,Particle:{type:"block",block_state:"minecraft:air"}}
+```mcfunction
+summon area_effect_cloud 10 64 30 {Tags:["delay"],Age:-70,Particle:{type:"block",block_state:"minecraft:air"}}
+```
However, if you want to use spawn_egg to simply create an AEC's for delay, then you need to add Radius and WaitTime:
- # 1.13 - 1.20.4
- give @s bat_spawn_egg{EntityTag:{id:"minecraft:area_effect_cloud",Tags:["delay"],Duration:100,Radius:0f,WaitTime:0}}
-
- # 1.20.5+
- give @s bat_spawn_egg[entity_data={id:"minecraft:area_effect_cloud",Tags:["delay"],Duration:100,Radius:0f,WaitTime:0}]
+```mcfunction
+# 1.13 - 1.20.4
+give @s bat_spawn_egg{EntityTag:{id:"minecraft:area_effect_cloud",Tags:["delay"],Duration:100,Radius:0f,WaitTime:0}}
-> [!NOTE]
-> You can use any `spawn_egg`, but not just `bat_spawn_egg`
+# 1.20.5+
+give @s bat_spawn_egg[entity_data={id:"minecraft:area_effect_cloud",Tags:["delay"],Duration:100,Radius:0f,WaitTime:0}]
+```
- # Command block / tick function
- execute at @e[type=area_effect_cloud,tag=delay,nbt={Age:99}] run summon zombie
+| 📝 Note |
+|---------|
+|You can use any `spawn_egg`, but not just `bat_spawn_egg`|
+```mcfunction
+# Command block / tick function
+execute at @e[type=area_effect_cloud,tag=delay,nbt={Age:99}] run summon zombie
+```
This is a simple way to execute any command at a specified position once with a specified delay.
@@ -60,67 +75,78 @@ This is a simple way to execute any command at a specified position once with a
If you need to execute a command not only once, but every 5 seconds, for example, at specific location, then you can use the [marker entity](https://minecraft.wiki/w/Marker) (1.17+) for this. If you are on an earlier version use an [`area_effect_cloud`](https://minecraft.wiki/w/Lingering_Potion#Area_effect_cloud) that will not despawn or an invisible [`armor_stand`](https://minecraft.wiki/w/Armor_Stand).
- # Summon
- summon marker ~ ~ ~ {Tags:["delay"]}
-
- # Spawn egg
- ## 1.17 - 1.20.4
- give @s bat_spawn_egg{EntityTag:{id:"minecraft:marker",Tags:["delay"]}}
-
- ## 1.20.5+
- give @s bat_spawn_egg[entity_data={id:"minecraft:marker",Tags:["delay"]}]
+```mcfunction
+# Summon
+summon marker ~ ~ ~ {Tags:["delay"]}
-In addition to the marker, you need to use a scoreboard timer, which each tick will add 1 to the score marker.
+# Spawn egg
+## 1.17 - 1.20.4
+give @s bat_spawn_egg{EntityTag:{id:"minecraft:marker",Tags:["delay"]}}
- # Command blocks / tick function
- scoreboard players add @e[type=marker,tag=delay] timer 1
- execute as @e[type=marker,tag=delay,scores={delay=100..}] at @s store success score @s delay run summon zombie
+## 1.20.5+
+give @s bat_spawn_egg[entity_data={id:"minecraft:marker",Tags:["delay"]}]
+```
+
+In addition to the marker, you need to use a scoreboard timer, which each tick will add 1 to the score marker.
+```mcfunction
+# Command blocks / tick function
+scoreboard players add @e[type=marker,tag=delay] timer 1
+execute as @e[type=marker,tag=delay,scores={delay=100..}] at @s store success score @s delay run summon zombie
+```
### Scoreboard
#### Java 1.13+ and Bedrock
-For a scoreboard timer you can have a repeating commandblock somewhere that's counting up/down in a particular scoreboard objective and then use `execute if score` in the commandblock that should have the delay. You can either use individual player scores (recommended for player dependant events/delays) or "[fake player](/wiki/questions/fakeplayer)" scores (set "fake" values for player names, recommended for player independant delays).
+For a scoreboard timer you can have a repeating commandblock somewhere that's counting up/down in a particular scoreboard objective and then use `execute if score` in the commandblock that should have the delay. You can either use individual player scores (recommended for player dependent events/delays) or "[fake player](/wiki/questions/fakeplayer)" scores (set "fake" values for player names, recommended for player independent delays).
+
+```mcfunction
+# Setup
+scoreboard objectives add timer dummy
- # Setup
- scoreboard objectives add timer dummy
-
- # The repeating command_block
- scoreboard players add @a timer 1
+# The repeating command_block
+scoreboard players add @a timer 1
- # The command_block that should run for every player with a timer score of 100
- execute as @a[scores={timer=100}] run say This command has 5 seconds delay.
- scoreboard players reset @a[scores={timer=100..}] timer
+# The command_block that should run for every player with a timer score of 100
+execute as @a[scores={timer=100}] run say This command has 5 seconds delay.
+scoreboard players reset @a[scores={timer=100..}] timer
- # Alternatively for a fake player timer
- scoreboard players add $FakePlayer timer 1
- execute if score $FakePlayer timer matches 120 run say This command has 6 seconds delay.
- execute if score $FakePlayer timer matches 120.. run scoreboard players reset $FakePlayer timer
+# Alternatively for a fake player timer
+scoreboard players add $FakePlayer timer 1
+execute if score $FakePlayer timer matches 120 run say This command has 6 seconds delay.
+execute if score $FakePlayer timer matches 120.. run scoreboard players reset $FakePlayer timer
+```
Or, if you do not create additional conditions, you can immediately reset the score in one command using `store success score` (only java edition):
- # Command blocks
- execute as @a[scores={timer=101..}] store success score @s timer run say This command has 5 seconds delay.
- execute if score $FakePlayer timer matches 121.. store success score $FakePlayer timer run say This command has 6 seconds delay.
+```mcfunction
+# Command blocks
+execute as @a[scores={timer=101..}] store success score @s timer run say This command has 5 seconds delay.
+execute if score $FakePlayer timer matches 121.. store success score $FakePlayer timer run say This command has 6 seconds delay.
+```
This command will not only execute the command, it also works as a timer reset command, however this implementation may not have the exact delay in some cases where your command is executed in some conditions and not in another.
You can also make the delay more dynamic by setting a score of a fake player and comparing it to the players score:
- # Set delay
- scoreboard players set #delay timer 300
-
- # Command block / tick function
- execute as @a if score @s timer >= #delay timer store success score @s timer run say Custom delay command.
+```mcfunction
+# Set delay
+scoreboard players set #delay timer 300
+
+# Command block / tick function
+execute as @a if score @s timer >= #delay timer store success score @s timer run say Custom delay command.
+```
#### Java pre-1.13
Before 1.13 we didn't have `execute if score` so we will need to use `scoreboard players test` for that.
- # command block
- scoreboard players add FakePlayerA TimerScore 1
- scoreboard players test FakePlayerA TimerScore 60
- # Chain conditional
- scoreboard players set FakePlayerA TimerScore 0
- # Conditional repeating command
-
+```mcfunction
+# command block
+scoreboard players add FakePlayerA TimerScore 1
+scoreboard players test FakePlayerA TimerScore 60
+# Chain conditional
+scoreboard players set FakePlayerA TimerScore 0
+# Conditional repeating command
+
+```
[Here's an example setup image](http://i.imgur.com/fGyA294.png)
@@ -128,19 +154,24 @@ Before 1.13 we didn't have `execute if score` so we will need to use `scoreboard
Using functions the [schedule command](https://minecraft.wiki/Commands/schedule) can be used to make a function run in ## amount of ticks.
- schedule function [append|replace]
+```mcfunction
+schedule function [append|replace]
+```
So you can create a simple way to run your commands not every tick, but, for example, once a second:
- # function example:load
- function example:loops/10s
-
- # function example:loops/10s
- schedule function example:loops/10s 10s
- say This will run every 10 second.
+```mcfunction
+# function example:load
+function example:loops/10s
+
+# function example:loops/10s
+schedule function example:loops/10s 10s
+say This will run every 10 second.
+```
-> [!NOTE]
-> Do not run the schedule function in a tick function, without any conditions. This will overwrite the schedule every tick and the schedule function will never run.
+| 📝 Note |
+|---------|
+|Do not run the schedule function in a tick function, without any conditions. This will overwrite the schedule every tick and the schedule function will never run|
This has several limitations:
@@ -149,7 +180,7 @@ This has several limitations:
3. It requires functions and thus datapacks to work.
4. It will be executed at position Y = -64 under the world spawn.
-```
+```mcfunction
# In chat
execute as @a run schedule function example:some_function 5s
@@ -161,27 +192,32 @@ If you want to schedule a function to execute as an entity, here is a method tha
Read the current gametime and store it in the score of the selected entity and add your delay to this score. Then run the schedule function and count the gametime again and find the entities with the same score value.
- # Run shedule function (as entity)
- execute store result score @s timer run time query gametime
- scoreboard players add @s timer 150
- schedule function example:delay_function 150t append
-
- # function example:delay_function
- execute store result score #this timer run time query gametime
- execute as @e if score @s timer = #this timer run say Example Command.
+```mcfunction
+# Run shedule function (as entity)
+execute store result score @s timer run time query gametime
+scoreboard players add @s timer 150
+schedule function example:delay_function 150t append
+
+# function example:delay_function
+execute store result score #this timer run time query gametime
+execute as @e if score @s timer = #this timer run say Example Command.
+```
-> [!NOTE]
-> If you frequently run the schedule function to delay, then use `append` mode to run the schedule function so that each run does not overwrite the previous one.
+| 📝 Note |
+|---------|
+|If you frequently run the schedule function to delay, then use `append` mode to run the schedule function so that each run does not overwrite the previous one|
### Success Count
An easy trick with command blocks to make a clock run at half its speed is the following command:
- # pre-1.13 syntax
- testforblock ~ ~ ~ repeating_command_block * {SuccessCount:0}
- # 1.13+ syntax
- execute if block ~ ~ ~ repeating_command_block{SuccessCount:0}
- # 1.13+ syntax (only run one command)
- execute if block ~ ~ ~ repeating_command_block{SuccessCount:0} run
+```mcfunction
+# pre-1.13 syntax
+testforblock ~ ~ ~ repeating_command_block * {SuccessCount:0}
+# 1.13+ syntax
+execute if block ~ ~ ~ repeating_command_block{SuccessCount:0}
+# 1.13+ syntax (only run one command)
+execute if block ~ ~ ~ repeating_command_block{SuccessCount:0} run
+```
Set up [like this](http://i.imgur.com/OULTCZx.png) (unless running only one command), the command will alternate between succeeding (as it failed last time so has `SuccessCount:0`) and failing (as it succeeded last time so has `SuccessCount:1`), and the conditional repeating block coming off of it will thus activate every other tick.
@@ -195,11 +231,13 @@ The entity [`command_block_minecart`](https://minecraft.wiki/w/Minecart_with_Com
Other methods such as a falling block clock exist and can be convenient, but cause block updates, lighting updates, and requires an entity.
In this example we use an armor stand with the tag `loop`, we will place a pressure plate with an impulse command block below with the following command:
-```
+
+```mcfunction
execute as @e[tag=loop,distance=..3,type=armor_stand] at @s run tp @s ~ ~5 ~
```
-To add more commands, just add a chain one to the previus impulse.
+To add more commands, just add a chain one to the previous impulse.
-> [!IMPORTANT]
-> It is not recomended to use this method
+| ⚠️ Important |
+|--------------|
+|It is not recommended to use this method|
diff --git a/questions/blockinvert.md b/questions/blockinvert.md
index aa7758469..4a4803497 100644
--- a/questions/blockinvert.md
+++ b/questions/blockinvert.md
@@ -1,26 +1,35 @@
# Do something if a command block *wasn't* successful
-> [!NOTE]
-> in 1.13+ we can use `execute unless ...` instead
+* [Java](#java)
+* [Bedrock](#bedrock)
+
+## Java
+
+| 📝 Note |
+|---------|
+|in 1.13+ we can use `execute unless ...` instead|
(This is for command blocks only. For functions, [see here](/wiki/questions/functionconditions))
-> [!NOTE]
-> You could use a redstone torch and a comparator, but it is **not** recomended as it causes more lag than the other methods described below.
+| 📝 Note |
+|---------|
+|You could use a redstone torch and a comparator, but it is **not** recommended as it causes more lag than the other methods described below|
When a command block runs, its `SuccessCount` tag is updated. This is the value used by comparators to decide how strong a signal to output from that command block. If the command block does not succeed, its `SuccessCount` will be `0`.
We can use another command block to check whether the first block has `SuccessCount:0` after running, so that this second block will be successful when the first block fails, then run our conditionals off of this second block. The commands would look like:
- # pre 1.13
- testfor @a[r=5]
- testforblock ~ ~ ~1 command_block * {SuccessCount:0}
- say Nobody is within 5 blocks!
-
- # 1.13+
-
- execute if block ~ ~ ~1 command_block{SuccessCount:0}
- say Command didn't succed
+```mcfunction
+# pre 1.13
+testfor @a[r=5]
+testforblock ~ ~ ~1 command_block * {SuccessCount:0}
+say Nobody is within 5 blocks!
+
+# 1.13+
+
+execute if block ~ ~ ~1 command_block{SuccessCount:0}
+say Command didn't succed
+```
[Example image](http://i.imgur.com/Syq4crm.png).
@@ -28,3 +37,7 @@ The first command is whatever you want to check wasn't successful.
In the second command you must adjust `~ ~ ~1 command_block` to match the location and type of the first block. For example, it may be `~-1 ~ ~ chain_command_block`.
The third command is conditional, and is whatever you want to happen when the first command fails.
+
+## Bedrock
+
+Because we can't access the `SuccessCount` in bedrock we will need to use a comparator pointing into a block that has a wall redstone torch to invert the output. Keep in mind that redstone is not run every tick.
\ No newline at end of file
diff --git a/questions/changeofscore.md b/questions/changeofscore.md
index 2657fead7..619d6898d 100644
--- a/questions/changeofscore.md
+++ b/questions/changeofscore.md
@@ -2,7 +2,7 @@
_Both Java and Bedrock_
-If you need to detect when and if a score of a player has changed, there are two ways to go about this. This is generally most useful if you're using a scoreboard objective that changes because of something the player is doing (e.g. clicking, attacking, sneaking) or the game is doing to the player (e.g. taking damage, change of health and hunger).
+If you need to detect when and if a score of a player has changed, there are two ways to go about this. This is generally most useful if you're using a scoreboard objective that changes because of something the player is doing (e.g., clicking, attacking, sneaking) or the game is doing to the player (e.g., taking damage, change of health and hunger).
If you are changing the score yourself, it is generally advised to also do the effects to the player yourself, as you're changing the score anyways (which is currently the case in 100% of the time in Bedrock), but in some edge cases this can still be useful to do anyways.
@@ -11,11 +11,11 @@ If you are changing the score yourself, it is generally advised to also do the e
This is the more commonly used method, because in many use cases it's not important to know the total score, just that the score changed. It is generally used for [item click detection](/wiki/questions/itemclick), [player deaths](/wiki/questions/playerdeaths) in minigames and more and involves resetting the score back to 0 once it has been changed.
_Some objective types are read-only, such as Health or Hunger. Those won't work for this method._
-So lets assume you have a score that detects a players death and want to do something with that player everytime they die once.
-
- execute as @a[scores={deaths=1..}] run say I died :(
- scoreboard players set @a[scores={dead=1..}] deaths 0
-
+So lets assume you have a score that detects a player's death and want to do something with that player every time they die once.
+```mcfunction
+execute as @a[scores={deaths=1..}] run say I died :(
+scoreboard players reset @a[scores={dead=1..}] deaths
+```
You can either `set` the score back to 0, or `reset` the score, whichever one fits your system better. In most cases either one will work fine.
@@ -23,15 +23,19 @@ You can either `set` the score back to 0, or `reset` the score, whichever one fi
Sometimes you have an objective you don't want to or cannot change. In those cases it's more difficult to know when an objective changed from the last tick to the current one and involves a second, type dummy objective which we use to store the previous value to be able to compare them. Assuming you're running this as the entity you want to check, have the objective called `deaths` and the additional one called `tmp`, the commands could look like this:
- execute unless score @s tmp = @s deaths run say My score has changed in the last tick!
- scoreboard players operation @s tmp = @s deaths
+```mcfunction
+execute unless score @s tmp = @s deaths run say My score has changed in the last tick!
+scoreboard players operation @s tmp = @s deaths
+```
This also allows us to know if the scoreboard value has incremented or decreased, here is an example using health
- # Command blocks
- execute as @a unless score @s health = @s health.tmp run say My health has changed!
- execute as @a if score @s health < @s health.tmp run say My health has decreased!
- execute as @a if score @s health > @s health.tmp run say My health has increased!
- execute as @a run scoreboard players operation @s health.tmp = @s health
+```mcfunction
+# Command blocks
+execute as @a unless score @s health = @s health.tmp run say My health has changed!
+execute as @a if score @s health < @s health.tmp run say My health has decreased!
+execute as @a if score @s health > @s health.tmp run say My health has increased!
+execute as @a run scoreboard players operation @s health.tmp = @s health
+```
The first command detects if the health is not the same as the value in the last tick and the second and third command detects if the value incremented or decreased. The last command updates the `health.tpm` scoreboard to be the same as the current health.
diff --git a/questions/commandcontext.md b/questions/commandcontext.md
index 7d7c97e8a..e9f0cdba8 100644
--- a/questions/commandcontext.md
+++ b/questions/commandcontext.md
@@ -18,7 +18,7 @@ See [the Minecraft wiki on the execute command](https://minecraft.wiki/wiki/Comm
When a command is run, it will get some default values depending on how it is run.
- A command **run from chat** is executed `as` and `at` (so positioned and rotated as) the player who runs it.
-- A command **run from a commandblock** is executed with the position set to the center of the commandblock in all three axis. It is always rotated `0 0`, so facing straight forward in south (positive z) direction. _There is no executing entity_.
+- A command **run from a commandblock** is executed with the position set to the center of the commandblock in all three axes. It is always rotated `0 0`, so facing straight forward in south (positive z) direction. _There is no executing entity_.
- A command **run from a function** can have various values, as functions themselves keep context. See below.
- A scheduled command does not keep context
- Tick and load functions run at world spawn
@@ -33,4 +33,6 @@ So a function run in chat will have the same defaults as any other command run f
A command run from either the `#minecraft:load` or `#minecraft:tick` [function tags](https://minecraft.wiki/wiki/Tag#Function_tags) will run positioned at world spawn (at the lowest end of the block, unlike the commandblock), rotated `0 0` and without an executing entity.
-This allows a lot of [optimization](/wiki/optimising) since you can use a selector once, running the function as that entity and then refer to that entity as `@s` for the rest of the function. It also allows for [entityless raycasting](/wiki/questions/raycast#wiki_without_an_entity) as the position and rotation is preserved between function calls.
+This allows a lot of [optimization](/wiki/optimising) since you can use a selector once, running the function as that entity and then refer to that entity as `@s` for the rest of the function. It also allows for [entityless raycasting](/wiki/questions/raycast#wiki_without_an_entity) as the position and rotation are preserved between function calls.
+
+You can find a more in depth explanation on [The Minecraft Wiki](https://minecraft.wiki/w/Command_context)
\ No newline at end of file
diff --git a/questions/compasstoplayer.md b/questions/compasstoplayer.md
index 1c491c68c..d396485b7 100644
--- a/questions/compasstoplayer.md
+++ b/questions/compasstoplayer.md
@@ -1,15 +1,19 @@
-# Make compass point towards player
+# Make compass point towards player/location
+
+## Java and Bedrock
Since the compass will always point to the worldspawnpoint, your only option is to move the worldspawn to the player you want to point the compass towards. **This means it can only point to one player at a time and the pointing is global, meaning everyone sees the same compass pointing.**
**Java & Bedrock syntax:**
- execute at @p[] run setworldspawn ~ ~ ~
+```mcfunction
+execute at @p[] run setworldspawn ~ ~ ~
+```
-> [!NOTE]
-> If a player dies, they will respawn at the world spawn (unless they have an individual spawn set), which this method is moving around.
->
-> To avoid this issue, you need to detect when the players respawns to then teleport them to the intended respawn point. In Java edition you can use the scoreboard criteria `custom:time_since_last_death` but in bedrock you will need [a more complex way](https://wiki.bedrock.dev/commands/on-player-death).
+| 📝 Note |
+|---------|
+|If a player dies, they will respawn at the world spawn (unless they have an individual spawn set), which this method is moving around|
+|To avoid this issue, you need to detect when the players respawns to then teleport them to the intended respawn point. In Java edition you can use the scoreboard criteria `custom:time_since_last_death` but in bedrock you will need [a more complex way](https://wiki.bedrock.dev/commands/on-player-death)|
## 1.16+ (Java only)
@@ -17,24 +21,26 @@ With 1.16 a new functionality has been introduced into the game: a Lodestone Com
The give command for such a compass which doesn't need a lodestone to work looks like this:
- /give @s compass{LodestoneTracked:0b,LodestonePos:{X:-460,Y:64,Z:-701},LodestoneDimension:"minecraft:overworld"}
+```mcfunction
+/give @s compass{LodestoneTracked:0b,LodestonePos:{X:-460,Y:64,Z:-701},LodestoneDimension:"minecraft:overworld"}
+```
Now, using data merge we can modify those numbers dynamically. For example, lets say you want to drop the compass to make it point to the second-nearest player, assuming the nearest player is you. The commands for something like that could look like this (using the [custom item tag](/wiki/questions/customitemtag) `playertracker:1b` to identify such a compass):
-tick.mcfunction
-
- execute as @e[type=item,nbt={Item:{tag:{playertracker:1b}}}] at @s run function namespace:update_compass
-
-update_compass.mcfunction
-
- tag @p add closest
- tag @p[tag=!closest] add target
- data modify entity @s Item.tag.LodestonePos.X set from entity @p[tag=target] Pos[0]
- data modify entity @s Item.tag.LodestonePos.Y set from entity @p[tag=target] Pos[1]
- data modify entity @s Item.tag.LodestonePos.Z set from entity @p[tag=target] Pos[2]
- tag @a remove closest
- tag @a remove target
- data modify entity @s PickupDelay set value 0s
+```mcfunction
+# Command block / tick function
+execute as @e[type=item,nbt={Item:{tag:{playertracker:1b}}}] at @s run function namespace:update_compass
+
+# function update_compass
+tag @p add closest
+tag @p[tag=!closest] add target
+data modify entity @s Item.tag.LodestonePos.X set from entity @p[tag=target] Pos[0]
+data modify entity @s Item.tag.LodestonePos.Y set from entity @p[tag=target] Pos[1]
+data modify entity @s Item.tag.LodestonePos.Z set from entity @p[tag=target] Pos[2]
+tag @a remove closest
+tag @a remove target
+data modify entity @s PickupDelay set value 0s
+```
(this assumes that the original given compass has the relevant tags (`LodestoneDimension`, `LodestoneTracked`, `LodestonePos`) already set to initial/correct values, as well as the aforementioned custom tag.)
diff --git a/questions/customcrafting.md b/questions/customcrafting.md
index 11571a9a2..25dcd5242 100644
--- a/questions/customcrafting.md
+++ b/questions/customcrafting.md
@@ -1,10 +1,18 @@
# Do custom crafting (with NBT)
+* [Java](#Java)
+* [Bedorck](#bedrock-edition-addon)
+
+## Java
The vanilla crafting system does not support NBT data. Although 1.20.5 added the ability to create recipes with custom crafting data, it still does not support custom data for ingredients. This article provides several ways to create custom crafts that support custom items for both the result and the ingredients.
+| 📝 Note |
+|--------------|
+|In 1.20.5 this became partially accessible|
+
----
-## Floor Crafting
+### Floor Crafting
The easiest way to create a custom craft is to use floor crafting. You can create crafting recipes with any ingredients and for each recipe you only need 1 command block, which makes it easy to create many recipes without creating an excessive load on the server.
@@ -81,7 +89,7 @@ Since version 1.20.5 NBT tags have been replaced with [components](https://minec
----
-## Custom Dropper Crafting
+### Custom Dropper Crafting
Another popular way to create custom crafts that support NBT data is to use custom dropper crafting. This method uses a dropper / dispenser interface to simulate the crafting grid as the crafting\_table. This method is more difficult to implement, but looks much better than floor crafting.
@@ -97,6 +105,9 @@ This crafting method consists of two parts: the controller and the recipes.
The controller is a command block that detects the placement of a spawn_egg to install a dropper block, as well as to remove the support entity when the block is destroyed by the player and return a spawn_egg to the player.
+
+ See commands
+
# Command blocks (controller) for 1.19.4 - 1.20.4
execute at @e[type=item_display,tag=custom_crafting,tag=placing] run setblock ~ ~ ~ dropper[facing=up]{CustomName:'"Custom Crafting Table"'}
tag @e[type=item_display,tag=custom_crafting,tag=placing] remove placing
@@ -109,6 +120,8 @@ The controller is a command block that detects the placement of a spawn_egg to i
execute as @e[type=item_display,tag=custom_crafting] at @s unless block ~ ~ ~ dropper[facing=up] run data modify entity @e[type=item,distance=..1,nbt={Item:{id:"minecraft:dropper"}},limit=1] Item set value {id:"minecraft:bat_spawn_egg",count:1,components:{"item_name":'"Custom Crafting Table"',"minecraft:entity_data":{id:"minecraft:item_display",Tags:["custom_crafting","placing"],Rotation:[0f,0f],brightness:{sky:10,block:10},transformation:{left_rotation:[0f,0f,0f,1f],right_rotation:[0f,0f,0f,1f],translation:[0f,0.5f,0f],scale:[1.01f,1.01f,1.01f]},item:{id:"minecraft:crafting_table",count:1}}}}
execute as @e[type=item_display,tag=custom_crafting] at @s unless block ~ ~ ~ dropper[facing=up] run kill @s
+
+
Recipes can be made as separate command blocks. Each recipe is a separate command block that checks the block data in the Items tag, and if the data matches, then replace the Items tag with your item as the crafting result.
**Hint:** If you find it difficult to create a command to check block data, then put your recipe in a dropper / dispenser. Exit the block interface and press `F3 + I` to copy the block data. You will receive a /setblock command with the full block data. This command has all of the blocks data, including data that is irrelevant or even hindering our ability to properly detect the relevant items. Thus you should not use the NBT data (`{}`) as-is, but remove any and all unnecessary NBT data. This involves removing all but the defining attributes of the item: `id`, `count`, `Slot` and potentially the custom data you used to mark your custom items.
@@ -119,6 +132,9 @@ Below is a schematic representation of the command to check the recipe:
Now you can create a ready-made command for the recipe. Below is an example of crafting without checking custom NBT tags for compactness, but you can add any NBT data for verification:
+
+ See commands
+
# Example recipe
[E][ ][E]
[R][D][R]
@@ -134,15 +150,17 @@ Now you can create a ready-made command for the recipe. Below is an example of c
# Command block (recipe) for 1.20.5+
execute at @e[type=item_display,tag=custom_crafting] if items block ~ ~ ~ container.0 emerald[custom_data~{some:true}] unless items block ~ ~ ~ container.1 * if items block ~ ~ ~ container.2 emerald[custom_data~{some:true}] if items block ~ ~ ~ container.3 redstone[custom_data~{data:true}] if items block ~ ~ ~ container.4 diamond[custom_data~{custom:true}] if items block ~ ~ ~ container.5 redstone[custom_data~{data:true}] if items block ~ ~ ~ container.6 redstone[custom_data~{data:true}] if items block ~ ~ ~ container.7 redstone[custom_data~{data:true}] if items block ~ ~ ~ container.8 redstone[custom_data~{data:true}] run data modify block ~ ~ ~ Items set value [{Slot:4b,id:"minecraft:ender_eye",count:1b,components:{"minecraft:custom_data":{custom_result:true},"minecraft:item_name":'"Some Custom Result"'}}]
+
+
**Note:** Empty slots that do not contain a recipe item will be ignored, so if the player leaves any items in these slots, then these items will be deleted. To avoid this, you can add, in addition to checking the block data, to check that there are no items in the empty slots using the `unless data block` subcommand. Each slot requires a separate subcommand:
execute at @e[type=item_display,tag=custom_crafting] if block ~ ~ ~ dropper{Items:[]} unless data block ~ ~ ~ Items[{Slot:}] unless data block ~ ~ ~ Items[{Slot:}] run data modify ...
----
-## Custom Knowledge Book Crafting
+### Custom Knowledge Book Crafting
-### Before 1.20
+#### Before 1.20
Before version 1.20 you could create custom crafts using the Knowledge Book method, however **this method does not support creating custom crafts with NBT data for ingredients, only for the result**.
@@ -160,6 +178,9 @@ And when creating all recipe advancements, you use recipe root advancement as th
Below is an example of how to implement this approach:
+
+ See datapck
+
# recipe example:some_custom_result (1.15-1.20.4)
{
"type": "minecraft:crafting_shaped",
@@ -249,9 +270,11 @@ Below is an example of how to implement this approach:
recipe take @s example:more_custom_result
...
+
+
The obvious disadvantages of this method are the inability to create a craft with custom ingredients, and if you give yourself all the recipes, it will give you all the custom items, but you still won’t be able to have your custom crafts in the recipe book.
-### After 1.20
+#### After 1.20
Starting with version 1.20, a new advancement trigger was added - `recipe_crafted`. This one triggers when you have crafted the specified craft, but not just unlocked it. Therefore you don't need to take recipes and you can have your crafts in the craft book, although these crafts will appear as knowledge\_book.
@@ -259,6 +282,8 @@ You can now use this advancement trigger to check the NBT data of the ingredient
Below is an example for creating an advancement for a custom craft, which must have ingredients with NBT data to get the craft result. Only the changes in this version are shown here, the rest of the code is unchanged:
+
+ See datapack
# advancement example:recipe/some_custom_result
{
"parent": "example:recipe/root",
@@ -332,14 +357,19 @@ Below is an example for creating an advancement for a custom craft, which must h
advancement revoke @s from example:recipe/root
clear @s minecraft:knowledge_book
+
+
**Important!** The player can still use regular items in crafting, but then the advancement will not work and the player will only craft the knowledge\_book. To avoid this, you need to create a more complex crafting system.
-### 1.20.5 and above
+#### 1.20.5 and above
Version 1.20.5 also added the ability to create crafts with custom data, but only for the craft result - NOT for ingredients. Therefore, if you want to use custom items in crafting, then in this version it will be the same as described for the previous version.
If you only need a custom item as a result of crafting, then now you can use only one recipe file and you do not need to use advancements and functions:
+
+ See datapck
+
# recipe example:some_custom_result
{
"type": "minecraft:crafting_shaped",
@@ -368,6 +398,8 @@ If you only need a custom item as a result of crafting, then now you can use onl
}
}
+
+
**Note:** If you use a custom tag for an item like `custom:1`, then the recipe will give you an item with the tag `custom:1b` due to the conversion of JSON to NBT format.
## Bedrock edition addon
@@ -393,6 +425,9 @@ You can also make [custom crafting tables](https://wiki.bedrock.dev/blocks/block
Here is an example of a shaped recipe from the bedrock wiki:
+
+ See example
+
{
"format_version": "1.17.41",
"minecraft:recipe_shaped": {
@@ -425,6 +460,7 @@ Here is an example of a shaped recipe from the bedrock wiki:
}
}
+
A quick explanation:
* `format_version` is the minecraft version, it is recomended to use the last relase.
diff --git a/questions/customitemtag.md b/questions/customitemtag.md
index 53fc41f24..28bacf7d2 100644
--- a/questions/customitemtag.md
+++ b/questions/customitemtag.md
@@ -1,7 +1,7 @@
# Give an item a custom tag to identify it by
-* [Java](#Java)
-* [Bedrock](#Bedrock)
+* [Java](#java)
+* [Bedrock](#bedrock)
## Java
@@ -73,7 +73,10 @@ When using a loot table since version 1.20.5, you need to use the `minecraft:set
Below are examples of loot tables for different versions. **For version 1.20.5+, two ways to set custom data are shown, but you should only use one.**
-```
+
+ See example
+
+```json
# 1.20.5 and above
{
"pools": [
@@ -122,6 +125,7 @@ Below are examples of loot tables for different versions. **For version 1.20.5+,
]
}
```
+
The new `set_custom_data` loot function is exactly the same as the `set_nbt` function, but sets data only to the `custom_data` component. But using `set_components` for set `custom_data` is different because it cannot be represented as a string with NBT data, but it must be a JSON object and follow [JSON formatting](https://minecraft.wiki/w/JSON). Thus, any text must be escaped, and numeric values must be specified without a variable type.
@@ -160,7 +164,7 @@ For example, the crafting recipe below (1.20.5+), which will give an item with t
```
## Bedrock
-In bedrock we will need use a workarround, because we can't use custom tags.
+In bedrock we will need use a workaround, because we can't use custom tags.
### Item data
To get an item with specific data, you can use a number between `2,147,483,647` and `-2,147,483,648`.
@@ -175,7 +179,7 @@ This stick will have a data of 5, that we can detect with the `hasitem` argument
/effect @a[hasitem={item=stick,data=5}] speed
### Name with color codes
-As proposed by [u/V1beRater](https://www.reddit.com/user/V1beRater/) in [this reddit post](https://www.reddit.com/r/MinecraftCommands/comments/xzbj5t/comment/irlhawd/). We can use color codes to change the name of an item of an apple to, for example, `§r§fApple`, wich is indistinguishable from a normal apple name, but you can detect if it's dropped with this command:
+As proposed by [u/V1beRater](https://www.reddit.com/user/V1beRater/) in [this Reddit post](https://www.reddit.com/r/MinecraftCommands/comments/xzbj5t/comment/irlhawd/). We can use color codes to change the name of an item of an apple to, for example, `§r§fApple`, which is indistinguishable from a normal apple name, but you can detect if it's dropped with this command:
kill @e[type=item, name="§r§fApple"]
diff --git a/questions/detectitem.md b/questions/detectitem.md
index 67e6ace7a..60bfc8a60 100644
--- a/questions/detectitem.md
+++ b/questions/detectitem.md
@@ -1,5 +1,8 @@
# Detect a specific item
+* [Java](#java)
+* [Bedrock](#bedrock)
+
## Java
Detecting an item by some property is a relatively easy task if you know your way around NBT. If you have control over how and when the item is given, [consider using a special item tag to detect it](/wiki/questions/customitemtag) (that post also contains useful information about how to nest the NBT, so read it before reading on).
@@ -59,7 +62,10 @@ The correct check in the `SelectedItem` slot would look something like this:
### Target selector
-In 1.20.5 you can check an item using the NBT data check in the [target selector](https://minecraft.wiki/w/Target_selectors#Selecting_targets_by_nbt), however now can use [`execute if items`](https://minecraft.wiki/w/Commands/execute#(if|unless)_items) to flexibly detect items and can now use the [predicate](https://minecraft.wiki/w/Predicate) not only for equipment, but also for any slot and now even without using a datapack.
+In 1.20.5 you can check an item using the NBT data check in the [target selector](https://minecraft.wiki/w/Target_selectors#Selecting_targets_by_nbt), however now can use [`execute if items`](https://minecraft.wiki/w/Commands/execute#(if%7Cunless)_items) to flexibly detect items and can now use the [predicate](https://minecraft.wiki/w/Predicate) not only for equipment, but also for any slot and now even without using a datapack.
+
+
+ See commands
# Any slot
@a[nbt={Inventory:[{id:"minecraft:stick",components:{"minecraft:custom_data":{awesome_stick:true}}}]}]
@@ -73,11 +79,13 @@ In 1.20.5 you can check an item using the NBT data check in the [target selector
@a[nbt={SelectedItem:{id:"minecraft:stick",components:{"minecraft:custom_data":{awesome_stick:true}}}}]
@a[nbt={SelectedItem:{id:"minecraft:stick",components:{"minecraft:custom_name":'"Awesome Stick"'}}}]
+
+
**Note:** The component `“minecraft:custom_data”` is escaped with parentheses because it contains the special character colon. And although you can omit `minecraft:` in /give and other commands, when checking NBT data in the target selector you should always specify the full format, which also includes the [namespace](https://minecraft.wiki/w/Resource_location#Namespaces).
### execute if items
-The syntax looks like this [\[wiki\]](https://minecraft.wiki/w/Commands/execute#(if|unless)_items):
+The syntax looks like this [\[wiki\]](https://minecraft.wiki/w/Commands/execute#(if%7Cunless)_items):
if/unless items block
if/unless items entity
@@ -146,7 +154,10 @@ When using predicates in a datapack, you can now check not only equipment slots,
This is an example of updating a predicate to detect an item with a custom tag:
-```
+
+ See predicate
+
+```json
{
"condition": "minecraft:entity_properties",
"entity": "this",
@@ -165,6 +176,7 @@ This is an example of updating a predicate to detect an item with a custom tag:
}
}
```
+
**Note:** If in the predicate you do not check the item ID, but only the NBT data of the item in the mainhand, then always also check the count item in this slot because of a bug [\[MC-229882\]](https://bugs.mojang.com/browse/MC-229882).
@@ -213,10 +225,11 @@ The items NBT is stored inside the `Item` NBT tag, so we can test for an item th
When using a datapack, you can check items in equipment slots. To do this, create a file `data//predicates/.json` in your datapack. For example, the predicate `data/example/predicates/has/awesome_stick.json` would have the resourcename `example:has/awesome_stick`. And you can check the predicate in any target selector, `execute if predicate `, as well as in loot and advancements tables.
Here is an example of a predicate and its use in a target selector:
-```
-execute as @a[predicate=example:has/awesome_stick] run say Example Command.
-# predicate example:has/awesome_stick
+
+ See predicate
+
+```json
{
"condition": "minecraft:entity_properties",
"entity": "this",
@@ -236,6 +249,8 @@ execute as @a[predicate=example:has/awesome_stick] run say Example Command.
}
```
+
+
**Note:** If in the predicate you do not check the item ID, but only the NBT data of the item in the mainhand, then always also check the count item in this slot because of a bug [\[MC-229882\]](https://bugs.mojang.com/browse/MC-229882).
## Bedrock
@@ -252,7 +267,7 @@ In the 1.18.20 beta they added the [`hasitem`](https://minecraft.wiki/wiki/Targe
A player with 5 or more apples in their inventory
- @a[hasitem={item:apple,quantity=5..}]
+ @a[hasitem={item=apple,quantity=5..}]
A player with an iron pickaxe in their mainhand
@@ -277,8 +292,9 @@ effect @a[hasitem={item=stick,data=5}] speed
#### before 1.18.20
-> [!NOTE]
-> This information is outaded and it is not useful for the current version of the game.
+| 📝 Note |
+|---------|
+|This information is outaded and it is not useful for the current version of the game|
Using the `clear` command with a max count of 0 will return a successful result if the item is in the players inventory, without actually removing the item, which can be picked up by either a conditional commandblock or a comparator. **You can only do this for 1 player at a time though, as if you use `@a` you have no way of knowing which one of the players has the item in their inventory.**
@@ -301,7 +317,8 @@ Detecting a specific item on the ground involves using its name.
**This method is language specific and won't work if your hosting player is not playing in english!** A way to circumvent that problem would be to either rename the item if possible, or to change every language file the game has to make the name of the item the same across all languages, which will require you to include a resourcepack.
-> [!NOTE]
-> You can use a [special item tag](/wiki/questions/customitemtag#Bedrock) to differentiate it from other `Dirt` items, this method consists of changing the name with color codes, which can not be differentiate from the normal name.
+| 📝 Note |
+|---------|
+|You can use a [special item tag](/wiki/questions/customitemtag#Bedrock) to differentiate it from other `Dirt` items, this method consists of changing the name with color codes, which can not be differentiate from the normal name|
kill @e[type=item, name="§r§Dirt"]
diff --git a/questions/escaping.md b/questions/escaping.md
new file mode 100644
index 000000000..57bfa075f
--- /dev/null
+++ b/questions/escaping.md
@@ -0,0 +1,85 @@
+# What is escaping?
+## Introduction to Escaping
+Escaping is the process of marking special characters in a string to be interpreted literally rather than as part of a special syntax. Commands and JSON rely on precise syntax where unescaped characters can break the structure.
+
+Escaping prevents errors and ensures that commands or JSON structures function as intended. It is essential for handling characters like quotes (`"`) or backslashes (`\`) that are part of the syntax.
+
+Using JSON text components required escaping quotes with a backslash (`\`):
+
+ /tellraw @a "I said \"Hi\" "
+
+If the backslash (`\`) is removed, the quotes would be misinterpreted as the end of the string, causing a syntax error. Escaping ensures special characters like quotes or backslashes are treated as part of the message rather than command syntax.
+
+## Combining Quotes to Avoid Escaping
+When writing NBT, both types of quotes can be combined to avoid the need to escape (this is not valid for JSON): `'I said "Hi"'` = `I said "Hi"`
+
+## Escaping backslashes
+Note that this means a single backslash \ cannot be used on its own as it will attempt to escape the succeeding character, and therefore will need to be escaped itself
+
+## Nested Strings
+Escaping becomes more complex when dealing with nested strings, where one string contains another string. In such cases, you must escape both the inner and outer layers of quotes to ensure the entire structure is parsed correctly.
+
+ give @p command_block[block_entity_data={id:"command_block",Command:"setblock ~ ~1 ~ command_block{Command:\"tellraw @a \\\\"Hi\\\\"\"}"}] 1
+
+The Command field is enclosed in quotes (Command:"..."), so the inner quotes within this string must be escaped.
+
+Inside the Command, the tellraw command also contains a string (tellraw @a "Hi"). To ensure "Hi" is treated literally, the quotes around it are escaped with a backslash (\").
+
+Since this entire tellraw string is itself nested within another string, the escape characters (\") also need escaping. This is done by adding another layer of backslashes (\\\").
+
+## Escaping in JSON Files
+Escaping is also required in JSON files, such as for resource packs, advancements, or custom loot tables:
+
+
+ See example
+
+```json
+{
+ "type": "minecraft:block",
+ "pools": [
+ {
+ "rolls": 1,
+ "entries": [
+ {
+ "type": "minecraft:item",
+ "name": "minecraft:diamond",
+ "functions": [
+ {
+ "function": "minecraft:set_name",
+ "name": {
+ "text": "The \"Shiny\" Diamond",
+ }
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
+```
+
+
+
+The "text" field contains The "Shiny" Diamond. The inner quotes around Shiny are escaped as \" to be treated as part of the string. Without escaping, the parser would misinterpret the quotes and throw an error.
+
+## Common errors
+
+Unescaped quotes:
+
+ "text": "This is a "broken" string"
+
+The quotes must be escaped.
+
+ "text": "This is a \"broken\" string"
+
+Mismatched Quotes:
+
+ /tellraw @a "Hi\"
+
+This quote must not be escaped as it defines the end of the string. The backslash must be removed to be interpreted correctly.
+
+Not nesting strings:
+
+ give @p command_block[block_entity_data={id:"command_block",Command:"setblock ~ ~1 ~ command_block{Command:\"tellraw @a \"Hi\"\"}"}] 1
+
+The string must be [nested](#nested-strings)
\ No newline at end of file
diff --git a/questions/fakeplayer.md b/questions/fakeplayer.md
index e3a6b0991..d5ed5f475 100644
--- a/questions/fakeplayer.md
+++ b/questions/fakeplayer.md
@@ -1,22 +1,24 @@
# What is a fake player
-When people talk about "using a fake player" on the scoreboard, they're talking about just writing down a name of a fictional playername instead of using a selector. This has the advantage that it is very fast and convenient to store and use scoreboard values.
+When people talk about "using a fake player" on the scoreboard, they're talking about just writing down a name of a fictional player name instead of using a selector. This has the advantage that it is very fast and convenient to store and use scoreboard values.
- scoreboard players set total points 100
- scoreboard players set 2 constant 2
+```mcfunction
+scoreboard players set total points 100
+scoreboard players set 2 constant 2
+```
-It's generally used for storing constants (e.g. when you need to divide a number by 20, you need to store that somewhere), global variables (e.g. for settings in a datapack or map), or temporary variables, but can be used whenever it seems helpful.
+It's generally used for storing constants (e.g., when you need to divide a number by 20, you need to store that somewhere), global variables (e.g., for settings in a datapack or map), or temporary variables, but can be used whenever it seems helpful.
They can be used like any other selector, but only make sense when dealing with scoreboards, as those don't require the selected player to be online (which is impossible with a fake player). It is highly favored over storing values on a persistent entity, as for that entity you need an `@e` selector which is significantly more performance hungry than using a fake player. Additionally a single objective can hold an near infinite number of fake player scores, while only one score per real entity can be stored.
## Special characters
-It is recommended to use special characters inside the fake player names to prevent conflicts with real players (see [things to look out for](#things_to_look_out_for)). While you cannot use spaces, you can use a lot more characters that normally wouldn't be possible to be used in normal playernames like `.#$%/*!`. The three most common ones are
+It is recommended to use special characters inside the fake player names to prevent conflicts with real players (see [things to look out for](#things-to-look-out-for)). While you cannot use spaces, you can use a lot more characters that normally wouldn't be possible to be used in normal player names like `.#$%/*!`. The three most common ones are
-- `.` generally used to create a sort of namespace (e.g. `homes.x`, `homes.y`)
-- `$` tends to be used at the start of the fake name. This likely stems from other programming languages where this character symbolises a variable. Not to be confused with macros.
+- `.` generally used to create a sort of namespace (e.g., `homes.x`, `homes.y`)
+- `$` tends to be used at the start of the fake name. This likely stems from other programming languages where this character symbolizes a variable. Not to be confused with macros.
- `#` also used at the start, as it has a **special feature**: If it's the first character in the name, it is not displayed on the sidebar when the objective is displayed there.
## Things to look out for
-When you use this method, if you're using something that could reasonably be an actual player name (like [`Max`](https://namemc.com/profile/Max.1)), and that player happens to be online at that time, you might run into conflicts. As such it is recommended to use those special characters to make sure no conflicts are possible or use seperate scoreboard objectives for fake player scores and real player scores.
+When you use this method, if you're using something that could reasonably be an actual player name (like [`Max`](https://namemc.com/profile/Max.1)), and that player happens to be online at that time, you might run into conflicts. As such it is recommended to use those special characters to make sure no conflicts are possible or use separate scoreboard objectives for fake player scores and real player scores.
diff --git a/questions/findsamescoreentity.md b/questions/findsamescoreentity.md
index 171a64e9b..c18526241 100644
--- a/questions/findsamescoreentity.md
+++ b/questions/findsamescoreentity.md
@@ -4,15 +4,18 @@ Related: [Check if a score is equal to, greater than, or less than another score
## Java 1.13+ and Bedrock
-> [!NOTE]
-> In bedrock edition use `c=` instead of `limit=`.
-> The method that involves using predicates can **not** be replicated in bedrock
+| 📝 Note |
+|---------|
+|In bedrock edition use `c=` instead of `limit=`|
+|The method that involves using predicates can **not** be replicated in bedrock|
### Method 1: Compare directly
For this method to work, we need to make sure that the entity that we want to compare to has to be unique in some way, so it can be found and is the only possible entity to result from its target selector. In this case we assume that it has been tagged with the `compare` tag and is the only entity to have that. Furthermore, the objective we're comparing is called `points`.
- execute as @a if score @s points = @e[tag=compare,limit=1] points run say I have the same points
+```mcfunction
+execute as @a if score @s points = @e[tag=compare,limit=1] points run say I have the same points
+```
This method works by changing the executor to all entities that need to be checked (in this case all players, `@a`) and then using the `execute if score` subcommand to check every executors score against the entities score.
@@ -20,46 +23,57 @@ This method works by changing the executor to all entities that need to be check
This method has the advantage over the first one that it only need to evaluate the selector for the special entity once, but it has the disadvantage that it needs 2 commands. ([what is a fake player?](/wiki/questions/fakeplayer))
- scoreboard players operation #fakeplayer points = @e[tag=compare,limit=1] points
- execute as @a if score @s points = #fakeplayer points run I have the same points
+```
+scoreboard players operation #fakeplayer points = @e[tag=compare,limit=1] points
+execute as @a if score @s points = #fakeplayer points run I have the same points
+```
When using a datapack, you can use this method for your [Scoreboard ID system](/wiki/questions/linkentity).
One command copies the `ID` score from the selected player to [fake player](/wiki/questions/fakeplayer) `#this ID` and the second adds the `this` tag to the selected entity, so that in the following commands you can simply select all entities except `this` entity. And after that you can easily select any entity that has the same `ID` score in any target selector. At the end of the function you need to remove `this` tag.
Below is an example of a function and predicate that selects an entity with the same `ID` score as the selected player:
- # funtion example:some_function (run as player)
- scoreboard players operation #this ID = @s ID
- tag @s add this
- execute as @e[predicate=example:this_id,tag=!this] run say Some ID!
- tellraw @s ["ID "{"selector":"@s"}," = ",{"selector":"@e[predicate=example:this_id,tag=!this]"}]
- tag @s remove this
-
- # predicate example:this_id
- {
- "condition": "minecraft:entity_scores",
- "entity": "this",
- "scores": {
- "ID": {
- "min": {
- "type": "minecraft:score",
- "target": {
- "type": "minecraft:fixed",
- "name": "#this"
- },
- "score": "ID"
+
+ See example
+
+```mcfunction
+# funtion example:some_function (run as player)
+scoreboard players operation #this ID = @s ID
+tag @s add this
+execute as @e[predicate=example:this_id,tag=!this] run say Some ID!
+tellraw @s ["ID ",{"selector":"@s"}," = ",{"selector":"@e[predicate=example:this_id,tag=!this]"}]
+tag @s remove this
+```
+
+```json
+# predicate example:this_id
+{
+ "condition": "minecraft:entity_scores",
+ "entity": "this",
+ "scores": {
+ "ID": {
+ "min": {
+ "type": "minecraft:score",
+ "target": {
+ "type": "minecraft:fixed",
+ "name": "#this"
},
- "max": {
- "type": "minecraft:score",
- "target": {
- "type": "minecraft:fixed",
- "name": "#this"
- },
- "score": "ID"
- }
+ "score": "ID"
+ },
+ "max": {
+ "type": "minecraft:score",
+ "target": {
+ "type": "minecraft:fixed",
+ "name": "#this"
+ },
+ "score": "ID"
}
}
}
+}
+```
+
+
**Note:** In addition, using predicate for the score comparison is preferable based on [performance comparisons](https://www.reddit.com/r/MinecraftCommands/comments/1ceck9n/comment/l1u6z2a) by [u/sanscadre](https://www.reddit.com/u/sanscadre).
@@ -67,23 +81,29 @@ Below is an example of a function and predicate that selects an entity with the
In this method we change the execution _location_ to be the player(s) and the execution _entity_ to be the entities to be compared to. That way `@p` is all the players respectively and `@s` is the entity to compare to. We can then get the player back into the execution chain using `@p`.
- execute at @a as @e if score @s id = @p id run ...
+```mcfunction
+execute at @a as @e if score @s id = @p id run ...
+```
## Java Pre-1.12
-> [!NOTE]
-> This method also works in bedrock before new execute.
-In bedrock this whole endeavour requires a few more commands, as execute doesn't have any subcommands like that and `/scoreboard players test` only allows for hardcoded ranges. Instead the way to go here is to remove the score from all the entities that need to be checked and then checking whether their score is 0.
+| 📝 Note |
+|---------|
+|This method also works in bedrock before new execute|
+
+In bedrock this whole endeavor requires a few more commands, as execute doesn't have any subcommands like that and `/scoreboard players test` only allows for hardcoded ranges. Instead the way to go here is to remove the score from all the entities that need to be checked and then checking whether their score is 0.
Again, we're assuming that the scoreboard objective you want to compare is called `points`, that we want to find any player with the same score, and that the entity to compare to is the only entity tagged with `compare`.
While we could just do the math operations on the original scores, we need to make sure to reset those afterwards if we want to keep the original scores around for one reason or another, so we're going to use a temporary scoreboard objective that we store the value in and can modify it without affecting the original score. This temporary objective is assumed to be called `pointsTmp`.
- # first we copy the score to the new objective
- execute @a ~~~ scoreboard players operation @s pointsTmp = @s points
-
- # next we deduct the score of the special entity from everyones copy
- execute @a ~~~ scoreboard players operation @s pointsTmp -= @e[tag=compare,c=1] points
-
- # now we know that anyone with a copied score of 0 has the same score as the entity
- execute @a[scores={pointsTmp=0}] ~~~ say I have the same score as the entity
+```mcfunction
+# first we copy the score to the new objective
+execute @a ~~~ scoreboard players operation @s pointsTmp = @s points
+
+# next we deduct the score of the special entity from everyones copy
+execute @a ~~~ scoreboard players operation @s pointsTmp -= @e[tag=compare,c=1] points
+
+# now we know that anyone with a copied score of 0 has the same score as the entity
+execute @a[scores={pointsTmp=0}] ~~~ say I have the same score as the entity
+```
\ No newline at end of file
diff --git a/questions/functionconditions.md b/questions/functionconditions.md
index 4af1f06eb..70fcbdeb8 100644
--- a/questions/functionconditions.md
+++ b/questions/functionconditions.md
@@ -8,11 +8,13 @@ For example, you want to execute a command when `@a[tag=TeamChange]` finds somet
Easiest way to do this is by prefixing the command with an `execute if entity`:
- execute if entity @a[tag=TeamChange,limit=1] run say test
+```mcfunction
+execute if entity @a[tag=TeamChange,limit=1] run say test
- # another example
- execute if entity @a[tag=TeamChange,limit=1] run function code:team_change
- execute unless entity @a[tag=!Ready,limit=1] run function code:ready
+# another example
+execute if entity @a[tag=TeamChange,limit=1] run function code:team_change
+execute unless entity @a[tag=!Ready,limit=1] run function code:ready
+```
Notice the `limit=1` in the above command, this is purely for performance reasons so the game stops after the first matching entity it found. [If you want to check whether there are an exact amount of entities found with a selector, click here](/wiki/questions/numplayers).
@@ -22,15 +24,19 @@ For this you will need to use `/execute store`.
First, set up a dummy scoreboard objective:
- scoreboard objectives add success_score dummy
+```mcfunction
+scoreboard objectives add success_score dummy
+```
-We're going to use a [fake player](/wiki/questions/fakeplayer) (because it's about checking a block, independently of an entity, it's recomended to use it) to store the result. This can of course be substituted for the executing entity or a different entity as well.
+We're going to use a [fake player](/wiki/questions/fakeplayer) (because it's about checking a block, independently of an entity, it's recommended to use it) to store the result. This can of course be substituted for the executing entity or a different entity as well.
Then, whenever you want to perform a conditional command:
- execute store success #success success_score if block 73 10 31 stone
- execute if score #success success_score matches 1 run say Succes!!
- execute unless score #success success_score matches 1 run say Not success!!
+```
+execute store success #success success_score if block 73 10 31 stone
+execute if score #success success_score matches 1 run say Success!!
+execute unless score #success success_score matches 1 run say Not success!!
+```
## 1.12
@@ -40,14 +46,18 @@ For example, you want to execute a command when `@a[tag=TeamChange]` finds somet
Easiest way to do this is by prefixing the command with an `execute`:
- execute @a[tag=TeamChange,c=1] ~ ~ ~ say test
+```mcfunction
+execute @a[tag=TeamChange,c=1] ~ ~ ~ say test
+```
----
-If you want to run commands without changing the executer, or run a command if the selector **fails**, you can use `/function`'s `if` or `unless` arguments. For example:
+If you want to run commands without changing the executor, or run a command if the selector **fails**, you can use `/function`'s `if` or `unless` arguments. For example:
- function code:team_change if @a[tag=TeamChange]
- function code:ready unless @a[tag=!Ready]
+```mcfunction
+function code:team_change if @a[tag=TeamChange]
+function code:ready unless @a[tag=!Ready]
+```
### My condition is whether or not another command succeeds
@@ -55,36 +65,48 @@ For this you will need to use `/stats`. If you have not used `/stats` in the pas
First, set up a dummy scoreboard objective:
- scoreboard objectives add success_score dummy
+```mcfunction
+scoreboard objectives add success_score dummy
+```
For the entity on which you will be executing the command you want to use as a conditional, set its `SuccessCount` stat to store in its `success_score`:
- stats entity @e[tag=main] set SuccessCount @s success_score
+```mcfunction
+stats entity @e[tag=main] set SuccessCount @s success_score
+```
(Note that the second selector will be evaluated **by** the entities found by the first selector. So `@s` here will target "themselves" rather than whatever's running the `/stats` command.)
Make sure the score is initiated (not null). Easy way to do this is by adding 0:
- scoreboard players add @e[tag=main] success_score 0
+```mcfunction
+scoreboard players add @e[tag=main] success_score 0
+```
----
Then, whenever you want to perform a conditional command:
- testforblock 73 10 31 stone *
- execute @s[score_success_score_min=1] ~ ~ ~ say Stone found!
- execute @s[score_success_score=0] ~ ~ ~ say Stone not found!
+```mcfunction
+testforblock 73 10 31 stone *
+execute @s[score_success_score_min=1] ~ ~ ~ say Stone found!
+execute @s[score_success_score=0] ~ ~ ~ say Stone not found!
+```
Alternatively, if you're **not** running this function off of the entity storing its `Successcount`:
- execute @e[tag=main] ~ ~ ~ testforblock 73 10 31 stone *
- execute @e[tag=main,score_success_score_min=1] ~ ~ ~ say Stone found!
- execute @e[tag=main,score_success_score=0] ~ ~ ~ say Stone not found!
+```mcfunction
+execute @e[tag=main] ~ ~ ~ testforblock 73 10 31 stone *
+execute @e[tag=main,score_success_score_min=1] ~ ~ ~ say Stone found!
+execute @e[tag=main,score_success_score=0] ~ ~ ~ say Stone not found!
+```
Be careful here of the order and affect that subsequent commands may have on the entity's `Successcount`. **For example, the following will not work**:
- testforblock 73 10 31 stone *
- execute @s[score_success_score=0] ~ ~ ~ say Stone not found!
- execute @s[score_success_score_min=1] ~ ~ ~ say Stone found!
+```mcfunction
+testforblock 73 10 31 stone *
+execute @s[score_success_score=0] ~ ~ ~ say Stone not found!
+execute @s[score_success_score_min=1] ~ ~ ~ say Stone found!
+```
That won't work because, even if the `/testforblock` succeeds, `execute @s[score_success_score=0] ...` will fail and set `success_score` to 0 before the next command runs.
diff --git a/questions/giveitembedrock.md b/questions/giveitembedrock.md
index 9cd4d7d90..660ec15ef 100644
--- a/questions/giveitembedrock.md
+++ b/questions/giveitembedrock.md
@@ -4,8 +4,9 @@ This article is for **Bedrock only**, as Java can just use NBT or item component
Using `/give` on bedrock only works for "basic" items, without any alterations like change of names or enchantments.
-> [!NOTE]
-> You can use external programs (such as world editors or "hacks") to get custom items, that are impossible to get, such as items with impossible enchantments.
+| 📝 Note |
+|---------|
+|You can use external programs (such as world editors or "hacks") to get custom items, that are impossible to get, such as items with impossible enchantments|
Thus, a different method needs to be followed, of which there are multiple common ones.
@@ -38,12 +39,12 @@ Either use step 4 or step 6, reasons and problems see below
5. tp the dropped items to the player
6. **or** if you didn't do #4, you can /clear the container from the players inventory instead
-Step 4: requires you to either rename the container or hope the player is playing in english, because @e[type=item,name="Chest"] only works in english. Alternatively you can change the language files for every language so all and every chest is called "Chest" in every language.
-Step 6: Has the advantage that you don't need to fiddle with the language files or renamed containers, but has the problem that the item may not be picked up instantly thus making it harder to set up properly.
+Step 4: requires you to either rename the container or hope the player is playing in English, because @e[type=item,name="Chest"] only works in English. Alternatively, you can change the language files for every language so all and every chest is called "Chest" in every language.
+Step 6: Has the advantage that you don't need to fiddle with the language files or renamed containers, but has the problem that the item may not be picked up instantly, thus making it harder to set up properly.
### Structure block
-Instead of storing the item in a chest, you store it in a structure block by saving a 1x1 structure that consists of just air and the item entities. So the step by step guide is:
+Instead of storing the item in a chest, you store it in a structure block by saving a 1x1 structure that consists of just air and the item entities. So the step-by-step guide is:
1. throw the item(s) on top of a structure block, save the structure with entities (probably as a 1x1x1 sized structure).
2. change the structure block to load mode
diff --git a/questions/heighttest.md b/questions/heighttest.md
index 1ac6c6527..1f63a9b3d 100644
--- a/questions/heighttest.md
+++ b/questions/heighttest.md
@@ -18,5 +18,5 @@ The same technique can be used to find players above/below any `x`/`y`/`z` coord
To detect below a certain height, you can make the `dy` negative.
- /execute at @a at @s run say @s[y=-30,dz=-500]
+ /execute as @a at @s run say @s[y=-30,dy=-500]
this will detect any players below `-30`
diff --git a/questions/highestscore.md b/questions/highestscore.md
index d8abb4f93..7bfdf9488 100644
--- a/questions/highestscore.md
+++ b/questions/highestscore.md
@@ -1,13 +1,14 @@
# Find player / entity with the highest score
-> [!NOTE]
-> This only works with online players / loaded entities. If you want to accomodate offline players / unloaded entities, you'll need a much more complicated system!
+| 📝 Note |
+|---------|
+|This only works with online players / loaded entities. If you want to accommodate offline players / unloaded entities, you'll need a much more complicated system!|
Thanks to `scoreboard player operations` this is a fairly easy question to answer, as the `>` operator will ensure the left score is at least as high as the right score.
-Thus the way to do this is as follows (assuming you're trying to find the highest score in an objective named `score`).
+Thus, the way to do this is as follows (assuming you're trying to find the highest score in an objective named `score`).
-First you set up a [fake player](/wiki/questions/fakeplayer) with the smallest possible score you can reasonably have, or alternatively you can use the smallest possible number (`-2147483648`).
+First, you set up a [fake player](/wiki/questions/fakeplayer) with the smallest possible score you can reasonably have, or alternatively you can use the smallest possible number (`-2147483648`).
scoreboard players set #max score -2147483648
diff --git a/questions/hostilefriendly.md b/questions/hostilefriendly.md
index 0cea7676a..410fd61c0 100644
--- a/questions/hostilefriendly.md
+++ b/questions/hostilefriendly.md
@@ -6,42 +6,52 @@ This method can be used to make both, disable PvP and make hostile mobs passive.
### Teams (Java only)
In java, we can create teams, and we can configure friendly fire to make people of that team unable to attack each other. This also works for mobs. In this example we are going to make zombies passive to players.
- # in chat / load function
- team add Friendly
- team join @a friendly
-
- # tick function / command blocks
- team join @e[team=!friendly,type=zombie] friendly
+```mcfunction
+# in chat / load function
+team add Friendly
+team join @a friendly
+# tick function / command blocks
+team join @e[team=!friendly,type=zombie] friendly
+```
### Weakness and resistance (Java and Bedrock)
-If you can’t use the `/team` command (because you are using it for another thing or you are in bedrock) you can use effects. If we give resistance level 5 or higher the entity will be invulnerable to all damages except the `/kill` command. Weakness is recommended to avoid the player or mob cause knockback.
+If you can’t use the `/team` command (because you are using it for another thing or you are in bedrock) you can use effects. If we give resistance level 5 or higher the entity will be invulnerable to all damages except the `/kill` command. Weakness is recommended to avoid the player or mob to cause knockback.
-> [!NOTE]
-> The entity will be invulnerable even to other damage sources, such as fall damage, entity cramming or attacks that aren’t caused by the player.
+| 📝 Note |
+|---------|
+|The entity will be invulnerable even to other damage sources, such as fall damage, entity cramming or attacks that aren’t caused by the player.|
In this example we are going to make all zombies unable to attack the player for one minute
- /effect give @e[type=zombie] weakness 60 127 true
+```mcfunction
+/effect give @e[type=zombie] weakness 60 127 true
+```
And if we want the player to be unable to attack the zombie
- /effect give @a weakness 60 127
+```mcfunction
+/effect give @a weakness 60 127
+```
-> [!NOTE]
-> You can still attack the player/entity if you have the sharpness enchantment, that's why we use resistance.
+| 📝 Note |
+|---------|
+|You can still attack the player/entity if you have the sharpness enchantment, that's why we use resistance|
## Only disable hostile
-This method wont work to dissable PvP, it will only prevent the entity attacking the player.
+This method wont work to disable PvP, it will only prevent the entity attacking the player.
### Helmet
It is unclear whether this is a bug, but it is shown [in this Reddit post](https://new.reddit.com/r/MinecraftCommands/comments/1cuibxp/comment/l4ya7gx/) that constantly using /item on the mob will mess up the AI and will thus prevent it from attacking the player.
-> [!NOTE]
-> This does **not** work in Bedrock
+| 📝 Note |
+|---------|
+|This does **not** work in Bedrock|
- # Java syntax
- /item replace entity @e[type=skeleton] armor.head with iron_helmet
+```mcfunction
+# Java syntax
+/item replace entity @e[type=skeleton] armor.head with iron_helmet
+```
### Follow range
You can modify the follow range attribute of some mobs so they can't find you. In bedrock you can use the invisibility effect to reduce this range, use mob heads or you change a mobs behavior file to change their follow range that way.
@@ -60,7 +70,16 @@ Important things to keep in mind when using this method:
* Arrows and other projectiles will be able to attack the entity
### Distance attribute (Java only)
-In java edition there are 2 attributes related to the range that players can interact with the world. we can reduce this range and set it to `-4.5` to make them unable to interact with other entities.
+In java edition, there is an attribute related to the range that players can interact with other entities. we can reduce this range to make them unable to interact with other entities.
-> [!NOTE]
-> This will affect right click too so they won't be able to trade with villagers for example.
+ attribute entity_interaction_range base set 0
+
+| 📝 Note |
+|---------|
+|This will affect right click too so they won't be able to trade with villagers, for example.|
+
+### Game Rule (Bedrock only)
+
+You can use the gamerule `pvp` but you can specify which players so it will take effect on everybody
+
+ gamerule pvp false
\ No newline at end of file
diff --git a/questions/itemclick.md b/questions/itemclick.md
index 439832e00..0cd6071f8 100644
--- a/questions/itemclick.md
+++ b/questions/itemclick.md
@@ -1,43 +1,57 @@
# Item Click Detection
+* [Java](#java)
+* [Java and Bedorck](#java-and-bedrock)
+
+## Java
+
For item clicks we have to differentiate between leftclick and rightclick detection in the hotbar / offhand as well as clicking on the item while it is in the inventory. Clicking on the item while it is in the inventory works since version 1.20.5 with the addition of a player cursor slot (`player.cursor`) for checking.
-## Left / right clicks in / on specific areas
+### Left / right clicks in / on specific areas
-### Interaction entity
+#### Interaction entity
Added in 1.19.4, the [interaction entity](https://minecraft.wiki/w/Interaction) now makes it easier to detect left/right clicks as it uses fewer commands and the hitbox size can be adjusted, making it less likely to miss a click, but otherwise has the same disadvantages as the [Hurt entity method](#hurt-entity).
Here's a simple example for command blocks:
- # Setup
- summon minecraft:interaction ~ ~ ~ {Tags:["click_scan"],width:0.5f,height:0.5f}
-
- # Command blocks
- execute as @e[type=interaction,tag=click_scan] store success entity @s attack.player[] int 0 on attacker run say Left Click!
- execute as @e[type=interaction,tag=click_scan] store success entity @s interaction.player[] int 0 on target run say Right Click!
+```mcfunction
+# Setup
+summon minecraft:interaction ~ ~ ~ {Tags:["click_scan"],width:0.5f,height:0.5f}
+
+# Command blocks
+execute as @e[type=interaction,tag=click_scan] store success entity @s attack.player[] int 0 on attacker run say Left Click!
+execute as @e[type=interaction,tag=click_scan] store success entity @s interaction.player[] int 0 on target run say Right Click!
+```
**Note:** Do not create an interaction entity that is too large, otherwise click detection will be inconsistent.
-> [!TIP]
-> To see interaction entity press `F3 + B` to show hitboxes.
+| 💡 Tip |
+|--------|
+|To see interaction entity press `F3 + B` to show hitboxes|
If you need to check left/right clicks in a large area (or anywhere), then use multiple interaction entities or create a separate interaction entity for each player and teleport to the player every tick, and use the [scoreboard ID system](/wiki/questions/linkentity) for linking.
You can also check what the player is holding in his hand, but then removing the `interaction` / `attack` tag must be done in a separate command:
- # Command blocks
- ## 1.19.4 - 1.20.4
- execute as @e[type=interaction,tag=click_scan] on target if entity @s[nbt={SelectedItem:{tag:{right_click:true}}}] run say Right Click!
- # 1.20.5+
- execute as @e[type=interaction,tag=click_scan] on target if items entity @s weapon *[custom_data~{right_click:true}] run say Right Click!
- execute as @e[type=interaction,tag=click_scan] run data remove entity @s interaction
+```mcfunction
+# Command blocks
+### 1.19.4 - 1.20.4
+execute as @e[type=interaction,tag=click_scan] on target if entity @s[nbt={SelectedItem:{tag:{right_click:true}}}] run say Right Click!
+
+### 1.20.5+
+execute as @e[type=interaction,tag=click_scan] on target if items entity @s weapon *[custom_data~{right_click:true}] run say Right Click!
+execute as @e[type=interaction,tag=click_scan] run data remove entity @s interaction
+```
When using a datapack, you don't have to run these commands in a tick function, but only once when interacting using advancements:
* Right click - `minecraft:player_interacted_with_entity` advancement trigger
* Left click - `minecraft:entity_hurt_player` advancement trigger
-```
+
+ See example
+
+```json
# advancement example:interaction/right_click
{
"criteria": {
@@ -61,16 +75,18 @@ When using a datapack, you don't have to run these commands in a tick function,
"function": "example:click/right"
}
}
-
+```
+```mcfunction
# function example:click/right
advancement revoke @s only example:interaction/right_click
say Right Click!
execute as @e[type=interaction,tag=click_scan] run data remove entity @s interaction
```
+
-## Left-click
+### Left-click
-### Hurt entity
+#### Hurt entity
This one is as easily explained as it is flawed: You can only detect left clicks, if you put something in front of the player to hit. Teleport some form of entity or mob that can take damage and has a hitbox directly in the players face or even over their head, so they have no other chance but to hit that entity. You can then "detect" the clicks either using an advancement with the `player_hurt_entity` trigger ([see here](https://minecraft.wiki/Advancements/JSON_format#minecraft:player_hurt_entity)) or with a scoreboard objective of type `minecraft.custom:minecraft.damage_dealt` ([see here](https://minecraft.wiki/Scoreboard#Criteria)). This method however has many obvious flaws:
@@ -80,11 +96,11 @@ This one is as easily explained as it is flawed: You can only detect left clicks
While you can use this method more reliably if this is about hitting some special mobs with a special item or something (the advancement method is really good at that), **general leftclick detection is discouraged unless you have a very controlled environment**.
-## Right-click
+### Right-click
-For rightclick detection we have [a lot of different ways](https://i.imgur.com/8gKEdp1.png) (image by [u/Dieuwt](https://www.reddit.com/u/Dieuwt)), and different situations might call for different solutions. Since we cannot write a detailed guide on all these methods, we'll only describe the two most common solutions here. A rundown of the knowledge book method can be found [here](https://www.reddit.com/r/MinecraftCommands/comments/g4jxzy/simple_rightclick_detection_without_sacrificing) (by [u/U2106_Later](https://www.reddit.com/u/U2106_Later).
+For rightclick detection we have [a lot of different ways](https://i.imgur.com/8gKEdp1.png) (image by [u/Dieuwt](https://www.reddit.com/u/Dieuwt), does not include 1.20.5+ methods), and different situations might call for different solutions. Since we cannot write a detailed guide on all these methods, we'll only describe the most common solutions here. A rundown of the knowledge book method can be found [here](https://www.reddit.com/r/MinecraftCommands/comments/g4jxzy/simple_rightclick_detection_without_sacrificing) (by [u/U2106_Later](https://www.reddit.com/u/U2106_Later)).
-### Carrot on a stick method
+#### Carrot on a stick method
_Note: This works the same with the warped fungus on a stick._
@@ -101,32 +117,49 @@ Pros:
Cons:
- Will attract pigs/boost pigs speed when riding a pig. _(or striders if using the wfoas instead)_
- Looks like a carrot on a stick (fix see below).
-- Has unremovable Damage NBT tag. This can be somewhat negated by making the CoaS unbreakable.
+- Only in pre-1.20.5: Has unremovable Damage NBT tag. This can be somewhat negated by making the CoaS unbreakable.
-#### Make the CoaS look like any item
+##### Make the CoaS look like any item
+
+###### 1.13+
People tend to use a carrot on a stick and then use a resource pack to remodel them for various CustomModelData tags. This way the CoaS looks like your desired item while still providing the same rightclick functionality.
-The models/item/carrot_on_a_stick.json file within the resource pack might end up looking like this:
+The `models/item/carrot_on_a_stick.json` file within the resource pack might end up looking like this:
+
+
+ See file
- {
- "parent": "item/handheld",
- "textures": {
- "layer0": "item/carrot_on_a_stick"
- },
+```json
+{
+ "parent": "item/handheld",
+ "textures": {
+ "layer0": "item/carrot_on_a_stick"
+ },
- "overrides": [
- {"predicate": {"custom_model_data":1}, "model": "item/blaze_powder"},
- {"predicate": {"custom_model_data":2}, "model": "item/nether_star"},
- {"predicate": {"custom_model_data":3}, "model": "item/blaze_rod"},
- {"predicate": {"custom_model_data":4}, "model": "item/black_dye"}
- ]
- }
+ "overrides": [
+ {"predicate": {"custom_model_data":1}, "model": "item/blaze_powder"},
+ {"predicate": {"custom_model_data":2}, "model": "item/nether_star"},
+ {"predicate": {"custom_model_data":3}, "model": "item/blaze_rod"},
+ {"predicate": {"custom_model_data":4}, "model": "item/black_dye"}
+ ]
+}
+```
+
+
+| 💡 Tip |
+|---------|
+|You can make the item completly invisible if using the custom model data of a chest|
+
+###### 1.21.2+
-> [!NOTE]
-> You can make the item completly invisible if using the custom model data of a chest.
+The new `item_model` component allows you to make any item look like any other item without a resource pack. See this example command of a carrot on a stick that looks like a nether star
-### Make item food method
+ give @p carrot[item_model="nether_star"] 1
+
+#### Make item food method
+
+##### 1.20.5+
From version 1.20.5 you can add a right click check for any item that does not already use a right click event.
@@ -134,55 +167,108 @@ This method involves adding the [`minecraft:food component`](https://minecraft.w
When using only command blocks, you need to actually consume this item in order for the usage statistics of your item to change. So it might make sense to set the `eat_seconds` tag to a small value, such as 0.05 seconds (1 tick). Here is a small example for command blocks:
- # Setup
- give @s minecraft:stick[minecraft:food={nutrition:0,saturation:0f,eat_seconds:0.05f,can_always_eat:true}]
- scoreboard objectives add click.stick used:stick
-
- # Command blocks
- execute as @a[scores={click.stick=1..}] run say Right Click!
- scoreboard players reset @a click.stick
+```mcfunction
+# Setup
+give @s minecraft:stick[minecraft:food={nutrition:0,saturation:0f,eat_seconds:0.05f,can_always_eat:true}]
+scoreboard objectives add click.stick used:stick
+
+# Command blocks
+execute as @a[scores={click.stick=1..}] run say Right Click!
+scoreboard players reset @a click.stick
+```
This method has obvious disadvantages, such as particles appearing when used, sounds and the fact that the item is actually used.
But when using a datapack, there are none of these disadvantages. Then you want to change `eat_seconds` to something very large so that the eating animation can't start and use the advancement trigger [`minecraft:using_item`](https://minecraft.wiki/w/Custom_advancement#minecraft:using_item) to check the item's usage. Since this advancement trigger is triggered every tick while the player is using the item, you can execute the command up to 20 times per second. However, often you don't want to do this as often and want to add a delay between command runs.
Below is an example for this with a delay that is easy to configure:
- # Setup
- give @s minecraft:stick[minecraft:custom_data={right_click:true},minecraft:food={nutrition:0,saturation:0f,eat_seconds:2147483648f,can_always_eat:true}]
- scoreboard objectives add stick.cooldown dummy
-
- # advancement example:stick/right_click
- {
- "criteria": {
- "requirement": {
- "trigger": "minecraft:using_item",
- "conditions": {
- "item": {
- "predicates": {
- "minecraft:custom_data": "{right_click:true}"
- }
+
+ See example
+
+```mcfunction
+# Example item
+give @s minecraft:stick[minecraft:custom_data={right_click:true},minecraft:food={nutrition:0,saturation:0f,eat_seconds:2147483648f,can_always_eat:true}]
+scoreboard objectives add stick.cooldown dummy
+```
+```json
+# advancement example:stick/right_click
+{
+ "criteria": {
+ "requirement": {
+ "trigger": "minecraft:using_item",
+ "conditions": {
+ "item": {
+ "predicates": {
+ "minecraft:custom_data": "{right_click:true}"
}
}
}
- },
- "rewards": {
- "function": "example:right_click"
}
+ },
+ "rewards": {
+ "function": "example:right_click"
}
-
- # function example:right_click
- execute store result score @s stick.cooldown run time query gametime
- scoreboard players add @s stick.cooldown 10
- schedule function example:reset_cooldown 10t append
- say Right Click!
-
- # function example:reset_cooldown
- execute store result score #reset stick.cooldown run time query gametime
- execute as @a if score @s stick.cooldown = #reset stick.cooldown run advancement revoke @s only example:stick/right_click
+}
+
+# function example:right_click
+execute store result score @s stick.cooldown run time query gametime
+scoreboard players add @s stick.cooldown 10
+schedule function example:reset_cooldown 10t append
+say Right Click!
+
+# function example:reset_cooldown
+execute store result score #reset stick.cooldown run time query gametime
+execute as @a if score @s stick.cooldown = #reset stick.cooldown run advancement revoke @s only example:stick/right_click
+```
+
+
This method allows you to check a right click for almost any item and you do not need to use a resourcepack to change the texture as for the CoaS / FoaS method.
-### Villager method
+##### 1.21.2+
+
+In 1.21.2 some part of the `food` component has been separated into the `consumable` component. So we will need to change the `give` command, depending on what of the two methods you are using. The `consume_seconds` will be set to `0`, that is now possible in 1.21.2+ (if using the scoreboard method) or to `2147483647` (if using an advancement)
+
+```
+# get item
+give @p stick[food={nutrition:0,saturation:0,can_always_eat:true},consumable={consume_seconds:2147483647}] 1
+```
+
+We can also add a cooldown (with the `use_cooldown` component) and use another animation instead of eating (it can be `none`, `eat`, `drink`, `block`, `bow`, `spear`, `crossbow`, `spyglass`, `toot_horn` or `brush`). Keep in mind that the item will be gone when using it. Here is a small example, detecting it using an advancement, of a nether star with the bow animation and a 5 second cooldown.
+
+
+ See example
+
+```mcfunction
+# Setup
+give @p nether_star[use_cooldown={seconds:5},food={nutrition:0,saturation:0,can_always_eat:true},consumable={consume_seconds:1,animation:"bow"},custom_data={right_click:true}] 1
+```
+```json
+# advancement example:right_click/nether_star
+{
+ "criteria": {
+ "requirement": {
+ "trigger": "minecraft:consume_item",
+ "conditions": {
+ "item": {
+ "predicates": {
+ "minecraft:custom_data": "{right_click:true}"
+ }
+ }
+ }
+ }
+ },
+ "rewards": {
+ "function": "example:right_click"
+ }
+}
+
+# function example:right_click
+say used nether star
+```
+
+
+#### Villager method
Spawn an invisible, NoAI, Silent dummy villager in front of the player and test if the player's "talked to villager" score increases (`minecraft.custom:minecraft.talked_to_villager`, see [here](https://minecraft.wiki/Scoreboard#Criteria)).
@@ -196,11 +282,12 @@ Cons:
_Parts of this post are taken and modified from [here](https://www.reddit.com/r/MinecraftCommands/comments/elnygk/item_abilities), which have been written by [u/Lemon_Lord1](https://www.reddit.com/u/Lemon_Lord1)_
-## Inventory click
+### Inventory click
-*Note:* This method works since version 1.20.5
-
-_Note: This will not work for creative players._
+| 📝 Note |
+|---------|
+|This method works since version 1.20.5|
+|This will not work for creative players.|
This method is based on checking the player's cursor slot. To do this, need to check slot `player.cursor` using the `if items` subcommand or predicates. Below is an example for running a command when holding a custom item in the cursor.
@@ -211,3 +298,41 @@ This method is based on checking the player's cursor slot. To do this, need to c
# Command blocks
execute as @a[scores={hold.in_cursor=0}] if items entity @s player.cursor *[minecraft:custom_data~{in_cursor:true}] run say Cursor Command.
execute as @a store success score @s hold.in_cursor if items entity @s player.cursor *[minecraft:custom_data~{in_cursor:true}]
+
+## Java and Bedrock
+
+### Bundles
+
+| 📝 Note |
+|---------|
+|In Java, it is recommended to use the other methods listed above|
+
+Right-clicking a bundle will take the first item that has. Because it will spawn an enitity, we can target it. In bedrock edition you will need [a complex method](wiki/questions/giveitembedrock) to be able to give a bundle with a renamed item inside, in this example the item is called `right_click` (so we can distinguish it from other items) and we are going to use the structure method to give the item. In Java, you can use custom data for better performance instead, but it’s recommended to use the other methods listed above.
+
+```mcfunction
+# bedrock
+execute at @e[type=item,name="right_click"] run tag @p add right_click
+replaceitem entity @a[tag=right_click] slot.weapon 0 air
+execute at @e[tag=right_click] run structure load right_click_bundle ~ ~ ~
+execute as @e[tag=rigth_click] at @s run say Right click
+kill @e[type=item,name="right_click"]
+tag @a[tag=right_click] remove right_click
+```
+
+Java
+
+
+ See example
+
+ # Example item
+ give @s bundle[custom_data:{bundle_click:true},bundle_contents=[{id:"minecraft:music_disc_11",count:1,components:{"minecraft:custom_data":{right_click_bundle:true}}}]]
+
+ # Command blocks:
+ execute as @e[type=item] if contents entity @s *[custom_data:{right_click_bundle:true}] on owner run tag @s run add right_click_bundle
+ execute as @e[type=item] if contents entity @s *[custom_data:{right_click_bundle:true}] run kill @s
+ clear @a *[custom_data:{right_click_bundle:true}]
+ execute as @a[tag=right_click_bundle] run say example
+ execute as @a[tag=right_click_bundle] if items entity @s weapon.mainhand bundle[custom_data:{bundle_click:true}] run item replace entity @s weapon.mainhand with bundle[custom_data:{bundle_click:true},bundle_contents=[{id:"minecraft:music_disc_11",count:1,components:{"minecraft:custom_data":{right_click_bundle:true}}}]]
+ execute as @a[tag=right_click_bundle] unless items entity @s weapon.mainhand bundle[custom_data:{bundle_click:true}] run item replace entity @s weapon.mainhand with bundle[custom_data:{bundle_click:true},bundle_contents=[{id:"minecraft:music_disc_11",count:1,components:{"minecraft:custom_data":{right_click_bundle:true}}}]]
+ tag @a[tag=right_click_bundle] remove right_click_bundle
+
\ No newline at end of file
diff --git a/questions/linkentity.md b/questions/linkentity.md
index 16d004ba4..53e6b4e7c 100644
--- a/questions/linkentity.md
+++ b/questions/linkentity.md
@@ -2,9 +2,12 @@
_Also known as a **scoreboard ID system**_.
+* [Java](#java)
+* [Java and Bedrock](#java-and-bedrock)
+
## Java
-Sometimes there is a need to link two entites together in a logical fashion. In Minecraft, we can achieve this by giving both entities the same scoreboard score. In this article we'll be linking an entity to a player.
+Sometimes there is a need to link two entities together in a logical fashion. In Minecraft, we can achieve this by giving both entities the same scoreboard score. In this article we'll be linking an entity to a player.
For example, let's create a dummy scoreboard for player/entity IDs.
@@ -20,20 +23,23 @@ This command selects all players who do not have a score `ID`, then increases th
If you are using a datapack, then you can use the command above in the tick function, or create a simple advancement that will only run once for each player:
- # advancement example:first_join
- {
- "criteria": {
- "requirement": {
- "trigger": "minecraft:tick"
- }
- },
- "rewards": {
- "function": "example:set_id"
- }
+```json
+# advancement example:first_join
+{
+ "criteria": {
+ "requirement": {
+ "trigger": "minecraft:tick"
}
-
- # function example:set_id
- execute store result score @s ID run scoreboard players add #new ID 1
+ },
+ "rewards": {
+ "function": "example:set_id"
+ }
+}
+```
+```mcfunction
+# function example:set_id
+execute store result score @s ID run scoreboard players add #new ID 1
+```
**And we're done, every player has a unique ID**. Now we can just copy the ID score to whatever entity we want to link up using `scoreboard players operation`, and use [this method](/wiki/questions/findsamescoreentity#method-2-store-the-score-in-a-fake-player-first) to find the entity with the same score (aka the linked entity).
@@ -41,12 +47,15 @@ If you are using a datapack, then you can use the command above in the tick func
## Java and Bedrock
-> [!NOTE]
-> The information below is outdated / inefficient for java. Use this only to better understand how the Scoreboard ID system works.
+| 📝 Note |
+|---------|
+|The information below is outdated / inefficient for java. Use this only to better understand how the Scoreboard ID system works|
First we need to set up a dummy scoreboard objective
- scoreboard objectives add id dummy
+```mcfunction
+scoreboard objectives add id dummy
+```
Next, to make sure that every player gets a unique id, we need a system that assigns every player a unique score. This can be achieved by simply counting up with every subsequent player that needs a score. For this, we'll set a [fake player](/wiki/questions/fakeplayer) score of this objective to 1 to start with.
@@ -54,33 +63,37 @@ Next, to make sure that every player gets a unique id, we need a system that ass
Next, to assign a unique id to every player that does not have an ID yet, it's best to use a function so that every new player get treated individually.
- # add 0 to all players' id score. This ensures that every player
- # has a score (of 0) while not changing any existing scores
- scoreboard players add @a id 0
-
- # Execute as all players that have a score of 0 (aka no ID yet)
- execute as @a[scores={id=0}] run function namespace:init_id
+```mcfunction
+# function example:tick
+# add 0 to all players' id score. This ensures that every player
+# has a score (of 0) while not changing any existing scores
+scoreboard players add @a id 0
-`init_id.mcfunction`
+# Execute as all players that have a score of 0 (aka no ID yet)
+execute as @a[scores={id=0}] run function example:init_id
+
+# function example:init_id
+# copy the score of the fake player to the player
+scoreboard players operation @s id = $total id
- # copy the score of the fake player to the player
- scoreboard players operation @s id = $total id
+# count up the score so the next player will get a different id
+scoreboard players add $total id 1
+```
- # count up the score so the next player will get a different id
- scoreboard players add $total id 1
+If for some reason you cannot use a function, use this code for your commandblocks instead. This means that it will take `n` ticks for `n` amount of players that need an id, while the other system is instant:
-If for some reason you cannot use a function, use this code for your commandblocks instead. This means that it will take n ticks for n amount of players that need an id, while the other system is instant:
+```mcfunction
+scoreboard players add @a id 0
- scoreboard players add @a id 0
+# select one random unassigned player to assign the id to
+tag @r[scores={id=0}] add addId
- # select one random unassigned player to assign the id to
- tag @r[scores={id=0}] add addId
-
- # apply id to this selected player, as above
- scoreboard players operation @a[tag=addId] id = $total id
- execute as @a[tag=addId] run scoreboard players add $total id 1
+# apply id to this selected player, as above
+scoreboard players operation @a[tag=addId] id = $total id
+execute as @a[tag=addId] run scoreboard players add $total id 1
- # remove tag so we're ready for the next player
- tag @a remove addId
+# remove tag so we're ready for the next player
+tag @a remove addId
+```
**And we're done, every player has a unique ID**. Now we can just copy the id score to whatever entity we want to link up using `scoreboard players operation`, and use [this method](/wiki/questions/findsamescoreentity) to find the entity with the same score (aka the linked entity).
diff --git a/questions/lookat.md b/questions/lookat.md
index 07908c9e6..227a6006f 100644
--- a/questions/lookat.md
+++ b/questions/lookat.md
@@ -10,84 +10,103 @@ in Java and later Bedrock versions this can actually be achieved in a single com
- `anchored eyes` to move the execution position up to the players eyes. For it to take effect, you'll need a positioned ^ ^ ^ subcommand at some point after this subcommand (which we have 2 subcommands later). See this related bug [MC-169665](https://bugs.mojang.com/browse/MC-169665).
- `facing ` to change the execution rotation to be facing our object / entity of desire
- `positioned ^ ^ ^1` to move 1 block in the direction of the object
-- `anchored feet` to move the anchor back down to the players feet (due to a bug in the game which would otherwise apply the eye height modification with each position change, which we don't want, as well as to be able to check for the players existence in the last subcommand, this is not the case in the current version of the game so it can be omited, see [MC-124140](https://bugs.mojang.com/browse/MC-124140))
+- `anchored feet` to move the anchor back down to the players feet (due to a bug in the game which would otherwise apply the eye height modification with each position change, which we don't want, as well as to be able to check for the players existence in the last subcommand, this is not the case in the current version of the game so it can be omitted, see [MC-124140](https://bugs.mojang.com/browse/MC-124140))
- `rotated as @s` to change the execution rotation back to be the same as the executing player
- `positioned ^ ^ ^-1` to move 1 block in the opposite direction of where the player is facing
-- `if entity @s[distance=..0.1]` to check whether after this back and forth we've arrived roughly back at the players position. To increase / decrease the tolerance for what is considered "close enough", change the distance parameter (it needs to be between 0 and 2, because 2 basically means "you can look in the opposite direction and it's still close enough. So realistically you want to most likely stay well below 1). To calculate the exact viewing cone angle, see below.
+- `if entity @s[distance=..0.1]` to check whether after this back and forth we've arrived roughly back at the player's position. To increase / decrease the tolerance for what is considered "close enough", change the distance parameter (it needs to be between 0 and 2, because 2 basically means "you can look in the opposite direction and it's still close enough". So realistically you want to most likely stay well below 1). To calculate the exact viewing cone angle, see below.
So, to bring it all together, the full command is as follows:
- execute as @a at @s anchored eyes facing anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.1] run
+```mcfunction
+execute as @a at @s anchored eyes facing anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.1] run
+```
Example 1: looking at the eyes of the closest cow with the tag "target":
- execute as @a at @s anchored eyes facing entity @e[type=cow,tag=target,limit=1,sort=nearest] eyes anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.1] run say hello cow!
+```mcfunction
+execute as @a at @s anchored eyes facing entity @e[type=cow,tag=target,limit=1,sort=nearest] eyes anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.1] run say hello cow!
+```
Example 2: looking at the position 10 20 30
- execute as @a at @s anchored eyes facing 10 20 30 anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.1] run say hello block
+```mcfunction
+execute as @a at @s anchored eyes facing 10 20 30 anchored feet positioned ^ ^ ^1 rotated as @s positioned ^ ^ ^-1 if entity @s[distance=..0.1] run say hello block
+```
## Java
### Predicate
There is a predicate that allows us to detect when a player is looking at an entity, it's the one used by the 3 advancements related to the spyglass.
- # function example:tick
- execute as @a[predicate=example:looking_cow] run say Hi, cow!
-
-
- # predicate example:looking_cow
- {
- "condition": "minecraft:entity_properties",
- "entity": "this",
- "predicate": {
- "type_specific": {
- "type": "minecraft:player",
- "looking_at": {
- "type": "minecraft:cow"
- }
- }
+
+ See example
+
+```mcfunction
+# function example:tick
+execute as @a[predicate=example:looking_cow] run say Hi, cow!
+```
+```json
+# predicate example:looking_cow
+{
+ "condition": "minecraft:entity_properties",
+ "entity": "this",
+ "predicate": {
+ "type_specific": {
+ "type": "minecraft:player",
+ "looking_at": {
+ "type": "minecraft:cow"
}
}
+ }
+}
+```
+
### Advancement
This example is the same advancement as the vanilla ones but without any display.
You can find (and edit) the preset in [misode's advancement generator](https://misode.github.io/advancement/?version=1.20.5&preset=adventure/spyglass_at_ghast))
- # advancement example:lookat/cow
- {
- "criteria": {
- "requirement": {
- "trigger": "minecraft:using_item",
- "conditions": {
- "player": [
- {
- "condition": "minecraft:entity_properties",
- "entity": "this",
- "predicate": {
- "type_specific": {
- "type": "minecraft:player",
- "looking_at": {
- "type": "minecraft:cow"
- }
- }
+
+ See example
+
+```json
+# advancement example:lookat/cow
+{
+ "criteria": {
+ "requirement": {
+ "trigger": "minecraft:using_item",
+ "conditions": {
+ "player": [
+ {
+ "condition": "minecraft:entity_properties",
+ "entity": "this",
+ "predicate": {
+ "type_specific": {
+ "type": "minecraft:player",
+ "looking_at": {
+ "type": "minecraft:cow"
}
}
- ],
- "item": {
- "items": "minecraft:spyglass"
}
}
+ ],
+ "item": {
+ "items": "minecraft:spyglass"
}
- },
- "rewards": {
- "function": "example:lookat/cow"
}
}
-
- # function example:lookat/cow
- advancement revoke @s only example:lookat/cow
- say I am looking at a cow
+ },
+ "rewards": {
+ "function": "example:lookat/cow"
+ }
+}
+```
+```mcfunction
+# function example:lookat/cow
+advancement revoke @s only example:lookat/cow
+say I am looking at a cow
+```
+
## Bedrock
@@ -97,28 +116,34 @@ In bedrock the process is the same as in Java, but due to a lack of advanced exe
Also, due to how rotations work in bedrock, this tends to be somewhat inaccurate when the target is on a different y level than the player. Hopefully this will be resolved when the new execute arrives in 1.19.
-This setup can only happen to one player at a time, so either use functions to make this better scaleable or experiment with executing from the players and their closest armorstands (which will still lead to some issues, but less so). Hence this will use `@p` to signify this restriction.
-
-
- # summon armorstand so we can do our check
- execute @p ~~~ summon armor_stand ~~~ none checker
- # tp armorstand to player including rotations
- execute @p ~~~ tp @e[name=checker] ~~~ ~~
- # move armorstand forward by 1 block from the players position
- # should also work if you execute as the checker instead
- execute @p ~~~ tp @e[name=checker] ^^^1
- # rotate the armorstand to face our target
- # target can be an entity or a block
- execute @e[name=checker] ~~~ tp @s ~~~ facing
- # teleport the armorstand backwards from where it's looking
- # so if the player is looking the same direction, it will have moved back and forth
- execute @e[name=checker] ~~~ tp @s ^^^-1
- # now if the as and the player are close (enough) together, the player is looking at the target
- execute @e[name=checker] ~~~ execute @p[r=0.1] ~~~ say hello there
- # remove entity
- kill @e[name=checker]
-
-To increase / decrease the tolerance for what is considered "close enough", change the radius (`r`) selector (it needs to be between 0 and 2, because 2 basically means "you can look in the opposite direction and it's still close enough. So realistically you want to most likely stay well below 1). To calculate the exact viewing cone angle, see below.
+This setup can only happen to one player at a time, so either use functions to make this better scalable or experiment with executing from the players and their closest armorstands (which will still lead to some issues, but less so). Hence this will use `@p` to signify this restriction.
+
+
+ See commands
+
+```mcfunction
+# summon armorstand so we can do our check
+execute @p ~~~ summon armor_stand ~~~ none checker
+# tp armorstand to player including rotations
+execute @p ~~~ tp @e[name=checker] ~~~ ~~
+# move armorstand forward by 1 block from the players position
+# should also work if you execute as the checker instead
+execute @p ~~~ tp @e[name=checker] ^^^1
+# rotate the armorstand to face our target
+# target can be an entity or a block
+execute @e[name=checker] ~~~ tp @s ~~~ facing
+# teleport the armorstand backwards from where it's looking
+# so if the player is looking the same direction, it will have moved back and forth
+execute @e[name=checker] ~~~ tp @s ^^^-1
+# now if the as and the player are close (enough) together, the player is looking at the target
+execute @e[name=checker] ~~~ execute @p[r=0.1] ~~~ say hello there
+# remove entity
+kill @e[name=checker]
+```
+
+
+
+To increase / decrease the tolerance for what is considered "close enough", change the radius (`r`) selector (it needs to be between 0 and 2, because 2 basically means "you can look in the opposite direction and it's still close enough". So realistically you want to most likely stay well below 1). To calculate the exact viewing cone angle, see below.
### Using Add-Ons
@@ -130,30 +155,36 @@ The lookat component then lets us fire an event which could then cause whatever
In this example the entity will (without cooldown) fire the `custom:ive_been_looked_at` event when a player (even in creative mode) within a radius of 20 blocks. It will not set the looker as its attack target.
- "minecraft:lookat": {
- "allow_invulnerable": true,
- "filters": {
- "test": "is_family",
- "value": "player"
- },
- "look_event": {
- "event": "custom:ive_been_looked_at"
- },
- "search_radius": 20,
- "look_cooldown": [0,0],
- "set_target": false
- }
-
+
+ See example
+
+```json
+"minecraft:lookat": {
+ "allow_invulnerable": true,
+ "filters": {
+ "test": "is_family",
+ "value": "player"
+ },
+ "look_event": {
+ "event": "custom:ive_been_looked_at"
+ },
+ "search_radius": 20,
+ "look_cooldown": [0,0],
+ "set_target": false
+}
+```
+
+
## Calculate viewing angle
To approximate the distance/radius you want to use based on your viewing angle, you can use the following formula, where `α` is the angle that you want this method to trigger inside of, left and right of the target:
- r = 2 * sin ( α / 2 )
+$r = 2 \times \sin \left( \frac{\alpha}{2} \right)$
or, the inverse to calculate what viewing angle a certain radius / distance (`r`) value will give you
- α = sin^(-1) (r / 2) * 2
+$\alpha = \sin^{-1} \left( \frac{r}{2} \right) \times 2$
_(remember that depending on your calculator you need to convert from radians to degrees)_.
diff --git a/questions/makecircle.md b/questions/makecircle.md
index 1e4070706..99415d9b0 100644
--- a/questions/makecircle.md
+++ b/questions/makecircle.md
@@ -4,30 +4,36 @@ Creating perfect (or as perfect as they can be with minecrafts blocky nature) ci
## The idea
-The idea of how to achieve this is pretty simple: Have an entity in the center that slowly rotates, then place what you want X blocks in front of it using the local coordinates (`^ ^ ^X)`.
+The idea of how to achieve this is pretty simple: Have an entity in the center that slowly rotates, then place what you want X blocks in front of it using the local coordinates (`^ ^ ^X`).
## Implementation
-For the example we're assuming that we want to make a block outline. You can easily adjust this to summon entities or make a filled circle by swapping the `/setblock` command for something else (e.g. summon / fill).
+For the example we're assuming that we want to make a block outline. You can easily adjust this to summon entities or make a filled circle by swapping the `/setblock` command for something else (e.g., `/summon`, `/ fill`).
-1. Summon your center entity. We're using an armorstand for parity, but in Java you can use other things like a marker or any NoAI entity.
+1. Summon your center entity. We're using an armorstand for parity, but in Java you can use other things like a [`marker`](https://minecraft.wiki/w/Marker) (for better performance) or any NoAI entity.
- /summon armor_stand ~ ~ ~
+```mcfunction
+/summon armor_stand ~ ~ ~
+```
2. tag the armorstand so we can reference it easily.
- # Bedrock
- /tag @e[type=armor_stand,c=1] add center
- # Java
- /tag @e[type=armor_stand,sort=nearest,limit=1] add center
+```mcfunction
+# Bedrock
+/tag @e[type=armor_stand,c=1] add center
+# Java 1.13+
+/tag @e[type=armor_stand,sort=nearest,limit=1] add center
+# Java 1.21+
+/tag @n[type=armor_stand] add center
+```
3. now, to automatically place the blocks, we'll want to put the following command into a repeating commandblock and the ones after that into chain commandblocks attached to the repeating one. Starting off with placing the block in front of the armorstand.
execute as @e[tag=center] at @s run setblock ^ ^ ^10 stone
-4. Next, we rotate by what seems a good rotation to cover the entire circle. You can do some maths to figure out a good stepsize, or you can just decrease the size if you end up with holes in your circle.
+4. Next, we rotate by what seems a good rotation to cover the entire circle. You can do some math to figure out a good stepsize, or you can just decrease the size if you end up with holes in your circle.
- The math works like this: You calculate the radian distance as follows: `d = (deg / 360) * 2 * π * radius`. Or, if we solve for the degrees needed from a distance between blocks: `deg = (180 * d) / (π * radius)`. So if your radius is 10 blocks as in the example above, and you want to place a block every one block of distance, you should rotate by (180 * 1) / (π * 10) = 5.7°. But with minecrafts blocky nature, if we want to place continous blocks, we might just want to aim for half of that.
+ The math works like this: You calculate the radian distance as follows: `d = (deg / 360) * 2 * π * radius`. Or, if we solve for the degrees needed from a distance between blocks: `deg = (180 * d) / (π * radius)`. So if your radius is 10 blocks as in the example above, and you want to place a block every one block of distance, you should rotate by (180 * 1) / (π * 10) = 5.7°. But with minecrafts blocky nature, if we want to place continuous blocks, we might just want to aim for half of that.
execute as @e[tag=center] at @s run tp @s ~ ~ ~ ~ ~2.35
@@ -37,6 +43,6 @@ You can of course expand on this basic system to make it more modular, run it ex
## Potential issues
-If you are trying to use this to make really big circles (hundreds of blocks in diameter), you might find that this won't work as you intend it to, seemingly skipping many steps inbetween.
+If you are trying to use this to make really big circles (hundreds of blocks in diameter), you might find that this won't work as you intend it to, seemingly skipping many steps in between.
-We're unsure as to why exactly this happens, but our best guess is that minecrafts internal calculations are limited to a certain rotational precision (e.g. angles get rounded to 0.01° for calculations). This doesn't have any noticeable effect on 99.99% of gameplay, but becomes visible in these situations.
\ No newline at end of file
+We're unsure as to why exactly this happens, but our best guess is that minecrafts internal calculations are limited to a certain rotational precision (e.g., angles get rounded to 0.01° for calculations). This doesn't have any noticeable effect on 99.99% of gameplay, but becomes visible in these situations.
\ No newline at end of file
diff --git a/questions/mobdeaths.md b/questions/mobdeaths.md
index 686da9309..063c5ec45 100644
--- a/questions/mobdeaths.md
+++ b/questions/mobdeaths.md
@@ -19,12 +19,14 @@ Key points:
Here's a quick example to detect if a zombie was killed by a player:
- # In chat / load function
- scoreboard objectives add killed.zombie killed:zombie
-
- # Command blocks / tick function
- execute as @a[scores={killed.zombie=1..}] run say Some zombie has died.
- scoreboard players reset @a[scores={killed.zombie=1..}] killed.zombie
+```mcfunction
+# In chat / load function
+scoreboard objectives add killed.zombie killed:zombie
+
+# Command blocks / tick function
+execute as @a[scores={killed.zombie=1..}] run say Some zombie has died.
+scoreboard players reset @a[scores={killed.zombie=1..}] killed.zombie
+```
----
@@ -42,34 +44,41 @@ Key points:
Here's a quick example to detect if a any skeleton type with the tag some\_tag was killed by a player:
- # advancement example:killed_skeleton
- {
- "criteria": {
- "requirement": {
- "trigger": "minecraft:player_killed_entity",
- "conditions": {
- "entity": [
- {
- "condition": "minecraft:entity_properties",
- "entity": "this",
- "predicate": {
- "type": "#minecraft:skeletons",
- "nbt": "{Tags:['some_tag']}"
- }
- }
- ]
+
+ See example
+
+```json
+# advancement example:killed_skeleton
+{
+ "criteria": {
+ "requirement": {
+ "trigger": "minecraft:player_killed_entity",
+ "conditions": {
+ "entity": [
+ {
+ "condition": "minecraft:entity_properties",
+ "entity": "this",
+ "predicate": {
+ "type": "#minecraft:skeletons",
+ "nbt": "{Tags:['some_tag']}"
+ }
}
- }
- },
- "rewards": {
- "function": "example:skeleton_death"
+ ]
}
}
-
- # function example:skeleton_death
- advancement revoke @s only example:killed_skeleton
- say Skeleton with tag some_tag has died.
-
+ },
+ "rewards": {
+ "function": "example:skeleton_death"
+ }
+}
+```
+```mcfunction
+# function example:skeleton_death
+advancement revoke @s only example:killed_skeleton
+say Skeleton with tag some_tag has died.
+```
+
+
----
## Passenger entity
@@ -90,74 +99,95 @@ Key points:
This method requires preliminary setup of the mob, for example, you can summon a mob with an entity marker as a passenger:
- summon husk ~ ~ ~ {Tags:["some_tag"],Passengers:[{id:"minecraft:marker",Tags:["death_detector"]}]}
+```mcfunction
+summon husk ~ ~ ~ {Tags:["some_tag"],Passengers:[{id:"minecraft:marker",Tags:["death_detector"]}]}
+```
From version 1.19.4 you can also add a marker entity as passenger to an existing mob using the [/ride command](https://minecraft.wiki/w/Commands/ride):
- summon marker ~ ~ ~ {Tags:["death_detector","set_ride"]}
- ride @e[type=marker,tag=death_detector,tag=set_ride,limit=1] mount
- tag @e[type=marker,tag=set_ride] remove set_ride
+```mcfunction
+summon marker ~ ~ ~ {Tags:["death_detector","set_ride"]}
+ride @e[type=marker,tag=death_detector,tag=set_ride,limit=1] mount
+tag @e[type=marker,tag=set_ride] remove set_ride
+```
On versions 1.16 - 1.19.3, the only way to check this mob is to use the [predicate](https://minecraft.wiki/w/Predicate) in the datapack:
- # function example:tick
- execute as @e[type=marker,tag=death_detector,predicate=example:death_mob] run function example:death_mob
- execute as @e[type=marker,tag=death_detector,predicate=example:despawn_mob] run function example:despawn_mob
-
- # function example:death_mob
- say Mob is dead!
- kill @s
-
- # function example:despawn_mob
- say Mob is despawn!
- kill @s
-
- # predicate example:death_mob
- {
- "condition": "minecraft:entity_properties",
- "entity": "this",
- "predicate": {
- "vehicle": {
- "nbt": "{DeathTime:1s}"
- }
- }
+
+ See example
+
+```mcfunction
+# function example:tick
+execute as @e[type=marker,tag=death_detector,predicate=example:death_mob] run function example:death_mob
+execute as @e[type=marker,tag=death_detector,predicate=example:despawn_mob] run function example:despawn_mob
+
+# function example:death_mob
+say Mob is dead!
+kill @s
+
+# function example:despawn_mob
+say Mob is despawn!
+kill @s
+```
+```json
+# predicate example:death_mob
+{
+ "condition": "minecraft:entity_properties",
+ "entity": "this",
+ "predicate": {
+ "vehicle": {
+ "nbt": "{DeathTime:1s}"
}
-
- # predicate example:despawn_mob
- {
- "condition": "minecraft:inverted",
- "term": {
- "condition": "minecraft:entity_properties",
- "entity": "this",
- "predicate": {
- "vehicle": {}
- }
- }
+ }
+}
+
+# predicate example:despawn_mob
+{
+ "condition": "minecraft:inverted",
+ "term": {
+ "condition": "minecraft:entity_properties",
+ "entity": "this",
+ "predicate": {
+ "vehicle": {}
}
+ }
+}
+```
+
+
As of version 1.19.4, you can use the [execute](https://minecraft.wiki/w/Commands/execute#on) `on vehicle` subcommand to select a dying mob:
- # Command blocks
- execute as @e[type=marker,tag=death_detector] on vehicle unless data entity @s {DeathTime:0s} run say This mob is dying!
- execute as @e[type=marker,tag=death_detector] on vehicle unless data entity @s {DeathTime:0s} on passengers run kill @s
+```mcfunction
+# Command blocks
+execute as @e[type=marker,tag=death_detector] on vehicle unless data entity @s {DeathTime:0s} run say This mob is dying!
+execute as @e[type=marker,tag=death_detector] on vehicle unless data entity @s {DeathTime:0s} on passengers run kill @s
+```
However, this implementation on command blocks may cause lags due to NBT checks every tick, so it is recommended to use a [check delay](/wiki/questions/blockdelay) or use a datapack with [schedule function](https://minecraft.wiki/w/Commands/schedule):
- # function example:load
- function example:loops/1s
-
- # function example:loops/1s
- schedule function example:loops/1s 1s
- execute as @e[type=marker,tag=death_detector] on vehicle unless data entity @s {DeathTime:0s} run function example:death_mob
- execute as @e[type=marker,tag=death_detector,predicate=example:despawn_mob] run function example:despawn_mob
-
- # function example:death_mob
- say Mob is dead!
- execute on passengers run kill @s
-
- # function example:despawn_mob
- say Mob is despawn!
- kill @s
+
+ See example
+
+```mcfunction
+# function example:load
+function example:loops/1s
+
+# function example:loops/1s
+schedule function example:loops/1s 1s
+execute as @e[type=marker,tag=death_detector] on vehicle unless data entity @s {DeathTime:0s} run function example:death_mob
+execute as @e[type=marker,tag=death_detector,predicate=example:despawn_mob] run function example:despawn_mob
+
+# function example:death_mob
+say Mob is dead!
+execute on passengers run kill @s
+
+# function example:despawn_mob
+say Mob is despawn!
+kill @s
+```
+
+
----
@@ -185,32 +215,39 @@ After detecting the death of a mob, it is also necessary to remove the UUID from
Below is an example to check the death of any mob that has the `death_check` tag:
- # function example:load
- function example:loops/1s
-
- # function example:loops/1s
- schedule function example:loops/1s 1s
- execute as @e[tag=death_check,tag=!init] run function example:death_check/init
- data modify storage example:macro death_check set from storage example:database death_check
- function example:death_check/check with storage example:macro death_check[-1]
-
- # function example:death_check/init
- function gu:convert with entity @s
- data remove storage example:data this
- data modify storage example:data this.UUID set from storage gu:main out
- data modify storage example:database death_check append from storage example:data this
- data modify entity @s PersistenceRequired set value true
- tag @s add init
-
- # function example:death_check/check
- $execute as $(UUID) unless data entity @s {DeathTime:0s} at @s run function example:death_check/death_event {UUID:$(UUID)}
- $data remove storage example:macro death_check[{UUID:$(UUID)}]
- function example:death_check/check with storage example:macro death_check[-1]
-
- # function example:death_check/death_event
- $data remove storage example:database death_check[{UUID:$(UUID)}]
- say This mob is dying!
- particle minecraft:soul_fire_flame ~ ~1 ~ 0.5 1 0.5 0.01 100
+
+ See example
+
+```mcfunction
+# function example:load
+function example:loops/1s
+
+# function example:loops/1s
+schedule function example:loops/1s 1s
+execute as @e[tag=death_check,tag=!init] run function example:death_check/init
+data modify storage example:macro death_check set from storage example:database death_check
+function example:death_check/check with storage example:macro death_check[-1]
+
+# function example:death_check/init
+function gu:convert with entity @s
+data remove storage example:data this
+data modify storage example:data this.UUID set from storage gu:main out
+data modify storage example:database death_check append from storage example:data this
+data modify entity @s PersistenceRequired set value true
+tag @s add init
+
+# function example:death_check/check
+$execute as $(UUID) unless data entity @s {DeathTime:0s} at @s run function example:death_check/death_event {UUID:$(UUID)}
+$data remove storage example:macro death_check[{UUID:$(UUID)}]
+function example:death_check/check with storage example:macro death_check[-1]
+
+# function example:death_check/death_event
+$data remove storage example:database death_check[{UUID:$(UUID)}]
+say This mob is dying!
+particle minecraft:soul_fire_flame ~ ~1 ~ 0.5 1 0.5 0.01 100
+```
+
+
**Note:** This method cannot detect mob despawn, so you need to set the `PersistenceRequired:true` tag to prevent despawn.
diff --git a/questions/modifyinventory.md b/questions/modifyinventory.md
index 90936f933..05ff14943 100644
--- a/questions/modifyinventory.md
+++ b/questions/modifyinventory.md
@@ -81,7 +81,7 @@ A shulker box is placed somewhere out of sight of the player. Sometimes far away
This yellow shulker box loot table was designed by Luetzie for Lantern, and is also used by Phi and AESTD. If you use the exact same loot table, you will have no conflicts with these data packs. **It has been established as the standard loot_table for this endeavour by this commands community, and it is highly suggested you use this one!**
-You can download it from here: https://lanternmc.com/yellow_shulker_box.json
+You can download it from here: [https://lanternmc.com/yellow_shulker_box.json](https://lanternmc.com/yellow_shulker_box.json)
### The commands:
@@ -90,19 +90,25 @@ Initialisation
# A shulker box is placed somewhere.
setblock minecraft:yellow_shulker_box
-Editing an item
+Editing an item
- # First, we copy the item to a storage.
- data modify storage lilith:example Item set from entity SelectedItem
-
- # We can now modify what we want about the item here. Its 'Slot' is set to 0.
- data modify storage lilith:example Item merge value {tag: {Enchantments: [{id: "minecraft:knockback", lvl: 1s}]}}
- data modify storage lilith:example Item.Slot set value 0b
-
- # Third, we copy the storage item to the shulker box. Because 'Slot' is 0, the item will be in the first slot.
- data modify block Items append from storage lilith:example Item
+
+ See example
- # Then, we move the shulker box item back to the player's inventory.
- loot replace entity weapon.mainhand 1 mine minecraft:air{drop_contents: 1b}
+```mcfunction
+# First, we copy the item to a storage.
+data modify storage lilith:example Item set from entity SelectedItem
+
+# We can now modify what we want about the item here. Its 'Slot' is set to 0.
+data modify storage lilith:example Item merge value {tag: {Enchantments: [{id: "minecraft:knockback", lvl: 1s}]}}
+data modify storage lilith:example Item.Slot set value 0b
+
+# Third, we copy the storage item to the shulker box. Because 'Slot' is 0, the item will be in the first slot.
+data modify block Items append from storage lilith:example Item
+
+# Then, we move the shulker box item back to the player's inventory.
+loot replace entity weapon.mainhand 1 mine minecraft:air{drop_contents: 1b}
+```
+
_Credit to Lilith on our Discord for writing this explanation and posting it into the #resources channel on there._
diff --git a/questions/movetoscore.md b/questions/movetoscore.md
index c60529e0d..3ab05a0c5 100644
--- a/questions/movetoscore.md
+++ b/questions/movetoscore.md
@@ -1,60 +1,76 @@
## Summon an entity at the position set in a score
-> [!NOTE]
-> This article is about Java Edition, except for binary teleport, found at the end of the article.
+| 📝 Note |
+|---------|
+|This article is about Java Edition, except for binary teleport, found at the end of the article, that will work in bedrock too|
-> [!IMPORTANT]
-> If the coordinate is inside a block and below it there isn't a solid block, the entity will clip trought and fall, this is common if you are storing the scoreboard value by storing the `Pos` value, when the player is not in a full block (for example a slab)
+| ⚠️ Important |
+|--------------|
+|If the coordinate is inside a block and below it there isn't a solid block, the entity will clip trought and fall, this is common if you are storing the scoreboard value by storing the `Pos` value, when the player is not in a full block (for example a slab)|
+
+If you want to store the position of the player see this [transfer nbt to score](wiki/questions/nbttransfer)
Since version 1.20.2 you can summon the entity directly at the position of the score using a [macro](https://minecraft.wiki/w/Function_(Java_Edition)#Macros) in the datapack. If you are using an earlier version, or do not use a datapack, then you cannot summon the entity directly at the position of the score, instead you have to summon the entity and then teleport it to your desired position.
Below is an example of summoning a pig according to the set value in the scoreboard:
- # Setup
- scoreboard objectives add pos dummy
- scoreboard players set X pos 10
- scoreboard players set Y pos 64
- scoreboard players set Z pos 10
- function example:summon/pig
-
- # function example:summon/pig
- execute store result storage example:macro pos.x int 1 run scoreboard players get X pos
- execute store result storage example:macro pos.y int 1 run scoreboard players get Y pos
- execute store result storage example:macro pos.z int 1 run scoreboard players get Z pos
- function example:summon/pig_macro with storage example:macro pos
-
- # function example:summon/pig_macro
- $summon minecraft:pig $(x) $(y) $(z) {Tags:["custom_pig"]}
- $particle minecraft:happy_villager $(x) $(y) $(z) 0.5 0.5 0.5 0 200
- $tellraw @a "Pig summoning at $(x) $(y) $(z)"
+
+ See example
+
+```mcfunction
+# Setup
+scoreboard objectives add pos dummy
+scoreboard players set X pos 10
+scoreboard players set Y pos 64
+scoreboard players set Z pos 10
+function example:summon/pig
+
+# function example:summon/pig
+execute store result storage example:macro pos.x int 1 run scoreboard players get X pos
+execute store result storage example:macro pos.y int 1 run scoreboard players get Y pos
+execute store result storage example:macro pos.z int 1 run scoreboard players get Z pos
+function example:summon/pig_macro with storage example:macro pos
+
+# function example:summon/pig_macro
+$summon minecraft:pig $(x) $(y) $(z) {Tags:["custom_pig"]}
+$particle minecraft:happy_villager $(x) $(y) $(z) 0.5 0.5 0.5 0 200
+$tellraw @a "Pig summoning at $(x) $(y) $(z)"
+```
+
**Note: You cannot use macro data in the same function in which you set data for the macro command. You should always run a separate function to execute the macro command.**
-The macro allows you to insert any numeric or text data into any part of the command, however, before using these values in the command you need to set this data in storage, read the data from the entity / block, or you can manually set the values when running the function. Below is an example:
+The macro allows you to insert any numeric or text data into any part of the command; however, before using these values in the command you need to set this data in storage, read the data from the entity / block, or you can manually set the values when running the function. Below is an example:
- # In chat
- function example:macro_summon {id:"minecraft:pig",x:25.5d, y:65.5d, z:-15.5d}
+```mcfunction
+# In chat
+function example:macro_summon {id:"minecraft:pig",x:25.5d, y:65.5d, z:-15.5d}
- # function example:macro_summon
- $summon $(id) $(x) $(y) $(z)
+# function example:macro_summon
+$summon $(id) $(x) $(y) $(z)
+```
## Teleport an entity to the position set in a score
Assuming your desired position is stored in the entity's posX, posY and posZ value, you can just run `execute store` to save the score into the Position like this:
- execute store result entity @s Pos[0] double 1 run scoreboard players get @s posX
- execute store result entity @s Pos[1] double 1 run scoreboard players get @s posY
- execute store result entity @s Pos[2] double 1 run scoreboard players get @s posZ
+```mcfunction
+execute store result entity @s Pos[0] double 1 run scoreboard players get @s posX
+execute store result entity @s Pos[1] double 1 run scoreboard players get @s posY
+execute store result entity @s Pos[2] double 1 run scoreboard players get @s posZ
+```
**Be aware that if the entity enters unloaded chunks at any point during this operation, it might not continue to work, especially if you're not using a function to do this**. So if your X moves the entity out of the loaded chunks, the Y and Z won't be applied anymore. If you're running the commands from above in a function you'll be fine, as we don't need to re-find the entity because we're using the `@s` selector.
But you can easily avoid unloading the entity if you do not change each axis separately, but first do it in storage and then copy the ready `Pos` tag from storage to the entity data:
- data merge storage example:data {Pos:[0d,0d,0d]}
- execute store result storage example:data Pos[0] double 1 run scoreboard players get @s posX
- execute store result storage example:data Pos[1] double 1 run scoreboard players get @s posY
- execute store result storage example:data Pos[2] double 1 run scoreboard players get @s posZ
- data modify entity @s Pos set from storage example:data Pos
+```mcfunction
+data merge storage example:data {Pos:[0d,0d,0d]}
+execute store result storage example:data Pos[0] double 1 run scoreboard players get @s posX
+execute store result storage example:data Pos[1] double 1 run scoreboard players get @s posY
+execute store result storage example:data Pos[2] double 1 run scoreboard players get @s posZ
+data modify entity @s Pos set from storage example:data Pos
+```
## Teleport the player to the position set in a score
@@ -64,25 +80,31 @@ The problem with the player is that the player NBT data cannot be modified and t
Since version 1.20.2 you can also use the [macro](https://minecraft.wiki/w/Function_(Java_Edition)#Macros) to teleport to specified coordinates. Here is an example of running a macro function with data from `storage example:macro pos`:
- execute store result storage example:macro pos.x int 1 run scoreboard players get X pos
- execute store result storage example:macro pos.y int 1 run scoreboard players get Y pos
- execute store result storage example:macro pos.z int 1 run scoreboard players get Z pos
- function example:tp/macro with storage example:macro pos
-
- # function example:tp/macro
- $tp @s $(x) $(y) $(z)
-
-**Note:** A macro cannot be read from a List/Array, but only from an object. Therefore, if you received a list (like Pos tag) as a tag for teleportation, you must convert this into objects:
-
- # Example input pos as List
- data merge storage example:data {Pos:[25d,100d,65d]}
- function example:tp/convert
-
- # function example:tp/convert
- data modify storage example:macro pos.x set from storage example:data Pos[0]
- data modify storage example:macro pos.y set from storage example:data Pos[1]
- data modify storage example:macro pos.z set from storage example:data Pos[2]
- function example:tp/macro with storage example:macro pos
+```mcfunction
+execute store result storage example:macro pos.x int 1 run scoreboard players get X pos
+execute store result storage example:macro pos.y int 1 run scoreboard players get Y pos
+execute store result storage example:macro pos.z int 1 run scoreboard players get Z pos
+function example:tp/macro with storage example:macro pos
+
+# function example:tp/macro
+$tp @s $(x) $(y) $(z)
+```
+
+| 📝 Note |
+|---------|
+|A macro cannot be read from a List/Array, but only from an object. Therefore, if you received a list (like `Pos` tag) as a tag for teleportation, you must convert this into objects|
+
+```mcfunction
+# Example input pos as List
+data merge storage example:data {Pos:[25d,100d,65d]}
+function example:tp/convert
+
+# function example:tp/convert
+data modify storage example:macro pos.x set from storage example:data Pos[0]
+data modify storage example:macro pos.y set from storage example:data Pos[1]
+data modify storage example:macro pos.z set from storage example:data Pos[2]
+function example:tp/macro with storage example:macro pos
+```
### 2: End Gateways
@@ -90,23 +112,27 @@ You can use end gateways to teleport the players to an exact location, see [this
Basically you can set its block NBT Data to `ExactTeleport:1b,ExitPortal:{X:1,Y:2,X:3}` using `data merge block` or `execute store` and then teleport the player into said portal. Thanks to `execute store` you can set the Exit Portal NBT dynamically:
- # 1.13 - 1.20.4
- setblock 0 5 0 minecraft:end_gateway{ExactTeleport:1b,ExitPortal:{X:0,Y:0,Z:0},Age:-9223372036854775808L}
- execute store result block 0 5 0 ExitPortal.X int 1 run scoreboard players get @s MapX
- execute store result block 0 5 0 ExitPortal.Y int 1 run scoreboard players get @s MapY
- execute store result block 0 5 0 ExitPortal.Z int 1 run scoreboard players get @s MapZ
- tp @s 0 5 0
+```mcfunction
+# 1.13 - 1.20.4
+setblock 0 5 0 minecraft:end_gateway{ExactTeleport:1b,ExitPortal:{X:0,Y:0,Z:0},Age:-9223372036854775808L}
+execute store result block 0 5 0 ExitPortal.X int 1 run scoreboard players get @s MapX
+execute store result block 0 5 0 ExitPortal.Y int 1 run scoreboard players get @s MapY
+execute store result block 0 5 0 ExitPortal.Z int 1 run scoreboard players get @s MapZ
+tp @s 0 5 0
+```
Make sure the position you're using for the endgateway is in the loaded chunks. _If the `Age` tag is not set to a negative number, then End Gateways sometimes shoot out beacon beams, especially when they are newly created, so you might want to set the portal once and not every time you need it._
Since version 1.20.5, the `ExitPortal` Compound tag has been replaced by the [Int Array](https://minecraft.wiki/w/NBT_format#Data_types) `exit_portal` tag (not a List).
- # 1.20.5+
- setblock 0 5 0 minecraft:end_gateway{ExactTeleport:1b,exit_portal:[I;0,0,0],Age:-9223372036854775808L}
- execute store result block 0 5 0 exit_portal[0] int 1 run scoreboard players get @s MapX
- execute store result block 0 5 0 exit_portal[1] int 1 run scoreboard players get @s MapY
- execute store result block 0 5 0 exit_portal[2] int 1 run scoreboard players get @s MapZ
- tp @s 0 5 0
+```mcfunction
+# 1.20.5+
+setblock 0 5 0 minecraft:end_gateway{ExactTeleport:1b,exit_portal:[I;0,0,0],Age:-9223372036854775808L}
+execute store result block 0 5 0 exit_portal[0] int 1 run scoreboard players get @s MapX
+execute store result block 0 5 0 exit_portal[1] int 1 run scoreboard players get @s MapY
+execute store result block 0 5 0 exit_portal[2] int 1 run scoreboard players get @s MapZ
+tp @s 0 5 0
+```
### 3: Use an entity
@@ -115,23 +141,30 @@ See [u/SanianCreations](https://www.reddit.com/u/SanianCreations) post about thi
### 4: Binary Teleportation
-> [!NOTE]
-> This method works with bedrock too
-
-You basically copy their score to some temporary score so you don't loose it when you modify it, and then you go through the different powers of 2 (hence the name), check if their score is above that and then teleport them relatively that far.
-
- execute as @a unless score @s xTmp matches 0 if score @s xTmp = @s xTmp run teleport @s 0 0 0
-
- execute as @a[scores={xTmp=128..}] at @s run tp @s ~128 ~ ~
- scoreboard players remove @a[scores={xTmp=128..}] xTmp 128
-
- execute as @a[scores={xTmp=64..}] at @s run tp @s ~64 ~ ~
- scoreboard players remove @a[scores={xTmp=64..}] xTmp 64
-
- execute as @a[scores={xTmp=32..}] at @s run tp @s ~32 ~ ~
- scoreboard players remove @a[scores={xTmp=32..}] xTmp 32
-
- ....
- all the way down to 1, repeat for all 3 coordinates
+| 📝 Note |
+|---------|
+|This method works in bedrock too|
+
+You basically copy their score to some temporary score so you don't lose it when you modify it, and then you go through the different powers of 2 (hence the name), check if their score is above that and then teleport them relatively that far.
+
+
+ See example
+
+```mcfunction
+execute as @a unless score @s xTmp matches 0 if score @s xTmp = @s xTmp run teleport @s 0 0 0
+
+execute as @a[scores={xTmp=128..}] at @s run tp @s ~128 ~ ~
+scoreboard players remove @a[scores={xTmp=128..}] xTmp 128
+
+execute as @a[scores={xTmp=64..}] at @s run tp @s ~64 ~ ~
+scoreboard players remove @a[scores={xTmp=64..}] xTmp 64
+
+execute as @a[scores={xTmp=32..}] at @s run tp @s ~32 ~ ~
+scoreboard players remove @a[scores={xTmp=32..}] xTmp 32
+
+....
+all the way down to 1, repeat for all 3 coordinates
+```
+
This does use a lot of commands but using a function it's fairly easy to do and you can go as high as you want. Always start with the highest power of 2.
diff --git a/questions/multipletags.md b/questions/multipletags.md
index 3e028a69d..c1be912e3 100644
--- a/questions/multipletags.md
+++ b/questions/multipletags.md
@@ -2,24 +2,30 @@
In 1.12 and below, you're unable to specify multiple selector arguments of the same key directly in a single selector. For example, `@e[tag=A,tag=B,tag=C]` ignores the first two arguments and acts the same as `@e[tag=c]`, regardless of whether the entity has tags `a` or `b`.
-**In 1.13, you are able to specify multiple specify multiple tags in a selector** making this tutorial irrelevant.
+**In 1.13, you are able to specify multiple tags in a selector**, making this tutorial irrelevant.
## Method 1: Nested `@s` execute (1.12 and above)
With the `@s` ("self") selector and nested executes, you can target one tag on each layer, so that the command at the end is only run if all tags are present. For example, to kill someone with all tags A-E:
- execute @a[tag=A] ~ ~ ~ execute @s[tag=B] ~ ~ ~ execute @s[tag=C] ~ ~ ~ execute @s[tag=D] ~ ~ ~ kill @s[tag=E]
+```mcfunction
+execute @a[tag=A] ~ ~ ~ execute @s[tag=B] ~ ~ ~ execute @s[tag=C] ~ ~ ~ execute @s[tag=D] ~ ~ ~ kill @s[tag=E]
+```
## Method 2: NBT tag checking
Scoreboard tags are stored in NBT as a `Tags` list. With NBT, you *can* test for multiple tags. What you can do to get around this problem then is adding a "master" tag based on their NBT data if they have all of the other tags:
- scoreboard players tag @e add HasAllTags {Tags:["A","B","C"]}
+```mcfunction
+scoreboard players tag @e add HasAllTags {Tags:["A","B","C"]}
+```
Then, you can select them with `@e[tag=HasAllTags]`.
To optimize how this performs, you can specify the least common tag in the `@e` selector, for example:
- scoreboard players tag @e[tag=A] add HasAllTags {Tags:["B","C"]}
+```mcfunction
+scoreboard players tag @e[tag=A] add HasAllTags {Tags:["B","C"]}
+```
This means that less entities will need to have their NBT checked.
\ No newline at end of file
diff --git a/questions/nbttransfer.md b/questions/nbttransfer.md
index e1f115f89..f0019be2f 100644
--- a/questions/nbttransfer.md
+++ b/questions/nbttransfer.md
@@ -6,26 +6,36 @@ Any **numeric** NBT tag, even inside lists, can be set to, or gotten into, a sco
The `/data get` command allows you to specify a block or entity, and retrieve NBT data from it. For example:
- data get entity @s
+```mcfunction
+data get entity @s
+```
Rather than printing out all data, you can specify a "path" to get one specific tag, like so:
- data get entity @s Pos[0]
+```mcfunction
+data get entity @s Pos[0]
+```
-Pos[0] means the first (indexes counting from 0) element of the `Pos` list, so the x coordinate (you can access tags inside of compounds as `compound.tag`).
+Pos[0] means the first (indexes counting from 0) element of the `Pos` list, so the x coordinate (you can access tags inside of compounds as `compound.tag`).
-This is cast into an integer, meaining if you are at `x=73.1031`, the command's result will be just `73`.
+This is cast into an integer, meaning if you are at `x=73.1031`, the command's result will be just `73`.
The optional `[]` factor lets you multiply the number by something before it's read to an integer, for more accuracy. For example, the following would have the result `7310` (100*x):
- data get entity @s Pos[0] 100
+```mcfunction
+data get entity @s Pos[0] 100
+```
Next we need to store the value of `/data get`'s result into a scoreboard objective, which is exactly what `/execute store` allows us to do:
- execute store result score run
+```mcfunction
+execute store result score run
+```
This will run ``, and store the result into the the ``'s `` score. So, putting it together, you could do something like this:
- execute store result score @s y_pos run data get entity @s Pos[1] 100
+```mcfunction
+execute store result score @s y_pos run data get entity @s Pos[1] 100
+```
Which will store 100 times the executer's y position into their `y_pos` score.
@@ -33,8 +43,10 @@ Which will store 100 times the executer's y position into their `y_pos` score.
Using NBT paths mentioned in the previous section, `/execute store` will also allow us to store the result of a command into any numeric NBT tag (other than players, you still can't edit player data). The syntax is:
- execute store result entity (byte|double|float|int|long|short) run
- execute store result block (byte|double|float|int|long|short) run
+```mcfunction
+execute store result entity (byte|double|float|int|long|short) run
+execute store result block (byte|double|float|int|long|short) run
+```
The `` you'll want to run is `/scoreboard players get `, which returns a specified score as its result.
@@ -44,7 +56,9 @@ The `` you'll want to run is `/scoreboard players get NBT
@@ -52,4 +66,6 @@ You can even store directly from an NBT path to another NBT path. Keep in mind t
For example, to have the nearest pig copy the nearest chicken's x-pos:
- execute store result entity @e[type=pig,limit=1,sort=nearest] Pos[0] double 0.01 run data get entity @e[type=chicken,limit=1,sort=nearest] Pos[0] 100
\ No newline at end of file
+```mcfunction
+execute store result entity @e[type=pig,limit=1,sort=nearest] Pos[0] double 0.01 run data get entity @e[type=chicken,limit=1,sort=nearest] Pos[0] 100
+```
\ No newline at end of file
diff --git a/questions/npc.md b/questions/npc.md
index 69167fedc..7b119fcc5 100644
--- a/questions/npc.md
+++ b/questions/npc.md
@@ -1,17 +1,20 @@
# How to create / customize an NPC?
This article will explain how to create NPCs and add commands to it.
-> [!NOTE]
-> This is for the entity in Bedrock edition called [`NPC`](https://minecraft.wiki/w/NPC)
+| 📝 Note |
+|---------|
+|This is for the entity in Bedrock edition called [`NPC`](https://minecraft.wiki/w/NPC)|
## Basics of an NPC
For spawning an NPC, you will need to use the `/summmon` or `/give` command:
- /summon npc
- /give @s spawn_egg 1 51
+```mcfunction
+/summon npc
+/give @s spawn_egg 1 51
+```
-For removing the NPC just left click it while you are in creative, or use the `/kill` command.
+For removing the NPC just left-click it while you are in creative, or use the `/kill` command.
A NPC is invulnerable if you try to kill it with other methods (unless when falling into the void), but it can be moved with water, lava, breeze's wind charges, explosions or pistons.
To edit an NPC right click it in creative, you will open a GUI that allows you to edit the display name and the skin.
@@ -19,10 +22,10 @@ To edit an NPC right click it in creative, you will open a GUI that allows you t
The NPC will be staring at the nearest player that is not in spectator, if it’s in a 6 block radius.
## Dialogues and commands
-> [!NOTE]
-> You can find useful information in [Wiki Bedrock Dev](https://wiki.bedrock.dev/entities/npc-dialogs.html).
->
-> You can use [this tool](https://jannisx11.github.io/dialogue-designer/) by [jannisx11](https://github.com/jannisx11) to add dialogue and commands easily.
+| 📝 Note |
+|---------|
+|You can find useful information in [Wiki Bedrock Dev](https://wiki.bedrock.dev/entities/npc-dialogs.html)|
+|You can use [this tool](https://jannisx11.github.io/dialogue-designer/) by [jannisx11](https://github.com/jannisx11) to add dialogue and commands easily|
When you interact with the NPC in creative, you will find a button called `Edit Dialog`. When you click it, you will be able to edit the dialogue. The maximum of characters you can have is 307.
You can **not** use target selectors in the dialog, for example, if the dialog is `@p`, the dialog will be `@p`, not the nearest player.
@@ -47,19 +50,23 @@ This is done thanks to the `/dialogue` command, that opens NPC dialogues.
First NPC (The one player will interact with), with the dialog “Do you want a challenge?”
- # Button mode with the text “Yes”
- dialogue open @e[tag=npc.confirm,type=npc] @initiator
-
- # Button mode with the text “No”
- # This is empty as when pressing any button, the NPC dialogue will close.
+```mcfunction
+# Button mode with the text “Yes”
+dialogue open @e[tag=npc.confirm,type=npc] @initiator
+
+# Button mode with the text “No”
+# This is empty, as when pressing any button, the NPC dialogue will close.
+```
Now we will hide a second NPC underground (so player will **not** see it) with the tag `npc.confirm`, With the dialogue “Are you sure?”
- # Button mode with the text “Yes”
- execute at @initiator run summon zombie
- say here is your challenge
+```mcfunction
+# Button mode with the text “Yes”
+execute at @initiator run summon zombie
+say here is your challenge
- # Button mode with the text “No”
- # This is empty as when pressing any button, the NPC dialogue will close.
+# Button mode with the text “No”
+# This is empty, as when pressing any button, the NPC dialogue will close.
+```
-And now you have a dialog that will pop up when you press a button. You can add more dialogues with more NPCs, but each one needs a different tag to identify it.
+And now you have a dialog that will pop up when you press a button. You can add more dialogues with more NPCs, but each one needs a different tag to identify it.
\ No newline at end of file
diff --git a/questions/numplayers.md b/questions/numplayers.md
index a131714b5..d9d56c2c6 100644
--- a/questions/numplayers.md
+++ b/questions/numplayers.md
@@ -1,35 +1,41 @@
-# Check if there are exactly X players matching a selector
+# Check if there are exactly X players (or entities) matching a selector?
For example, you want to check if a team has exactly 2 players.
-> [!NOTE]
-> if a selector such as `@a[team=red]` selects `Alice, Bob, Carol, Dave`, then `@a[team=red,limit=2]` will select `Alice, Bob` and run the command on those players. `limit=2` does not mean *"only run if there are 2 players"*, but rather *"limit the players selected to at most 2"*. (Same for `c` in bedrock).
+| 📝 Note |
+|---------|
+|if a selector such as `@a[team=red]` selects `Alice, Bob, Carol, Dave`, then `@a[team=red,limit=2]` will select `Alice, Bob` and run the command on those players. `limit=2` does not mean *"only run if there are 2 players"*, but rather *"limit the players selected to at most 2"*. (Same for `c` in bedrock).|
A command will still run (and potentially succeed once) even if `@a[team=red,limit=2]` only finds one player, and succeeding once is all that is needed for conditional blocks coming off of the command block to run.
## Java and Bedrock
-> [!NOTE]
-> This method will work in Java too, but its recomended to use the Java exclusive method
+| 📝 Note |
+|---------|
+|This method will work in Java too, but it's recommended to use the Java exclusive method|
-The easiest way to do this in bedrock is to have the found entities count up the score of another entity or a [fake player](/wiki/questions/fakeplayer) (the later is currently a little harder to check for their score, so it is not used in this tutorial).
+The easiest way to do this in bedrock is to have the found entities count up the score of another entity or a [fake player](/wiki/questions/fakeplayer) (the latter is currently a little harder to check for their score, so it is not used in this tutorial).
Using a dummy scoreboard objective named `result` and an entity with the `counter` tag, we can count how many players there are in team red:
- scoreboard players set @e[tag=counter] result 0
- execute as @a[team=red] run scoreboard players add @e[tag=counter] result 1
- execute as @e[tag=counter,scores={result=2}] run say there are exactly 2 people on the red team
+```mcfunction
+scoreboard players set @e[tag=counter] result 0
+execute as @a[team=red] run scoreboard players add @e[tag=counter] result 1
+execute as @e[tag=counter,scores={result=2}] run say there are exactly 2 people on the red team
+```
You can also use [ranges](wiki/questions/ranges)
- execute as @e[tag=counter,scores={result=2..}] run say there are 2 or more people on the red team
- execute as @e[tag=counter,scores={result=..2}] run say there are 2 or less people on the red team
- execute as @e[tag=counter,scores={result=2..9}] run say there are between 2 and 9 people on the red team
-
+```mcfunction
+execute as @e[tag=counter,scores={result=2..}] run say there are 2 or more people on the red team
+execute as @e[tag=counter,scores={result=..2}] run say there are 2 or less people on the red team
+execute as @e[tag=counter,scores={result=2..9}] run say there are between 2 and 9 people on the red team
+```
## Bedrock
-> [!NOTE]
-> It is not recomended to use this method
+| 📝 Note |
+|---------|
+|It is not recommended to use this method|
-You can use a comparator with the `/testfor` command, the output, in signal strengh, is the same as the number of online players.
+You can use a comparator with the `/testfor` command, the output, in signal strength, is the same as the number of online players.
## Java
@@ -38,39 +44,48 @@ You can use a comparator with the `/testfor` command, the output, in signal stre
Introduced in 1.13 and replacing the `/stats` command, the `store` subcommand of `execute` is able to store the result of the command after it in multiple ways, including into a scoreboard.
Using a dummy scoreboard objective name `result` and the [fake player](/wiki/questions/fakeplayer) `#count`, we can count the amount of entities a command finds and then execute off of that. Note that we can use [ranges](wiki/questions/ranges)
- execute store result score #count result if entity @a[team=red]
- execute if score #count result matches 2 run say there are exactly 2 players on team red.
-
-The fake player can be replaced by an entity, which then changes the second command to
+```mcfunction
+execute store result score #count result if entity @a[team=red]
+execute if score #count result matches 2 run say there are exactly 2 players on team red.
+```
- execute if entity @e[,scores={result=2}] run say there are exactly 2 players on team red.
+The fake player can be replaced by an entity, although it is not recommended, which then changes the second command to
+```mcfunction
+execute if entity @e[,scores={result=2}] run say there are exactly 2 players on team red.
+```
It also works with [ranges](wiki/questions/ranges)
- execute if score #count result matches 2.. run say there are 2 or more players on team red.
- execute if score #count result matches ..2 run say there are 2 or less players on team red.
+```mcfunction
+execute if score #count result matches 2.. run say there are 2 or more players on team red.
+execute if score #count result matches ..2 run say there are 2 or less players on team red.
+```
### Method 2: Checking the command block's `SuccessCount`
-> [!NOTE]
-> This method is outdated and should not be used in current versions of the game.
-> For the sake of allowing users of 1.12 and below to access this for them still useful information, it is kept around.
+| 📝 Note |
+|---------|
+|This method is outdated and should not be used in current versions of the game|
+|For the sake of allowing users of 1.12 and below to access this for them still useful information, it is kept around|
When a `/testfor` command is run, the command block's `SuccessCount` NBT tag will be set equal to the number of entities that the selector found. You can then use a `/testforblock` command in another block to check whether the first command block's `SuccessCount` is a certain number.
For example, this will test for *exactly* 2 players on the red team (no more, no less):
- testfor @a[team=red]
- testforblock X Y Z command_block -1 {SuccessCount:2}
+```mcfunction
+testfor @a[team=red]
+testforblock command_block -1 {SuccessCount:2}
+```
-Change `X Y Z` in the second command block to the coordinates of the first command block. You may also need to change `command_block` to `chain_command_block` or `repeating_command_block`.
+Change ` ` in the second command block to the coordinates of the first command block. You may also need to change `command_block` to `chain_command_block` or `repeating_command_block`.
-The second command will only succeed if the first command has a SuccessCount of 1 (it found exactly 1 player). You can then run a conditional chain block off of that second command to activate whatever you want to happen when there are exactly 1 player:
+The second command will only succeed if the first command has a SuccessCount of 1 (it found exactly 1 player). You can then run a conditional chain block off of that second command to activate whatever you want to happen when there is exactly 1 player:
### Method 3: With `/stats` (1.8-1.12)
-> [!NOTE]
-> This method is outdated and can not be used in current versions of the game.
+| 📝 Note |
+|---------|
+|This method is outdated and can not be used in current versions of the game|
Stats are harder to understand and set up, but gives you more flexibility (works in functions, can test a range rather than exact values, can test things other than SuccessCount). If you have not used `/stats` in the past, you will need to watch/read a tutorial (or multiple) and play around with them until you are confident in its usage. Then:
diff --git a/questions/playerdeaths.md b/questions/playerdeaths.md
index e3759425b..7430c42f1 100644
--- a/questions/playerdeaths.md
+++ b/questions/playerdeaths.md
@@ -2,78 +2,104 @@
_Related: [Detect Player Kills](/wiki/questions/playerkills)_
+* [Java](#java)
+* [Bedrock](#bedrock)
+
## Java
### Just death check
In Java, detecting a dead player is relatively easy. For simple death detection you can use [`deathCount`](https://minecraft.wiki/w/Scoreboard#Single_criteria) / [`custom:deaths`](https://minecraft.wiki/w/Statistics#List_of_custom_statistic_names) scoreboard criteria and whenever that one increases, the player just died (and is likely still dead).
- # In chat / load function
- scoreboard objectives add death deathCount
-
- # Command blocks / tick function
- execute as @a[scores={death=1..}] run say Death!
- scoreboard players reset @a death
+```mcfunction
+# In chat / load function
+scoreboard objectives add death deathCount
+
+# Command blocks / tick function
+execute as @a[scores={death=1..}] run say Death!
+scoreboard players reset @a death
+```
### Run command at death position
-To do this you can use the method described above, but if gamerule `doImmediateRespawn` is true, then the commands from the example above will actually be executed after respawn, which can be a problem if you want to do something at the player's death position.
+To do this, you can use the method described above, but if gamerule `doImmediateRespawn` is true, then the commands from the example above will actually be executed after respawn, which can be a problem if you want to do something at the player's death position.
If you are limited to using command blocks, then you can read the [player data](https://minecraft.wiki/w/Player.dat_format) `LastDeathLocation` tag (1.19+) to get dimension (`dimension`) and position (`pos`). But since the `LastDeathLocation.pos` tag is an Int Array, but the Pos tag entity is a list, you need to first convert the Int Array to a Double list. Then check the `LastDeathLocation.dimension` in which dimension the player died and set this dimension [`execute in `](https://minecraft.wiki/w/Commands/execute#in), summon area_effect_cloud and move to the death position and in the same tick execute the command on the position of this area_effect_cloud entity.
Below is an example for 1.19.4 and above versions:
- # Setup
- data merge storage example:data {pos:{list:[0d,0d,0d],int_array:[I;0,0,0]}}
+
+ See example
+
+```mcfunction
+# Setup
+data merge storage example:data {pos:{list:[0d,0d,0d],int_array:[I;0,0,0]}}
+
+# Command blocks
+data modify storage example:data pos.int_array set from entity @a[scores={death=1..},limit=1] LastDeathLocation.pos
+execute store result storage example:data pos.list[0] double 1 run data get storage example:data pos.int_array[0]
+execute store result storage example:data pos.list[1] double 1 run data get storage example:data pos.int_array[1]
+execute store result storage example:data pos.list[2] double 1 run data get storage example:data pos.int_array[2]
+execute if data entity @a[scores={death=1..},limit=1] LastDeathLocation{dimension:"minecraft:overworld"} in minecraft:overworld summon area_effect_cloud store success score @s death run data modify entity @s Pos set from storage example:data pos.list
+...
+execute at @e[type=area_effect_cloud,scores={death=1}] run summon zombie ~ ~ ~ {PersistenceRequired:true,CanPickUpLoot:true}
+scoreboard players reset @a[scores={death=1..},limit=1] death
+```
- # Command blocks
- data modify storage example:data pos.int_array set from entity @a[scores={death=1..},limit=1] LastDeathLocation.pos
- execute store result storage example:data pos.list[0] double 1 run data get storage example:data pos.int_array[0]
- execute store result storage example:data pos.list[1] double 1 run data get storage example:data pos.int_array[1]
- execute store result storage example:data pos.list[2] double 1 run data get storage example:data pos.int_array[2]
- execute if data entity @a[scores={death=1..},limit=1] LastDeathLocation{dimension:"minecraft:overworld"} in minecraft:overworld summon area_effect_cloud store success score @s death run data modify entity @s Pos set from storage example:data pos.list
- ...
- execute at @e[type=area_effect_cloud,scores={death=1}] run summon zombie ~ ~ ~ {PersistenceRequired:true,CanPickUpLoot:true}
- scoreboard players reset @a[scores={death=1..},limit=1] death
+
This method requires reading data for each dimension in the world in a separate command block.
Using a datapack will make executing any command in the death position much easier. This method is based on the fact that the [advancement trigger](https://minecraft.wiki/w/Advancement/JSON_format) `minecraft:entity_hurt_player` does not depend on the tick schedule, but on events, so this trigger is executed before the player is respawned, and even before the scoreboard is updated, so score health will not work, but only the NBT check player data:
- # advancement example:death
- {
- "criteria": {
- "requirement": {
- "trigger": "minecraft:entity_hurt_player",
- "conditions": {
- "player": [
- {
- "condition": "minecraft:entity_properties",
- "entity": "this",
- "predicate": {
- "nbt": "{Health:0f}"
- }
- }
- ]
+
+ See example
+
+```json
+# advancement example:death
+{
+ "criteria": {
+ "requirement": {
+ "trigger": "minecraft:entity_hurt_player",
+ "conditions": {
+ "player": [
+ {
+ "condition": "minecraft:entity_properties",
+ "entity": "this",
+ "predicate": {
+ "nbt": "{Health:0f}"
+ }
}
- }
- },
- "rewards": {
- "function": "example:death"
+ ]
}
}
-
- # function example:death
- advancement revoke @s only example:death
- summon zombie ~ ~ ~ {PersistenceRequired:true,CanPickUpLoot:true}
+ },
+ "rewards": {
+ "function": "example:death"
+ }
+}
+```
+```mcfunction
+# function example:death
+advancement revoke @s only example:death
+summon zombie ~ ~ ~ {PersistenceRequired:true,CanPickUpLoot:true}
+```
+
+
+
+You can also use a loot table to drop items in player death, located in `data/minecraft/loot_table/entities/player.json`.
+
+### Run a command when the player respawns
Likewise, using `minecraft.custom:minecraft.time_since_death` you can detect a player who just respawned, since this objective will stay 0 during the death screen and start counting up the moment the player clicks "Respawn".
- # Setup
- scoreboard objectives add respawn custom:time_since_death
-
- # Command blocks / tick function
- execute as @a[scores={respawn=1}] run say I just respawned!
+```mcfunction
+# Setup
+scoreboard objectives add respawn custom:time_since_death
+
+# Command blocks / tick function
+execute as @a[scores={respawn=1}] run say I just respawned!
+```
## Bedrock
@@ -81,16 +107,18 @@ In Bedrock the same question is more difficult to answer, since at the time of w
The best way to do this in bedrock is with the following commands, in this order:
- /tag @a add dead
- /tag @e[type=player] remove dead
- /scoreboard players add @a[tag=dead,tag=!still_dead] deathCount 1
- /tag @a add still_dead
- /tag @e[type=player] remove still_dead
+```mcfunction
+/tag @a add dead
+/tag @e[type=player] remove dead
+/scoreboard players add @a[tag=dead,tag=!still_dead] deathCount 1
+/tag @a add still_dead
+/tag @e[type=player] remove still_dead
+```
Set up a dummy scoreboard called `deathCount` and it will count up every time a player dies.
This works because the `@a` selector selects all players, but the `@e` selector can only select living entities. You can find more information on [the Bedrock wiki](https://wiki.bedrock.dev/commands/on-player-death.html#top).
-_This system was first suggested on the subreddit by /u/Sprunkles137 [here](https://old.reddit.com/r/MinecraftCommands/comments/g5b4n8/challenge_1/fo3p5p0/)._
+_This system was first suggested on the Subreddit by /u/Sprunkles137 [here](https://old.reddit.com/r/MinecraftCommands/comments/g5b4n8/challenge_1/fo3p5p0/)._
-There is a different way as well, which can only be used in a very controlled environment where players cannot set their own spawnpoints with beds but all spawning is controlled by the mapmaker. This way you can set everyone's spawnpoint to an otherwise inaccessible position in the world, then detect players respawning there, count up their death score and teleport them to the "actual" spawnpoint. **It is not advised to use this system anymore, as the first system is easier to do, requires less setup and has a wider range of applicable possibilities!**
+There is a different way as well, which can only be used in a very controlled environment where players cannot set their own spawnpoints with beds, but all spawning is controlled by the mapmaker. This way you can set everyone's spawnpoint to an otherwise inaccessible position in the world, then detect players respawning there, count up their death score, and teleport them to the "actual" spawnpoint. **It is not advised to use this system anymore, as the first system is easier to do, requires less setup and has a wider range of applicable possibilities!**
diff --git a/questions/playerjoin.md b/questions/playerjoin.md
index 50fa4bd1c..74935155f 100644
--- a/questions/playerjoin.md
+++ b/questions/playerjoin.md
@@ -1,32 +1,42 @@
# Detect a player joining
+* [Java](#java)
+* [Bedrock](#bedrock)
+
For this, we'll have to differentiate between players joining for the first time and players *re*joining the world for the Nth time, as the approaches are slightly different.
+| 📝 Note |
+|---------|
+|In this example we are using a tellraw command, but in 1.21.5+ the tellraw syntax has changed, so you will need to update it accordingly.|
+
## First time
-A player that joins a world for the first time is a blank slate, they have no scores, no tags, no advancements, no nothing on them. We can use this to detect the lack of an initialisation tag on the player, apply all our actions to them, then give them the tag.
+A player that joins a world for the first time is a blank slate, they have no scores, no tags, no advancements, no nothing on them. We can use this to detect the lack of an initialization tag on the player, apply all our actions to them, then give them the tag.
### Tags
- execute as @a[tag=!init] run tellraw @a ["",{"selector":"@s"},{"text":" just logged in for the first time!"}]
- tag @a[tag=!init] add init
+execute as @a[tag=!init] run tellraw @a ["",{"selector":"@s"},{"text":" just logged in for the first time!"}]
+tag @a[tag=!init] add init
### Advancements
-Another way to do this is using an advancement in a datapack, this advancement will we garanted every tick, so new players (that don't have this advancement) will receive it and will run the function specified in the reward.
-
- # advancement example:first_join
- {
- "criteria": {
- "requirement": {
- "trigger": "minecraft:tick"
- }
- },
- "rewards": {
- "function": "example:first_join"
- }
- }
-
- # function example:first_join
- tellraw @a [{"selector":"@s"}," just logged in for the first time!"]
+Another way to do this is using an advancement in a datapack, this advancement will we granted every tick, so new players (that don't have this advancement) will receive it and will run the function specified in the reward.
+
+```json
+# advancement example:first_join
+{
+ "criteria": {
+ "requirement": {
+ "trigger": "minecraft:tick"
+ }
+ },
+ "rewards": {
+ "function": "example:first_join"
+ }
+}
+```
+```mcfunction
+# function example:first_join
+tellraw @a [{"selector":"@s"}," just logged in for the first time!"]
+```
## Consecutive Time
@@ -35,21 +45,26 @@ Another way to do this is using an advancement in a datapack, this advancement w
You can set up an objective of type `minecraft.custom:minecraft.leave_game`, which will count up the moment a player leaves the server, which you can then detect the moment they come back, because, even if the score has been updated, the player is not online and we can't target it with `@a[scores={leave=1}]`.
Assuming you called the objective `leave`, it could look like this:
- execute as @a[scores={leave=1..}] run tellraw @a ["",{"selector":"@s"},{"text":" just came back to us!"}]
- scoreboard players reset @a[scores={leave=1..}] leave
+```mcfunction
+execute as @a[scores={leave=1..}] run tellraw @a ["",{"selector":"@s"},{"text":" just came back to us!"}]
+scoreboard players reset @a[scores={leave=1..}] leave
+```
-> [!NOTE]
-> This method counts exits from the game, but not joins to the server, because the score increases when the player leaves, but since you cannot target an offline player using the target selector, we cannot check that the score has been changed and this can only be done when the player joins to the server again.
+| 📝 Note |
+|---------|
+|This method counts exits from the game, but not joins to the server, because the score increases when the player leaves, but since you cannot target an offline player using the target selector, we cannot check that the score has been changed and this can only be done when the player joins the server again|
### Bedrock
In Bedrock we don't have the luxury of the `leave_game` objective, so we'll need to find a workaround. One such workaround could be to have a fake player count up a score every tick/second, then check whether the player has the same score, if not run whatever you want on them, then set the score to the same score as the fake player. Example with a dummy scoreboard objective called "online":
- scoreboard players add @a online 1
- scoreboard players add .total online 1
- scoreboard players operation @a online -= .total online
- execute as @a[scores={online=..-1}] run say I relogged!
- scoreboard players operation @a online = .total online
+```mcfunction
+scoreboard players add @a online 1
+scoreboard players add .total online 1
+scoreboard players operation @a online -= .total online
+execute as @a[scores={online=..-1}] run say I relogged!
+scoreboard players operation @a online = .total online
+```
This seems to be working even in singleplayer.
However, be aware that it will stop working after 3 years of the world being active if you're running it every tick due to integer overflow. If you change it to run every second instead, this system will last you 60 years.
@@ -59,37 +74,43 @@ However, be aware that it will stop working after 3 years of the world being act
### Java
We can combine these two if you want the same thing to happen in both cases. The easiest here would of course be a function that's just run in both cases, but it'd be similarly easy to remove the tag from anyone with the score so you don't need to do everything twice but instead just need one additional command:
- tag @a[scores={leave=1..}] remove init
- execute as @a[tag=!init] ....
- tag @a[tag=!init] add init
- scoreboard players set @a[scores={leave=1..}] leave 0
+```mcfunction
+tag @a[scores={leave=1..}] remove init
+execute as @a[tag=!init] run say I relogged!
+tag @a[tag=!init] add init
+scoreboard players set @a[scores={leave=1..}] leave 0
+```
But it can be simplified to only 2 commands (and one for creating the scoreboard).
First we detect if the player has no set score (so they are a new player) and we store the success of the tellraw. The score is now set to 1 (from no score at all), because the tellraw always succeeds.
Then if the value is not 1 (so it is 2, so they leaved the game) we will store the succes of another tellraw command in the scoreboard, because it is the success it will set it to 1.
- # In chat
- scoreboard objectives add leave custom:leave_game
-
- # command blocks
- execute as @a unless score @s leave = @s leave store success score @s leave run tellraw @a [{"selector":"@s"}," just logged in for the first time!"]
- execute as @a unless score @s leave matches 1 store success score @s leave run tellraw @a [{"selector":"@s"}," just came back to us!"]
+```mcfunction
+# In chat
+scoreboard objectives add leave custom:leave_game
+
+# command blocks
+execute as @a unless score @s leave = @s leave store success score @s leave run tellraw @a [{"selector":"@s"}," just logged in for the first time!"]
+execute as @a unless score @s leave matches 1 store success score @s leave run tellraw @a [{"selector":"@s"}," just came back to us!"]
+```
### Bedrock
In bedrock we don't have `execute store` so we will need to split the command in 2.
-> [!Note]
-> This method is the same as the 2 others merged, nothing else changed.
-
- # in chat
- /scoreboard objectives add online dummy
-
- # in command block
- scoreboard players add @a online 1
- scoreboard players add .total online 1
- scoreboard players operation @a online -= .total online
- execute as @a[scores={online=..-1}] run say I rejoined
- scoreboard players operation @a online = .total online
- execute as @a[tag=!init] run say I joined for first time
- tag @a[tag=!init] add init
-
+| 📝 Note |
+|---------|
+|This method is the same as the 2 others merged, nothing else changed|
+
+```mcfunction
+# In chat
+scoreboard objectives add online dummy
+
+# Command block
+scoreboard players add @a online 1
+scoreboard players add .total online 1
+scoreboard players operation @a online -= .total online
+execute as @a[scores={online=..-1}] run say I rejoined
+scoreboard players operation @a online = .total online
+execute as @a[tag=!init] run say I joined for the first time
+tag @a[tag=!init] add init
+```
\ No newline at end of file
diff --git a/questions/playerkills.md b/questions/playerkills.md
index 6b481e158..c53700a28 100644
--- a/questions/playerkills.md
+++ b/questions/playerkills.md
@@ -2,13 +2,17 @@
_Related: [Detect Player Deaths](/wiki/questions/playerdeaths)_
+* [Java](#java)
+* [Bedrock](#bedrock)
+
## Java
-In Java this is easy, as there is a whole lot of [scoreboard objectives criteria](https://minecraft.wiki/Scoreboard#Criteria) for every entity you can kill in the game, using the format `minecraft.killed:minecraft.`, where `` is a valid type of entity.
+In Java this is easy, as there is a whole lot of [scoreboard objective criteria](https://minecraft.wiki/Scoreboard#Criteria) for every entity you can kill in the game, using the format `minecraft.killed:minecraft.`, where `` is a valid type of entity.
This method for command blocks cannot check any NBT data, including the tag of the killed mob.
But this can be done using advancement using the [`player_killed_entity`](https://minecraft.wiki/wiki/Advancement/JSON_format#minecraft:player_killed_entity) advancement trigger, if you're using a datapack that looks like this:
-```
+
+```json
{
"criteria": {
"requirement": {
@@ -27,8 +31,9 @@ But this can be done using advancement using the [`player_killed_entity`](https:
}
```
-The advancement from above will check if the entity that the player killed has that NBT (so it has the tag `example` in this case) if you don't want to check NBT you can just use:
-```
+The advancement from above will check if the entity that the player killed has that NBT (so it has the tag `example` in this case); if you don't want to check NBT you can just use:
+
+```json
{
"criteria": {
"requirement": {
@@ -46,52 +51,61 @@ The advancement from above will check if the entity that the player killed has t
}
```
-When the player kills a pig, they will run the funcion `example:kill_entity` as it is set as a reward.
+When the player kills a pig, they will run the function `example:kill_entity` as it is set as a reward.
## Bedrock
In Bedrock this is much more tricky, as there is only the dummy objective type.
-The best way this subreddit has come up with so far is to use a modified loot table, making the entity drop a certain item on death that they otherwise wouldn't drop. _This also works for players, but only if the `keepInventory` gamerule is false._ To change an entities loot table, you will have to modify their behavior file and change the loot table to be your custom one or replace their default loot table if they have one. Find the `minecraft:loot` component (or add it if it doesn't exist) and give it your custom loottable.
-
- "minecraft:loot": {
- "table": "loot_tables/.json"
- },
-
-Now, you of course need to create said loot table as well, here is an example of a loot table that will always drop 1 dragon egg if the entity was killed by a player:
-
- {
- "pools": [
- {
- "conditions": [
- {
- "condition": "killed_by_player_or_pets"
- }
- ],
- "rolls": 1,
- "entries": [
- {
- "type": "item",
- "name": "minecraft:dragon_egg",
- "weight": 1
- }
- ]
- }
- ]
- }
+The best way this Subreddit has come up with so far is to use a modified loot table, making the entity drop a certain item on death that they otherwise wouldn't drop. _This also works for players, but only if the `keepInventory` gamerule is false._ To change an entities loot table, you will have to modify their behavior file and change the loot table to be your custom one or replace their default loot table if they have one. Find the `minecraft:loot` component (or add it if it doesn't exist) and give it your custom loot table.
+
+```json
+"minecraft:loot": {
+ "table": "loot_tables/.json"
+},
+```
+
+Now, you of course need to create said loot table as well. Here is an example of a loot table that will always drop 1 dragon egg if the entity is killed by a player:
+
+
+ See example
+
+```json
+{
+ "pools": [
+ {
+ "conditions": [
+ {
+ "condition": "killed_by_player_or_pets"
+ }
+ ],
+ "rolls": 1,
+ "entries": [
+ {
+ "type": "item",
+ "name": "minecraft:dragon_egg",
+ "weight": 1
+ }
+ ]
+ }
+ ]
+}
+```
+
+
-_This will overwrite the normal loottable for the entity. If you want the item to be dropped in addition to the normal loot, you will have to modify the entities standard loot table._
+_This will overwrite the normal loot table for the entity. If you want the item to be dropped in addition to the normal loot, you will have to modify the entity's standard loot table._
From here you can go two ways:
-1. Either you give the player closest to the dropped item the credit for the kill by counting their score up by one, then killing the item. Be aware that this can easily create false results if the combat is ranged or in a chaotic environment, where the closest player to the killed player isn't necessarily the killer.
+1. Either you give the player closest to the dropped item the credit for the kill by counting their score up by one, then kill the item. Be aware that this can easily create false results if the combat is ranged or in a chaotic environment, where the closest player to the killed player isn't necessarily the killer.
2. Or you require the players to pick up the item for their kill to be counted, check for the item in their inventory, count up by 1 if you find it and clear 1 from their inventory.
Read [here](/wiki/questions/detectitem) how you can detect a certain item.
-_Credit to /u/DanRileyCG, for the original [thread here](https://www.reddit.com/r/MinecraftCommands/comments/f7jd9f/help_with_server/)_
+_Credit to [u/DanRileyCG](https://www.reddit.com/user/DanRileyCG/), for the original [thread here](https://www.reddit.com/r/MinecraftCommands/comments/f7jd9f/help_with_server/)_
### Without behavior packs
**If you don't have access to the files and are thus unable to create a behavior pack for this, there is a toned down version for player kills only that you can do.**
-It involves giving the player the special item into their inventory and making sure they drop it on death. To make it fool-proof / non-abuseable, there are a few more systems required (don't repeatedly replace it or they could farm kills, only replace it if it's empty, don't award a kill if the player does have a bees nest in their inventory, etc.). Too much to go into in this wiki article, but here is a video where they show off one such system: https://www.youtube.com/watch?v=zuhd3qEOJ1I
+It involves giving the player the special item into their inventory and making sure they drop it on death. To make it fool-proof / non-abuseable, there are a few more systems required (don't repeatedly replace it, or they could farm kills, only replace it if it's empty, don't award a kill if the player does have a bee nest in their inventory, etc.). Too much to go into in this wiki article, but here is a video where they show off one such system: [https://www.youtube.com/watch?v=zuhd3qEOJ1I](https://www.youtube.com/watch?v=zuhd3qEOJ1I). Keep in mind that this video uses the old `execute` syntax and it will need to be updated, see [this information](https://wiki.bedrock.dev/commands/new-execute.html) about the changes
\ No newline at end of file
diff --git a/questions/randomnumber.md b/questions/randomnumber.md
index 2f9b06b61..7e29d6807 100644
--- a/questions/randomnumber.md
+++ b/questions/randomnumber.md
@@ -1,18 +1,28 @@
# Generate a random number
-This article talks about the Java Edition of the game. In Bedrock, you can just use `scoreboard players random` to get a random number into your scoreboard and don't need to go through all this hassle, the command is the following one:
- scoreboard players random
+| 📝 Note |
+|---------|
+|**None of these numbers are truly random**. They are all only "pseudo" random (which means they only feel like they are random to a human, but are using some form of deterministic algorithm behind the scenes) because that's how computers work. They will be refered to "random" generator for simplicity. This likely won't affect your contraption, but it's important to point out|
+
+## Bedrock
+
+In Bedrock, you can use `scoreboard players random` to get a random number into your scoreboard, the command is the following one:
+
+```mcfunction
+scoreboard players random
+```
So for example, from 1 to 10 in a score called `some_score`
- scoreboard players random @p some_score 1 10
+```mcfunction
+scoreboard players random @p some_score 1 10
+```
-> [!NOTE]
-> **None of these numbers are truly random**. They are all only "pseudo" random (which means they only feel like they are random to a human, but are using some form of deterministic algorithm behind the scenes) because that's how computers work. They will be refered to "random" generator for simplicity. This likely won't affect your contraption, but it's important to point out.
+## Java
-## /random command
-**This method is, currently, the best, there is no reason to use the others**
+### /random command
+This method is, currently, the best, there is no reason to use the others unless you want to have something happen with a random chance, then use a predicate.
Effective Range [-2'147'483'648 to 2'147'483'647]
@@ -20,46 +30,58 @@ This command is used to generate a random number specifying the maximum and the
First we need to create a scoreboard where we will store the random number.
- /scoreboard objectives add random dummy
+```mcfunction
+/scoreboard objectives add random dummy
+```
+
We need to store the result of the [`/random`](https://minecraft.wiki/w/random) command to a fake player
- /execute store result score run random value ..
-
+```mcfunction
+/execute store result score run random value ..
+```
+
For example:
- execute store result score #command random run random value 1..5
+```
+execute store result score #command random run random value 1..5
+```
And now we need to check the value of the scoreboard, in this case we used numbers from 1 to 5 so we use one command to check every possible scoreboard value.
- execute if score #command random matches 1 run
- execute if score #command random matches 2 run
- execute if score #command random matches 3 run
- execute if score #command random matches 4 run
- execute if score #command random matches 5 run
+```
+execute if score #command random matches 1 run
+execute if score #command random matches 2 run
+execute if score #command random matches 3 run
+execute if score #command random matches 4 run
+execute if score #command random matches 5 run
+```
Or we can use [ranges](wiki/questions/ranges) to detect more of one number.
- execute if score #command random matches 1..3 run say 1, 2 or 3
- execute if score #command random matches 4..5 run say 4 or 5
-
-## without /random command (Pre-1.20.2)
-> [!NOTE]
-> This information is outdated and should **not** be used in the current version of the game.
+```
+execute if score #command random matches 1..3 run say 1, 2 or 3
+execute if score #command random matches 4..5 run say 4 or 5
+```
-There are many ways to get a random number in minecraft. the first two are arguably the best as they have the least limitations and require the least work to set up.
-## Have something happen with a random chance
+### Have something happen with a random chance
For this special case, you don't need any of the random number methods, thanks to 1.15's predicates. A simple predicate can be used to run something with an e.g. 1/10 chance like this:
- {
- "condition": "minecraft:random_chance",
- "chance": 0.1
- }
+```json
+{
+ "condition": "minecraft:random_chance",
+ "chance": 0.1
+}
+```
-If you need to choose one of 10 things at random, you should read on.
+---
+| 📝 Note |
+|---------|
+|The following information is outdated and should **not** be used in the current version of the game as there are better methods of randomess descrived above|
+|The following methods should only be used in pre-1.20.2|
-## 1: PRNG/LCG
+### 1: PRNG/LCG
Effective Range: Depends on the implementation, one of the ones on the discord server has [0, 130000]
@@ -69,7 +91,7 @@ If you don't want to do it yourself, you can go on the [discord](https://discord
_Probably the best listed method if the range is enough for you, as it creates the least amount of server strain while having a very high range that should be enough for most purposes._
-## 2: UUID
+### 2: UUID
Effective Range: [-2147483648, 2147483647]
@@ -91,7 +113,7 @@ _The second best option listed here. More taxing on the server due to it's creat
The NBT tags `UUIDLeast` and `UUIDMost` are both the size of a `long` (64 bits), while `data get` can only return an `int` (32 bits). To shrink the `long` sized value into the size of an `int`, we use the scale value `0.00000000023283064365386962890625` which we get from the value of `1 / (2^32)`. This effectively gives us the upper half of the `long`.
-## 3: Loot Tables
+### 3: Loot Tables
Effective Range: [0, 10000] (in theory all the way up to 2^(31)-1, but since you're summoning an entity which gets deleted instantly again for this to work, anything above a few thousand will likely lag your game).
@@ -99,29 +121,36 @@ This method takes advantage of the fact that using `execute store` with the `loo
Example loot table:
+
+ See example
+
+```json
+{
+ "type": "minecraft:empty",
+ "pools": [
{
- "type": "minecraft:empty",
- "pools": [
+ "rolls": {
+ "min": 1,
+ "max": 5
+ },
+ "entries": [
{
- "rolls": {
- "min": 1,
- "max": 5
- },
- "entries": [
+ "type": "minecraft:item",
+ "name": "stone",
+ "functions": [
{
- "type": "minecraft:item",
- "name": "stone",
- "functions": [
- {
- "function": "minecraft:set_count",
- "count": 0
- }
- ]
+ "function": "minecraft:set_count",
+ "count": 0
}
]
}
]
}
+ ]
+}
+```
+
+
Change the rolls to fit your desired range (not negative, 0 is allowed), and/or use the method described below to fit it into a range using modulo, so you don't need a different loottable for every different range.
@@ -133,7 +162,7 @@ _The third best option, with a small effective range. Use only for smaller amoun
_Taken from [this](https://www.reddit.com/r/MinecraftCommands/comments/evoghb/another_rng_method/) post on the subreddit_.
-## 4: item rotation
+### 4: item rotation
**Outdated**
@@ -141,7 +170,7 @@ Effective Range: [0, 360]
A way to get a random number before 1.13 in the range of up to 360 numbers was to summon an entity like a squid, kill it and check the rotation of the inksac item entity it just dropped, since that rotation is always random. It's very much deprecated now though, thanks to Number 2 in this list.
-## 5: @r / @e[sort=random]
+### 5: @r / @e[sort=random]
Effective Range: [0, 10] (theoretically infinite, but practically anything above 10 is not worth it)
@@ -149,7 +178,7 @@ Before we got the (arguably much better) solutions above, we could use `@e[limit
## 6: spreadplayers
-**Outdated.**
+**Outdated**
Effective Range: [0, 100] (theoretically 900000000000000 if you're using every single block in a minecraft world as a position, practically even 100 is a stretch)
@@ -157,11 +186,11 @@ Another Minecraft-included way for randomisation is `/spreadplayers`, which will
A different way to use the spreadplayers randomisation is to `data get` the position the entity ends up on. This only works reliably in loaded chunks. Since spreadplayers does load the chunk the entity is placed in briefly, it _may_ work when using a function or chained commands, but this method of chunkloading has been quite unreliable in the past.
-## 7: running score
+### 7: running score
A very primitive way to get somewhat random numbers but probably the easiest one. It relies on time to get a random number, so this is not applicable for when random numbers are needed in predefined time lengths (X amount of ticks, maybe even the same tick) and **it is advised not to use this**, as there are much better alternatives. How it works is you basically count up a scoreboard from the minimum to the maximum random number, incrementing by one per tick and resetting it to the minimum once you reached the maximum. Then to get a "random" number you just take whatever number this running score happens to be on at that moment.
-## Get the number into the desired range
+### Get the number into the desired range
Many of the generators above have a range that only covers positive numbers, reaching from 0 up to X. But what if you need a random number between 5 and 15? what about -10 and 10?
diff --git a/questions/range.md b/questions/range.md
index 4b7625932..50e913168 100644
--- a/questions/range.md
+++ b/questions/range.md
@@ -1,6 +1,6 @@
# Ranges
-Multiple selectors (e.g. `scores` or `distance`) allow for you to specify a **range** of values to test for, instead of just a single value. They are denoted by two dots which seperate the min and max value (including): `min..max`
+Multiple selectors (e.g., `scores` or `distance`) allow for you to specify a **range** of values to test for, instead of just a single value. They are denoted by two dots that separate the min and max value (including): `min..max`
Either one can be left out to signify an open-ended range. Leaving writing a single number signifies an exact check for this value alone.
`1` means "exactly 1"
@@ -10,5 +10,6 @@ Either one can be left out to signify an open-ended range. Leaving writing a sin
Some selectors (like `distance`) also allow for decimal numbers. `0.5..0.9` works fine in those instances.
-> [!IMPORTANT]
-> Ranges are not useable when checking for NBT!
+| ⚠️ Important |
+|--------------|
+|Ranges are not usable when checking for NBT!|
diff --git a/questions/raycast.md b/questions/raycast.md
index 0dabd52e8..ec668972a 100644
--- a/questions/raycast.md
+++ b/questions/raycast.md
@@ -1,17 +1,21 @@
# Raycast
-> [!NOTE]
-> If you're trying to check whether an entity / player is looking at a specific entity / position, you might be able to use a more streamlined method [described here](/wiki/questions/lookat).
+* [Java](#java)
+* [Bedrock](#bedrock)
+
+| 📝 Note |
+|--------------|
+|If you're trying to check whether an entity / player is looking at a specific entity / position, you might be able to use a more streamlined method [described here](/wiki/questions/lookat)|
## What is a raycast?
-Raycasting (or more accurately in this context: ray marching) in minecraft commands describes a process of moving forward in small increments (basically "drawing" a line) until a certain condition is met. It has many possible usecases, most often it is used to check what a player/entity is looking at by following the looking direction.
+Raycasting (or more accurately in this context: ray marching) in minecraft commands describes a process of moving forward in small increments (basically "drawing" a line) until a certain condition is met. It has many possible use cases, most often it is used to check what a player/entity is looking at by following the looking direction.
-A raycast is possible due to the introduction of [local coordinates](https://minecraft.wiki/wiki/Coordinates#Local_coordinates) (`^ ^ ^`) which allows a commands origin to be moved relative to the entities local coordinates instead of absolute or world based relative coordinates.
+A raycast is possible due to the introduction of [local coordinates](https://minecraft.wiki/wiki/Coordinates#Local_coordinates) (`^ ^ ^`) which allows a command's origin to be moved relative to the entities local coordinates instead of absolute or world based relative coordinates.
-In all of the below examples we'll use a step-size of 0.1 blocks at a time. This is a reasonable compromise between error margin and performance hit, but depending on the usecase a smaller or larger step size is absolutely thinkable.
+In all of the below examples, we'll use a step-size of 0.1 blocks at a time. This is a reasonable compromise between error margin and performance hit, but depending on the use case, a smaller or larger step size is absolutely thinkable.
-Due to the way these raycasts tend to be implemented, they move forward until they hit the desired target (e.g. a block that is not air, but you may also want to not detect other non-solid blocks as water). However, this way it is possible that a ray will never find its terminating condition, so a second ending condition is added: The maximum step amount. This generally consists of a scoreboard value that is increased/decreased with every step, counting the number of steps thus stopping the ray after a certain distance.
+Due to the way these raycasts tend to be implemented, they move forward until they hit the desired target (e.g., a block that is not air, but you may also want to not detect other non-solid blocks as water). However, this way it is possible that a ray will never find its terminating condition, so a second ending condition is added: The maximum step amount. This generally consists of a scoreboard value that is increased/decreased with every step, counting the number of steps, thus, stopping the ray after a certain distance.
Please remember that a raycast _can_ (depending on the exact implementation) be a somewhat performance intensive procedure, so you need to try to find a balance between accuracy, distance and frequency of your raycast to avoid lag.
@@ -23,38 +27,91 @@ You can generate a raycasting datapack using this generator: https://sourceblock
### Without an entity
-This is the preferred method of raycasting, as this entityless approach causes less strain on the server and you don't need to clean up the used entity afterwards. Of course you can still summon an entity to mark the position you've found for later useage, but it is often encouraged to do it all in a single tick.
+This is the preferred method of raycasting, as this entityless approach causes less strain on the server and you don't need to clean up the used entity afterwards. Of course you can still summon an entity to mark the position you've found for later usage, but it is often encouraged to do it all in a single tick.
This method only works in a single tick, so if you need the raycast to be over a period of time instead of instantaneous, use the entity based method instead. It also requires functions to work, so if you're unable to use a datapack, you also need to use the other method.
-First, the command that will initiate a raycast. We're anchoring the execution point at the entities eyes (moving up from their feet), changing the execution position to the eye level and then, due to a quirk in minecrafts keeping of context, move the anchor back to the feet to avoid the game reapplying the hight of the eyes to every step.
+First, the command that will initiate a raycast. We're anchoring the execution point at the entities eyes (moving up from their feet), changing the execution position to the eye level, and then, due to a quirk in minecraft's keeping of context, move the anchor back to the feet to avoid the game reapplying the height of the eyes to every step. The subcommand `anchored feet` should not be used in recent versions of the game.
+
+```mcfunction
+execute as at @s anchored eyes positioned ^ ^ ^ anchored feet run function namespace:start_ray
+```
+
+Next up, the ray setup. We need to set a maximum amount of steps that we can go before we abort our search. This means we can just set a score to the maximum amount of steps. Here, a `dummy` scoreboard named `ray_steps` is used. It's set to 50 steps, so a maximum distance of 5 blocks considering our step distance is 0.1 blocks per step (which is also the reach distance of a player). We also want to store whether our ray successfully hit something, so we know whether to continue or to stop. In this case another `dummy` objective is used, called `ray_success`. Instead of two scoreboards you can also use a single scoreboard and use [fake players](/wiki/questions/fakeplayer) to store the scores.
+
+```mcfunction
+# function example:start_ray
+scoreboard players set @s ray_steps 50
+scoreboard players set @s ray_success 0
+function example:ray
+```
+
+Next, the actual ray is being cast. For that, we first check whether our stopping condition has been achieved and run a success function if we did. Next, we count up the steps we can still take by 1. And lastly, we run the function again, moved forward by our step size, if we neither hit the stopping condition nor the maximum step size. In this example the stopping condition is hitting a block that is not air.
- execute as at @s anchored eyes positioned ^ ^ ^ anchored feet run function namespace:start_ray
+```mcfunction
+# function example:ray
+execute unless block ~ ~ ~ minecraft:air run function example:hit_block
+scoreboard players remove @s ray_steps 1
+execute if score @s ray_steps matches 1.. if score @s ray_success matches 0 positioned ^ ^ ^0.1 run function example:ray
+```
-Next up, the ray setup. We need to set a maxium amount of steps that we can go before we abort our search. This means we can just set a score to the maximum amount of steps. Here a `dummy` scoreboard named `ray_steps` is used. It's set to 50 steps, so a maximum distance of 5 blocks considering our step distance is 0.1 blocks per step (which is also the reach distance of a player). We also want to store whether our ray successfully hit something, so we know whether to continue or to stop. In this case another `dummy` objective is used, called `ray_success`. Instead of two scoreboards you can also use a single scoreboard and use [fake players](/wiki/questions/fakeplayer) to store the scores.
+Lastly, we can use the success function to run whatever we intend to do at the found place. In this case we'll just set a stone block. _Make sure to set the `ray_success` score to 1 at some point in the function though!_
-`namespace:start_ray`
+```mcfunction
+# function example:hit_block
+scoreboard players set @s ray_success 1
+setblock ~ ~ ~ stone
+```
- scoreboard players set @s ray_steps 50
- scoreboard players set @s ray_success 0
- function namespace:ray
+And that's the basic skeleton of a raycast, which can now be extended to your heart's content.
-Next, the actual ray is being cast. For that, we first check whether our stopping condition has been achieved and run a success function if we did. Next we count up the steps we can still take by 1. And lastly we run the function again, moved forward by our step size, if we neither hit the stopping condition nor the maximum step size. In this example the stopping condition is hitting a block that is not air.
+
+ See datapack
-`namespace:ray`
+```mcfunction
+# function example:start_ray
+scoreboard players set @s ray_steps 50
+scoreboard players set @s ray_success 0
+function example:ray
- execute unless block ~ ~ ~ minecraft:air run function namespace:hit_block
- scoreboard players remove @s ray_steps 1
- execute if score @s ray_steps matches 1.. if score @s ray_success matches 0 positioned ^ ^ ^0.1 run function namespace:ray
+# function example:ray
+execute unless block ~ ~ ~ minecraft:air run function example:hit_block
+scoreboard players remove @s ray_steps 1
+execute if score @s ray_steps matches 1.. if score @s ray_success matches 0 positioned ^ ^ ^0.1 run function example:ray
-Lastly we can use the success function to run whatever we intend to do at the found place. In this case we'll just set a stone block. _Make sure to set the `ray_success` score to 1 at some point in the function though!_
+# function example:hit_block
+scoreboard players set @s ray_success 1
+setblock ~ ~ ~ stone
+```
+
-`namespace:hit_block`
+Since 1.20.2, we can use `return` to stop a function early. So the `example:ray` function does not need to check the value of the `ray_success` since we don't need this scoreboard anymore.
- scoreboard players set @s ray_success 1
- setblock ~ ~ ~ stone
+```mcfunction
+# function example:ray
+execute unless block ~ ~ ~ minecraft:air run return run function example:hit_block
+scoreboard players remove @s ray_steps 1
+execute if score @s ray_steps matches 1.. positioned ^ ^ ^0.1 run function example:ray
+```
+
+
+ See datapack
+
+```mcfunction
+# function example:start_ray
+scoreboard players set @s ray_steps 50
+function example:ray
+
+# function example:ray
+execute unless block ~ ~ ~ minecraft:air run return run function example:hit_block
+scoreboard players remove @s ray_steps 1
+execute if score @s ray_steps matches 1.. positioned ^ ^ ^0.1 run function example:ray
+
+# function example:hit_block
+setblock ~ ~ ~ stone
+```
+
-And that's the basic skeleton of a raycast, which can now be extended to your hearts content.
### With an entity
@@ -62,27 +119,30 @@ Please see the [without an entity](#wiki_without_an_entity) section above for a
The main difference being that we are now moving an entity instead of just the execution context, so we also need to create said entity.
-`namespace:start_ray`
+```mcfunction
+# function example:start_ray
- # summon entity to use as a marker
- summon area_effect_cloud ~ ~ ~ {Tags:["ray_marker"]}
- # make sure the marker entity is rotated in the same way as the executing entity
- tp @e[tag=ray_marker] ~ ~ ~ ~ ~
-
- scoreboard players set @e[tag=ray_marker] ray_steps 50
- scoreboard players set @e[tag=ray_marker] ray_success 0
- execute as @e[tag=ray_marker] at @s run function namespace:ray
+# summon entity to use as a marker
+summon area_effect_cloud ~ ~ ~ {Tags:["ray_marker"]}
+# make sure the marker entity is rotated in the same way as the executing entity
+tp @e[tag=ray_marker] ~ ~ ~ ~ ~
-We are now executing the ray function as the marker entity instead of the executing entity. So, to move the execution position, we need to teleport the entity and make sure we re-align the function position to the entity at every step, instead of just repositioning the execution context.
+scoreboard players set @e[tag=ray_marker] ray_steps 50
+scoreboard players set @e[tag=ray_marker] ray_success 0
+execute as @e[tag=ray_marker] at @s run function example:ray
+```
-`namespace:ray`
+We are now executing the ray function as the marker entity instead of the executing entity. So, to move the execution position, we need to teleport the entity and make sure we re-align the function position to the entity at every step, instead of just repositioning the execution context.
- execute unless block ~ ~ ~ minecraft:air run function namespace:hit_block
- scoreboard players remove @s ray_steps 1
- tp @s ^ ^ ^0.1
- execute if score @s ray_steps matches 1.. if score @s ray_success matches 0 at @s run function namespace:ray
+```mcfunction
+# function example:ray
+execute unless block ~ ~ ~ minecraft:air run function example:hit_block
+scoreboard players remove @s ray_steps 1
+tp @s ^ ^ ^0.1
+execute if score @s ray_steps matches 1.. if score @s ray_success matches 0 at @s run function example:ray
+```
-Make sure you kill the entity once it's done it's job, for example by putting the kill command into the success function or at the end of the `start_ray` function.
+Make sure you kill the entity once it's done its job, for example, by putting the kill command into the success function or at the end of the `start_ray` function.
If you're doing this **without a datapack**, just using commands, then you just need to make sure all the commands that are in the `ray` function are executed as and at the ray_marker entity, that the commands in the `start_ray` function are executed as the ray shooter entity and that you're only affecting the one ray_marker that was summoned on that entity.
@@ -92,7 +152,7 @@ If you're doing this **without a datapack**, just using commands, then you just
### Without an entity
-Thanks to the new execute syntax introduced in 1.19.50, you can use the same system as described in Java - without an entity.
+Thanks to the new execute syntax introduced in 1.19.50, you can use the same system as described in [Java - without an entity](#without-an-entity).
### With an entity
@@ -102,53 +162,67 @@ A technique first brought up by [/u/VentedMCBE](https://www.reddit.com/u/VentedM
As mentioned, this works with just commandblocks, so for the following commands you can either put them into a repeating-chain of commandblocks or in a function.
- # ignore non-specifically summoned xp orbs
- tag @e[type=xp_orb] add ignore
- # Summon ray marker per player
- execute as @a at @s run summon xp_orb
- # Rotate and relocate the ray marker
- execute as @e[type=xp_orb] at @s at @p rotated as @p anchored eyes run tp @s ~~~ ~ ~
- # Move the ray forwards
- execute as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[type=xp_orb,tag=!ignore] at @s run tp @s ^^^0.1 true
- # Run a command or display ray end point
- execute at @e[type=xp_orb,tag=!ignore] run particle minecraft:basic_crit_particle ~~~
- # Kill ray orbs
- kill @e[type=xp_orb,tag=!ignore]
-
-The 4th command is where the magic happens: Due to us splitting the execution path into 2, every time `as @e[c=2]` is called, we're essentially doubling the executions over and over. So because we're calling it 9 times, the rest of the command will be run 2^9 = 512 times. You can adjust this accordingly to your needs. In this case we're moving the ray forwards by 0.1 blocks (thus to a maximum of 51.2 blocks), only if we can move into the block there (as denoted by the `true` at the end of the tp command). Thus this command would cause us to find the next solid block the player is looking at (in a 51 block radius).
-
-So, for different applications you'd modify the 4th command to find different things. For example, to stop moving if there is a creeper (feet) close by, going through blocks, the command could look like this:
+
+ See commands
- execute as @e[c=2] ... as @e[c=2] as @e[type=xp_orb,tag=!ignore] at @s positioned ^^^0.1 unless entity @e[type=creeper,r=1] at @s run tp @s ^^^0.1
+```mcfunction
+# ignore non-specifically summoned xp orbs
+tag @e[type=xp_orb] add ignore
+# Summon ray marker per player
+execute as @a at @s run summon xp_orb
+# Rotate and relocate the ray marker
+execute as @e[type=xp_orb] at @s at @p rotated as @p anchored eyes run tp @s ~~~ ~ ~
+# Move the ray forwards
+execute as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[c=2] as @e[type=xp_orb,tag=!ignore] at @s run tp @s ^^^0.1 true
+# Run a command or display ray end point
+execute at @e[type=xp_orb,tag=!ignore] run particle minecraft:basic_crit_particle ~~~
+# Kill ray orbs
+kill @e[type=xp_orb,tag=!ignore]
+```
-#### Using functions
-
-This is the same method as described in the "[with an entity](#wiki_with_an_entity)" section above, just using bedrock syntax. Please see above for an explanation on what is going on.
+
-> **Please note that there seems to be a limitation in bedrock at the time of writing (1.18) that limits the entities up/down movement to 45° angles or just straight up 0°!** Thus a different method might need to be found, possibly using custom projectiles.
+The 4th command is where the magic happens: Due to us splitting the execution path into 2, every time `as @e[c=2]` is called, we're essentially doubling the executions over and over. So because we're calling it 9 times, the rest of the command will be run 2^9 = 512 times. You can adjust this accordingly to your needs. In this case we're moving the ray forwards by 0.1 blocks (thus, to a maximum of 51.2 blocks), only if we can move into the block there (as denoted by the `true` at the end of the tp command). Thus, this command would cause us to find the next solid block the player is looking at (in a 51 block radius).
-It is _highly_ recommended to use a custom entity for the raycast, as you not only want it to be invisible, without any AI but also unaffected by gravity.
+So, for different applications you'd modify the 4th command to find different things. For example, to stop moving if there is a creeper (feet) close by, going through blocks, the command could look like this:
-Command to start the raycast (the execution point is moved up manually towards player standing eye level. This means that if the player is not standing up normally (e.g. crouching or swimming) this will produce unexpected results):
+```mcfunction
+execute as @e[c=2] ... as @e[c=2] as @e[type=xp_orb,tag=!ignore] at @s positioned ^^^0.1 unless entity @e[type=creeper,r=1] at @s run tp @s ^^^0.1
+```
- execute ~ ~1.62 ~ function namespace:start_ray
+#### Using functions (Old execute)
-`namespace:start_ray`
+| ⚠️ Important |
+|--------------|
+|This is only for old execute versions, so it does not work in the last release|
- # summon entity to use as a marker
- summon custom:entity ray_marker ~ ~ ~
- # make sure the marker entity is rotated in the same way as the executing entity
- tp @e[name=ray_marker] ^ ^ ^-0.1 facing @s
-
- scoreboard players set @e[name=ray_marker] ray_steps 50
- scoreboard players set @e[name=ray_marker] ray_success 0
- execute @e[name=ray_marker] ~ ~ ~ function namespace:ray
+This is the same method as described in the "[with an entity](#wiki_with_an_entity)" section above, just using bedrock syntax. Please see above for an explanation on what is going on.
-checking for all but one block needs a few more steps in bedrock, so in this example we're instead checking for the block being grass.
+> **Please note that there seems to be a limitation in bedrock at the time of writing (1.18) that limits the entities up/down movement to 45° angles or just straight up 0°!** , a different method might need to be found, possibly using custom projectiles.
-`namespace:ray`
+It is _highly_ recommended to use a custom entity for the raycast, as you not only want it to be invisible, without any AI but also unaffected by gravity.
- execute @s ~ ~ ~ detect ~ ~ ~ grass function namespace:hit_block
- scoreboard players remove @s ray_steps 1
- tp @s ^ ^ ^0.1
- execute @s[scores={ray_steps=1..,ray_success=0}] ~ ~ ~ function namespace:ray
+Command to start the raycast (the execution point is moved up manually towards player standing eye level. This means that if the player is not standing up normally (e.g., crouching or swimming), this will produce unexpected results):
+
+```mcfunction
+# Start ray
+execute ~ ~1.62 ~ function example:start_ray
+
+# functio example:start_ray
+# summon entity to use as a marker
+summon custom:entity ray_marker ~ ~ ~
+# make sure the marker entity is rotated in the same way as the executing entity
+tp @e[name=ray_marker] ^ ^ ^-0.1 facing @s
+# set scoreboard values
+scoreboard players set @e[name=ray_marker] ray_steps 50
+scoreboard players set @e[name=ray_marker] ray_success 0
+execute @e[name=ray_marker] ~ ~ ~ function example:ray
+
+# function example:ray
+execute @s ~ ~ ~ detect ~ ~ ~ grass function example:hit_block
+scoreboard players remove @s ray_steps 1
+tp @s ^ ^ ^0.1
+execute @s[scores={ray_steps=1..,ray_success=0}] ~ ~ ~ function example:ray
+```
+
+Checking for all but one block needs a few more steps in bedrock, so in this example we're instead checking for the block being grass.
\ No newline at end of file
diff --git a/questions/runonce.md b/questions/runonce.md
index bf1501bf7..dd724fcb1 100644
--- a/questions/runonce.md
+++ b/questions/runonce.md
@@ -1,128 +1,151 @@
# Activate a command *once* when a player does something (e.g: enters an area)
-> [!NOTE]
-> In bedrock `distance` does not exist so instead of `distance=..X` use `r=X` and instead of `distance=X..` use `rm=X` and instead of `distance=X..Y` use `rm=X,r=Y`, all methods only work in Java unless stated otherwise.
+| 📝 Note |
+|--------------|
+|In bedrock `distance` does not exist so instead of `distance=..X` use `r=X` and instead of `distance=X..` use `rm=X` and instead of `distance=X..Y` use `rm=X,r=Y`, all methods only work in Java unless stated otherwise|
This makes a command act as if it was on a comparator, without the lag and multiplayer incompatibility that comes from using a comparator. The general idea here is to select players that match a selector, but did **not** match that same selector in the previous tick. For example, players who have just entered an area (with `@a[x=73,y=10,z=3,distance=..1]`), just gained level 5 (with `@a[level=5]`), just entered creative (with `@a[gamemode=creative]`), etc.
## Scoreboard
-For this method our first command checks two things: Your condition for running the command (e.g. `@a[x=73,y=10,z=3,distance=..1]`) and the condition that it didn't already match in the last tick (e.g. `[scores={matched=0}]`). We're storing the success of your condition in a scoreboard in the second command through a success check:
+For this method, our first command checks two things: Your condition for running the command (e.g. `@a[x=73,y=10,z=3,distance=..1]`) and the condition that it didn't already match in the last tick (e.g. `[scores={matched=0}]`). We're storing the success of your condition in a scoreboard in the second command through a success check:
- # In chat / load function
- scoreboard objectives add matched dummy
-
- # Command blocks / tick function
- execute as @a[scores={matched=0},x=73,y=10,z=3,distance=..1] run say I just entered the area!
- execute as @a store success score @s matched if entity @s[x=73,y=10,z=3,distance=..1]
+```mcfunction
+# In chat / load function
+scoreboard objectives add matched dummy
-> [!NOTE]
-> The order in which the commands are executed is important here. In the first command you check your condition and execute the command, and the second command store the success of executing your condition.
+# Command blocks / tick function
+execute as @a[scores={matched=0},x=73,y=10,z=3,distance=..1] run say I just entered the area!
+execute as @a store success score @s matched if entity @s[x=73,y=10,z=3,distance=..1]
+```
+
+| 📝 Note |
+|--------------|
+|The order in which the commands are executed is important here. In the first command you check your condition and execute the command, and the second command store the success of executing your condition|
The previous example doesn't work in Bedrock Edition. Here is a setup that works in both Java and Bedrock Edition (if you change `distance=..X` to `rm=X`):
+```mcfunction
+execute as @a[scores={matched=0},x=73,y=10,z=3,distance=..1] run say I just entered the area!
+scoreboard players set @a[scores={matched=0},x=73,y=10,z=3,distance=..1] matched 1
+execute as @a unless entity @s[scores={matched=1},x=73,y=10,z=3,distance=..1] run scoreboard players set @s matched 0
+```
- execute as @a[scores={matched=0},x=73,y=10,z=3,distance=..1] run say I just entered the area!
- scoreboard players set @a[scores={matched=0},x=73,y=10,z=3,distance=..1] matched 1
- execute as @a unless entity @s[scores={matched=1},x=73,y=10,z=3,distance=..1] run scoreboard players set @s matched 0
-
Besides the player, this could be some kind of global event, for example, it started to rain (Java 1.20.5+):
- # Command blocks / tick function
- execute if score #raining matched matches 0 if predicate {condition:"weather_check",raining:true} run say It's starting to rain!
- execute store result score #raining matched if predicate {condition:"weather_check",raining:true}
+```
+# Command blocks / tick function
+execute if score #raining matched matches 0 if predicate {condition:"weather_check",raining:true} run say It's starting to rain!
+execute store result score #raining matched if predicate {condition:"weather_check",raining:true}
+```
## Advancements
If you are using a datapack and need to do a lot of similar checks, then you can use [advancements](https://minecraft.wiki/w/Advancement/JSON_format) in the datapack for this.
-This method involves creating a [predicate](https://minecraft.wiki/w/Predicate) that you check against the player, in this example we want to know whether the player is at the server spawn area (`predicate example:at_spawn`). Then we create two advancements - the first one checks the predicate (player is at spawn) and the second one inverts this check (player isn't at spawn). Then inside the run function you execute the desired command when the player enters / leaves spawn and revoke the opposite advancement.
-
- # predicate example:at_spawn
- {
- "condition": "minecraft:location_check",
- "predicate": {
- "position": {
- "x": {
- "min": -100,
- "max": 100
- },
- "z": {
- "min": 200,
- "max": 400
- }
- }
+This method involves creating a [predicate](https://minecraft.wiki/w/Predicate) that you check against the player, in this example, we want to know whether the player is at the server spawn area (`predicate example:at_spawn`). Then we create two advancements - the first one checks the predicate (player is at spawn), and the second one inverts this check (player isn't at spawn). Then, inside the run function, you execute the desired command when the player enters / leaves spawn and revoke the opposite advancement.
+
+
+ See example
+
+```json
+# predicate example:at_spawn
+{
+ "condition": "minecraft:location_check",
+ "predicate": {
+ "position": {
+ "x": {
+ "min": -100,
+ "max": 100
+ },
+ "z": {
+ "min": 200,
+ "max": 400
}
}
-
- # advancement example:spawn/enter
- {
- "criteria": {
- "requirement": {
- "trigger": "minecraft:location",
- "conditions": {
- "player": [
- {
- "condition": "minecraft:reference",
- "name": "example:at_spawn"
- }
- ]
+ }
+}
+
+# advancement example:spawn/enter
+{
+ "criteria": {
+ "requirement": {
+ "trigger": "minecraft:location",
+ "conditions": {
+ "player": [
+ {
+ "condition": "minecraft:reference",
+ "name": "example:at_spawn"
}
- }
- },
- "rewards": {
- "function": "example:spawn/enter"
+ ]
}
}
-
- # function example:spawn/enter
- advancement revoke @s only example:spawn/leave
- tellraw @s "Welcome to spawn!"
-
- # advancement example:spawn/leave
- {
- "criteria": {
- "requirement": {
- "trigger": "minecraft:location",
- "conditions": {
- "player": [
- {
- "condition": "minecraft:inverted",
- "term": {
- "condition": "minecraft:reference",
- "name": "example:at_spawn"
- }
- }
- ]
+ },
+ "rewards": {
+ "function": "example:spawn/enter"
+ }
+}
+```
+```mcfunction
+# function example:spawn/enter
+advancement revoke @s only example:spawn/leave
+tellraw @s "Welcome to spawn!"
+
+```json
+# advancement example:spawn/leave
+{
+ "criteria": {
+ "requirement": {
+ "trigger": "minecraft:location",
+ "conditions": {
+ "player": [
+ {
+ "condition": "minecraft:inverted",
+ "term": {
+ "condition": "minecraft:reference",
+ "name": "example:at_spawn"
+ }
}
- }
- },
- "rewards": {
- "function": "example:spawn/leave"
+ ]
}
}
-
- # function example:spawn/leave
- advancement revoke @s only example:spawn/enter
- tellraw @s "You leave spawn!"
-
-> [!NOTE]
-> In the predicate `example:at_spawn` omits the Y position check, so a player at any height in the specified area will match the conditions of the predicate.
+ },
+ "rewards": {
+ "function": "example:spawn/leave"
+ }
+}
+```
+```mcfunction
+# function example:spawn/leave
+advancement revoke @s only example:spawn/enter
+tellraw @s "You leave spawn!"
+```
+
+
+| 📝 Note |
+|--------------|
+|In the predicate `example:at_spawn` omits the Y position check, so a player at any height in the specified area will match the conditions of the predicate|
Such a check may seem very large, but this method allows you not to check the same condition 2 times per tick, but only 1 time per second (because the `minecraft:location` advancement trigger only runs once per second), which can be important with a large online number of players.
## Add/remove tag
-> [!NOTE]
-> This method will work in Bedrock too
+| 📝 Note |
+|--------------|
+|This method will work in Bedrock too|
The following commands, running in this order, will keep track of whether a player matched the selector `@a[x=73,y=10,z=3,distance=..1]`:
- tag @a[tag=alreadyMatched] remove alreadyMatched
- tag @a[x=73,y=10,z=3,distance=..1] add alreadyMatched
+```mcfunction
+tag @a[tag=alreadyMatched] remove alreadyMatched
+tag @a[x=73,y=10,z=3,distance=..1] add alreadyMatched
+```
Players who matched the selector will get the `alreadyMatched` scoreboard tag (you can call this scoreboard tag whatever you want, so long as you're consistent with it). At the start of the next tick, players who matched the selector in the previous tick will have the `alreadyMatched` scoreboard tag. This means that we can select players who don't have the scoreboard tag (`tag=!alreadyMatched`, meaning they didn't match in the previous tick) but do *now* match the selector:
- execute as @a[x=73,y=10,z=3,distance=..1,tag=!alreadyMatched] run say I just entered the area!
- tag @a[tag=alreadyMatched] remove alreadyMatched
- tag @a[x=73,y=10,z=3,distance=..1] add alreadyMatched
+```mcfunction
+# Command blocks / tick function
+execute as @a[x=73,y=10,z=3,distance=..1,tag=!alreadyMatched] run say I just entered the area!
+tag @a[tag=alreadyMatched] remove alreadyMatched
+tag @a[x=73,y=10,z=3,distance=..1] add alreadyMatched
+```
\ No newline at end of file
diff --git a/questions/scorecompare.md b/questions/scorecompare.md
index 12400354b..0947a067b 100644
--- a/questions/scorecompare.md
+++ b/questions/scorecompare.md
@@ -4,7 +4,7 @@
### 1.13 and above
-In 1.13, the [`if score`](https://minecraft.wiki/w/Commands/execute#(if|unless)_score) execute subcommand makes this a lot easier. The syntax you'll want is:
+In 1.13, the [`if score`](https://minecraft.wiki/w/Commands/execute#(if%7Cunless)_score) execute subcommand makes this a lot easier. The syntax you'll want is:
execute if score (<|<=|=|>|>=) run
@@ -24,7 +24,7 @@ You can also use `matches` to check for a [range](/wiki/questions/range) if you
### 1.12 and below
-To do this we must take one score from another, check if the score is now equal to/greater than/less than 0, then add the score back (to restore the first score's original value).
+To do this, we must take one score from another, check if the score is now equal to/greater than/less than 0, then add the score back (to restore the first score's original value).
For example, select all players whose `kills` score is greater than their `deaths` score:
@@ -46,40 +46,48 @@ For example, select all players whose `kills` score is greater than their `death
### 1.20.5 and above
-Since version 1.20.5 can also compare values in storage directly, without copying values to scoreboard. Below is an example of using the `minecraft:value_check` condition to compare values in storage.
-
- # Example storage
- data merge storage example:data {value:7.5f,min:0,max:10}
-
- # predicate example:storage_compire
- {
- "condition": "minecraft:value_check",
- "value": {
- "type": "minecraft:storage",
- "storage": "example:data",
- "path": "value"
- },
- "range": {
- "min": {
- "type": "minecraft:storage",
- "storage": "example:data",
- "path": "min"
- },
- "max": {
- "type": "minecraft:storage",
- "storage": "example:data",
- "path": "max"
- }
- }
+Since version 1.20.5 can also compare values in storage directly, without copying values to the scoreboard. Below is an example of using the `minecraft:value_check` condition to compare values in storage.
+
+
+ See example
+
+```mcfunction
+# Example storage
+data merge storage example:data {value:7.5f,min:0,max:10}
+```
+```json
+# predicate example:storage_compire
+{
+ "condition": "minecraft:value_check",
+ "value": {
+ "type": "minecraft:storage",
+ "storage": "example:data",
+ "path": "value"
+ },
+ "range": {
+ "min": {
+ "type": "minecraft:storage",
+ "storage": "example:data",
+ "path": "min"
+ },
+ "max": {
+ "type": "minecraft:storage",
+ "storage": "example:data",
+ "path": "max"
}
+ }
+}
+```
+
+
This now allows to compare values more accurately because it supports non-integer variable values for comparison.
### 1.15 and above
-Since version 1.15 you can also use [predicates](https://minecraft.wiki/w/Predicate) in a datapack to compare scores. Unlike using the `if score` subcommand, you cannot in most cases compare the score values between two entities. Basically this is only available in mob loot tables and you can only compare the score between the killed mob (`this`) and the entity that killed the mob (`killer` / `killer_player`), or the projectile that killed the mob (`direct_killer`). In other cases, you can only check the score of the selected entity (`this`) and score [fakename](/wiki/questions/fakeplayer).
+Since version 1.15 you can also use [predicates](https://minecraft.wiki/w/Predicate) in a datapack to compare scores. Unlike using the `if score` subcommand, you cannot, in most cases, compare the score values between two entities. Basically this is only available in mob loot tables and you can only compare the score between the killed mob (`this`) and the entity that killed the mob (`killer` / `killer_player`), or the projectile that killed the mob (`direct_killer`). In other cases, you can only check the score of the selected entity (`this`) and score [fakename](/wiki/questions/fakeplayer).
-You can compare score in a predicate using the `minecraft:entity_scores` condition to compare the score of the selected entity with a specific value or a specified range of values, as well as using the `minecraft:value_check` condition which does the same thing, but without using the entity.
+You can compare scores in a predicate using the `minecraft:entity_scores` condition to compare the score of the selected entity with a specific value or a specified range of values, as well as using the `minecraft:value_check` condition, which does the same thing, but without using the entity.
But you can't just use comparison operators (=, >, <, >=, <=), but only compare whether the value is in the specified range.
@@ -92,71 +100,57 @@ For `entity_score` condition, you can compare the value of the selected entity w
Example to compare that players score `kills` >= score `deaths`:
- # execute if score @s kills >= @s deaths
- {
- "condition": "minecraft:entity_scores",
- "entity": "this",
- "scores": {
- "kills": {
- "min": {
- "type": "minecraft:score",
- "target": "this",
- "score": "deaths"
- }
- }
+
+ See example
+
+```json
+# execute if score @s kills >= @s deaths
+{
+ "condition": "minecraft:entity_scores",
+ "entity": "this",
+ "scores": {
+ "kills": {
+ "min": {
+ "type": "minecraft:score",
+ "target": "this",
+ "score": "deaths"
}
}
+ }
+}
+```
+
For the <= operator, simply replace `"min"` with `"max"` in the predicate above.
But if you want to check that score `kills` > `deaths`, then checking in the predicate will be a little more complicated. So, we need to do two checks: first check that `kills` >= `deaths`, AND the second check is the inversion of the condition `kills` <= `deaths`.
- # execute if score @s kills > @s deaths
- [
- {
- "condition": "minecraft:entity_scores",
- "entity": "this",
- "scores": {
- "kills": {
- "min": {
- "type": "minecraft:score",
- "target": "this",
- "score": "deaths"
- }
- }
- }
- },
- {
- "condition": "minecraft:inverted",
- "term": {
- "condition": "minecraft:entity_scores",
- "entity": "this",
- "scores": {
- "kills": {
- "max": {
- "type": "minecraft:score",
- "target": "this",
- "score": "deaths"
- }
- }
- }
+
+ See example
+
+```json
+# execute if score @s kills > @s deaths
+[
+ {
+ "condition": "minecraft:entity_scores",
+ "entity": "this",
+ "scores": {
+ "kills": {
+ "min": {
+ "type": "minecraft:score",
+ "target": "this",
+ "score": "deaths"
}
}
- ]
-
-If you need to check that `kills` = `deaths` score, then you can do one range check, where `"min"` and `"max"` are the same score.
-
- # execute if score @s kills = @s deaths
- {
+ }
+ },
+ {
+ "condition": "minecraft:inverted",
+ "term": {
"condition": "minecraft:entity_scores",
"entity": "this",
"scores": {
"kills": {
- "min": {
- "type": "minecraft:score",
- "target": "this",
- "score": "deaths"
- },
"max": {
"type": "minecraft:score",
"target": "this",
@@ -165,3 +159,35 @@ If you need to check that `kills` = `deaths` score, then you can do one range ch
}
}
}
+ }
+]
+```
+
+
+
+If you need to check that `kills` = `deaths` score, then you can do one range check, where `"min"` and `"max"` are the same score.
+
+
+ See example
+
+```json
+# execute if score @s kills = @s deaths
+{
+ "condition": "minecraft:entity_scores",
+ "entity": "this",
+ "scores": {
+ "kills": {
+ "min": {
+ "type": "minecraft:score",
+ "target": "this",
+ "score": "deaths"
+ },
+ "max": {
+ "type": "minecraft:score",
+ "target": "this",
+ "score": "deaths"
+ }
+ }
+ }
+}
+```
\ No newline at end of file
diff --git a/questions/shootfacing.md b/questions/shootfacing.md
index ba7361cc1..71d6441e0 100644
--- a/questions/shootfacing.md
+++ b/questions/shootfacing.md
@@ -26,74 +26,91 @@ So, we can get the players location using its `Pos` NBT values and we can summon
Or rather, make use of the fact that we can use the worlds zero position and pretend the player is there. And because X - 0 = X, we don't need to do the math ourselves but can directly store the result into the entity. Here is how it works (running `as` and `at` the player):
- # summon temporary entity "in front of the player", if the player was standing at 0 0 0
- execute positioned 0.0 0 0.0 run summon marker ^ ^ ^1 {Tags:["direction"]}
+
+ See example
- # summon the projectile entity (e.g. sheep, but can also be an arrow/snowball/etc.
- # When using a projectile, you might want to summon it in front of the player so it doesn't hit the player themselves)
- # you might want to summon it at the players eyes as well using anchored eyes
- summon sheep ~ ~ ~ {Tags:["projectile"]}
+```mcfunction
+# summon temporary entity "in front of the player", if the player was standing at 0 0 0
+execute positioned 0.0 0 0.0 run summon marker ^ ^ ^1 {Tags:["direction"]}
- # copy the markers position tag to the sheeps motion tag
- data modify entity @e[type=sheep,tag=projectile,limit=1] Motion set from entity @e[type=marker,tag=direction,limit=1] Pos
+# summon the projectile entity (e.g. sheep, but can also be an arrow/snowball/etc.
+# When using a projectile, you might want to summon it in front of the player so it doesn't hit the player themselves)
+# you might want to summon it at the players eyes as well using anchored eyes
+summon sheep ~ ~ ~ {Tags:["projectile"]}
- # clean up
- tag @e[tag=projectile] remove projectile
- kill @e[tag=direction]
+# copy the markers position tag to the sheeps motion tag
+data modify entity @e[type=sheep,tag=projectile,limit=1] Motion set from entity @e[type=marker,tag=direction,limit=1] Pos
+
+# clean up
+tag @e[tag=projectile] remove projectile
+kill @e[tag=direction]
+```
+
+
**This method requires the worlds `0 0 0` point to be loaded to work. If that is not the case or cannot be guaranteed, use the following modification instead (still `as` and `at` the player).** It ensures that the marker entity doesn't get lost along the way by being teleported to unloaded chunks. Luckily the `@s` selector is able to still select the entity even if it was unloaded, which means we can do it as follows.
- # summon the temporary entity at the players position
- summon marker ~ ~ ~ {Tags:["direction"]}
-
- # execute the below function as the marker entity, so it doesn't get lost from being unloaded
- # also run positioned at the world zero point
- execute as @e[tag=direction,limit=1] positioned 0.0 0.0 0.0 run function namespace:get_motion
-
- # summon the projectile entity. Again, it might make sense to summon the projectile at the players eyes
- # and in front of them, so we'll do that in this example
- execute anchored eyes run summon sheep ^ ^ ^1 {Tags:["projectile"]}
-
- # store the previously stored Motion into the projectile entity
- data modify entity @e[tag=projectile,limit=1] Motion set from storage namespace:storage Motion
-
- # clean up the tag
- tag @e[tag=projectile] remove projectile
-
-`get_motion.mcfunction`
-
- # this function is executed as the marker entity, positioned at 0 0 0 and still rotated as the player
- # (as that wasn't changed with the function call)
-
- # teleport the entity forward by 1 block (based on the player rotation and the position 0 0 0).
- tp @s ^ ^ ^1
-
- # store the current position in the worlds NBT storage so we don't loose it
- data modify storage namespace:storage Motion set from entity @s Pos
-
- # we don't need this entity anymore
- kill @s
+
+ See example
+
+```mcfunction
+# summon the temporary entity at the players position
+summon marker ~ ~ ~ {Tags:["direction"]}
+
+# execute the below function as the marker entity, so it doesn't get lost from being unloaded
+# also run positioned at the world zero point
+execute as @e[tag=direction,limit=1] positioned 0.0 0.0 0.0 run function example:get_motion
+
+# summon the projectile entity. Again, it might make sense to summon the projectile at the players eyes
+# and in front of them, so we'll do that in this example
+execute anchored eyes run summon sheep ^ ^ ^1 {Tags:["projectile"]}
+
+# store the previously stored Motion into the projectile entity
+data modify entity @e[tag=projectile,limit=1] Motion set from storage example:storage Motion
+
+# clean up the tag
+tag @e[tag=projectile] remove projectile
+
+# function example:get_motion
+
+# this function is executed as the marker entity, positioned at 0 0 0 and still rotated as the player
+# (as that wasn't changed with the function call)
+
+# teleport the entity forward by 1 block (based on the player rotation and the position 0 0 0).
+tp @s ^ ^ ^1
+
+# store the current position in the worlds NBT storage so we don't loose it
+data modify storage example:storage Motion set from entity @s Pos
+
+# we don't need this entity anymore
+kill @s
+```
+
Since version 1.19.4 you can use `summon` inside the `/execute` command, which allows you to simplify shootfacing and combine the command of calling the direction of an entity and modifying the `Motion` tag of the projectile.
Now, instead of a marker that must be manually killed, you can use area_effect_cloud, which will disappear on its own on the next tick. Also, force loaded coordinates 0 0 0 are no longer required to work, since we are creating and using direction entities within one command, but it is still strongly recommended to load chunks [-1, -1] to [0, 0], since area_effect_cloud will not be deleted in unloaded chunks automatically.
- # Summon the projectile entity
- summon sheep ~ ~ ~ {Tags:["projectile"]}
-
- # Use player rotation to create an area_effect_cloud of about 0 0 and immediately copy the position of this entity into the projectile motion tag.
- execute rotated as positioned 0.0 0.0 0.0 positioned ^ ^ ^1 summon area_effect_cloud run data modify entity @e[tag=projectile,limit=1] Motion set from entity @s Pos
-
- # Remove projectile tag
- tag @e[tag=projectile] remove projectile
+```mcfunction
+# Summon the projectile entity
+summon sheep ~ ~ ~ {Tags:["projectile"]}
+
+# Use player rotation to create an area_effect_cloud of about 0 0 and immediately copy the position of this entity into the projectile motion tag.
+execute rotated as positioned 0.0 0.0 0.0 positioned ^ ^ ^1 summon area_effect_cloud run data modify entity @e[tag=projectile,limit=1] Motion set from entity @s Pos
+
+# Remove projectile tag
+tag @e[tag=projectile] remove projectile
+```
`^ ^ ^1` is used as the throw strength.
You can go ahead and do this using almost just one command block. You can perform all settings using `store success entity`. For example, for a fireball, you can immediately set ExplosionPower and power[1] so that the projectile does not fly in a straight line, but in an arc:
- # Command blocks
- tag @e[type=fireball,tag=!exist] add exist
- execute as at @s anchored eyes positioned ^ ^ ^3 summon fireball store success entity @s ExplosionPower byte 4 store success entity @s power[1] double -0.08 positioned 0.0 0.0 0.0 positioned ^ ^ ^1 summon area_effect_cloud run data modify entity @e[type=fireball,tag=!exist,limit=1] Motion set from entity @s Pos
+```mcfunction
+# Command blocks
+tag @e[type=fireball,tag=!exist] add exist
+execute as at @s anchored eyes positioned ^ ^ ^3 summon fireball store success entity @s ExplosionPower byte 4 store success entity @s power[1] double -0.08 positioned 0.0 0.0 0.0 positioned ^ ^ ^1 summon area_effect_cloud run data modify entity @e[type=fireball,tag=!exist,limit=1] Motion set from entity @s Pos
+```
However, you may notice that this projectile lags in flight. Read about how to fix this in the [\[Visual bug fix\]](#visual-bug-fix) section.
@@ -105,33 +122,39 @@ However, you may notice that this projectile lags in flight. Read about how to f
This example will assume you have a dummy scoreboard objective set up that is named `pos` and that you're running these commands `as` and `at` the player (in a function). Whenever you see `#` this is a [fake player](/wiki/questions/fakeplayer) that we use for convenient value storage. Because scoreboards can only hold integer values (whole numbers), we scale up the values by 1000 when storing them and down by 0.001 when putting them back into the Motion tag so we don't lose too much accuracy. We need to use scoreboards however, because we need to do some subtractions which is only conveniently possible with scoreboard operations. (This means that the system will stop working once you go above a position of 2'000'000 on either axis, if that is a concern, change it to 100/0.01, that way you can reach 2/3 to the worldborder without issues.)
- # summon the temporary entity
- summon marker ^ ^ ^1 {Tags:["direction"]}
-
- # get the coordinates of the player and the entity
- execute store result score #playerX pos run data get entity @s Pos[0] 1000
- execute store result score #playerY pos run data get entity @s Pos[1] 1000
- execute store result score #playerZ pos run data get entity @s Pos[2] 1000
- execute store result score #targetX pos as @e[type=marker,tag=direction,limit=1] run data get entity @s Pos[0] 1000
- execute store result score #targetY pos as @e[type=marker,tag=direction,limit=1] run data get entity @s Pos[1] 1000
- execute store result score #targetZ pos as @e[type=marker,tag=direction,limit=1] run data get entity @s Pos[2] 1000
-
- # do the math
- scoreboard players operation #targetX pos -= #playerX pos
- scoreboard players operation #targetY pos -= #playerY pos
- scoreboard players operation #targetZ pos -= #playerZ pos
-
- # summon the projectile entity
- summon sheep ~ ~ ~ {Tags:["projectile"]}
-
- # apply motion to projectile
- execute store result entity @e[type=sheep,tag=projectile,limit=1] Motion[0] double 0.001 run scoreboard players get #targetX pos
- execute store result entity @e[type=sheep,tag=projectile,limit=1] Motion[1] double 0.001 run scoreboard players get #targetY pos
- execute store result entity @e[type=sheep,tag=projectile,limit=1] Motion[2] double 0.001 run scoreboard players get #targetZ pos
-
- # clean up, ready for the next player
- tag @e[tag=projectile] remove projectile
- kill @e[tag=direction]
+
+ See example
+
+```mcfunction
+# summon the temporary entity
+summon marker ^ ^ ^1 {Tags:["direction"]}
+
+# get the coordinates of the player and the entity
+execute store result score #playerX pos run data get entity @s Pos[0] 1000
+execute store result score #playerY pos run data get entity @s Pos[1] 1000
+execute store result score #playerZ pos run data get entity @s Pos[2] 1000
+execute store result score #targetX pos as @e[type=marker,tag=direction,limit=1] run data get entity @s Pos[0] 1000
+execute store result score #targetY pos as @e[type=marker,tag=direction,limit=1] run data get entity @s Pos[1] 1000
+execute store result score #targetZ pos as @e[type=marker,tag=direction,limit=1] run data get entity @s Pos[2] 1000
+
+# do the math
+scoreboard players operation #targetX pos -= #playerX pos
+scoreboard players operation #targetY pos -= #playerY pos
+scoreboard players operation #targetZ pos -= #playerZ pos
+
+# summon the projectile entity
+summon sheep ~ ~ ~ {Tags:["projectile"]}
+
+# apply motion to projectile
+execute store result entity @e[type=sheep,tag=projectile,limit=1] Motion[0] double 0.001 run scoreboard players get #targetX pos
+execute store result entity @e[type=sheep,tag=projectile,limit=1] Motion[1] double 0.001 run scoreboard players get #targetY pos
+execute store result entity @e[type=sheep,tag=projectile,limit=1] Motion[2] double 0.001 run scoreboard players get #targetZ pos
+
+# clean up, ready for the next player
+tag @e[tag=projectile] remove projectile
+kill @e[tag=direction]
+```
+
Instead of using 2 entities, you can also only use the projectile entity. Make sure if you teleport it twice (once to the "target" position and then to the "starting" position) that you apply the motion **after** the teleportation, because teleportation resets y motion.
@@ -143,42 +166,52 @@ Also, using this Method instead of Method 1, you can more easily modify the indi
However, you may notice that some entities that you want to use may visually lag when summoned and fall in front of the player. This is due to the fact that the movement of this entity is not updated on the client, but this can be easily fixed by updating the NBT data **on the next tick** in any way. The simplest and "safest" thing is to update the `Air` store tag with some value.
- execute as @e[tag=projectile] store result entity @s Air short 1 run time query gametime
+```mcfunction
+execute as @e[tag=projectile] store result entity @s Air short 1 run time query gametime
+```
**It is important to update the data on the next tick, but not on the current one!** But for some projectiles it may be necessary to update the `Air` tag every tick, but not just once.
If you are using command blocks, you can achieve this by running this command **before** summon and changing the `Motion` tag. Here is a complete example for command blocks:
- # In chat
- scoreboard objectives add click used:carrot_on_a_stick
- forceload add -1 -1 0 0
-
- # Command blocks
- execute as @e[tag=projectile] store result entity @s Air short 1 run time query gametime
- tag @e[tag=projectile] remove projectile
- execute as @a[scores={click=1..}] at @s anchored eyes run summon snowball ^ ^ ^ {Tags:["projectile"]}
- execute rotated as @a[scores={click=1..}] positioned 0.0 0.0 0.0 positioned ^ ^ ^1 summon minecraft:area_effect_cloud run data modify entity @e[tag=projectile,limit=1] Motion set from entity @s Pos
- scoreboard players reset @a click
+```mcfunction
+# In chat
+scoreboard objectives add click used:carrot_on_a_stick
+forceload add -1 -1 0 0
+
+# Command blocks
+execute as @e[tag=projectile] store result entity @s Air short 1 run time query gametime
+tag @e[tag=projectile] remove projectile
+execute as @a[scores={click=1..}] at @s anchored eyes run summon snowball ^ ^ ^ {Tags:["projectile"]}
+execute rotated as @a[scores={click=1..}] positioned 0.0 0.0 0.0 positioned ^ ^ ^1 summon minecraft:area_effect_cloud run data modify entity @e[tag=projectile,limit=1] Motion set from entity @s Pos
+scoreboard players reset @a click
+```
When using a datapack, you can use the schedule function to do this fix.
- # function example:tick
- execute as @a[scores={click=1..}] at @s run function example:click
-
- # function example:click
- scoreboard players reset @s click
- execute anchored eyes positioned ^ ^ ^ summon snowball run function example:shootfacing
-
- # function example:shootfacing
- tag @s add this
- execute positioned 0.0 0.0 0.0 positioned ^ ^ ^1 summon minecraft:area_effect_cloud run data modify entity @e[tag=this,limit=1] Motion set from entity @s Pos
- tag @s remove this
- tag @s add fix
- schedule function example:fix 2t replace
-
- # function example:fix
- execute unless entity @s as @e[tag=fix] run function example:fix
- execute store result entity @s Air short 1 run time query gametime
- tag @s remove fix
+
+ See example
+
+```mcfunction
+# function example:tick
+execute as @a[scores={click=1..}] at @s run function example:click
+
+# function example:click
+scoreboard players reset @s click
+execute anchored eyes positioned ^ ^ ^ summon snowball run function example:shootfacing
+
+# function example:shootfacing
+tag @s add this
+execute positioned 0.0 0.0 0.0 positioned ^ ^ ^1 summon minecraft:area_effect_cloud run data modify entity @e[tag=this,limit=1] Motion set from entity @s Pos
+tag @s remove this
+tag @s add fix
+schedule function example:fix 2t replace
+
+# function example:fix
+execute unless entity @s as @e[tag=fix] run function example:fix
+execute store result entity @s Air short 1 run time query gametime
+tag @s remove fix
+```
+
You may notice that in the case of the datapack, the schedule is runs with a delay of 2 ticks, but not 1 tick. This is because inside a tick schedule, the tick function runs before the schedule function runs, and therefore a 1 tick delay when running from a tick function will run the function on the same tick, but not on the next one.
diff --git a/questions/shop.md b/questions/shop.md
index 6a10ef612..de34fbb04 100644
--- a/questions/shop.md
+++ b/questions/shop.md
@@ -1,13 +1,17 @@
# How to make a shop
This is a quick guide of how to make a shop where you can buy items with other items or costing a scoreboard value (money or coins).
+* [Java](#java)
+* [Bedrock](#bedrock)
+
## Item shop
This method consists of buying items with other items, in this example, you will buy 1 netherite ingot with 5 diamonds.
-_Related:_ [Count how much of X item the player has](wiki/questions/amountitems)
+_Related:_ [Count how much of X item the player has](/wiki/questions/amountitems)
-> [!NOTE]
-> You can add any command you want to run (for example a playsound) before the last command, but the selector must be the same as the command before.
+| 📝 Note |
+|--------------|
+|You can add any command you want to run (for example a playsound) before the last command, but the selector must be the same as the command before|
### Java
@@ -20,52 +24,59 @@ Using command blocks we need to make sure we select the correct player every tim
To avoid the player getting unintentionally re-selected we remove the tag at the end.
Using functions we can rely on `@s` instead, assuming the function is executed `as` the relevant player.
- # Command blocks
- tag @p add buyer.netherite
- execute as @a[tag=buyer.netherite] store result score @s diamonds run clear @s diamond 0
- give @a[tag=buyer.netherite,scores={diamonds=5..}] netherite_ingot 1
- clear @a[tag=buyer.netherite,scores={diamonds=5..}] diamond 5
- tellraw @a[tag=buyer.netherite,scores={diamonds=5..}] {"text":"You bought a netherite ingot for 5 diamonds","color":"green"}
- tellraw @a[tag=buyer.netherite,scores={diamonds=..4}] {"text":"You don't have 5 diamonds","color":"dark_red"}
- tag @a remove buyer.netherite
+```mcfunction
+# Command blocks
+tag @p add buyer.netherite
+execute as @a[tag=buyer.netherite] store result score @s diamonds run clear @s diamond 0
+give @a[tag=buyer.netherite,scores={diamonds=5..}] netherite_ingot 1
+clear @a[tag=buyer.netherite,scores={diamonds=5..}] diamond 5
+tellraw @a[tag=buyer.netherite,scores={diamonds=5..}] {"text":"You bought a netherite ingot for 5 diamonds","color":"green"}
+tellraw @a[tag=buyer.netherite,scores={diamonds=..4}] {"text":"You don't have 5 diamonds","color":"dark_red"}
+tag @a remove buyer.netherite
+```
Or if you prefer a function:
- # function example:load
- scoreboard objectives add diamonds dummy
-
- # function example:buy/netherite
- execute store result score @s diamonds run clear @s diamond 0
- execute if entity @s[scores={diamonds=5..}] run function example:buy/netherite/success
- execute unless entity @s[scores={diamonds=5..}] run tellraw @s {"text":"You don't have 5 diamonds","color":"dark_red"}
+```mcfunction
+# function example:load
+scoreboard objectives add diamonds dummy
- # function example:buy/netheirte/success
- give @s netherite_ingot 1
- clear @s diamond 5
- tellraw @s {"text":"You bought a netherite ingot for 5 diamonds","color":"green"}
+# function example:buy/netherite
+execute store result score @s diamonds run clear @s diamond 0
+execute if entity @s[scores={diamonds=5..}] run function example:buy/netherite/success
+execute unless entity @s[scores={diamonds=5..}] run tellraw @s {"text":"You don't have 5 diamonds","color":"dark_red"}
-> [!NOTE]
-> The function `example:buy/netherite` must be run `as` the player
+# function example:buy/netheirte/success
+give @s netherite_ingot 1
+clear @s diamond 5
+tellraw @s {"text":"You bought a netherite ingot for 5 diamonds","color":"green"}
+```
+
+| 📝 Note |
+|--------------|
+|The function `example:buy/netherite` must be run `as` the player|
In 1.20.5 `execute if items` was added, which allows to count items in a diferent way.
To use this method, all command remains the same, as the previus example except the one for counting items that is this one:
- execute as @a[tag=buyer.netherite] store result score @s diamonds run clear @s diamond 0
-
+```mcfunction
+execute as @a[tag=buyer.netherite] store result score @s diamonds run clear @s diamond 0
+```
That we can replace it for this one:
-
- execute as @p[tag=buyer.netherite] store result score @s diamonds if items entity @s container.* diamond
-
+```mcfunction
+execute as @p[tag=buyer.netherite] store result score @s diamonds if items entity @s container.* diamond
+```
Or if you are using the example function, you need to replace this command
-
- execute store result score @s diamonds run clear @s diamond 0
-
+```mcfunction
+execute store result score @s diamonds run clear @s diamond 0
+```
With this command:
- execute store result score @s diamonds if items entity @s container.* diamond
+execute store result score @s diamonds if items entity @s container.* diamond
-> [!NOTE]
-> The method that uses the `/clear` command will work in 1.20.5+ but it is recomended to use the one specific for that versions (using `execute if items`, that will not work below 1.20.5).
+| 📝 Note |
+|--------------|
+|The method that uses the `/clear` command will work in 1.20.5+ but it is recomended to use the one specific for that versions (using `execute if items`, that will not work below 1.20.5)|
#### Using a villager
Villagers are a passive mob that can be interacted with, and will open the trading GUI.
@@ -91,7 +102,8 @@ Here is an example command:
```
/summon villager ~ ~ ~ {Offers:{Recipes:[{rewardExp:0b,maxUses:2147483647,buy:{id:"minecraft:diamond",count:1},buyB:{id:"minecraft:emerald",count:1},sell:{id:"minecraft:netherite_ingot",count:1}}]}}
```
-Let's break it donw:
+
+Let's break it down:
* Inside `Offers` we have `Recipes`, there will be all listed trades.
* This trade has `rewardExp:0b` so the player will not get any experience when buying it (you can enable it if you want).
* `maxUses:2147483647` is the maximum times it can be traded, this is the maximum value we can set.
@@ -114,19 +126,24 @@ In bedrock we have the `hasitem` argument, so it uses less commands than in Java
If you don't want to use an NPC can use this method, it is very similar to Java but it uses the `hasitem` argument instead.
- tag @p add buyer.netherite
- give @a[tag=buyer.netherite,hasitem={item=diamond,quantity=5..}] netherite_ingot
- tellraw @a[tag=buyer.netherite,hasitem={item=diamond,quantity=5..}] {"rawtext":[{"text":"§2You bought a netherite ingot"}]}
- tellraw @a[tag=buyer.netherite,hasitem={item=diamond,quantity=..5}] {"rawtext":[{"text":"§3You don't have 5 diamonds"}]}
- clear @a[tag=buyer.netherite,hasitem={item=diamond,quantity=5..}] diamond 5
- tag @a remove buyer.netherite
+```mcfunction
+# Command blocks
+tag @p add buyer.netherite
+give @a[tag=buyer.netherite,hasitem={item=diamond,quantity=5..}] netherite_ingot
+tellraw @a[tag=buyer.netherite,hasitem={item=diamond,quantity=5..}] {"rawtext":[{"text":"§2You bought a netherite ingot"}]}
+tellraw @a[tag=buyer.netherite,hasitem={item=diamond,quantity=..5}] {"rawtext":[{"text":"§3You don't have 5 diamonds"}]}
+clear @a[tag=buyer.netherite,hasitem={item=diamond,quantity=5..}] diamond 5
+tag @a remove buyer.netherite
+```
-> [!NOTE]
-> in order for it to work with npc, change `@p` to `@initiator`
-> _Related: [How to setup a NPC?](wiki/questions/npc)_
+| 📝 Note |
+|--------------|
+|in order for it to work with npc, change `@p` and `@a` to `@initiator`|
+|_Related: [How to setup a NPC?](/wiki/questions/npc)_|
-> [!NOTE]
-> It is super important to clear the diamonds in the last step before removing the tag
+| 📝 Note |
+|--------------|
+|It is super important to clear the diamonds in the last step before removing the tag|
### Add more than one items
In this gide we will use just one item, but you can have multiples but it will require a second tag, that must be added if the player has both items.
@@ -134,17 +151,19 @@ Then when we clear the items we are going to clear them for the player with that
In this example we will buy a gold block with 2 emeralds and 5 diamonds. If you are in Java you will need one scoreboard for each item, assuming you already store the items result in each one.
- # Example
- tag @p add buyer.example
- execute as @a[tag=buyer.example] run tag @s[scores={diamonds=5..,emeralds=2..}] add buy.example
- # run any tellraw to the player with the tag buy.example
- clear @a[tag=buy.example] diamond 5
- clear @a[tag=buy.example] emerald 2
- give @a[tag=buy.example] gold_block 1
-And then we remove all the previus used tags:
-
- tag @a remove buy.example
- tag @a remove buyer.example
+```mcfunction
+# Command blocks
+tag @p add buyer.example
+execute as @a[tag=buyer.example] run tag @s[scores={diamonds=5..,emeralds=2..}] add buy.example
+# Run any tellraw to the player with the tag buy.example
+clear @a[tag=buy.example] diamond 5
+clear @a[tag=buy.example] emerald 2
+give @a[tag=buy.example] gold_block 1
+
+# And then we remove all the previus used tags
+tag @a remove buy.example
+tag @a remove buyer.example
+```
In bedrock use the `hasitem` argument instead of `scores`
@@ -158,28 +177,34 @@ In this example the currency is a `dummy` scoreboard called `coins`.
#### With command blocks
-> [!NOTE]
-> This example uses Java syntax for the message that appears when the player buys the item
-
- /tag @p add buyer.diamond
- /execute as @p[tag=buyer.diamond] run tag @s[scores={coins=10..}] add buy.diamond
- /scoreboard players remove @a[tag=buy.diamond] coins 10
- /tellraw @a[tag=buyer_diamond,tag=!buy.diamond] "You need at least 10 coins"
- /tellraw @a[tag=buy.diamond] "You bought a diamond"
- /tag @a remove buy.diamond
- /tag @a remove buyer.diamond
+| 📝 Note |
+|--------------|
+|This example uses Java syntax for the message that appears when the player buys the item|
+
+```mcfunction
+tag @p add buyer.diamond
+execute as @p[tag=buyer.diamond] run tag @s[scores={coins=10..}] add buy.diamond
+scoreboard players remove @a[tag=buy.diamond] coins 10
+tellraw @a[tag=buyer_diamond,tag=!buy.diamond] "You need at least 10 coins"
+tellraw @a[tag=buy.diamond] "You bought a diamond"
+tag @a remove buy.diamond
+tag @a remove buyer.diamond
+```
#### In a function
This is more optimized compared to using command blocks as functions keep the context
- # function example:buy/diamond
- execute if entity @s[scores={coins=10..}] run function example:buy/diamond/success
- tellraw @s[scores={coins=..9}] {"text":"You don't have 10 coins","color":"red"}
+```mcfunction
+# function example:buy/diamond
+execute if entity @s[scores={coins=10..}] run function example:buy/diamond/success
+tellraw @s[scores={coins=..9}] {"text":"You don't have 10 coins","color":"red"}
- # function example:buy/diamond/success
- give @s diamond
- scoreboard players remove @s coins 10
- tellraw @s {"text":"You bought a diamond","color":"green"}
+# function example:buy/diamond/success
+give @s diamond
+scoreboard players remove @s coins 10
+tellraw @s {"text":"You bought a diamond","color":"green"}
+```
-> [!NOTE]
-> The function `example:buy/diamond` must be run `as` the player
+| 📝 Note |
+|--------------|
+|The function `example:buy/diamond` must be run `as` the player|
\ No newline at end of file
diff --git a/questions/storeinventory.md b/questions/storeinventory.md
index eeb9c4160..a3c9920d0 100644
--- a/questions/storeinventory.md
+++ b/questions/storeinventory.md
@@ -12,8 +12,9 @@ For this, you need to put them somewhere in a confined space, so the items don't
Same for the return part, as you only want to give the player who owns the items those items back. You also need to consider that a completely full inventory (including armor) will not be able to be picked up instantly by the player without them manually equipping their armor.
-> [!CAUTION]
-> You will lose any item with the curse of vanishing enchantment
+| ⚠️ Caution |
+|------------|
+|You will lose any item with the curse of vanishing enchantment|
### Custom Hopper Entity
@@ -21,34 +22,40 @@ This method requires you to make a custom entity that has both an `minecraft:inv
The `inventory_size` needs to be at least 40 slots, but it is recommended in this case to just add a few more for good measure.
- "components": {
- "minecraft:inventory": {
- "inventory_size": 45,
- "container_type": "container"
- }
- }
+```json
+"components": {
+ "minecraft:inventory": {
+ "inventory_size": 45,
+ "container_type": "container"
+ }
+}
+```
Next, since you'll want to add an event that removes the `item_hopper` component and one that kills the entity (e.g. by setting its health to 0), both of these components need to be in a component group.
- "component_groups": {
- "mcc:kill_entity": {
- "minecraft:health": {"value": 0, "max": 0}
- },
- "mcc:pickup_active": {
- "minecraft:item_hopper": {}
- }
- }
+```json
+"component_groups": {
+ "mcc:kill_entity": {
+ "minecraft:health": {"value": 0, "max": 0}
+ },
+ "mcc:pickup_active": {
+ "minecraft:item_hopper": {}
+ }
+}
+```
*We can't just kill the entity without removing the item hopper functionality first, as it would spew out the items on death but would pick up 1-2 items during the death animation again which would then be deleted!*
For convenience, we can create a single event that deals with both of these component groups so we only need to execute one event.
- "events": {
- "mcc:release_items": {
- "add": {"component_groups": [ "mcc:kill_entity" ]},
- "remove": {"component_groups": [ "mcc:pickup_active" ]}
- }
- }
+```json
+"events": {
+ "mcc:release_items": {
+ "add": {"component_groups": [ "mcc:kill_entity" ]},
+ "remove": {"component_groups": [ "mcc:pickup_active" ]}
+ }
+}
+```
For a better performance however I recommend to remove the item_hopper component once you're done picking up the items through a dedicated event.
@@ -81,20 +88,28 @@ Since version 1.20.2, [macro](https://minecraft.wiki/w/Function_(Java_Edition)#M
Below is an example of storing a player's inventory in storage using the [scoreboard ID system](/wiki/questions/linkentity), or you can store the UUID / nickname instead of using the scoreboard ID system. To do this you need to run the function `example:storing` as a player.
- # function example:storing
- data remove storage example:inv this
- execute store result storage example:inv this.ID int 1 run scoreboard players get @s ID
- data modify storage example:inv this.Inventory set from entity @s Inventory
- function example:storing/update with storage example:inventory this
-
- # function example:storing/update
- $execute unless data storage example:inv players[{ID:$(ID)}] run data modify storage example:inv players append {ID:$(ID)}
- $data modify storage example:inv players[{ID:$(ID)}] merge from storage example:inv this
+
+ See example
+
+```mcfunction
+# function example:storing
+data remove storage example:inv this
+execute store result storage example:inv this.ID int 1 run scoreboard players get @s ID
+data modify storage example:inv this.Inventory set from entity @s Inventory
+function example:storing/update with storage example:inventory this
+
+# function example:storing/update
+$execute unless data storage example:inv players[{ID:$(ID)}] run data modify storage example:inv players append {ID:$(ID)}
+$data modify storage example:inv players[{ID:$(ID)}] merge from storage example:inv this
+```
+
This player data storage system will create an in storage `example:inv` object for each player in the `players` list that will look something like:
- # storage example:inv players[{ID:5}]
- {ID:5,Inventory:[{Slot:0b,id:"minecraft:stick",Count:1b}]}
+```mcfunction
+# storage example:inv players[{ID:5}]
+{ID:5,Inventory:[{Slot:0b,id:"minecraft:stick",Count:1b}]}
+```
However, this implementation can support any data other than player `ID` and `Inventory` and you can easily add saving any other data.
@@ -104,17 +119,24 @@ The way to do this is to store the players `Inventory` NBT somewhere safe. There
So, assume we want to **store** a players inventory then. This part is the easy part, as it just takes a few commands (assuming it's executed in a function `as` the player but **not** `at` the player. Instead if possible, make sure this is executed in the spawnchunks or an otherwise ensured to be loaded chunk so the marker entities stay loaded). This also assumes you have a [scoreboard ID system](/wiki/questions/linkentity) set up to link the entity to the player.
- # summon marker
- summon marker ~ ~ ~ {Tags:["inv_store","inv_new"]}
-
- # link marker to player
- scoreboard players operation @e[tag=inv_new] id = @s id
-
- # copy Inventory of player to marker data.Inventory
- data modify entity @e[tag=inv_new,limit=1] data.Inventory set from from entity @s Inventory
-
- # remove the new tag to get ready for the next player
- tag @e[tag=inv_new] remove inv_new
+
+ See example
+
+```mcfunction
+# function example:new_marker
+# summon marker
+summon marker ~ ~ ~ {Tags:["inv_store","inv_new"]}
+
+# link marker to player
+scoreboard players operation @e[tag=inv_new] id = @s id
+
+# copy Inventory of player to marker data.Inventory
+data modify entity @e[tag=inv_new,limit=1] data.Inventory set from from entity @s Inventory
+
+# remove the new tag to get ready for the next player
+tag @e[tag=inv_new] remove inv_new
+```
+
And **that's it, the entire inventory is now stored in this marker** that has been linked through a scoreboard to our player.
@@ -140,106 +162,123 @@ For items without tags, you need to create an empty tag before running the macro
Below is an example for versions 1.20.2 - 1.20.4. To do this need to run function `example:returning` as a player:
- # function example:load
- scoreboard objectives add Slot dummy
-
- # function example:returning
- ## Read player Scoreboard ID
- execute store result storage example:inv this.ID int 1 run scoreboard players get @s ID
- ## Reading the selected player's data from the entire array of data of all players.
- function example:returning/read with storage example:inv this
- ## Create an empty tag if there is no tag data in the current slot.
- execute unless data storage example:inv this.Inventory[-1].tag run data modify storage example:inv this.Inventory[-1].tag set value ""
- ## Running the function of returning items from the end of the list.
- function example:returning/item with storage example:inv this.Inventory[-1]
-
- # function example:returning/read
- $data modify storage example:inv this set from storage example:inv players[{ID:$(ID)}]
-
- # function example:returning/item
- ## Set the current slot to select slot processing
- $scoreboard players set #this Slot $(Slot)
- execute if score #this Slot matches 0..35 run function example:returning/inventory with storage example:inv this.Inventory[-1]
- execute unless score #this Slot matches 0..35 run function example:returning/equipment with storage example:inv this.Inventory[-1]
- ## After returning the current item, remove this slot from storage and start returning the next item
- data remove storage example:inv this.Inventory[-1]
- execute unless data storage example:inv this.Inventory[-1].tag run data modify storage example:inv this.Inventory[-1].tag set value ""
- function example:returning/item with storage example:inv this.Inventory[-1]
-
- # function example:returning/inventory
- ## For inventory slots, can directly insert Slot into the /item command
- function example:returning/equipment with storage example:inv this.Inventory[-1]
- $item replace entity @s container.$(Slot) $(id)$(tag) $(Count)
-
- # function example:returning/equipment
- ## Equipment slots require converting slot number to slot name
- $execute if score #this Slot matches -106 run item replace entity @s weapon.offhand $(id)$(tag) $(Count)
- $execute if score #this Slot matches 100 run item replace entity @s armor.feet $(id)$(tag) $(Count)
- $execute if score #this Slot matches 101 run item replace entity @s armor.legs $(id)$(tag) $(Count)
- $execute if score #this Slot matches 102 run item replace entity @s armor.chest $(id)$(tag) $(Count)
- $execute if score #this Slot matches 103 run item replace entity @s armor.head $(id)$(tag) $(Count)
-
+
+ See example
+
+```mcfunction
+# function example:load
+scoreboard objectives add Slot dummy
+
+# function example:returning
+## Read player Scoreboard ID
+execute store result storage example:inv this.ID int 1 run scoreboard players get @s ID
+## Reading the selected player's data from the entire array of data of all players.
+function example:returning/read with storage example:inv this
+## Create an empty tag if there is no tag data in the current slot.
+execute unless data storage example:inv this.Inventory[-1].tag run data modify storage example:inv this.Inventory[-1].tag set value ""
+## Running the function of returning items from the end of the list.
+function example:returning/item with storage example:inv this.Inventory[-1]
+
+# function example:returning/read
+$data modify storage example:inv this set from storage example:inv players[{ID:$(ID)}]
+
+# function example:returning/item
+## Set the current slot to select slot processing
+$scoreboard players set #this Slot $(Slot)
+execute if score #this Slot matches 0..35 run function example:returning/inventory with storage example:inv this.Inventory[-1]
+execute unless score #this Slot matches 0..35 run function example:returning/equipment with storage example:inv this.Inventory[-1]
+## After returning the current item, remove this slot from storage and start returning the next item
+data remove storage example:inv this.Inventory[-1]
+execute unless data storage example:inv this.Inventory[-1].tag run data modify storage example:inv this.Inventory[-1].tag set value ""
+function example:returning/item with storage example:inv this.Inventory[-1]
+
+# function example:returning/inventory
+## For inventory slots, can directly insert Slot into the /item command
+function example:returning/equipment with storage example:inv this.Inventory[-1]
+$item replace entity @s container.$(Slot) $(id)$(tag) $(Count)
+
+# function example:returning/equipment
+## Equipment slots require converting slot number to slot name
+$execute if score #this Slot matches -106 run item replace entity @s weapon.offhand $(id)$(tag) $(Count)
+$execute if score #this Slot matches 100 run item replace entity @s armor.feet $(id)$(tag) $(Count)
+$execute if score #this Slot matches 101 run item replace entity @s armor.legs $(id)$(tag) $(Count)
+$execute if score #this Slot matches 102 run item replace entity @s armor.chest $(id)$(tag) $(Count)
+$execute if score #this Slot matches 103 run item replace entity @s armor.head $(id)$(tag) $(Count)
+```
+
However, as of version 1.20.5, item tags have now been replaced with components that cannot simply be inserted into the /item command, so for this need use a loot table written inline.
Below is an example of a loot table in which you need to put the item data using a macro:
+
+ See example
+
+```json
+{
+ "pools": [
{
- "pools": [
+ "rolls": 1,
+ "entries": [
{
- "rolls": 1,
- "entries": [
+ "type": "minecraft:item",
+ "name": "$(id)",
+ "functions": [
+ {
+ "function": "minecraft:set_count",
+ "count": $(count)
+ },
{
- "type": "minecraft:item",
- "name": "$(id)",
- "functions": [
- {
- "function": "minecraft:set_count",
- "count": $(count)
- },
- {
- "function": "minecraft:set_components",
- "components": $(components)
- }
- ]
+ "function": "minecraft:set_components",
+ "components": $(components)
}
]
}
]
}
+ ]
+}
+```
+
**Note: This loot table should be inside a macro function, and not as a separate loot table file!**
Below is an updated example for version 1.20.5 without comments, since otherwise it is the same as for version 1.20.2:
- # function example:load
- scoreboard objectives add Slot dummy
-
- # function example:returning
- execute store result storage example:inv this.ID int 1 run scoreboard players get @s ID
- function example:returning/read with storage example:inv this
- execute unless data storage example:inv this.Inventory[-1].components run data modify storage example:inv this.Inventory[-1].components set value {}
- function example:returning/item with storage example:inv this.Inventory[-1]
-
- # function example:returning/read
- $data modify storage example:inv this set from storage example:inv players[{ID:$(ID)}]
-
- # function example:returning/item
- $scoreboard players set #this Slot $(Slot)
- execute if score #this Slot matches 0..35 run function example:returning/inventory with storage example:inv this.Inventory[-1]
- execute unless score #this Slot matches 0..35 run function example:returning/equipment with storage example:inv this.Inventory[-1]
- data remove storage example:inv this.Inventory[-1]
- execute unless data storage example:inv this.Inventory[-1].components run data modify storage example:inv this.Inventory[-1].components set value {}
- function example:returning/item with storage example:inv this.Inventory[-1]
-
- # function example:returning/inventory with storage example:inv this.Inventory[-1]
- $loot replace entity @s container.$(Slot) loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
-
- # function example:returning/equipment
- $execute if score #this Slot matches -106 run loot replace entity @s weapon.offhand loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
- $execute if score #this Slot matches 100 run loot replace entity @s armor.feet loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
- $execute if score #this Slot matches 101 run loot replace entity @s armor.legs loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
- $execute if score #this Slot matches 102 run loot replace entity @s armor.chest loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
- $execute if score #this Slot matches 103 run loot replace entity @s armor.head loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
+
+ See datapack
+
+```mcfunction
+# function example:load
+scoreboard objectives add Slot dummy
+
+# function example:returning
+execute store result storage example:inv this.ID int 1 run scoreboard players get @s ID
+function example:returning/read with storage example:inv this
+execute unless data storage example:inv this.Inventory[-1].components run data modify storage example:inv this.Inventory[-1].components set value {}
+function example:returning/item with storage example:inv this.Inventory[-1]
+
+# function example:returning/read
+$data modify storage example:inv this set from storage example:inv players[{ID:$(ID)}]
+
+# function example:returning/item
+$scoreboard players set #this Slot $(Slot)
+execute if score #this Slot matches 0..35 run function example:returning/inventory with storage example:inv this.Inventory[-1]
+execute unless score #this Slot matches 0..35 run function example:returning/equipment with storage example:inv this.Inventory[-1]
+data remove storage example:inv this.Inventory[-1]
+execute unless data storage example:inv this.Inventory[-1].components run data modify storage example:inv this.Inventory[-1].components set value {}
+function example:returning/item with storage example:inv this.Inventory[-1]
+
+# function example:returning/inventory with storage example:inv this.Inventory[-1]
+$loot replace entity @s container.$(Slot) loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
+
+# function example:returning/equipment
+$execute if score #this Slot matches -106 run loot replace entity @s weapon.offhand loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
+$execute if score #this Slot matches 100 run loot replace entity @s armor.feet loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
+$execute if score #this Slot matches 101 run loot replace entity @s armor.legs loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
+$execute if score #this Slot matches 102 run loot replace entity @s armor.chest loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
+$execute if score #this Slot matches 103 run loot replace entity @s armor.head loot {pools:[{rolls:1,entries:[{type:"minecraft:item",name:"$(id)",functions:[{function:"minecraft:set_count",count:$(count)},{function:"minecraft:set_components",components:$(components)}]}]}]}
+```
+
#### Putting things in the original slot (from marker)
@@ -248,66 +287,74 @@ This one is a little command intensive, but probably the easiest to understand.
**This replaces all items that might still be in the players inventory.**
Running this function `as` the marker entity and having the target player marked with the `target` tag. This assumes you have a `temp` dummy scoreboard you can use.
+
+ See example
- # count the amount of items in the array so we know how often to repeat
- execute store result score #items temp run data get entity @s data.Inventory
-
- # if there is at least one item, start the process.
- execute if score #items temp matches 1.. positioned run function namespace:return_item
-
- # remove entity, it served its purpose. If you want to keep it around
- # you should first copy the data and work on the copy instead.
- kill @s
+```mcfunction
+# count the amount of items in the array so we know how often to repeat
+execute store result score #items temp run data get entity @s data.Inventory
-`return_item.mcfunction`
+# if there is at least one item, start the process.
+execute if score #items temp matches 1.. positioned run function namespace:return_item
- # get the slot number into a scoreboard so we can use it later
- execute store result score #slot temp run data get entity @s data.Inventory[0].Slot
- # remove the Slot data so it doesn't get removed from the chest
- data remove entity @s data.Inventory[0].Slot
- # empty the chest items
- data merge block ~ ~ ~ {Items:[]}
- # copy the item data to the chest
- data modify block ~ ~ ~ Items append from entity @s data.Inventory[0]
-
- # give player the item based the slot number
- execute as @a[tag=target] run function namespace:give_correct_slot
-
- # remove item data from entity
- data remove entity @s data.Inventory[0]
- # count down the remaining slots
- scoreboard players remove #items temp 1
- # run the same function again if there are more items to process
- execute if score #items temp matches 1.. run function namespace:return_item
+# remove entity, it served its purpose. If you want to keep it around
+# you should first copy the data and work on the copy instead.
+kill @s
+```
-`give_correct_slot.mcfunction`
+`return_item.mcfunction`
- # based on the previously stored slotnumber copy the item to the correct slot
-
- # offhand
- execute if score #slot temp matches -106 run item replace entity @s weapon.offhand from block ~ ~ ~ container.0
-
- # hotbar
- execute if score #slot temp matches 0 run item replace entity @s hotbar.0 from block ~ ~ ~ container.0
- execute if score #slot temp matches 1 run item replace entity @s hotbar.1 from block ~ ~ ~ container.0
- execute if score #slot temp matches 2 run item replace entity @s hotbar.2 from block ~ ~ ~ container.0
- execute if score #slot temp matches 3 run item replace entity @s hotbar.3 from block ~ ~ ~ container.0
- ...
- execute if score #slot temp matches 8 run item replace entity @s hotbar.8 from block ~ ~ ~ container.0
-
- # inv
- execute if score #slot temp matches 9 run item replace entity @s inventory.0 from block ~ ~ ~ container.0
- execute if score #slot temp matches 10 run item replace entity @s inventory.1 from block ~ ~ ~ container.0
- execute if score #slot temp matches 11 run item replace entity @s inventory.2 from block ~ ~ ~ container.0
- execute if score #slot temp matches 12 run item replace entity @s inventory.3 from block ~ ~ ~ container.0
- ...
- execute if score #slot temp matches 35 run item replace entity @s inventory.26 from block ~ ~ ~ container.0
-
- # armor
- execute if score #slot temp matches 100 run item replace entity @s armor.feet from block ~ ~ ~ container.0
- execute if score #slot temp matches 101 run item replace entity @s armor.legs from block ~ ~ ~ container.0
- execute if score #slot temp matches 102 run item replace entity @s armor.chest from block ~ ~ ~ container.0
- execute if score #slot temp matches 103 run item replace entity @s armor.head from block ~ ~ ~ container.0
+```mcfunction
+# get the slot number into a scoreboard so we can use it later
+execute store result score #slot temp run data get entity @s data.Inventory[0].Slot
+# remove the Slot data so it doesn't get removed from the chest
+data remove entity @s data.Inventory[0].Slot
+# empty the chest items
+data merge block ~ ~ ~ {Items:[]}
+# copy the item data to the chest
+data modify block ~ ~ ~ Items append from entity @s data.Inventory[0]
+
+# give player the item based the slot number
+execute as @a[tag=target] run function namespace:give_correct_slot
+
+# remove item data from entity
+data remove entity @s data.Inventory[0]
+# count down the remaining slots
+scoreboard players remove #items temp 1
+# run the same function again if there are more items to process
+execute if score #items temp matches 1.. run function namespace:return_item
+```
+`give_correct_slot.mcfunction`
+```mcfunction
+# based on the previously stored slotnumber copy the item to the correct slot
+
+# offhand
+execute if score #slot temp matches -106 run item replace entity @s weapon.offhand from block ~ ~ ~ container.0
+
+# hotbar
+execute if score #slot temp matches 0 run item replace entity @s hotbar.0 from block ~ ~ ~ container.0
+execute if score #slot temp matches 1 run item replace entity @s hotbar.1 from block ~ ~ ~ container.0
+execute if score #slot temp matches 2 run item replace entity @s hotbar.2 from block ~ ~ ~ container.0
+execute if score #slot temp matches 3 run item replace entity @s hotbar.3 from block ~ ~ ~ container.0
+...
+execute if score #slot temp matches 8 run item replace entity @s hotbar.8 from block ~ ~ ~ container.0
+
+# inv
+execute if score #slot temp matches 9 run item replace entity @s inventory.0 from block ~ ~ ~ container.0
+execute if score #slot temp matches 10 run item replace entity @s inventory.1 from block ~ ~ ~ container.0
+execute if score #slot temp matches 11 run item replace entity @s inventory.2 from block ~ ~ ~ container.0
+execute if score #slot temp matches 12 run item replace entity @s inventory.3 from block ~ ~ ~ container.0
+...
+execute if score #slot temp matches 35 run item replace entity @s inventory.26 from block ~ ~ ~ container.0
+
+# armor
+execute if score #slot temp matches 100 run item replace entity @s armor.feet from block ~ ~ ~ container.0
+execute if score #slot temp matches 101 run item replace entity @s armor.legs from block ~ ~ ~ container.0
+execute if score #slot temp matches 102 run item replace entity @s armor.chest from block ~ ~ ~ container.0
+execute if score #slot temp matches 103 run item replace entity @s armor.head from block ~ ~ ~ container.0
+```
+
+
#### Don't care about the slot
@@ -315,30 +362,38 @@ This means that we can just go through all the items in the array and give them
Thankfully we can just recursively run through all the entries/items in the array and thus summon them all in the same tick. This is assuming you're executing this `as` the linked marker entity, but `at` the player and that you have a dummy objective you can use, this example uses `temp`.
- # count the amount of items in the array so we know how often to repeat
- execute store result score #items temp run data get entity @s data.Inventory
+
+ See example
+
+```mcfunction
+# count the amount of items in the array so we know how often to repeat
+execute store result score #items temp run data get entity @s data.Inventory
+
+# if there is at least one item, start the process.
+execute if score #items temp matches 1.. run function namespace:return_items
- # if there is at least one item, start the process.
- execute if score #items temp matches 1.. run function namespace:return_items
-
- # remove entity, it served its purpose. If you want to keep it around
- # you should first copy the data and work on the copy instead.
- kill @s
+# remove entity, it served its purpose. If you want to keep it around
+# you should first copy the data and work on the copy instead.
+kill @s
+```
`return_items.mcfunction`
- # summon a new item entity
- summon item ~ ~ ~ {Item:{id:"minecraft:stone",Count:1b},Tags:["new_item"]}
- # copy the info about the entity from the marker entity
- data modify entity @e[tag=new_item,limit=1] Item set from entity @s data.Inventory[0]
- # remove the item from the marker
- data remove entity @s data.Inventory[0]
- # remove 1 from the amount of items that we still need to process
- scoreboard players remove #items temp 1
- # remove item tag
- tag @e[tag=new_item] remove new_item
- # run the same function again if there are more items to process
- execute if score #items temp matches 1.. run function namespace:return_items
+```mcfunction
+# summon a new item entity
+summon item ~ ~ ~ {Item:{id:"minecraft:stone",Count:1b},Tags:["new_item"]}
+# copy the info about the entity from the marker entity
+data modify entity @e[tag=new_item,limit=1] Item set from entity @s data.Inventory[0]
+# remove the item from the marker
+data remove entity @s data.Inventory[0]
+# remove 1 from the amount of items that we still need to process
+scoreboard players remove #items temp 1
+# remove item tag
+tag @e[tag=new_item] remove new_item
+# run the same function again if there are more items to process
+execute if score #items temp matches 1.. run function namespace:return_items
+```
+
And we should be getting all our items back in a single tick. Items that do not fit in our inventory stay on the floor as item entities instead.
@@ -352,34 +407,39 @@ So first, make sure you have the loottable from the link above added to your dat
Next, run this function `as` the marker, where the target player is `@a[tag=target]`.
- # count the amount of items in the array so we know how often to repeat
- execute store result score #items temp run data get entity @s data.Inventory
- # if there is at least one item, start the process.
- execute if score #items temp matches 1.. positioned run function namespace:restore_shulker
-
- # remove entity, it served its purpose. If you want to keep it around
- # you should first copy the data and work on the copy instead.
- kill @s
+
+ See example
+```mcfunction
+# count the amount of items in the array so we know how often to repeat
+execute store result score #items temp run data get entity @s data.Inventory
+# if there is at least one item, start the process.
+execute if score #items temp matches 1.. positioned run function namespace:restore_shulker
-`restore_shulker.mcfunction`
-
- # reset the shulkerbox
- data merge block ~ ~ ~ {Items:[]}
- # remove Slot data from item
- data remove entity @s data.Inventory[0].Slot
- # copy first item over to the shulkerbox
- data modify block ~ ~ ~ Items append from entity @s data.Inventory[0]
- # use /loot to give it back to the player
- loot give @a[tag=target] mine ~ ~ ~ minecraft:air{drop_contents:1b}
- # remove the first entry in the list
- data remove entity @s data.Inventory[0]
- # remove 1 from the amount of items that we still need to process
- scoreboard players remove #items temp 1
-
- # run the same function again if there are more items to process
- execute if score #items temp matches 1.. run function namespace:restore_shulker
+# remove entity, it served its purpose. If you want to keep it around
+# you should first copy the data and work on the copy instead.
+kill @s
+```
+`restore_shulker.mcfunction`
+```mcfunction
+# reset the shulkerbox
+data merge block ~ ~ ~ {Items:[]}
+# remove Slot data from item
+data remove entity @s data.Inventory[0].Slot
+# copy first item over to the shulkerbox
+data modify block ~ ~ ~ Items append from entity @s data.Inventory[0]
+# use /loot to give it back to the player
+loot give @a[tag=target] mine ~ ~ ~ minecraft:air{drop_contents:1b}
+# remove the first entry in the list
+data remove entity @s data.Inventory[0]
+# remove 1 from the amount of items that we still need to process
+scoreboard players remove #items temp 1
+
+# run the same function again if there are more items to process
+execute if score #items temp matches 1.. run function namespace:restore_shulker
+```
+
@@ -397,36 +457,44 @@ The second option is described here in more detail. See the explanation for the
For this we assume the two chests of the double chest are located at `~ ~ ~` and `~1 ~ ~`. Execute positioned and adjust the relative coordinates accordingly. Replace `` with the yellow shulkerbox position. Have a dummy `temp` scoreboard objective.
- # reset/empty the chests
- data merge block ~ ~ ~ {Items:[]}
- data merge block ~1 ~ ~ {Items:[]}
- # count the amount of items in the array so we know how often to repeat
- execute store result score #items temp run data get entity @s data.Inventory
- # if there is at least one item, start the process.
- execute if score #items temp matches 1.. run function namespace:into_chest
-
- # remove entity, it served its purpose. If you want to keep it around
- # you should first copy the data and work on the copy instead.
- kill @s
+
+ See example
+
+```mcfunction
+# reset/empty the chests
+data merge block ~ ~ ~ {Items:[]}
+data merge block ~1 ~ ~ {Items:[]}
+# count the amount of items in the array so we know how often to repeat
+execute store result score #items temp run data get entity @s data.Inventory
+# if there is at least one item, start the process.
+execute if score #items temp matches 1.. run function namespace:into_chest
+
+# remove entity, it served its purpose. If you want to keep it around
+# you should first copy the data and work on the copy instead.
+kill @s
+```
`into_chest.mcfunction`
- # reset the shulkerbox
- data merge block {Items:[]}
- # remove Slot data from item
- data remove entity @s data.Inventory[0].Slot
- # copy first item over to the shulkerbox
- data modify block Items append from entity @s data.Inventory[0]
- # use /loot to put it into the chest, depending on which chest it needs to be
- execute if score #items temp matches 27.. run loot insert ~ ~ ~ mine minecraft:air{drop_contents:1b}
- execute if score #items temp matches ..26 run loot insert ~1 ~ ~ mine minecraft:air{drop_contents:1b}
- # remove the first entry in the list
- data remove entity @s data.Inventory[0]
- # remove 1 from the amount of items that we still need to process
- scoreboard players remove #items temp 1
-
- # run the same function again if there are more items to process
- execute if score #items temp matches 1.. run function namespace:into_chest
+```mcfunction
+# reset the shulkerbox
+data merge block {Items:[]}
+# remove Slot data from item
+data remove entity @s data.Inventory[0].Slot
+# copy first item over to the shulkerbox
+data modify block Items append from entity @s data.Inventory[0]
+# use /loot to put it into the chest, depending on which chest it needs to be
+execute if score #items temp matches 27.. run loot insert ~ ~ ~ mine minecraft:air{drop_contents:1b}
+execute if score #items temp matches ..26 run loot insert ~1 ~ ~ mine minecraft:air{drop_contents:1b}
+# remove the first entry in the list
+data remove entity @s data.Inventory[0]
+# remove 1 from the amount of items that we still need to process
+scoreboard players remove #items temp 1
+
+# run the same function again if there are more items to process
+execute if score #items temp matches 1.. run function namespace:into_chest
+```
+
### Some explanations on why we do it this way
@@ -449,74 +517,83 @@ We often see something like `Inventory[0]` in this article. This is an array sel
It is possible to select an item from the array based on its Slot like this: `Inventory[{Slot:10b}]`. We could use this for the "correct slot" method, if it weren't for the fact that we can't use `/item replace` with arbitrary data but we need to use something that is guaranteed to be an item. So we can't skip the step of first putting it into a container / entity inventory first.
### storing in a chest
-> [!NOTE]
-> This method is not effective (unless you don't want to use functions) and it is **not** multiplyer compatible (unless using 2 chests for every player)
+| 📝 Note |
+|---------|
+|This method is not effective (unless you don't want to use functions) and it is **not** multiplyer compatible (unless using 2 chests for every player)|
This method consist on using `/item` (on Java) or to replace all slots in 2 containers (for example 2 chest) with the items in the player inventory. You can use command blocks, but you will need to run every command `as` the player and change `~ ~ ~` to the positon of the chest
-> [!NOTE]
-> You must run this function `as` the player
-
- # function example:storing
- execute positioned run function example:storing/container_1
-
- # function example:storing/container_1
- # First we store the hotbar
- item replace block ~ ~ ~ container.0 with entity @s hotbar.0
- item replace block ~ ~ ~ container.1 with entity @s hotbar.1
- [...]
- item replace block ~ ~ ~ container.8 with entity @s hotbar.8
- # Now we store the inventory
- item replace block ~ ~ ~ container.9 with entity @s inventory.0
- [...]
- item replace block ~ ~ ~ container.26 with entity @s inventory.17
- # Now the container is full (if you are using a chest or barrel as they can't only have 27 slots)
- # We will need to run the second function in the position of the second chest
- execute positioned run function example:storing/container_2
-
- # function example:storing/container_2
- item replace block ~ ~ ~ container.0 with entity @s inventory.19
- item replace block ~ ~ ~ container.1 with entity @s inventory.20
- item replace block ~ ~ ~ container.2 with entity @s inventory.21
- [...]
- item replace block ~ ~ ~ container.8 with entity @s inventory.26
- # now we will store the armor and offhand
- item replace block ~ ~ ~ container.9 with entity @s armor.head
- item replace block ~ ~ ~ container.10 with entity @s armor.chest
- item replace block ~ ~ ~ container.11 with entity @s armor.legs
- item replace block ~ ~ ~ container.12 with entity @s armor.feet
- item replace block ~ ~ ~ container.13 with entity @s weapon.offhand
-
-And now we stored the entire inventory in 2 chest (or barrels). To give it back (returning the inventory) we will need to do the same but replacing the player slots with the container's slots.
-
- # function example:returning
- execute positioned run function example:returning/container_1
-
- # function example:returning/container_1
- # First we store the hotbar
- item replace entity @s container.0 with block ~ ~ ~ container.0
- item replace entity @s container.1 with block ~ ~ ~ container.1
- [...]
- item replace entity @s container.8 with block ~ ~ ~ container.8
- # Now we store the inventory
- item replace entity @s container.9 with block ~ ~ ~ container.9
- [...]
- item replace entity @s container.26 with block ~ ~ ~ container.26
- # Now the container is full (if you are using a chest or barrel as they can't only have 27 slots)
- # We will need to run the second function in the position of the second chest
- execute positioned run function example:returning/container_2
-
- # function example:returning/container_2
- item replace entity @s container.27 with block ~ ~ ~ container.0
- item replace entity @s container.28 with block ~ ~ ~ container.1
- item replace entity @s container.29 with block ~ ~ ~ container.2
- [...]
- item replace entity @s container.35 with block ~ ~ ~ container.8
- # now we will store the armor and offhand
- item replace entity @s armor.head with block ~ ~ ~ container.9
- item replace entity @s armor.chest with block ~ ~ ~ container.10
- item replace entity @s armor.legs with block ~ ~ ~ container.11
- item replace entity @s armor.feet with block ~ ~ ~ container.12
- item replace entity @s weapon.offhand with block ~ ~ ~ container.13
-
-As you can see it takes 40 commands for storing and 40 for returning, so it is a very ineficient way to store the inventory.
+| 📝 Note |
+|---------|
+|You must run this function `as` the player|
+
+
+ See example
+
+```mcfunction
+# function example:storing
+execute positioned run function example:storing/container_1
+
+# function example:storing/container_1
+# First we store the hotbar
+item replace block ~ ~ ~ container.0 with entity @s hotbar.0
+item replace block ~ ~ ~ container.1 with entity @s hotbar.1
+[...]
+item replace block ~ ~ ~ container.8 with entity @s hotbar.8
+# Now we store the inventory
+item replace block ~ ~ ~ container.9 with entity @s inventory.0
+[...]
+item replace block ~ ~ ~ container.26 with entity @s inventory.17
+# Now the container is full (if you are using a chest or barrel as they can't only have 27 slots)
+# We will need to run the second function in the position of the second chest
+execute positioned run function example:storing/container_2
+
+# function example:storing/container_2
+item replace block ~ ~ ~ container.0 with entity @s inventory.19
+item replace block ~ ~ ~ container.1 with entity @s inventory.20
+item replace block ~ ~ ~ container.2 with entity @s inventory.21
+[...]
+item replace block ~ ~ ~ container.8 with entity @s inventory.26
+# now we will store the armor and offhand
+item replace block ~ ~ ~ container.9 with entity @s armor.head
+item replace block ~ ~ ~ container.10 with entity @s armor.chest
+item replace block ~ ~ ~ container.11 with entity @s armor.legs
+item replace block ~ ~ ~ container.12 with entity @s armor.feet
+item replace block ~ ~ ~ container.13 with entity @s weapon.offhand
+
+# And now we stored the entire inventory in 2 chest (or barrels). To give it back (returning the inventory) we will need to do the same but replacing the player slots with the container's slots.
+
+# function example:returning
+execute positioned run function example:returning/container_1
+
+# function example:returning/container_1
+# First we store the hotbar
+item replace entity @s container.0 with block ~ ~ ~ container.0
+item replace entity @s container.1 with block ~ ~ ~ container.1
+[...]
+item replace entity @s container.8 with block ~ ~ ~ container.8
+# Now we store the inventory
+item replace entity @s container.9 with block ~ ~ ~ container.9
+[...]
+item replace entity @s container.26 with block ~ ~ ~ container.26
+# Now the container is full (if you are using a chest or barrel as they can't only have 27 slots)
+# We will need to run the second function in the position of the second chest
+execute positioned run function example:returning/container_2
+
+# function example:returning/container_2
+item replace entity @s container.27 with block ~ ~ ~ container.0
+item replace entity @s container.28 with block ~ ~ ~ container.1
+item replace entity @s container.29 with block ~ ~ ~ container.2
+[...]
+item replace entity @s container.35 with block ~ ~ ~ container.8
+# now we will store the armor and offhand
+item replace entity @s armor.head with block ~ ~ ~ container.9
+item replace entity @s armor.chest with block ~ ~ ~ container.10
+item replace entity @s armor.legs with block ~ ~ ~ container.11
+item replace entity @s armor.feet with block ~ ~ ~ container.12
+item replace entity @s weapon.offhand with block ~ ~ ~ container.13
+```
+
+
+
+As you can see it takes 40 commands for storing and 40 for returning, so it is a very ineficient way to store the inventory.
\ No newline at end of file
diff --git a/questions/tagentity.md b/questions/tagentity.md
index 9e9eafea3..491001a58 100644
--- a/questions/tagentity.md
+++ b/questions/tagentity.md
@@ -1,29 +1,41 @@
# Do something (e.g: kill) to the entity I just found with /execute if entity (testfor)
-If your execute if entity **does not rely on NBT data**, you can simply move the selector into the command you want to use. For example, if you have:
+If your `execute if entity` **does not rely on NBT data**, you can simply move the selector into the command you want to use. For example, if you have:
- execute if entity @a[team=red]
+```mcfunction
+execute if entity @a[team=red]
+```
You can also use:
- kill @a[team=red]
+```mcfunction
+kill @a[team=red]
+```
## Relies on NBT, 1.12 and below
If your testfor **relies on NBT data**, you will need to use either `scoreboard players set` or `scoreboard players tag` to give them a scoreboard score/tag, then select them based off of that. For example if you have:
- testfor @a {OnGround:1b}
+```mcfunction
+testfor @a {OnGround:1b}
+```
You can give them a tag like this:
- scoreboard players tag @a add IsGrounded {OnGround:1b}
+```mcfunction
+scoreboard players tag @a add IsGrounded {OnGround:1b}
+```
Then select them with `@a[tag=IsGrounded]`. You'll probably want to remove this tag afterwards, so that people who match the data once won't always have the tag:
- scoreboard players tag @a[tag=IsGrounded] remove IsGrounded
+```mcfunction
+scoreboard players tag @a[tag=IsGrounded] remove IsGrounded
+```
## Relies on NBT, 1.13 and above
In 1.13, you can specify NBT data directly in a selector, for example:
- kill @a[nbt={OnGround:1b}]
\ No newline at end of file
+```mcfunction
+kill @a[nbt={OnGround:1b}]
+```
\ No newline at end of file
diff --git a/resources.md b/resources.md
index 08eff33bb..8ec4d8a6e 100644
--- a/resources.md
+++ b/resources.md
@@ -2,269 +2,80 @@
This page contains a list of links to utilities and references relating to commands and map making that you may find useful.
-Submit a pull request or create a GitHub issue if you've found a useful tool or reference that you think would fit here.
-
-## NBT
-
-### Utilities
-
-- [NBT Studio](https://github.com/tryashtar/nbt-studio) (tryashtar)
-- [NBTExplorer](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1262665-nbtexplorer-nbt-editor-for-windows-and-mac) (jaquadro)
-- [Web NBT Editor](https://irath96.github.io/webNBT/) (irath96)
-- [NBT Workbench](https://rttv.ca) ([On GitHub](https://github.com/RealRTTV/nbtworkbench)) (RealRTTV)
-- [Tag checker](http://www.mediafire.com/file/n38fgnjnr0q113d/PCN+1.4.zip) (pca006132)
-- [Web NBT Validator](https://www.soltoder.com/NBTLint/#{Hello:%22reddit%22,Test:{Int:267,Short:345s,TooLarge:9999999999,%221.12%20Compatible%22:[I;1,2,3]}}) (AjaxGb)
-- [1.16 UUID Converter](https://www.soltoder.com/mc-uuid-converter/) (AjaxGb)
-- [UUID <--> UUIDMost/Least converter](https://minecraft.repertor.space/uuid.html) (Repertor)
-- [UUID <--> UUIDMost/Least converter](http://skylinerw.com/uuid/index.php?convert=dechex&uuidleast=1&uuidmost=1) (Skylinerw)
-
-### References
-
-- [Chunk format](http://minecraft.wiki/Chunk_format) (Wiki)
-- [Player.dat format](http://minecraft.wiki/Player.dat_format) (Wiki)
-- [Structure file format](http://minecraft.wiki/Structure_block_file_format) (Wiki)
+Submit a [pull request](https://github.com/MinecraftCommands/wiki/pulls) or create a [GitHub issue](https://github.com/MinecraftCommands/wiki/issues) if you've found a useful tool or reference that you think would fit here.
## Commands
### Utilities
-- [Command language](http://zipkrowd.com/tools.htm#cbp) (CBP)
-- [Command language](http://commandstudio.github.io/commandstudio/) (CommandStudio)
-- [Command language](http://smelt.gnasp.com/) (Smelt)
-- [Command language](http://energyxxer.com/cpm/) (CPM)
-- [Commands from C/assembly](https://github.com/simon816/Command-Block-Assembly) (simon816)
-- [One command generator](https://mrgarretto.com/commanddump) (MrGarretto)
-- [Command editor/one command generator](https://blockbench.net/tools/clg/) (JannisX11)
-- [Selector generator](https://blockbench.net/tools/selector/) (JannisX11)
-- [Command generator](https://mcstacker.net/mcstacker1.13.php) (MCStacker)
-- [Command generator](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/2142815-1-11-1-12-minecraft-command-generator-v2) (Cubiccl)
-
-### References
-
-- [Commands list](http://minecraft.wiki/Commands) (Wiki)
-- [Statistics list](http://minecraft.wiki/Statistics) (Wiki)
-- [Full syntax tree (as JSON, useful for tools)](https://gist.github.com/Dinnerbone/7370a2846953eee2d8fc64514fb76de8) (Dinnerbone)
-
-## Loot tables (& predicates)
-
-### Utilities
-
-- [Generator](https://misode.github.io/loot-table/) (Misode)
-- [Predicate generator](https://misode.github.io/predicate) (Misode)
-- [Generator](https://jsfiddle.net/MrPingouin/125mx5r5/embedded/result/) (MrPingouin)
-- [Generator](https://amaury.carrade.eu/minecraft/loot_tables) (Amaury, based on MrPingouin's)
-- [Generator](http://minecraft.tools/en/loots.php) (Minecraft Tools) ^[Missing features]
-- [Evaluator](https://sourceblock.net/beta/tools/loot-table-evaluator) (Skylinerw)
-- [VSCode Schema](https://marketplace.visualstudio.com/items?itemName=Levertion.mcjson) (Levertion)
+- [MCStacker](https://mcstacker.net): All commands generators
+- [MinecraftJSON](https://minecraftjson.com): All things text
+- [Minecraft Tools](https://minecraft.tools): Mainly for books and titles
+- [Colorize Fun](https://colorize.fun/en/minecraft): For text gradients
+- [Gamergeeks](https://www.gamergeeks.net): Almost all commands generators, it's better if MCStacker looks confusing for you
### References
-- [Guide](http://minecraft.wiki/Loot_table) (Wiki)
-- [Guide](https://github.com/skylinerw/guides/blob/master/java/loot%20tables.md) (Skylinerw)
-- [New 1.14 features guide](https://gist.github.com/misode/66456e57372ce62cd9b65d1052521069) (Misode)
-
-## Functions
-
-### Utilities
+- [Commands list](http://minecraft.wiki/Commands), The Minecraft Wiki
+- [Statistics list](http://minecraft.wiki/Statistics), The Minecraft Wiki
+- [Attributes list](https://minecraft.wiki/w/Attribute#Attributes), The Minecraft Wiki
-- [VSCode syntax highlighter](https://marketplace.visualstudio.com/items?itemName=arcensoth.language-mcfunction) (Arcensoth)
-- [VSCode language server & more](https://marketplace.visualstudio.com/items?itemName=SPGoding.datapack-language-server) (SPGoding)
-- [Sublime syntax highlighter](https://github.com/AjaxGb/Sublime-MCFunction) (AjaxGb)
-- [Sublime syntax highlighter](https://github.com/42iscool42/MCC) (42iscool42)
-- [Atom syntax highlighter](https://atom.io/packages/mcfunction) (MrYurihi)
-
-### References
-
-- [Info](http://minecraft.wiki/Function) (Wiki)
-
-## Advancements
-
-### Utilities
-
-- [Generator](http://commandcreator.com/advancements/) (Command Creator)
-- [Generator](https://advancements.thedestruc7i0n.ca/) (destruc7i0n)
-- [Generator](https://misode.github.io/advancement/) (Misode)
-- [Evaluator](https://sourceblock.net/beta/tools/advancement-evaluator) (Skylinerw)
-- [Empty vanilla advancements, for overwriting default ones](http://www.mediafire.com/file/oku6p2tje0vv9lc/Impossible%20Advancements.zip) (18w22c)
-- [VSCode Schema](https://marketplace.visualstudio.com/items?itemName=Levertion.mcjson) (Levertion)
-
-
-### References
-
-- [Guide](https://github.com/skylinerw/guides/blob/master/java/advancements.md) (Skylinerw)
-- [Format](http://minecraft.wiki/Advancements#JSON_Format) (Wiki)
-- [Biome list](https://pastebin.com/MK61Xuzf) (Skylinerw)
-- [Order of trigger activations in a tick](http://i.imgur.com/pz5mU0G.png) (Skylinerw)
-
-## Recipes
-
-### Utilities
-
-- [Generator](http://minecraft.tools/en/custom-crafting.php#) (Minecraft Tools)
-- [Generator](https://crafting.thedestruc7i0n.ca/) (destruc7i0n)
-- [Generator](http://commandcreator.com/Craft/) (Command Creator)
-- [Evaluator](https://sourceblock.net/beta/tools/recipe-evaluator) (Skylinerw)
-
-### References
-
-- [Guide](https://github.com/skylinerw/guides/blob/master/java/recipes.md) (Skylinerw)
-
-## Text formatting
-
-### Utilities
-
-- [Title](http://minecraft.tools/en/title.php) (Minecraft Tools)
-- [Title](https://minecraftcommand.science/title-generator) (Command Science)
-- [Sign](http://minecraft.tools/en/sign.php) (Minecraft Tools)
-- [Sign](https://minecraftcommand.science/command-sign-generator) (Command Science) ^[Escapes incorrectly]
-- [Sign](https://mctoolbox.cmd.science/sign/) (MCToolBox)
-- [Book](http://minecraft.tools/en/book.php) (Minecraft Tools)
-- [Tellraw](http://minecraft.tools/en/tellraw.php) (Minecraft Tools)
-- [Tellraw](https://blockbench.net/tools/tellraw/) (JannisX11)
-- [Evaluator](https://sourceblock.net/beta/tools/text-component-evaluator) (Skylinerw)
-- [§ code Texteditor](https://plagiatus.net/tools/colortext/) (Plagiatus)
-
-### References
-
-- [Guide](https://github.com/skylinerw/guides/blob/master/java/text%20component.md) (Skylinerw)
-- [§ codes](http://minecraft.wiki/Formatting_codes) (Wiki)
-- [§ codes](http://minecraft.tools/en/color-code.php) (Minecraft Tools)
-
-## Give
+## NBT
### Utilities
-- [Give generator](https://mcstacker.net/mcstacker1.13.php) (MCStacker)
-- [Item](https://minecraftcommand.science/custom-item-generator) (Command Science)
-- [Tools/weapons](https://minecraftcommand.science/tool-generator) (Command Science)
-- [Potions](https://minecraftcommand.science/potion-generator) (Command Science)
-- [Armor](https://minecraftcommand.science/armor-generator) (Command Science)
-- [Firework generator](http://minecraft.tools/en/firework.php) (Minecraft Tools)
+- [irath96](http://irath96.github.io/webNBT/): web nbt editor, no need to download any program
+- [NBT Workbench](https://rttv.ca/main): web nbt editor, no need to download any program
### References
-## Entities
-
-### Utilities
-
-- [Summon generator](http://minecraft.tools/en/spawn.php) (Minecraft Tools)
-- [Summon generator](https://mcstacker.net/mcstacker1.13.php) (MCStacker)
-- [Summon generator](http://www.summon-helper.net/entitySelection.html) (Summon Helper)
-- [Spawner generator](https://mcstacker.net/mcstacker1.13.php) (MCStacker, select mob spawner in `/setblock`)
-- [Villager shop](https://minecraftcommand.science/shop-generator) (Command Science)
-- [Hologram text](https://minecraftcommand.science/hologram-generator) (Command Science)
-- [Hologram text](https://mctoolbox.cmd.science/holograms/) (MCToolBox)
-- [Mob click detection](http://mctoolbox.cmd.science/click-mobs/) (MCToolBox)
+- [Chunk format](http://minecraft.wiki/Chunk_format), The Minecraft Wiki
+- [Player.dat format](http://minecraft.wiki/Player.dat_format), The Minecraft Wiki
+- [Structure file format](http://minecraft.wiki/Structure_block_file_format), The Minecraft Wiki
-### References
-
-- [Chunk format](http://minecraft.wiki/Chunk_format) (Wiki)
-## World editing
+## Datapacks
### Utilities
-- [Amulet Editor](https://www.amulet-editor.com/)
-- [MCEdit Unified](http://www.mcedit-unified.net)
-- [MCEdit 2.0 beta](http://www.mcedit.net/downloads.html) ^[Beta, missing features]
-- [MCEdit filter collection](http://www.brightmoore.net/mcedit-filters-1) (Adrian Brightmoore)
-- [MCEdit filter collection](http://web.archive.org/web/20161229045538/http://elemanser.com/filters.html) (Texelelf)
-- [WorldPainter](http://worldpainter.net/) (Captain Chaos)
-- [WorldSynth](https://www.worldsynth.net) (booleanbyte)
-- [MCA Selector](https://github.com/Querz/mcaselector) (Querz)
-- [Shape planner](http://www.plotz.co.uk/) (Plotz)
-- [Template manager](https://www.youtube.com/watch?v=LjixFRcqxSs) (bananenbroek4)
+- [Datapack Helper+](https://marketplace.visualstudio.com/items?itemName=SPGoding.datapack-language-server): syntax highlighter.
+- [Misode’s Generator](https://misode.github.io): loot table, predicate, item modifier, advancement, recipe, dimension, structure and tag generator, between others.
+- [Datapack Assembler](https://far.ddns.me): generate data pack from commands
### References
-- [Data values](http://minecraft.wiki/Data_values) (Wiki)
-- [Building guides](https://www.reddit.com/r/Minecraft/comments/6eua5z/a_reminder_of_some_excellent_build_guidesbuilders/) (Adrian Brightmoore)
-- [Biome colour-map](http://i.imgur.com/05QGuPX.png) (Word_Wizzard)
-
-## World generation
-
-### Utilities
-
-- [Custom world setting generator](https://misode.github.io/worldgen/) (Misode)
-- [Superflat preset generator](http://minecraft.tools/en/flat.php) (Minecraft Tools)
+- [Functions](http://minecraft.wiki/Function), The Minecraft Wiki
+- [Loot Tables](http://minecraft.wiki/Loot_table), The Minecraft Wiki
+- [Predicates](http://minecraft.wiki/Predicate), The Minecraft Wiki
+- [Advancements](http://minecraft.wiki/Advancements#JSON_Format), The Minecraft Wiki
+- [Dimension](https://minecraft.wiki/w/Dimension_definition), The Minecraft Wiki
+- [Vanilla Data Pack](https://mcasset.cloud/)
-### References
+## Misc
-- [Custom world type format](https://minecraft.wiki/Custom)
-- [Noise settings examples](https://gist.github.com/misode/b83bfe4964e6bf53b2dd31b22ee94157) (Misode)
-- [Vanilla worldgen reference files](https://t.co/cm3pJcAHcy) (Mojang)
+- [Order of trigger activations in a tick](https://gist.github.com/misode/77ee37217a69a3c74032679d8084d6c6#file-tick_order-md)
-## Resource packs
+## Resource Packs
### Utilities
-- [Model creator](https://blockbench.net/) (BlockBench)
-- [Model creator](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/2146545-opls-model-creator-free-3d-model-editor) (opl)
-- [Model creator](https://mrcrayfish.com/tools?id=mc) (MrCrayfish)
-- [Model creator](http://thejonwithnoh.github.io/SetblockWebModeler/) (thejonwithnoh)
-- [Model creator](https://cubik.studio/) (Cubik) ^[Paid]
-- [Damage predicate generator](http://accidentalgames.com/media/durabilityModels.php) (Accidental games)
-- [Upgraded damage predicate generator](https://geenium.github.io/damage-value-generator/) (Upgraded by geenium)
-- [Resource pack creator](https://minecraft.novaskin.me/resourcepacks) (Novaskin)
-- [Resource pack creator](https://mcrpw.github.io/) (MightyPork)
-- [Block designer](https://codecrafted.net/blockdesigner) (CodeCrafted, concept by Simplysarc)
+- [BlockBench](https://www.blockbench.net): model editor.
+- [Misode’s Generators](https://misode.github.io): blockstate, model, font and atlas.
### References
-- [Model format](http://minecraft.wiki/Model) (Wiki)
-- [Sounds list](https://minecraft.wiki/Sounds.json/Java_Edition_values) (Wik)
+- [Model format](http://minecraft.wiki/Model), The Minecraft Wiki
+- [Sounds list](https://minecraft.wiki/Sounds.json/Java_Edition_values), The Minecraft Wiki
- [Font json format](https://discordapp.com/channels/154777837382008833/154777837382008833/468913675017912320) (AmberW)
- [Shader `post` json format](https://discordapp.com/channels/154777837382008833/154777837382008833/490651571261014036) (Mrpingouin)
- [Shader `program` special variables](https://discordapp.com/channels/154777837382008833/306175724942000128/491380153960628231) (Mrpingouin)
- [Shader guide](https://docs.google.com/document/d/15TOAOVLgSNEoHGzpNlkez5cryH3hFF3awXL5Py81EMk/edit?usp=sharing) (SirBenet)
+- [Vanilla Resource Pack Assets](https://mcasset.cloud/)
-## Map publishing
-
-### Utilities
-
-- [Map auto-install creator](https://github.com/mrjvs/mpm/releases) (mrjvs)
-- [Minecraft Maps](http://www.minecraftmaps.com) (Site for maps)
-- [Minecraft Forum](https://www.minecraftforum.net/forums/mapping-and-modding-java-edition/maps) (Site for maps)
-- [Planet Minecraft](https://www.planetminecraft.com) (Site for maps)
-
-### References
-
-## Miscellaneous
-
-### Heads
-
-- [Head generator](https://minecraftcommand.science/head-generator) (Command Science)
-- [Custom heads](http://heads.freshcoal.com/maincollection.php) (Freshcoal)
-- [Mob head display sizes](https://twitter.com/samasaurus6/status/787010091094540288) (samasaurus6)
-
-### Banners/shields
-
-- [Banner designer](http://www.needcoolshoes.com/banner) (Miners Need Cool Shoes)
-- [Banner designer](http://www.planetminecraft.com/banner/) (Planet Minecraft)
-- [Banner designer](http://minecraft.tools/en/banner.php) (Minecraft Tools)
-- [Shield designer](http://minecraft.tools/en/shield.php) (Minecraft Tools)
-
-### Color
-
-- [Beacon color](http://minecraft.tools/en/beacon-color.php) (Minecraft Tools)
-- [Armor color](http://minecraft.tools/en/armor.php) (Minecraft Tools)
-- [Armor color](https://minecraftcommand.science/armor-color) (Command Science)
-- [Color picker](http://skylinerw.com/color/) (Skylinerw)
-- [Block colors](http://mrgarretto.com/blockcolors) (MrGarretto)
-- [Particle color](http://mctoolbox.cmd.science/particles/) (MCToolBox)
-- [Biome water colors](https://pastebin.com/2zYzzymu) (extracted by MrPingouin using [Fabric](https://fabricmc.net/))
-
-### Map items
-
-- [Image to map](https://mc-map.djfun.de/) (MC Map Item Tool)
-- [Image to map](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1261738-linux-windows-imagetomap-in-game-text-and-images) (ImageToMap)
-- [Image to map](https://github.com/tryashtar/image-map/raw/master/Image%20Map/bin/Debug/Image%20Map.exe) (tryashtar)
-- [NBT reference](http://minecraft.wiki/Player.dat_format#Maps) (Wiki)
+## Ask for help
-### Animation
+- [/r/MinecraftCommands](https://www.reddit.com/r/MinecraftCommands/)
+- [Discord server](https://discord.com/invite/9wNcfsH)
-- [Animator](https://github.com/JannisX11/animator/releases/tag/v1.1.1) (Jannis)
-- [Cutscene generator](https://www.youtube.com/watch?v=ukR7126RkU4) (The Redstone Scientist)
-- [Armorstand animator](https://mrgarretto.com/armorstand/) (MrGarretto)
-- [Block model animator](http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/2715476-block-models-json-model-animator) (fizzy81)
+For older versions of minecraft (1.14 and before) check the [pre-1.15 resources page](wiki/oldresources)
\ No newline at end of file