Skip to content

Commit 7c0be15

Browse files
authored
Update Wiki (#1)
* Update detectitem.md * Update detectitem.md Fixed formatting. * Update customitemtag.md Updated with changes in 1.20.5. * Update customitemtag.md Fix links * Update amountitems.md Updated with changes in 1.20.5. * Update amountitems.md * Update itemclick.md - Added interaction entity method - Added right click method for any item - New click detection - Inventory click * Update modifyinventory.md - Updated with changes in 1.20.5 - Added examples for /item 1.17 * Update scorecompare.md - Updated with changes in 1.20.5. * Update findsamescoreentity.md Added example of Scoreboard ID system implementation for datapack. * Update findsamescoreentity.md Added a link to compare the performance of the score check. * Update movetoscore.md - Added macro methods - Updated with changes in 1.20.5. * Update linkentity.md Added a faster and easier method for creating a system Scoreboard ID. * Update runonce.md Add scoreboard and advancement metods * Update areas.md Added more methods. * Update playerdeaths.md Added a method for running commands at the player's death position. * Update blockdelay.md - Add marker method - Add more examples * Update shootfacing.md - Added a simplified version for method 1. - Added a section on fixing visual lag. * Update shootfacing.md * Update shootfacing.md Some fixes. * Update storeinventory.md Added method storing/returning player inventory using storage. * Update storeinventory.md * Create customcrafting.md New article * Create mobdeaths.md New article * Added links Added links to new articles * Update amountitems.md * Update blockdelay.md * Update customcrafting.md * Update customitemtag.md * Update detectitem.md * Update findsamescoreentity.md * Update itemclick.md * Update linkentity.md * Update mobdeaths.md * Update movetoscore.md * Update runonce.md * Update scorecompare.md * Update shootfacing.md * Update storeinventory.md * Update customcrafting.md
1 parent 2a3f062 commit 7c0be15

18 files changed

+2100
-92
lines changed

questions.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Because in 1.19.50, the [new execute syntax](https://learn.microsoft.com/en-us/m
1414
[Detect rightclick or leftclick (on an item)?](/wiki/questions/itemclick)
1515
[Give a special item (Bedrock)?](/wiki/questions/giveitembedrock)
1616
[Change an item while it's in the players inventory?](/wiki/questions/modifyinventory)
17+
[Do custom crafting](/wiki/questions/customcrafting)
1718

1819
### Scores
1920

@@ -50,6 +51,7 @@ Because in 1.19.50, the [new execute syntax](https://learn.microsoft.com/en-us/m
5051
[Make one mob attack another mob/player?](/wiki/questions/angermob)
5152
[Do raycasting?](/wiki/questions/raycast)
5253
[Make a circle (of blocks / entities)?](/wiki/questions/makecircle/)
54+
[Detect when a mob has died](/wiki/questions/mobdeaths)
5355

5456
## What is...
5557

@@ -66,6 +68,3 @@ Because in 1.19.50, the [new execute syntax](https://learn.microsoft.com/en-us/m
6668
## Still needed articles
6769

6870
*Found something that should be added? Maybe even want to contribute an article? Submit a pull request or create a GitHub issue.*
69-
70-
- Detect when a mob has died?
71-
- Do custom crafting (with NBT)

questions/amountitems.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,56 @@
22

33
## Java
44

5+
### Clear
6+
57
Using the [`clear`](https://minecraft.wiki/Commands/clear) command with a `[<maxCount>]` of 0 will return the amount of items a player has, without actually clearing any of them.
6-
That means we can use `execute store` to save that number somewhere and then execute depending on that:
8+
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:
9+
10+
# Setup
11+
scoreboard objectives add diamonds dummy
712

13+
# Commands
814
execute store result score @s diamonds run clear @s diamond 0
915
execute if score @s diamonds matches 5 run say I have exactly 5 diamonds in my inventory.
1016
execute if score @s diamonds matches 1..4 run say I have somewhere between 1 and 4 diamonds in my inventory.
1117
execute if score @s diamonds matches 10.. run say I have 10 or more diamonds in my inventory.
1218
execute if score @s diamonds matches ..20 run say I have 20 or less diamonds in my inventory.
1319

20+
### Execute if items
21+
22+
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.
23+
24+
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):
25+
26+
# In chat
27+
execute if items entity @s container.* *
28+
29+
You can find out more details on how to detect specific items here: [Detect a specific item](/wiki/questions/detectitem)
30+
31+
Below is an example for getting the amount of a custom item and executing some command depending on the result:
32+
33+
# Example item
34+
give @s diamond[minecraft:custom_data={diamond:true},minecraft:item_name="'Custom Diamond'"]
35+
36+
# Command blocks
37+
execute as @a store result score @s diamonds if items entity @s container.* *[custom_data~{diamond:true}]
38+
execute as @a[scores={diamonds=5}] run say I have exactly 5 coins.
39+
execute as @a[scores={diamonds=1..4}] run say I have somewhere between 1 and 4 coins.
40+
execute as @a[scores={diamonds=10..}] run say I have 10 or more coins.
41+
execute as @a[scores={diamonds=..20}] run say I have 20 or less coins.
42+
43+
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.
44+
45+
Here are some examples for this:
46+
47+
# Counting items in chest or any container
48+
execute store result score #container diamonds if items block <pos> container.* *[custom_data~{diamond:true}]
49+
50+
# Counting items in ender_chest
51+
execute as @a store result score @s diamonds if items entity @s enderchest.* *[custom_data~{diamond:true}]
52+
1453
## Bedrock
1554

1655
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, check the link above for more information.
1756

18-
execute @a[hasitem={item:apple,quantity=5..}] ~~~ run say I have 5 or more apples in my inventory
57+
execute @a[hasitem={item:apple,quantity=5..}] ~~~ run say I have 5 or more apples in my inventory

questions/areas.md

Lines changed: 108 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
_Java Syntax, but this can be applied to Bedrock just as well by changing the selector arguments to Bedrock Syntax._
44

5-
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).
5+
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).
66

7-
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.
7+
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.
88

99
gamemode adventure @a[x=0,y=0,z=0,distance=..X]
1010
gamemode survival @a[x=0,y=0,z=0,distance=X..]
1111

1212
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.
1313

14-
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).
14+
## Hardcoded locations
1515

16+
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.
17+
18+
# Command blocks / tick function
1619
tag @a remove inArea
1720
tag @a[x=0,y=0,z=0,distance=..X] add inArea
1821
tag @a[x=100,y=64,z=100,dx=70,dy=16,dz=28] add in Area
@@ -25,5 +28,105 @@ To prevent chatspam for the players and unnecessary gamemode changes, we suggest
2528
gamemode adventure @a[tag=inArea,gamemode=!adventure]
2629
gamemode survival @a[tag=!inArea,gamemode=!survival]
2730

28-
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 by /u/Afanofall23:
29-
https://www.reddit.com/r/MinecraftCommands/comments/mw11xm/do_something_to_players_in_multiple_specific/
31+
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).
32+
33+
## Anchor entities
34+
35+
If you need to check if the player is in one of several spherical areas, for example to switch gamemode to adventure, then you can use some kind of entity as an anchor to check if the player is nearby. 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.
36+
37+
# Summon marker
38+
summon marker <pos> {Tags:["adventure_area"]}
39+
40+
# Command blocks / tick function
41+
execute as @a[gamemode=survival] at @s if entity @e[type=marker,tag=adventure_area,distance=..X,limit=1] run gamemode adventure
42+
execute as @a[gamemode=adventure] at @s unless entity @e[type=marker,tag=adventure_area,distance=..X,limit=1] run gamemode survival
43+
44+
`X - distance at which players should be switched into adventure mode.`
45+
46+
To make placing markers more convenient, you can give a spawn_egg containing a marker with the tag:
47+
48+
# 1.17 - 1.20.4
49+
give @s bat_spawn_egg{EntityTag:{id:"minecraft:marker",Tags:["adventure_area"]},display:{Name:'{"text":"Adventure Area Marker","italic":false}'}}
50+
51+
# 1.20.5+
52+
give @s minecraft:bat_spawn_egg[entity_data={id:"minecraft:marker",Tags:["adventure_area"]},item_name='"Adventure Area Marker"']
53+
54+
## Block layer
55+
56+
If you need to execute a command when a player enters a very randomly shaped area, then you can place under the map, for example, at a height of Y=-63, a layer of some block that you will check under the player.
57+
58+
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:
59+
60+
# Command block / tick function (1.20.5+)
61+
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!
62+
63+
## Predicates
64+
65+
If you need to check multiple cubic, spherical or cylindrical areas, you can also use [predicates](https://minecraft.wiki/w/Predicate) in datapack or command blocks (1.20.5+).
66+
67+
In a predicate, you can use the `minecraft:alternative` (1.14-1.19.4) or `minecraft:any_of` (1.20+) condition to check multiple areas in one predicate using the `minecraft:location_check` condition.
68+
69+
Below is an example of a predicate for checking three cubic areas:
70+
71+
{
72+
"condition": "minecraft:any_of",
73+
"terms": [
74+
{
75+
"condition": "minecraft:location_check",
76+
"predicate": {
77+
"position": {
78+
"x": {
79+
"min": 10,
80+
"max": 20
81+
},
82+
"y": {
83+
"min": 64,
84+
"max": 70
85+
},
86+
"z": {
87+
"min": 30,
88+
"max": 40
89+
}
90+
}
91+
}
92+
},
93+
{
94+
"condition": "minecraft:location_check",
95+
"predicate": {
96+
"position": {
97+
"x": {
98+
"min": 60,
99+
"max": 85
100+
},
101+
"y": {
102+
"min": -20,
103+
"max": 10
104+
},
105+
"z": {
106+
"min": 10,
107+
"max": 80
108+
}
109+
}
110+
}
111+
},
112+
{
113+
"condition": "minecraft:location_check",
114+
"predicate": {
115+
"position": {
116+
"x": {
117+
"min": -80,
118+
"max": -20
119+
},
120+
"y": {
121+
"min": 125,
122+
"max": 155
123+
},
124+
"z": {
125+
"min": 55,
126+
"max": 78
127+
}
128+
}
129+
}
130+
}
131+
]
132+
}

0 commit comments

Comments
 (0)