diff --git a/datapacks/Bookshelf/data/bs.view/functions/as_aimed_entity.mcfunction b/datapacks/Bookshelf/data/bs.view/functions/as/aimed_entity.mcfunction similarity index 100% rename from datapacks/Bookshelf/data/bs.view/functions/as_aimed_entity.mcfunction rename to datapacks/Bookshelf/data/bs.view/functions/as/aimed_entity.mcfunction diff --git a/datapacks/Bookshelf/data/bs.view/functions/as_looked_entity.mcfunction b/datapacks/Bookshelf/data/bs.view/functions/as/looked_entity.mcfunction similarity index 96% rename from datapacks/Bookshelf/data/bs.view/functions/as_looked_entity.mcfunction rename to datapacks/Bookshelf/data/bs.view/functions/as/looked_entity.mcfunction index 64ceaf2dec..d559ce403b 100644 --- a/datapacks/Bookshelf/data/bs.view/functions/as_looked_entity.mcfunction +++ b/datapacks/Bookshelf/data/bs.view/functions/as/looked_entity.mcfunction @@ -14,6 +14,7 @@ # CODE ------------------------------------------------------------------------ +execute unless predicate bs.view:is_looking_at_entity run return 0 execute if entity @e[tag=bs.view.is_lookable,tag=!bs.view.bi,sort=arbitrary,limit=1] run function bs.view:looked_entity/setup execute if score #view.looked_entity bs.data matches 1.. if predicate bs.view:looked_entity/b0 run tag @e[tag=bs.view.bi,tag=!bs.view.b0] remove bs.view.bi execute if score #view.looked_entity bs.data matches 2.. if predicate bs.view:looked_entity/b1 run tag @e[tag=bs.view.bi,tag=!bs.view.b1] remove bs.view.bi diff --git a/datapacks/Bookshelf/data/bs.view/functions/at_aimed_block.mcfunction b/datapacks/Bookshelf/data/bs.view/functions/at/aimed_block.mcfunction similarity index 72% rename from datapacks/Bookshelf/data/bs.view/functions/at_aimed_block.mcfunction rename to datapacks/Bookshelf/data/bs.view/functions/at/aimed_block.mcfunction index 542b45b2cd..acf5a847ca 100644 --- a/datapacks/Bookshelf/data/bs.view/functions/at_aimed_block.mcfunction +++ b/datapacks/Bookshelf/data/bs.view/functions/at/aimed_block.mcfunction @@ -22,6 +22,8 @@ data modify storage bs:in raycast set from storage bs:data view.raycast # run the command at the block that was found or return early execute if score #raycast.distance bs.data matches 2147483647 run return 0 -data modify entity B5-0-0-0-1 Pos set from storage bs:out raycast.targeted_block -$execute at B5-0-0-0-1 run $(run) -execute in minecraft:overworld run tp B5-0-0-0-1 -30000000 0 1600 +$data modify storage bs:ctx _ set value '$(run)' +data modify storage bs:ctx x set from storage bs:out raycast.targeted_block[0] +data modify storage bs:ctx y set from storage bs:out raycast.targeted_block[1] +data modify storage bs:ctx z set from storage bs:out raycast.targeted_block[2] +execute at @s run function bs.view:at/run with storage bs:ctx diff --git a/datapacks/Bookshelf/data/bs.view/functions/at_aimed_entity.mcfunction b/datapacks/Bookshelf/data/bs.view/functions/at/aimed_entity.mcfunction similarity index 100% rename from datapacks/Bookshelf/data/bs.view/functions/at_aimed_entity.mcfunction rename to datapacks/Bookshelf/data/bs.view/functions/at/aimed_entity.mcfunction diff --git a/datapacks/Bookshelf/data/bs.view/functions/at_aimed_point.mcfunction b/datapacks/Bookshelf/data/bs.view/functions/at/aimed_point.mcfunction similarity index 73% rename from datapacks/Bookshelf/data/bs.view/functions/at_aimed_point.mcfunction rename to datapacks/Bookshelf/data/bs.view/functions/at/aimed_point.mcfunction index 0df9c891ee..f10dc06e64 100644 --- a/datapacks/Bookshelf/data/bs.view/functions/at_aimed_point.mcfunction +++ b/datapacks/Bookshelf/data/bs.view/functions/at/aimed_point.mcfunction @@ -22,6 +22,8 @@ data modify storage bs:in raycast set from storage bs:data view.raycast # run the command at the hit point that was found or return early execute if score #raycast.distance bs.data matches 2147483647 run return 0 -data modify entity B5-0-0-0-1 Pos set from storage bs:out raycast.hit_point -$execute at B5-0-0-0-1 run $(run) -execute in minecraft:overworld run tp B5-0-0-0-1 -30000000 0 1600 +$data modify storage bs:ctx _ set value '$(run)' +data modify storage bs:ctx x set from storage bs:out raycast.hit_point[0] +data modify storage bs:ctx y set from storage bs:out raycast.hit_point[1] +data modify storage bs:ctx z set from storage bs:out raycast.hit_point[2] +execute at @s run function bs.view:at/run with storage bs:ctx diff --git a/datapacks/Bookshelf/data/bs.view/functions/at_looked_entity.mcfunction b/datapacks/Bookshelf/data/bs.view/functions/at/looked_entity.mcfunction similarity index 96% rename from datapacks/Bookshelf/data/bs.view/functions/at_looked_entity.mcfunction rename to datapacks/Bookshelf/data/bs.view/functions/at/looked_entity.mcfunction index e091e120c9..b20682edd6 100644 --- a/datapacks/Bookshelf/data/bs.view/functions/at_looked_entity.mcfunction +++ b/datapacks/Bookshelf/data/bs.view/functions/at/looked_entity.mcfunction @@ -14,6 +14,7 @@ # CODE ------------------------------------------------------------------------ +execute unless predicate bs.view:is_looking_at_entity run return 0 execute if entity @e[tag=bs.view.is_lookable,tag=!bs.view.bi,sort=arbitrary,limit=1] run function bs.view:looked_entity/setup execute if score #view.looked_entity bs.data matches 1.. if predicate bs.view:looked_entity/b0 run tag @e[tag=bs.view.bi,tag=!bs.view.b0] remove bs.view.bi execute if score #view.looked_entity bs.data matches 2.. if predicate bs.view:looked_entity/b1 run tag @e[tag=bs.view.bi,tag=!bs.view.b1] remove bs.view.bi diff --git a/datapacks/Bookshelf/data/bs.view/functions/at_placed_block.mcfunction b/datapacks/Bookshelf/data/bs.view/functions/at/placed_block.mcfunction similarity index 75% rename from datapacks/Bookshelf/data/bs.view/functions/at_placed_block.mcfunction rename to datapacks/Bookshelf/data/bs.view/functions/at/placed_block.mcfunction index b39a556e0d..b12efa10d9 100644 --- a/datapacks/Bookshelf/data/bs.view/functions/at_placed_block.mcfunction +++ b/datapacks/Bookshelf/data/bs.view/functions/at/placed_block.mcfunction @@ -22,14 +22,14 @@ data modify storage bs:in raycast set from storage bs:data view.raycast # run the command at the block before the block that was found or return early execute if score #raycast.distance bs.data matches 2147483647 run return 0 +$data modify storage bs:ctx _ set value '$(run)' execute store result score #view.x1 bs.data run data get storage bs:out raycast.targeted_block[0] execute store result score #view.y1 bs.data run data get storage bs:out raycast.targeted_block[1] execute store result score #view.z1 bs.data run data get storage bs:out raycast.targeted_block[2] execute store result score #view.x2 bs.data run data get storage bs:out raycast.hit_normal[0] execute store result score #view.y2 bs.data run data get storage bs:out raycast.hit_normal[1] execute store result score #view.z2 bs.data run data get storage bs:out raycast.hit_normal[2] -execute store result entity B5-0-0-0-1 Pos[0] double 1 run scoreboard players operation #view.x1 bs.data += #view.x2 bs.data -execute store result entity B5-0-0-0-1 Pos[1] double 1 run scoreboard players operation #view.y1 bs.data += #view.y2 bs.data -execute store result entity B5-0-0-0-1 Pos[2] double 1 run scoreboard players operation #view.z1 bs.data += #view.z2 bs.data -$execute at B5-0-0-0-1 run $(run) -execute in minecraft:overworld run tp B5-0-0-0-1 -30000000 0 1600 +execute store result storage bs:ctx x int 1 run scoreboard players operation #view.x1 bs.data += #view.x2 bs.data +execute store result storage bs:ctx y int 1 run scoreboard players operation #view.y1 bs.data += #view.y2 bs.data +execute store result storage bs:ctx z int 1 run scoreboard players operation #view.z1 bs.data += #view.z2 bs.data +execute at @s run function bs.view:at/run with storage bs:ctx diff --git a/datapacks/Bookshelf/data/bs.view/functions/at/run.mcfunction b/datapacks/Bookshelf/data/bs.view/functions/at/run.mcfunction new file mode 100644 index 0000000000..8e0a8f3ca6 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/functions/at/run.mcfunction @@ -0,0 +1 @@ +$execute positioned $(x) $(y) $(z) run $(_) diff --git a/datapacks/Bookshelf/data/bs.view/functions/can_see_ata.mcfunction b/datapacks/Bookshelf/data/bs.view/functions/can_see_ata.mcfunction index 4bd7e791a0..c5986aa996 100644 --- a/datapacks/Bookshelf/data/bs.view/functions/can_see_ata.mcfunction +++ b/datapacks/Bookshelf/data/bs.view/functions/can_see_ata.mcfunction @@ -18,6 +18,6 @@ data modify storage bs:data view.raycast set from storage bs:in raycast data modify storage bs:in raycast merge value {block_collision:true,entity_collision:false} data modify storage bs:in raycast.ignored_blocks set from storage bs:in view.can_see_ata.ignored_blocks execute store result storage bs:in raycast.max_distance double 0.001 run function #bs.position:get_distance_ata {scale:1000} -execute anchored eyes positioned ^ ^ ^ run function #bs.raycast:run +execute facing entity @s eyes run function #bs.raycast:run data modify storage bs:in raycast set from storage bs:data view.raycast execute if score #raycast.distance bs.data matches 2147483647 run return 1 diff --git a/datapacks/Bookshelf/data/bs.view/predicates/is_looking_at_entity.json b/datapacks/Bookshelf/data/bs.view/predicates/is_looking_at_entity.json new file mode 100644 index 0000000000..78e8832391 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/predicates/is_looking_at_entity.json @@ -0,0 +1,12 @@ +{ + "condition": "minecraft:entity_properties", + "entity": "this", + "predicate": { + "type_specific": { + "type": "player", + "looking_at": { + "nbt": "{Tags:[\"bs.view.is_lookable\"]}" + } + } + } +} diff --git a/datapacks/Bookshelf/data/bs.view/tags/functions/as_aimed_entity.json b/datapacks/Bookshelf/data/bs.view/tags/functions/as_aimed_entity.json index 2fdbb125d4..bd62c1b523 100644 --- a/datapacks/Bookshelf/data/bs.view/tags/functions/as_aimed_entity.json +++ b/datapacks/Bookshelf/data/bs.view/tags/functions/as_aimed_entity.json @@ -1,5 +1,5 @@ { "values": [ - "bs.view:as_aimed_entity" + "bs.view:as/aimed_entity" ] } diff --git a/datapacks/Bookshelf/data/bs.view/tags/functions/as_looked_entity.json b/datapacks/Bookshelf/data/bs.view/tags/functions/as_looked_entity.json index 533475d740..7b402c7680 100644 --- a/datapacks/Bookshelf/data/bs.view/tags/functions/as_looked_entity.json +++ b/datapacks/Bookshelf/data/bs.view/tags/functions/as_looked_entity.json @@ -1,5 +1,5 @@ { "values": [ - "bs.view:as_looked_entity" + "bs.view:as/looked_entity" ] } diff --git a/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_block.json b/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_block.json index 14b7a94f0a..ad4a674925 100644 --- a/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_block.json +++ b/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_block.json @@ -1,5 +1,5 @@ { "values": [ - "bs.view:at_aimed_block" + "bs.view:at/aimed_block" ] } diff --git a/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_entity.json b/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_entity.json index c8d16d03b1..453f9654c6 100644 --- a/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_entity.json +++ b/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_entity.json @@ -1,5 +1,5 @@ { "values": [ - "bs.view:at_aimed_entity" + "bs.view:at/aimed_entity" ] } diff --git a/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_point.json b/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_point.json index 11ee96e274..dd7cb42e9c 100644 --- a/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_point.json +++ b/datapacks/Bookshelf/data/bs.view/tags/functions/at_aimed_point.json @@ -1,5 +1,5 @@ { "values": [ - "bs.view:at_aimed_point" + "bs.view:at/aimed_point" ] } diff --git a/datapacks/Bookshelf/data/bs.view/tags/functions/at_looked_entity.json b/datapacks/Bookshelf/data/bs.view/tags/functions/at_looked_entity.json index e57b933919..20c38a57ae 100644 --- a/datapacks/Bookshelf/data/bs.view/tags/functions/at_looked_entity.json +++ b/datapacks/Bookshelf/data/bs.view/tags/functions/at_looked_entity.json @@ -1,5 +1,5 @@ { "values": [ - "bs.view:at_looked_entity" + "bs.view:at/looked_entity" ] } diff --git a/datapacks/Bookshelf/data/bs.view/tags/functions/at_placed_block.json b/datapacks/Bookshelf/data/bs.view/tags/functions/at_placed_block.json index f241f8851b..483ba780f9 100644 --- a/datapacks/Bookshelf/data/bs.view/tags/functions/at_placed_block.json +++ b/datapacks/Bookshelf/data/bs.view/tags/functions/at_placed_block.json @@ -1,5 +1,5 @@ { "values": [ - "bs.view:at_placed_block" + "bs.view:at/placed_block" ] } diff --git a/datapacks/Bookshelf/data/bs.view/tests/as/aimed_entity.mcfunction b/datapacks/Bookshelf/data/bs.view/tests/as/aimed_entity.mcfunction new file mode 100644 index 0000000000..9985135f9c --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/tests/as/aimed_entity.mcfunction @@ -0,0 +1,7 @@ +# Callback is run as the targeted entity +# @batch bs.view +# @dummy + +summon minecraft:armor_stand ~.5 ~ ~1.5 {Tags:["bs.raycast.is_solid"],NoGravity:1b} +function #bs.view:as_aimed_entity {run:"tag @s add found"} +assert entity @e[type=minecraft:armor_stand,tag=found] inside diff --git a/datapacks/Bookshelf/data/bs.view/tests/as/looked_entity.mcfunction b/datapacks/Bookshelf/data/bs.view/tests/as/looked_entity.mcfunction new file mode 100644 index 0000000000..b9506745ab --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/tests/as/looked_entity.mcfunction @@ -0,0 +1,7 @@ +# Callback is run as the looked at entity +# @batch bs.view +# @dummy + +summon minecraft:armor_stand ~.5 ~ ~1.5 {Tags:["bs.view.is_lookable"],NoGravity:1b} +function #bs.view:as_looked_entity {run:"tag @s add found"} +assert entity @e[type=minecraft:armor_stand,tag=found] inside diff --git a/datapacks/Bookshelf/data/bs.view/tests/at/aimed_block.mcfunction b/datapacks/Bookshelf/data/bs.view/tests/at/aimed_block.mcfunction new file mode 100644 index 0000000000..e5049d293c --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/tests/at/aimed_block.mcfunction @@ -0,0 +1,7 @@ +# Callback is run at the targeted block +# @batch bs.view +# @dummy + +setblock ~ ~1 ~1 minecraft:sponge +function #bs.view:at_aimed_block {run:"setblock ~ ~ ~ minecraft:bookshelf"} +assert block ~ ~1 ~1 minecraft:bookshelf diff --git a/datapacks/Bookshelf/data/bs.view/tests/at/aimed_entity.mcfunction b/datapacks/Bookshelf/data/bs.view/tests/at/aimed_entity.mcfunction new file mode 100644 index 0000000000..e674e9ac6d --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/tests/at/aimed_entity.mcfunction @@ -0,0 +1,7 @@ +# Callback is run at the targeted entity +# @batch bs.view +# @dummy + +summon minecraft:armor_stand ~.5 ~ ~1.5 {Tags:["bs.raycast.is_solid"],NoGravity:1b} +function #bs.view:at_aimed_entity {run:"tag @e[distance=0] add found"} +assert entity @e[type=minecraft:armor_stand,tag=found] inside diff --git a/datapacks/Bookshelf/data/bs.view/tests/at/aimed_point.mcfunction b/datapacks/Bookshelf/data/bs.view/tests/at/aimed_point.mcfunction new file mode 100644 index 0000000000..e5ef4a455a --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/tests/at/aimed_point.mcfunction @@ -0,0 +1,8 @@ +# Callback is run at the hit point +# @batch bs.view +# @dummy + +setblock ~ ~1 ~1 minecraft:bookshelf +function #bs.view:at_aimed_point {run:"summon minecraft:marker ~ ~ ~ {UUID:[181,0,0,0]}"} +execute store success score #success bs.data run data modify entity B5-0-0-0-0 Pos set from storage bs:out raycast.hit_point +assert score #success bs.data matches 0 diff --git a/datapacks/Bookshelf/data/bs.view/tests/at/looked_entity.mcfunction b/datapacks/Bookshelf/data/bs.view/tests/at/looked_entity.mcfunction new file mode 100644 index 0000000000..d23ca70de9 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/tests/at/looked_entity.mcfunction @@ -0,0 +1,7 @@ +# Callback is run at the looked at entity +# @batch bs.view +# @dummy + +summon minecraft:armor_stand ~.5 ~ ~1.5 {Tags:["bs.view.is_lookable"],NoGravity:1b} +function #bs.view:at_looked_entity {run:"tag @e[distance=0] add found"} +assert entity @e[type=minecraft:armor_stand,tag=found] inside diff --git a/datapacks/Bookshelf/data/bs.view/tests/at/placed_block.mcfunction b/datapacks/Bookshelf/data/bs.view/tests/at/placed_block.mcfunction new file mode 100644 index 0000000000..4f1fd8b16a --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/tests/at/placed_block.mcfunction @@ -0,0 +1,7 @@ +# Callback is run at the placed block +# @batch bs.view +# @dummy + +setblock ~ ~1 ~1 minecraft:sponge +function #bs.view:at_placed_block {run:"setblock ~ ~ ~ minecraft:bookshelf"} +assert block ~ ~1 ~ minecraft:bookshelf diff --git a/datapacks/Bookshelf/data/bs.view/tests/can_see_ata.mcfunction b/datapacks/Bookshelf/data/bs.view/tests/can_see_ata.mcfunction new file mode 100644 index 0000000000..6275c7fd5d --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/tests/can_see_ata.mcfunction @@ -0,0 +1,7 @@ +# Check the whole distance between the executor and the position +# @batch bs.view +# @dummy + +setblock ~ ~1 ~1 minecraft:bookshelf +execute at @s positioned ~ ~1 ~.5 if function #bs.view:can_see_ata run fail "Position must be obstructed when reaching a block" +execute at @s positioned ~ ~1 ~.49 unless function #bs.view:can_see_ata run fail "Position must be unobstructed before reaching a block" diff --git a/datapacks/Bookshelf/data/bs.view/tests/in_view_ata.mcfunction b/datapacks/Bookshelf/data/bs.view/tests/in_view_ata.mcfunction new file mode 100644 index 0000000000..9df2df9bba --- /dev/null +++ b/datapacks/Bookshelf/data/bs.view/tests/in_view_ata.mcfunction @@ -0,0 +1,7 @@ +# Check multiple vision angles +# @batch bs.view +# @dummy + +data modify storage bs:in view.in_view_ata.angle set value 90 +execute at @s anchored eyes positioned ^1 ^ ^1 if function #bs.view:in_view_ata run fail "Position must not be within the 90-degree viewing angle" +execute at @s anchored eyes positioned ^.99 ^ ^1 unless function #bs.view:in_view_ata run fail "Position must be within the 90-degree viewing angle" diff --git a/docs/modules/view.md b/docs/modules/view.md index aace40596f..3e349f74e4 100644 --- a/docs/modules/view.md +++ b/docs/modules/view.md @@ -66,6 +66,8 @@ Run a command as the entity that is aimed by the current entity. **Execution `as `**: Entity whose eyes determine the vision origin. **Macro Var `run` [string]**: Command to run as the targeted entity. + + **Tag**: Tag for entities that can be aimed (default: `bs.raycast.is_solid`). ``` *Run a command as the entity that you are looking at:* @@ -86,6 +88,8 @@ Run a command at the entity that is aimed by the current entity. **Execution `as `**: Entity whose eyes determine the vision origin. **Macro Var `run` [string]**: Command to run at the targeted entity. + + **Tag**: Tag for entities that can be aimed (default: `bs.raycast.is_solid`). ``` *Run a command at the entity that you are looking at:*