User:Aeldrion/Projects/AESTD/Function library

The AESTD function library is the biggest feature of AESTD. It is a collection of functions that can be used by other datapacks. Functions are sorted in seven categories:,  ,  ,  ,  ,   and.

Some functions take the executing entity's scores and tags as input. In these cases, setting the right tags and scores should always be done right before executing the function as some functions in AESTD can modify these scores and tags.

anger.mcfunction
Simulates the damaging of the executing entity by a 'target entity' whose UUID was saved in the save chunk with the  function. If the entity is neutral or hostile, it will become angry at the target entity. If the target entity is a player, the entity's death will count as a player kill and experience orbs will drop. Does not work for players (obviously).

execute as @p run function aestd:entity/get_uuid function aestd:entity/anger
 * 1) This function will make the executing entity angry against the nearest player

damage.mcfunction
Damages the executing entity by a score divided by 100. Can be set to burn or anger the damaged entity with  function. Does not work for players. Input:

scoreboard players set @s aestd.damage 600 tag @s add aestd.damage.hurt_by_player tag @s add aestd.damage.fire function aestd:entity/damage
 * 1) This function will damage the executing entity by 6HP, make it angry against the nearest player and set it on fire

fake_damage.mcfunction
Simulates the damaging of the executing entity. Unlike, this function will not trigger any behavior from the executing entity and will not cause it to drop experience at death. Does not work for players.

get_direction.mcfunction
Returns the direction of the executing entity to three scores, scaled up by 1000 and rounded to integers. Output:,  ,

get_distance.mcfunction
Gets the distance between the executing entity's position and the context position, multiplied by 50. Output:

execute at @s positioned ^ ^ ^20 run function aestd:entity/get_distance
 * 1) Returns 1000 (because 20*50 = 1000)

get_motion.mcfunction
Returns the motion of the executing entity to three scores, scaled up by 1000 and rounded to integers. Output:,  ,

get_motion_magnitude.mcfunction
Returns the magnitude of the executng entity's motion vector, multiplied by 1000. For example, if the executing entity has a motion of (1.784, 5.139, 3.396), the returned value will be 6412. Output:

get_rotation.mcfunction
Returns the direction of the executing entity to two scores, rounded to integers. Output: ,

get_position.mcfunction
Returns the position of the executing entity to three scores, rounded to integers. Output:,  ,

get_uuid.mcfunction
Saves the /  pair of the executing entity to the save chunk, which can then be used by other functions such as. Output: (1519204 6 0), (1519204 6 0)

knockback.mcfunction
Inflicts knockback on the executing entity, as if it was struck from a player at context position. Does not work for players. Horizontal motion caps at 0.3 in both axes, and vertical motion is 0.3.

execute as @e[type=minecraft:cow,limit=1,sort=nearest] at @p run function aestd:entity/knockback execute as @p run function aestd:entity/get_uuid scoreboard players set @e[type=minecraft:cow,limit=1,sort=nearest] aestd.damage 100 tag @e[type=minecraft:cow,limit=1,sort=nearest] add aestd.damage.hurt_by_entity execute as @e[type=minecraft:cow,limit=1,sort=nearest] run function aestd.damage.hurt_by_entity
 * 1) This function simulates the hitting of the nearest cow by the nearest player (see also aestd:entity/damage)

offset_position.mcfunction
Offsets the executing entity's position by three scores. Input:,  ,

scoreboard players set @s aestd.delta.x 4 scoreboard players set @s aestd.delta.y 0 scoreboard players set @s aestd.delta.z -2 function aestd:entity/offset_position
 * 1) This function will have the same effect as teleport @s ~4 ~ ~-2

set_direction.mcfunction
Sets the direction of the executing entity from three scores. Does not work for players. Input:,  ,

set_head.mcfunction
Places on the executing entity's head slot a player head whose skin owner's name was previously saved using the  function. Does not work on players.

execute as @p run function aestd:player/get_name function aestd:entity/set_head
 * 1) This function copies the nearest player's head to the executing entity

set_head_to_block.mcfunction
Places on the executing entity's head a block whose id was previously saved with the  function. Does not work on players. Input:  (generated by  )

execute positioned ~ ~-1 ~ run function aestd:block/get_block_id function aestd:entity/set_head_to_block
 * 1) This function places on a mob's head the block it is standing on

set_motion.mcfunction
Sets the motion of the executing entity from three scores. Does not work for players. Values are divided by 1000. Input:,  ,

set_motion_from_position.mcfunction
Sets the motion of the executing entity towards the context position. Does not work for players. Motion magnitude is the fourth of the distance to context position.

execute as @e[type=minecraft:creeper] at @p run function aestd:entity/set_motion_from_position
 * 1) This function shoots creepers to the nearest player

set_motion_from_rotation.mcfunction
Sets the motion of the executing entity forward. Does not work for players. This is just a simple implementation of. The context position is five blocks in front of the executing entity, so the motion will have a magnitude of 1.25.

set_motion_magnitude.mcfunction
Changes the magnitude of a moving entity's motion. Does not work for players. The value is divided by 1000. Input:

execute as @e[type=#aestd:mobs] run function aestd:entity/get_motion_magnitude scoreboard players set #aestd aestd.math.var 3 execute as @e[type=#aestd:mobs] run scoreboard players operation @s aestd.math.out *= #aestd aestd.math.var execute as @e[type=#aestd:mobs] run scoreboard players operation @s aestd.math.in = @s aestd.math.out execute as @e[type=#aestd:mobs] run function aestd:entity/set_motion_magnitude
 * 1) This function triples the motion of all mobs

scoreboard players set @e[type=minecraft:creeper] aestd.math.in 1000 execute as @e[type=minecraft:creeper] run function aestd:entity/set_motion_magnitude
 * 1) Simpler example: this function gives all creepers a constant motion magnitude of 1

set_owner_uuid.mcfunction
Sets the /  tags pair to values previously stored in the save chunk using. These tags are used by projectiles to determine by whom they were shot. This is useful, for example, to get manually summoned arrows to make shot mobs angry, count their death in stats or drop experience (internally used by ).

execute anchored eyes run summon minecraft:arrow ^ ^ ^1 {Tags:["new"]} function aestd:entity/get_uuid execute as @e[type=minecraft:arrow,tag=new,limit=1] run function aestd:entity/set_owner_uuid execute anchored eyes positioned ^ ^ ^10 as @e[type=minecraft:arrow,tag=new,limit=1] run function aestd:entity/set_motion_from_position tag @e[type=minecraft:arrow] remove new playsound entity.arrow.shoot master @a
 * 1) A player who runs this function will shoot an arrow as if it was fired from a bow (see also aestd:entity/set_motion_from_position

set_position.mcfunction
Sets the position of the executing entity from three scores. For players, the function  should be more efficient, but both work. Input:,  ,

set_rotation.mcfunction
Sets the rotation of the executing entity from two scores. For players, the function  should be more efficient, but both work. Input: ,

teleport_surface.mcfunction
Teleports the executing entity on the highest non-air block matching the x and z coordinates of the context position (the surface).

execute as @a[nbt={SelectedItem:{id:"minecraft:chorus_fruit"}}] at @s run function aestd:entity/teleport_surface
 * 1) This function teleports all players holding a chorus fruit to the surface

teleport_to_chunk_corner.mcfunction
Teleports the executing entity to the westernmost, northernmost corner of the chunk it is in. Does not work for players.

wandering_trader/set_wandertarget.mcfunction
Sets the position a wandering target will pathfind to. Because of wandering traders' behavior, this tag may be reset if the trader encounters any danger (ex. a zombie). Input:,  ,

wolf/tame.mcfunction
Tames a wolf and sets its owner to a player whose UUID was previously saved in the save chunk with the  function. This probably works for other tameable mobs too, but I haven't taken the time to check. Input: (1519204 6 0)

execute as @p run function aestd:player/get_uuid execute as @e[type=minecraft:wolf,limit=1,sort=random] run function aestd:entity/tame
 * 1) This function will make the nearest player tame a random wolf

Item functions
Item functions modify an item. The item that is modified can be an item entity or an inventory item, in a block or in a mob's or a player's inventory. The item slot that is selected is defined by the  score of the executing entity and the tags it has.

If the executing entity has the  tag, an item will be selected in a block entity at context position. If there is no block entity there, nothing will happen. The executing entity's  score corresponds to the   tag of the selected item (0-26 in a chest, for example).

If the executing entity doesn't have the  tag and is an item entity, it will be directly modified. If it doesn't have the tag but is a mob, a player or an armor stand, its  score will tell what item is being modified. For players, the score corresponds to the  tag of the selected item: 0-8 is in the hotbar, 9-35 is in the inventory, 100-103 is the armor and -106 is the offhand slot. -1 will select the mainhand and -2 the offhand. For mobs and armor stands, 100-103 corresponds to armor items, -1 will select the mainhand and -2 the offhand.

add_count.mcfunction
Adds a score to the count of an item, limiting to the item's stack size. Input:

scoreboard players set @s aestd.item.slot -2 scoreboard players set @s aestd.item.count -1 function aestd:item/add_count
 * 1) This function reduces the count of a player's or mob's offhand item

add_custom_model_data.mcfunction
Adds a score to the custom model data field of an item. Input:

add_damage.mcfunction
Adds a score to the damage of an item. If this score is negative, the item will be repaired instead of damaged. Input:

scoreboard players set @a aestd.item.dmg 5 scoreboard players set @a aestd.item.slot -1 execute as @a run function aestd:item/add_damage
 * 1) This function damages all player's selected items

add_enchantment.mcfunction
Adds an enchantment to an item. Input: ,

Enchantments use the following values for, corresponding to their protocol ID:
 * 0 - Protection
 * 1 - Fire Protection
 * 2 - Feather Falling
 * 3 - Blast Protection
 * 4 - Projectile Protection
 * 5 - Respiration
 * 6 - Aqua Affinity
 * 7 - Thorns
 * 8 - Depth Strider
 * 9 - Frost Walker
 * 10 - Curse of Binding
 * 11 - Sharpness
 * 12 - Smite
 * 13 - Bane of Arthropods
 * 14 - Knockback
 * 15 - Fire Aspect
 * 16 - Looting
 * 17 - Sweeping Edge
 * 18 - Efficiency
 * 19 - Silk Touch
 * 20 - Unbreaking
 * 21 - Fortune
 * 22 - Power
 * 23 - Punch
 * 24 - Flame
 * 25 - Infinity
 * 26 - Luck of the Sea
 * 27 - Lure
 * 28 - Loyalty
 * 29 - Impaling
 * 30 - Riptide
 * 31 - Channeling
 * 32 - Multishot
 * 33 - Quick Charge
 * 34 - Piercing
 * 35 - Mending
 * 36 - Curse of Vanishing

'''These values do not all correspond to the ones previously used in the  NBT tag.

scoreboard players set @s aestd.item.slot -1 scoreboard players set @s aestd.item.ench 11 scoreboard players set @s aestd.item.lvl 5 function aestd:item/add_enchantment
 * 1) This function adds sharpness V to a player's or mob's held item

add_lore.mcfunction
Adds a line of lore to an item from a text string saved to the save chunk. Input: (1519204 6 0). The  makes this function treat the text string as a text component.

data modify block 1519204 6 0 RecordItem.tag.aestd.text set value "Hello world" scoreboard players set @p aestd.item.slot 4 function aestd:item/add_lore data modify block 1519204 6 0 RecordItem.tag.aestd.text set value '{"text":"Hello world","color":"aqua","italic":false}' tag @s add aestd.preformatted_text function aestd:item/add_lore
 * 1) This function adds the text "Hello world" to the item contained in the fifth hotbar slot of the nearest player, with default formatting then with a different color and style.

break.mcfunction
Removes an item from a player's or mob's inventory and makes a breaking sound as if the item was depleted.

get_max_durability.mcfunction
Returns the durability of a vanilla item (values are hardcoded for every item with durability, so items from mods cannot be evaluated). Output:

load.mcfunction
Loads an item from the save chunk, previously saved with the  function.

merge_nbt.mcfunction
Merges NBT from the save chunk to the 'tag' tag of an item. This can be used to add custom tags as well as default vanilla tags. '''In Minecraft 1.14.4 Pre-release 5, it is already possible to do with the data merge command. However, this will not work if the item does not already have metadata and this relies on a bug which may be fixed in the future.''' Input:  tag in the jukebox placed at (1519204, 6, 0)

data modify block 1519204 6 0 RecordItem.tag.aestd.nbt set value {display:{Name:'"hello"'}} scoreboard players set @s aestd.item.slot 103 function aestd:item/merge_nbt
 * 1) Merges a player's head item with the nbt {display:{Name:'"hello"'}}

remove_attribute_modifiers.mcfunction
Removes attribute modifiers from an item.

scoreboard players set @s aestd.item.slot 4 tag @s add aestd.item.container scoreboard players set @s aestd.list_mode -1 execute if block ~ ~ ~ minecraft:dropper run function aestd:item/remove_attribute_modifiers
 * 1) This function removes the last attribute modifier of the item in the center of a dropper

remove_data.mcfunction
Clear the entire item's NBT data (name, enchantments, lore, damage…)

remove_enchantments.mcfunction
Removes enchantments from an item.

scoreboard players set @s aestd.item.slot 103 scoreboard players set @s aestd.list_mode 1 function aestd:item/remove_enchantments
 * 1) This function removes all enchantments on the player's helmet

remove_lore.mcfunction
Removes lines of lore from an item.

save.mcfunction
Saves an item to the save chunk. This function is used internally by most item functions.

scoreboard players set @s aestd.item.slot -1 function aestd:item/save scoreboard players set @s aestd.item.slot -2 function aestd:item/load
 * 1) This function uses aestd:item/load and aestd:item/save to move a player's mainhand item to his offhand

set_count.mcfunction
Sets the count of an item to a score, limiting to the item's stack size. Setting the score to 0 or any negative value before running this function will delete the item. Input:

set_custom_model_data.mcfunction
Sets the custom model data field of an item to a score. Input:

set_damage.mcfunction
Sets the damage of an item to a score. Input:

set_nbt.mcfunction
Sets an item 'tag' tag's NBT to NBT from the save chunk. This can be used to add custom tags as well as default vanilla tags. '''In Minecraft 1.14.4 Pre-release 5, it is already possible to do with the data modify command. However, this will not work if the item does not already have metadata and this relies on a bug which may be fixed in the future.''' Input:  tag in the jukebox placed at (1519204, 6, 0)

data modify block 1519204 6 0 RecordItem.tag.aestd.nbt set value {display:{Name:'"hello"'}} scoreboard players set @s aestd.item.slot 103 function aestd:item/set_nbt
 * 1) Resets a player's head item NBT and sets the NBT {display:{Name:'"hello"'}}

get_block_id.mcfunction
Saves a block's numerical ID to a score. This numerical ID corresponds to a protocol ID in the  file. This ID is used in other functions. Output:

highlight_block.mcfunction
Highlights the block at context position with end rod particles.

load.mcfunction
Loads a previously saved block to the block at context position.

randomize_structure_block.mcfunction
Randomizes the mirror and the rotation of the load structure block at context position.

save.mcfunction
Copies the block at context position to the save chunk.

set_skull_owner.mcfunction
Sets the owner of the player head at context position to a player whose name was previously saved by the  function.

get_biome.mcfunction
Saves the biome ID at context position to the sender's  score.

get_position.mcfunction
Saves the context position to 3 scores, rounded to integers.

get_rotation.mcfunction
Saves the context rotation to 2 scores, rounded to integers.

load_chunk.mcfunction
Loads the chunk in which this function runs for the current tick.

get_block_looking_at.mcfunction
Finds the coordinates of the block the player is looking at, in a distance defined by a score. Resets scores if the player isn't looking at a block. The maximum raycasting distance is 256 and the default is 80. Any value below 0 will be set to 3. Input:, output:  ,  ,

get_name.mcfunction
Saves the name of the player to the save chunk. Output: (1519204 6 0)

get_spawnpoint.mcfunction
Saves the player's spawnpoint to three scores. Output:,  ,

get_uuid.mcfunction
Saves the entire UUID of the player to the save chunk (not the same as, which saves the  /  pair). Output: (1519204 6 0)

set_experience_levels.mcfunction
Sets the player's experience levels to a score. Input:

set_position.mcfunction
Teleports the player to coordinates from three scores. Input:,  ,

Math
Most math functions take input from the executing entity's  and   scores and send output to its   score.

absolute.mcfunction
Returns |i|

Examples: 316 -> 316; -752 -> 752

cos.mcfunction
Returns 1000*cos(i) where i is an angle in degrees

Examples: 30 -> 866, 120 -> -500

get_vector_magnitude.mcfunction
Returns the magnitude of a 3-dimensional Euclidean vector with given coordinates. Takes input from,   and.

Example: (1784, 5139, 3396) -> 6412

linear_interpolation.mcfunction
Returns a linear interpolation between  and   for the   parameter between 0 and 1000 (if the parameter is 0, returns in; if the parameter is 1000, returns in2)

Example: (in1=3, in2=68, var=400) -> 29

power.mcfunction
Returns i^i2 where i2 is in the range [1;30]

Example: (in=2, in2=26) -> 67 108 864

random.mcfunction
Returns a random integer between 0 and aestd.random.max (excluded). Uses modulus on an entity's UUID.

random_lcg.mcfunction
Returns a random integer between 0 and aestd.random.max (excluded). Uses a linear congruential generator, which is more efficient than the UUID method used in.

random_range.mcfunction
Returns a random integer in the [aestd.random.min;aestd.random.max[ range.

set_vector_magnitude.mcfunction
Sets the magnitude of a 3-dimensional Euclidean vector with given coordinates. Takes input from and outputs to,   and.

Example: (1784, 5139, 3396), magnitude=5000 -> (1391, 4007, 2648)

sin.mcfunction
Returns 1000*sin(i) where i is an angle in degrees

Examples: 30 -> 500, 240 -> -866

smoothstep.mcfunction
Returns S1(i). should be between 0 and 1000 and the result will be between 0 and 1000.

Example: 400 -> 352

square_root.mcfunction
Returns the square root of i using the Babylonian method.

Example: 2 147 395 600 -> 46 340

add_marker.mcfunction
Summons a marker entity (area effect cloud) at given coordinates with an  tag for the current tick. Only one marker can exist at any given time; adding a marker will remove the last marker. Input:,  ,

get_daytime.mcfunction
Saves the current period of the day to the sender's  score.

get_moon_phase.mcfunction
Saves the current moon phase to the sender's  score.

get_weather.mcfunction
Saves the current weather to the sender's  score.