From 297f9030387e5dddb54bd93e9d54ccae666b375e Mon Sep 17 00:00:00 2001 From: asn44nb Date: Fri, 3 Apr 2026 06:03:04 +0000 Subject: [PATCH] feat: add for_each_in_radius, is_on_ground, is_burning, offhand_item, get_time - entity/for_each_in_radius: radius-filtered entity iteration - player/is_on_ground: wrapper for macro:is_on_ground predicate - player/is_burning: wrapper for macro:is_burning predicate - inv/offhand_item: offhand equivalent of selected_item - world/get_time: daytime / total / day to macro:output --- .../entity/for_each_in_radius.mcfunction | 16 ++++++++++++++ .../function/inv/offhand_item.mcfunction | 15 +++++++++++++ .../function/player/is_burning.mcfunction | 22 +++++++++++++++++++ .../function/player/is_on_ground.mcfunction | 22 +++++++++++++++++++ data/macro/function/world/get_time.mcfunction | 17 ++++++++++++++ 5 files changed, 92 insertions(+) create mode 100644 data/macro/function/entity/for_each_in_radius.mcfunction create mode 100644 data/macro/function/inv/offhand_item.mcfunction create mode 100644 data/macro/function/player/is_burning.mcfunction create mode 100644 data/macro/function/player/is_on_ground.mcfunction create mode 100644 data/macro/function/world/get_time.mcfunction diff --git a/data/macro/function/entity/for_each_in_radius.mcfunction b/data/macro/function/entity/for_each_in_radius.mcfunction new file mode 100644 index 0000000..7036240 --- /dev/null +++ b/data/macro/function/entity/for_each_in_radius.mcfunction @@ -0,0 +1,16 @@ +# ───────────────────────────────────────────────────────────────── +# macro:entity/for_each_in_radius +# Runs a function as every entity of a given type within radius +# of the named player. +# +# INPUT : $(player) → player name (origin) +# $(type) → entity type (e.g. "minecraft:zombie") +# $(radius) → search radius in blocks +# $(func) → function to run as each entity (at its position) +# +# EXAMPLE: +# function macro:entity/for_each_in_radius {player:"Steve",type:"minecraft:zombie",radius:10,func:"mypack:on_zombie"} +# ───────────────────────────────────────────────────────────────── + +$execute as @a[name=$(player),limit=1] at @s run execute as @e[type=$(type),distance=..$(radius)] at @s run function $(func) +$tellraw @a[tag=macro.debug] ["",{"text":"[AME] ","color":"#00AAAA","bold":true},{"text":"entity/for_each_in_radius ","color":"aqua"},{"text":"$(player) r=$(radius) → ","color":"gray"},{"text":"$(type)","color":"aqua"}] diff --git a/data/macro/function/inv/offhand_item.mcfunction b/data/macro/function/inv/offhand_item.mcfunction new file mode 100644 index 0000000..abb8d27 --- /dev/null +++ b/data/macro/function/inv/offhand_item.mcfunction @@ -0,0 +1,15 @@ +# ───────────────────────────────────────────────────────────────── +# macro:inv/offhand_item +# Runs a command/function for each player in @a whose offhand +# matches the given item id and custom data. +# Mirrors the pattern of macro:inv/selected_item (mainhand). +# +# INPUT : $(item) → item id (e.g. "minecraft:shield") +# $(customData) → custom_data compound to match (e.g. "{my_tag:1b}") +# $(invoke) → command to run as the matching player +# +# EXAMPLE: +# function macro:inv/offhand_item {item:"minecraft:shield",customData:"{my_tag:1b}",invoke:"function mypack:on_shield"} +# ───────────────────────────────────────────────────────────────── + +$execute as @a at @s if items entity @s weapon.offhand $(item)[minecraft:custom_data=$(customData)] run $(invoke) diff --git a/data/macro/function/player/is_burning.mcfunction b/data/macro/function/player/is_burning.mcfunction new file mode 100644 index 0000000..bcf4d14 --- /dev/null +++ b/data/macro/function/player/is_burning.mcfunction @@ -0,0 +1,22 @@ +# ───────────────────────────────────────────────────────────────── +# macro:player/is_burning +# Checks whether a named player is currently on fire. +# Uses the macro:is_burning predicate (entity_flags). +# +# INPUT : $(player) → player name +# OUTPUT: macro:output result → 1b if burning, 0b otherwise +# macro:output found → 1b if player online, 0b otherwise +# +# EXAMPLE: +# function macro:player/is_burning {player:"Steve"} +# → macro:output result = 1b +# ───────────────────────────────────────────────────────────────── + +data modify storage macro:output found set value 0b +data modify storage macro:output result set value 0b + +$execute unless entity @a[name=$(player),limit=1] run return 0 + +data modify storage macro:output found set value 1b +$execute as @a[name=$(player),limit=1] if predicate macro:is_burning run data modify storage macro:output result set value 1b +$tellraw @a[tag=macro.debug] ["",{"text":"[AME] ","color":"#00AAAA","bold":true},{"text":"player/is_burning ","color":"aqua"},{"text":"$(player) → ","color":"gray"},{"storage":"macro:output","nbt":"result","color":"green"}] diff --git a/data/macro/function/player/is_on_ground.mcfunction b/data/macro/function/player/is_on_ground.mcfunction new file mode 100644 index 0000000..d4276ad --- /dev/null +++ b/data/macro/function/player/is_on_ground.mcfunction @@ -0,0 +1,22 @@ +# ───────────────────────────────────────────────────────────────── +# macro:player/is_on_ground +# Checks whether a named player is currently on the ground. +# Uses the macro:is_on_ground predicate (entity_flags). +# +# INPUT : $(player) → player name +# OUTPUT: macro:output result → 1b if on ground, 0b otherwise +# macro:output found → 1b if player online, 0b otherwise +# +# EXAMPLE: +# function macro:player/is_on_ground {player:"Steve"} +# → macro:output result = 1b +# ───────────────────────────────────────────────────────────────── + +data modify storage macro:output found set value 0b +data modify storage macro:output result set value 0b + +$execute unless entity @a[name=$(player),limit=1] run return 0 + +data modify storage macro:output found set value 1b +$execute as @a[name=$(player),limit=1] if predicate macro:is_on_ground run data modify storage macro:output result set value 1b +$tellraw @a[tag=macro.debug] ["",{"text":"[AME] ","color":"#00AAAA","bold":true},{"text":"player/is_on_ground ","color":"aqua"},{"text":"$(player) → ","color":"gray"},{"storage":"macro:output","nbt":"result","color":"green"}] diff --git a/data/macro/function/world/get_time.mcfunction b/data/macro/function/world/get_time.mcfunction new file mode 100644 index 0000000..0651216 --- /dev/null +++ b/data/macro/function/world/get_time.mcfunction @@ -0,0 +1,17 @@ +# ───────────────────────────────────────────────────────────────── +# macro:world/get_time +# Reads the current world time and writes it to macro:output. +# +# OUTPUT: macro:output daytime → ticks within the current day (0–23999) +# macro:output total → total world age in ticks (never resets) +# macro:output day → current in-game day number +# +# EXAMPLE: +# function macro:world/get_time +# data get storage macro:output daytime +# ───────────────────────────────────────────────────────────────── + +execute store result storage macro:output daytime int 1 run time query daytime +execute store result storage macro:output total int 1 run time query gametime +execute store result storage macro:output day int 1 run time query day +tellraw @a[tag=macro.debug] ["",{"text":"[AME] ","color":"#00AAAA","bold":true},{"text":"world/get_time ","color":"aqua"},{"text":"day=","color":"gray"},{"storage":"macro:output","nbt":"day","color":"green"},{"text":" daytime=","color":"gray"},{"storage":"macro:output","nbt":"daytime","color":"green"}]