User:Aeldrion/Projects/AESTD/Snippets

This article collects examples of functions using AESTD, to help understanding how to use it and what it can do. This is not meant to be a documentation: the full documentation for AESTD can be found in the main article.

Swapping hands
scoreboard players set @s aestd.item.slot -1 function aestd:item/save summon minecraft:item ~ ~ ~ {Tags:["placeholder"]} execute as @e[type=minecraft:item,tag=placeholder,limit=1] run function aestd:item/load scoreboard players set @s aestd.item.slot -2 function aestd:item/save scoreboard players set @s aestd.item.slot -1 function aestd:item/load execute as @e[type=minecraft:item,tag=placeholder,limit=1] run function aestd:item/save scoreboard players set @s aestd.item.slot -2 function aestd:item/load kill @e[type=minecraft:item,tag=placeholder,limit=1]
 * 1) This function uses aestd:item/save and aestd:item/load to swap a player's hand items. A placeholder entity is used to save one of the items before it is replaced by the other.
 * 2) @s = a player
 * 1) Saving the player's mainhand item to an item entity
 * 1) Replacing the player's mainhand item with his offhand item
 * 1) Replacing the player's offhand item with the item saved earlier

Adding lore to an item
scoreboard players set @s aestd.random.max 3 function aestd:math/random execute if score @s aestd.random matches 0 run data modify block 1519204 6 0 RecordItem.tag.aestd.text set value "Hello world" execute if score @s aestd.random matches 1 run data modify block 1519204 6 0 RecordItem.tag.aestd.text set value "AESTD rocks!" execute if score @s aestd.random matches 2 run data modify block 1519204 6 0 RecordItem.tag.aestd.text set value "Hi r/MinecraftCommands" tag @s add aestd.item.container scoreboard players set @s aestd.item.slot 12 function aestd:item/add_lore
 * 1) This function adds random lines of lore to an item in the middle slot of a chest.
 * 2) @s = an entity, position = a chest
 * 1) Generating a random number
 * 1) Modifying the text to add depending on the random number
 * 1) Adding the text

Area of effect damage
scoreboard players set @e[distance=1..10] aestd.random.min 500 scoreboard players set @e[distance=1..10] aestd.random.max 700 execute as @e[distance=1..10] run function aestd:math/random_range function aestd:entity/get_uuid tag @e[distance=1..10] add aestd.damage.hurt_by_player execute as @e[distance=1..10] run function aestd:entity/damage
 * 1) This function makes the executing entity randomly damage nearby enemies using the aestd:entity/damage function
 * 1) Setting up damage
 * 1) Damaging + making mobs react as if they were hit by the executing entity