diff --git a/datapacks/Bookshelf/data/bs.interaction/.metadata/generated/features.json b/datapacks/Bookshelf/data/bs.interaction/.metadata/generated/features.json new file mode 100644 index 000000000..26a575646 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/.metadata/generated/features.json @@ -0,0 +1,112 @@ +[ + { + "name": "clear_events", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#clear-events", + "authors": [ + "Aksiome" + ], + "created": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + } + }, + { + "name": "on_hover", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + }, + { + "name": "on_hover_enter", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + }, + { + "name": "on_hover_leave", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + }, + { + "name": "on_left_click", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + }, + { + "name": "on_right_click", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + } +] diff --git a/datapacks/Bookshelf/data/bs.interaction/.metadata/generated/module.json b/datapacks/Bookshelf/data/bs.interaction/.metadata/generated/module.json new file mode 100644 index 000000000..5dbb0f2b4 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/.metadata/generated/module.json @@ -0,0 +1,21 @@ +{ + "name": "bs.interaction", + "display_name": "Interaction", + "description": "A low-level API to create GUI based on Interaction entity by binding events to it.", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "weak_dependencies": [ + "bs.log" + ], + "features": [ + "bs.interaction:clear_events", + "bs.interaction:on_hover", + "bs.interaction:on_hover_enter", + "bs.interaction:on_hover_leave", + "bs.interaction:on_left_click", + "bs.interaction:on_right_click" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/.metadata/module.json b/datapacks/Bookshelf/data/bs.interaction/.metadata/module.json new file mode 100644 index 000000000..97fed5117 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/.metadata/module.json @@ -0,0 +1,9 @@ +{ + "name": "bs.interaction", + "display_name": "Interaction", + "description": "A low-level API to create GUI based on Interaction entity by binding events to it.", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html", + "weak_dependencies": [ + "bs.log" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/advancement/left_click.json b/datapacks/Bookshelf/data/bs.interaction/advancement/left_click.json new file mode 100644 index 000000000..b5e7b1f05 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/advancement/left_click.json @@ -0,0 +1,27 @@ +{ + "criteria": { + "requirement": { + "trigger": "minecraft:player_hurt_entity", + "conditions": { + "entity": [ + { + "condition": "minecraft:entity_properties", + "entity": "this", + "predicate": { + "type": "minecraft:interaction", + "nbt": "{ Tags: [ \"bs.interaction.listen_left_click\" ] }", + "distance": { + "absolute": { + "max": 24 + } + } + } + } + ] + } + } + }, + "rewards": { + "function": "bs.interaction:on_event/left_click/left_click" + } +} diff --git a/datapacks/Bookshelf/data/bs.interaction/advancement/right_click.json b/datapacks/Bookshelf/data/bs.interaction/advancement/right_click.json new file mode 100644 index 000000000..d968fb3fc --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/advancement/right_click.json @@ -0,0 +1,27 @@ +{ + "criteria": { + "requirement": { + "trigger": "minecraft:player_interacted_with_entity", + "conditions": { + "entity": [ + { + "condition": "minecraft:entity_properties", + "entity": "this", + "predicate": { + "type": "minecraft:interaction", + "nbt": "{ Tags: [ \"bs.interaction.listen_right_click\" ] }", + "distance": { + "absolute": { + "max": 24 + } + } + } + } + ] + } + } + }, + "rewards": { + "function": "bs.interaction:on_event/right_click/right_click" + } +} diff --git a/datapacks/Bookshelf/data/bs.interaction/function/__help__.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/__help__.mcfunction new file mode 100644 index 000000000..7bd82aece --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/__help__.mcfunction @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html +# ------------------------------------------------------------------------------------------------------------ + +tellraw @s [{"text": "[bs.interaction documentation]", "color": "dark_aqua", "clickEvent": {"action": "open_url", "value": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html"}, "hoverEvent": {"action": "show_text", "contents": "Click to open URL"}}] diff --git a/datapacks/Bookshelf/data/bs.interaction/function/__load__.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/__load__.mcfunction new file mode 100644 index 000000000..108c2edcd --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/__load__.mcfunction @@ -0,0 +1,27 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +forceload add -30000000 1600 +execute unless entity B5-0-0-0-2 run summon minecraft:text_display -30000000 0 1600 {UUID:[I;181,0,0,2],Tags:["bs.entity","bs.persistent","smithed.entity","smithed.strict"],view_range:0f} + +scoreboard objectives add bs.ctx dummy [{"text":"BS ","color":"dark_gray"},{"text":"Context","color":"aqua"}] +scoreboard objectives add bs.data dummy [{"text":"BS ","color":"dark_gray"},{"text":"Data","color":"aqua"}] +scoreboard objectives add bs.const dummy [{"text":"BS ","color":"dark_gray"},{"text":"Constants","color":"aqua"}] + +scoreboard objectives add bs.interaction.id dummy [{"text":"BS ","color":"dark_gray"},{"text":"Interaction ID","color":"aqua"}] +scoreboard objectives add bs.interaction.hover dummy [{"text":"BS ","color":"dark_gray"},{"text":"Interaction Hover","color":"aqua"}] +scoreboard objectives add bs.interaction.logout minecraft.custom:leave_game [{"text":"BS ","color":"dark_gray"},{"text":"Interaction Logout","color":"aqua"}] + +scoreboard players set 2 bs.const 2 diff --git a/datapacks/Bookshelf/data/bs.interaction/function/__unload__.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/__unload__.mcfunction new file mode 100644 index 000000000..a769e2a63 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/__unload__.mcfunction @@ -0,0 +1,27 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +kill B5-0-0-0-2 +forceload remove -30000000 1600 + +execute as @e[type=minecraft:interaction] run function #bs.interaction:clear_events {with:{}} + +scoreboard objectives remove bs.interaction.id + +scoreboard objectives remove bs.ctx +scoreboard objectives remove bs.data +scoreboard objectives remove bs.const + +data remove storage bs:data interaction diff --git a/datapacks/Bookshelf/data/bs.interaction/function/callback/glow.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/callback/glow.mcfunction new file mode 100644 index 000000000..3264b2a84 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/callback/glow.mcfunction @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#default-callback +# ------------------------------------------------------------------------------------------------------------ + +# Note: +# Glows the current entity. + +data modify entity @s Glowing set value 1b diff --git a/datapacks/Bookshelf/data/bs.interaction/function/callback/none.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/callback/none.mcfunction new file mode 100644 index 000000000..1833eb26b --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/callback/none.mcfunction @@ -0,0 +1,16 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#default-callback +# ------------------------------------------------------------------------------------------------------------ diff --git a/datapacks/Bookshelf/data/bs.interaction/function/callback/unglow.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/callback/unglow.mcfunction new file mode 100644 index 000000000..6a0060c6a --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/callback/unglow.mcfunction @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#default-callback +# ------------------------------------------------------------------------------------------------------------ + +# Note: +# Unglows the current entity. + +data modify entity @s Glowing set value 0b diff --git a/datapacks/Bookshelf/data/bs.interaction/function/clear_events/clear_events.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/clear_events/clear_events.mcfunction new file mode 100644 index 000000000..d10159c81 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/clear_events/clear_events.mcfunction @@ -0,0 +1,20 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#clear-events +# ------------------------------------------------------------------------------------------------------------ + +$data modify storage bs:ctx _ set value $(with) +execute store result storage bs:ctx y int 1 run scoreboard players get @s bs.interaction.id +return run function bs.interaction:clear_events/remove_matching with storage bs:ctx diff --git a/datapacks/Bookshelf/data/bs.interaction/function/clear_events/remove_matching.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/clear_events/remove_matching.mcfunction new file mode 100644 index 000000000..b3e16255f --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/clear_events/remove_matching.mcfunction @@ -0,0 +1,32 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +$execute store result score #i bs.ctx run data remove storage bs:data interaction.$(y)[$(_)] + +$execute unless data storage bs:data interaction.$(y)[-1] run scoreboard players reset @s bs.interaction.id +$execute unless data storage bs:data interaction.$(y)[{type:"hover"}] run tag @s remove bs.interaction.listen_hover +$execute unless data storage bs:data interaction.$(y)[{type:"hover_enter"}] run tag @s remove bs.interaction.listen_hover_enter +$execute unless data storage bs:data interaction.$(y)[{type:"hover_leave"}] run tag @s remove bs.interaction.listen_hover_leave +$execute unless data storage bs:data interaction.$(y)[{type:"left_click"}] run tag @s remove bs.interaction.listen_left_click +$execute unless data storage bs:data interaction.$(y)[{type:"right_click"}] run tag @s remove bs.interaction.listen_right_click + +execute unless entity @s[tag=bs.interaction.listen_hover] \ + unless entity @s[tag=bs.interaction.listen_hover_enter] \ + unless entity @s[tag=bs.interaction.listen_hover_leave] \ + run tag @s remove bs.interaction.is_hoverable + +execute unless entity @s[tag=bs.interaction.is_hoverable] run scoreboard players set #interaction.process bs.data 0 + +return run scoreboard players get #i bs.ctx diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/as_target.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/as_target.mcfunction new file mode 100644 index 000000000..1460dd1a2 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/as_target.mcfunction @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +execute if entity @s[tag=bs.interaction.listen_hover] run function bs.interaction:on_event/hover/dispatch with storage bs:ctx +tag @s remove bs.interaction.target diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/dispatch.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/dispatch.mcfunction new file mode 100644 index 000000000..c3cb8db97 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/dispatch.mcfunction @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +data modify storage bs:data interaction.run set value [] +$data modify storage bs:data interaction.run append from storage bs:data interaction.$(y)[{type:"hover"}] +execute if data storage bs:data interaction.run[-1] run function bs.interaction:on_event/run with storage bs:data interaction.run[-1] diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/hover.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/hover.mcfunction new file mode 100644 index 000000000..d8b9523e3 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/hover.mcfunction @@ -0,0 +1,24 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +# Check only the interaction that the player was looking at. +# If the player is not looking at any interaction, return the hover leave event and restart the whole cycle. + +tag @s add bs.interaction.source +execute store result storage bs:ctx y int 1 run scoreboard players get @s bs.interaction.id +execute as @n[type=minecraft:interaction,predicate=bs.interaction:check_id] run tag @s add bs.interaction.target +$execute unless predicate {"condition":"minecraft:entity_properties","entity":"this","predicate":{"type_specific":{"type":"minecraft:player","looking_at":{"type":"minecraft:interaction","nbt":"{\"Tags\":[\"bs.interaction.target\"]}","distance":{"absolute":{"max":$(y)}}}}}} run return run function bs.interaction:on_event/hover_leave/hover_leave +execute as @n[type=minecraft:interaction,tag=bs.interaction.target,distance=..24] run function bs.interaction:on_event/hover/as_target +tag @s remove bs.interaction.source diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/reset.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/reset.mcfunction new file mode 100644 index 000000000..29810592e --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover/reset.mcfunction @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +scoreboard players reset @s bs.interaction.id +scoreboard players reset @s bs.interaction.logout diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/as_target.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/as_target.mcfunction new file mode 100644 index 000000000..b38382790 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/as_target.mcfunction @@ -0,0 +1,21 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +scoreboard players add @s bs.interaction.hover 1 +scoreboard players add #interaction.active_hover bs.data 1 +execute store result storage bs:ctx y int 1 run scoreboard players operation @p[distance=0,tag=bs.interaction.source] bs.interaction.id = @s bs.interaction.id +execute if entity @s[tag=bs.interaction.listen_hover_enter] run function bs.interaction:on_event/hover_enter/dispatch with storage bs:ctx +execute if entity @s[tag=bs.interaction.listen_hover] run function bs.interaction:on_event/hover/dispatch with storage bs:ctx +tag @s remove bs.interaction.target diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/dispatch.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/dispatch.mcfunction new file mode 100644 index 000000000..83bf97883 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/dispatch.mcfunction @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +data modify storage bs:data interaction.run set value [] +$data modify storage bs:data interaction.run append from storage bs:data interaction.$(y)[{type:"hover_enter"}] +execute if data storage bs:data interaction.run[-1] run function bs.interaction:on_event/run with storage bs:data interaction.run[-1] diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/get_target/filter.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/get_target/filter.mcfunction new file mode 100644 index 000000000..aaf2f3149 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/get_target/filter.mcfunction @@ -0,0 +1,23 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +scoreboard players set #n bs.ctx 0 +execute as @n[type=minecraft:interaction,tag=bs.interaction.target,distance=..24,limit=2147483647] run function bs.interaction:on_event/hover_enter/get_target/mask + +execute store result score #s bs.ctx if predicate {"condition":"minecraft:entity_properties","entity":"this","predicate":{"type_specific":{"type":"minecraft:player","looking_at":{"type":"minecraft:interaction","nbt":"{\"Tags\":[\"bs.interaction.mask\"]}","distance":{"absolute":{"max":24}}}}}} +execute if score #s bs.ctx matches 0 run tag @n[type=minecraft:interaction,tag=bs.interaction.target,tag=bs.interaction.mask,distance=..24,limit=2147483647] remove bs.interaction.target +execute if score #s bs.ctx matches 1 run tag @n[type=minecraft:interaction,tag=bs.interaction.target,tag=!bs.interaction.mask,distance=..24,limit=2147483647] remove bs.interaction.target + +execute if score #n bs.ctx matches 3.. run function bs.interaction:on_event/hover_enter/get_target/filter diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/get_target/mask.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/get_target/mask.mcfunction new file mode 100644 index 000000000..357261748 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/get_target/mask.mcfunction @@ -0,0 +1,19 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +tag @s remove bs.interaction.mask +execute store result score #m bs.ctx run scoreboard players add #n bs.ctx 1 +scoreboard players operation #m bs.ctx %= 2 bs.const +execute if score #m bs.ctx matches 1 run tag @s add bs.interaction.mask diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/hover_enter.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/hover_enter.mcfunction new file mode 100644 index 000000000..166c78763 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_enter/hover_enter.mcfunction @@ -0,0 +1,22 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +$execute unless predicate {"condition":"minecraft:entity_properties","entity":"this","predicate":{"type_specific":{"type":"minecraft:player","looking_at":{"type":"minecraft:interaction","nbt":"{\"Tags\":[\"bs.interaction.is_hoverable\"]}","distance":{"absolute":{"max":$(y)}}}}}} run return fail + +tag @s add bs.interaction.source +tag @n[type=minecraft:interaction,tag=bs.interaction.is_hoverable,distance=..24,limit=2147483647] add bs.interaction.target +function bs.interaction:on_event/hover_enter/get_target/filter +execute as @n[type=minecraft:interaction,tag=bs.interaction.target,distance=..24] run function bs.interaction:on_event/hover_enter/as_target +tag @s remove bs.interaction.source diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/as_target.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/as_target.mcfunction new file mode 100644 index 000000000..7f05b361c --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/as_target.mcfunction @@ -0,0 +1,20 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +tag @s add bs.interaction.target +scoreboard players remove @s bs.interaction.hover 1 +scoreboard players remove #interaction.active_hover bs.data 1 +execute if entity @s[tag=bs.interaction.listen_hover_leave] run function bs.interaction:on_event/hover_leave/dispatch with storage bs:ctx +tag @s remove bs.interaction.target diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/dispatch.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/dispatch.mcfunction new file mode 100644 index 000000000..38061effd --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/dispatch.mcfunction @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +data modify storage bs:data interaction.run set value [] +$data modify storage bs:data interaction.run append from storage bs:data interaction.$(y)[{type:"hover_leave"}] +execute if data storage bs:data interaction.run[-1] run function bs.interaction:on_event/run with storage bs:data interaction.run[-1] diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/hover_leave.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/hover_leave.mcfunction new file mode 100644 index 000000000..0d7546203 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/hover_leave.mcfunction @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +execute as @n[type=minecraft:interaction,tag=bs.interaction.target] run function bs.interaction:on_event/hover_leave/as_target +tag @s remove bs.interaction.source +scoreboard players reset @s bs.interaction.id diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/try_leave.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/try_leave.mcfunction new file mode 100644 index 000000000..aa4e85ba5 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/hover_leave/try_leave.mcfunction @@ -0,0 +1,20 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +execute store result score #i bs.ctx run scoreboard players get @s bs.interaction.hover +execute store result storage bs:ctx y int 1 run scoreboard players get @s bs.interaction.id +execute at @s store result score #p bs.ctx if entity @a[distance=..24,predicate=bs.interaction:check_id] +scoreboard players operation #i bs.ctx -= #p bs.ctx +execute if score #i bs.ctx matches 1.. run function bs.interaction:on_event/hover_leave/as_target diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/left_click/as_target.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/left_click/as_target.mcfunction new file mode 100644 index 000000000..0a80e9ab9 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/left_click/as_target.mcfunction @@ -0,0 +1,20 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +execute on attacker unless entity @s[tag=bs.interaction.source] run return fail +tag @s add bs.interaction.target +execute store result storage bs:ctx y int 1 run scoreboard players get @s bs.interaction.id +function bs.interaction:on_event/left_click/dispatch with storage bs:ctx +tag @s remove bs.interaction.target diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/left_click/dispatch.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/left_click/dispatch.mcfunction new file mode 100644 index 000000000..81ad875d5 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/left_click/dispatch.mcfunction @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +data modify storage bs:data interaction.run set value [] +$data modify storage bs:data interaction.run append from storage bs:data interaction.$(y)[{type:"left_click"}] +execute if data storage bs:data interaction.run[-1] run function bs.interaction:on_event/run with storage bs:data interaction.run[-1] diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/left_click/left_click.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/left_click/left_click.mcfunction new file mode 100644 index 000000000..2a650b8c9 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/left_click/left_click.mcfunction @@ -0,0 +1,22 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +# Note: +# Function called when a left click is done on a left click listener. + +advancement revoke @s only bs.interaction:left_click +tag @s add bs.interaction.source +execute as @n[type=minecraft:interaction,tag=bs.interaction.listen_left_click,distance=..24,limit=2147483647] run function bs.interaction:on_event/left_click/as_target +tag @s remove bs.interaction.source diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/player_process.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/player_process.mcfunction new file mode 100644 index 000000000..a5b17d521 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/player_process.mcfunction @@ -0,0 +1,20 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +execute if score @s bs.interaction.logout matches 1.. run return run function bs.interaction:on_event/hover/reset +execute store result storage bs:ctx y double .000001 run attribute @s minecraft:entity_interaction_range get 1000000 +execute unless score @s bs.interaction.id matches 1.. run return run function bs.interaction:on_event/hover_enter/hover_enter with storage bs:ctx +execute if score @s bs.interaction.id matches 1.. run function bs.interaction:on_event/hover/hover with storage bs:ctx +scoreboard players remove #interaction.unhandled_hover bs.data 1 diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/process.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/process.mcfunction new file mode 100644 index 000000000..fdfa79c5c --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/process.mcfunction @@ -0,0 +1,22 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +scoreboard players operation #interaction.unhandled_hover bs.data = #interaction.active_hover bs.data +execute as @a at @s run function bs.interaction:on_event/player_process +execute if score #interaction.unhandled_hover bs.data matches 1.. \ + as @n[type=minecraft:interaction,scores={bs.interaction.hover=1..},limit=2147483647] \ + run function bs.interaction:on_event/hover_leave/try_leave + +execute if score #interaction.process bs.data matches 1 run schedule function bs.interaction:on_event/process 1t diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/right_click/as_target.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/right_click/as_target.mcfunction new file mode 100644 index 000000000..e1bdedd4a --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/right_click/as_target.mcfunction @@ -0,0 +1,20 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +execute on target unless entity @s[tag=bs.interaction.source] run return fail +tag @s add bs.interaction.target +execute store result storage bs:ctx y int 1 run scoreboard players get @s bs.interaction.id +function bs.interaction:on_event/right_click/dispatch with storage bs:ctx +tag @s remove bs.interaction.target diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/right_click/dispatch.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/right_click/dispatch.mcfunction new file mode 100644 index 000000000..00db1526e --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/right_click/dispatch.mcfunction @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +data modify storage bs:data interaction.run set value [] +$data modify storage bs:data interaction.run append from storage bs:data interaction.$(y)[{type:"right_click"}] +execute if data storage bs:data interaction.run[-1] run function bs.interaction:on_event/run with storage bs:data interaction.run[-1] diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/right_click/right_click.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/right_click/right_click.mcfunction new file mode 100644 index 000000000..cdf133f6c --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/right_click/right_click.mcfunction @@ -0,0 +1,22 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +# Note: +# Function called when a right click is done on a right click listener. + +advancement revoke @s only bs.interaction:right_click +tag @s add bs.interaction.source +execute as @n[type=minecraft:interaction,tag=bs.interaction.listen_right_click,distance=..24,limit=2147483647] run function bs.interaction:on_event/right_click/as_target +tag @s remove bs.interaction.source diff --git a/datapacks/Bookshelf/data/bs.interaction/function/on_event/run.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/on_event/run.mcfunction new file mode 100644 index 000000000..4a090ff25 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/on_event/run.mcfunction @@ -0,0 +1,18 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +$execute as $(executor) run $(run) +data remove storage bs:data interaction.run[-1] +execute if data storage bs:data interaction.run[-1] run function bs.interaction:on_event/run with storage bs:data interaction.run[-1] diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/hover.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/hover.mcfunction new file mode 100644 index 000000000..4f78d0963 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/hover.mcfunction @@ -0,0 +1,61 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event +# ------------------------------------------------------------------------------------------------------------ + +# Note: +# Add a new command to trigger continuously when the current interaction is hovered. +# +# Input: +# - macro variable { run: , executor: target|source| | { selector: , lazy: true|false } } +# Output: +# - Fail if the current entity is not an interaction. + +execute unless entity @s[type=interaction] run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover", \ + tag: "on_hover", \ + message: '"The current entity is not an interaction."', \ +} +$data modify storage bs:ctx _ set value { run: '$(run)', executor: $(executor), type: "hover" } + +execute store success score #s bs.ctx run function bs.interaction:register/utils/check_command with storage bs:ctx _ +execute unless score #s bs.ctx matches 1 run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover", \ + tag: "on_hover", \ + message: '"The command is not valid."', \ +} + +execute unless function bs.interaction:register/utils/executor/setup \ + run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover", \ + tag: "on_hover", \ + message: '"The executor is not valid or cannot be interpreted."', \ + } + +execute if score #i bs.ctx matches 2.. run function #bs.log:warn { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover", \ + tag: "on_hover", \ + message: '"The selector points to multiple entities. Only the first one is selected."' \ +} + +tag @s add bs.interaction.is_hoverable +tag @s add bs.interaction.listen_hover +scoreboard players set #interaction.process bs.data 1 +schedule function bs.interaction:on_event/process 1t replace +return run function bs.interaction:register/utils/setup_listener diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/hover_enter.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/hover_enter.mcfunction new file mode 100644 index 000000000..47cca608c --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/hover_enter.mcfunction @@ -0,0 +1,61 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event +# ------------------------------------------------------------------------------------------------------------ + +# Note: +# Add a new command to trigger when the current interaction is hovered. +# +# Input: +# - macro variable { run: , executor: target|source| | { selector: , lazy: true|false } } +# Output: +# - Fail if the current entity is not an interaction. + +execute unless entity @s[type=interaction] run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover_enter", \ + tag: "on_hover_enter", \ + message: '"The current entity is not an interaction."', \ +} +$data modify storage bs:ctx _ set value { run: '$(run)', executor: $(executor), type: "hover_enter" } + +execute store success score #s bs.ctx run function bs.interaction:register/utils/check_command with storage bs:ctx _ +execute unless score #s bs.ctx matches 1 run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover_enter", \ + tag: "on_hover_enter", \ + message: '"The command is not valid."', \ +} + +execute unless function bs.interaction:register/utils/executor/setup \ + run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover_enter", \ + tag: "on_hover_enter", \ + message: '"The executor is not valid or cannot be interpreted."', \ + } + +execute if score #i bs.ctx matches 2.. run function #bs.log:warn { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover_enter", \ + tag: "on_hover_enter", \ + message: '"The selector points to multiple entities. Only the first one is selected."' \ +} + +tag @s add bs.interaction.is_hoverable +tag @s add bs.interaction.listen_hover_enter +scoreboard players set #interaction.process bs.data 1 +schedule function bs.interaction:on_event/process 1t replace +return run function bs.interaction:register/utils/setup_listener diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/hover_leave.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/hover_leave.mcfunction new file mode 100644 index 000000000..16d8f26a8 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/hover_leave.mcfunction @@ -0,0 +1,61 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event +# ------------------------------------------------------------------------------------------------------------ + +# Note: +# Add a new command to trigger when the current interaction is no longer hovered. +# +# Input: +# - macro variable { run: , executor: target|source| | { selector: , lazy: true|false } } +# Output: +# - Fail if the current entity is not an interaction. + +execute unless entity @s[type=interaction] run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover_leave", \ + tag: "on_hover_leave", \ + message: '"The current entity is not an interaction."', \ +} +$data modify storage bs:ctx _ set value { run: '$(run)', executor: $(executor), type: "hover_leave" } + +execute store success score #s bs.ctx run function bs.interaction:register/utils/check_command with storage bs:ctx _ +execute unless score #s bs.ctx matches 1 run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover_leave", \ + tag: "on_hover_leave", \ + message: '"The command is not valid."', \ +} + +execute unless function bs.interaction:register/utils/executor/setup \ + run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover_leave", \ + tag: "on_hover_leave", \ + message: '"The executor is not valid or cannot be interpreted."', \ + } + +execute if score #i bs.ctx matches 2.. run function #bs.log:warn { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_hover_leave", \ + tag: "on_hover_leave", \ + message: '"The selector points to multiple entities. Only the first one is selected."' \ +} + +tag @s add bs.interaction.is_hoverable +tag @s add bs.interaction.listen_hover_leave +scoreboard players set #interaction.process bs.data 1 +schedule function bs.interaction:on_event/process 1t replace +return run function bs.interaction:register/utils/setup_listener diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/left_click.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/left_click.mcfunction new file mode 100644 index 000000000..a4a6b2d72 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/left_click.mcfunction @@ -0,0 +1,58 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event +# ------------------------------------------------------------------------------------------------------------ + +# Note: +# Add a new command to trigger when the current interaction is left clicked. +# +# Input: +# - macro variable { run: , executor: target|source| | { selector: , lazy: true|false } } +# Output: +# - Fail if the current entity is not an interaction. + +execute unless entity @s[type=interaction] run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_left_click", \ + tag: "on_left_click", \ + message: '"The current entity is not an interaction."', \ +} +$data modify storage bs:ctx _ set value { run: '$(run)', executor: $(executor), type: "left_click" } + +execute store success score #s bs.ctx run function bs.interaction:register/utils/check_command with storage bs:ctx _ +execute unless score #s bs.ctx matches 1 run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_left_click", \ + tag: "on_left_click", \ + message: '"The command is not valid."', \ +} + +execute unless function bs.interaction:register/utils/executor/setup \ + run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_left_click", \ + tag: "on_left_click", \ + message: '"The executor is not valid or cannot be interpreted."', \ + } + +execute if score #i bs.ctx matches 2.. run function #bs.log:warn { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_left_click", \ + tag: "on_left_click", \ + message: '"The selector points to multiple entities. Only the first one is selected."' \ +} + +tag @s add bs.interaction.listen_left_click +return run function bs.interaction:register/utils/setup_listener diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/right_click.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/right_click.mcfunction new file mode 100644 index 000000000..3d59be625 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/right_click.mcfunction @@ -0,0 +1,58 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# +# Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event +# ------------------------------------------------------------------------------------------------------------ + +# Note: +# Add a new command to trigger when the current interaction is right clicked. +# +# Input: +# - macro variable { run: , executor: target|source| | { selector: , lazy: true|false } } +# Output: +# - Fail if the current entity is not an interaction. + +execute unless entity @s[type=interaction] run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_right_click", \ + tag: "on_right_click", \ + message: '"The current entity is not an interaction."', \ +} +$data modify storage bs:ctx _ set value { run: '$(run)', executor: $(executor), type: "right_click" } + +execute store success score #s bs.ctx run function bs.interaction:register/utils/check_command with storage bs:ctx _ +execute unless score #s bs.ctx matches 1 run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_right_click", \ + tag: "on_right_click", \ + message: '"The command is not valid."', \ +} + +execute unless function bs.interaction:register/utils/executor/setup \ + run return run function #bs.log:error { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_right_click", \ + tag: "on_right_click", \ + message: '"The executor is not valid or cannot be interpreted."', \ + } + +execute if score #i bs.ctx matches 2.. run function #bs.log:warn { \ + namespace: bs.interaction, \ + path: "#bs.interaction:on_right_click", \ + tag: "on_right_click", \ + message: '"The selector points to multiple entities. Only the first one is selected."' \ +} + +tag @s add bs.interaction.listen_right_click +return run function bs.interaction:register/utils/setup_listener diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/utils/check_command.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/check_command.mcfunction new file mode 100644 index 000000000..1a6079653 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/check_command.mcfunction @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +return 1 +$$(run) diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/check.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/check.mcfunction new file mode 100644 index 000000000..61ad144fa --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/check.mcfunction @@ -0,0 +1,17 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +return 1 +$execute if entity $(executor) diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/interpret.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/interpret.mcfunction new file mode 100644 index 000000000..7c75ec9e4 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/interpret.mcfunction @@ -0,0 +1,20 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +$execute store result score #i bs.ctx run tag $(selector) add bs.interaction.this +data modify entity B5-0-0-0-2 text set value '{"selector":"@n[tag=bs.interaction.this]"}' +function bs.interaction:register/utils/executor/unquote with entity B5-0-0-0-2 +data modify storage bs:ctx _.executor set from storage bs:ctx _.executor.insertion +tag @e[tag=bs.interaction.this] remove bs.interaction.this diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/setup.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/setup.mcfunction new file mode 100644 index 000000000..6b6268ffb --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/setup.mcfunction @@ -0,0 +1,25 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +# Set the executor to the target or the source +execute if data storage bs:ctx _{executor: "target"} run data modify storage bs:ctx _.executor set value "@s" +execute if data storage bs:ctx _{executor: "source"} run data modify storage bs:ctx _.executor set value "@p[distance=0,tag=bs.interaction.source]" +# The executor should be interpreted now only if lazy is set to false +execute if data storage bs:ctx _.executor{lazy: false} run function bs.interaction:register/utils/executor/interpret with storage bs:ctx _.executor +# If executor is still an object, replace the executor by the internal selector +data modify storage bs:ctx _.executor set from storage bs:ctx _.executor.selector +# Check if the executor is a valid selector +execute store success score #s bs.ctx run function bs.interaction:register/utils/executor/check with storage bs:ctx _ +return run scoreboard players get #s bs.ctx diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/unquote.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/unquote.mcfunction new file mode 100644 index 000000000..ae62c7617 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/executor/unquote.mcfunction @@ -0,0 +1,16 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +$data modify storage bs:ctx _.executor set value $(text) diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/utils/register_listener.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/register_listener.mcfunction new file mode 100644 index 000000000..4ec85df1c --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/register_listener.mcfunction @@ -0,0 +1,27 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +# The registered event has the following properties: +# - id: The ID of the event. +# - type: The type of event. +# - run: The command to execute. +# - executor: The executor of the command. + +# Get a new ID based on the ID of the last registered event incremented by 1. +$execute store result score #i bs.ctx run data get storage bs:data interaction.$(y)[0].id +execute store result storage bs:ctx _.id int 1 run scoreboard players add #i bs.ctx 1 + +$data modify storage bs:data interaction.$(y) prepend from storage bs:ctx _ +return run scoreboard players get #i bs.ctx diff --git a/datapacks/Bookshelf/data/bs.interaction/function/register/utils/setup_listener.mcfunction b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/setup_listener.mcfunction new file mode 100644 index 000000000..55cc45cca --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/function/register/utils/setup_listener.mcfunction @@ -0,0 +1,19 @@ +# ------------------------------------------------------------------------------------------------------------ +# Copyright (c) 2024 Gunivers +# +# This file is part of the Bookshelf project (https://github.com/Gunivers/Bookshelf). +# +# This source code is subject to the terms of the Mozilla Public License, v. 2.0. +# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# Conditions: +# - You may use this file in compliance with the MPL v2.0 +# - Any modifications must be documented and disclosed under the same license +# +# For more details, refer to the MPL v2.0. +# ------------------------------------------------------------------------------------------------------------ + +execute unless score @s bs.interaction.id matches 1.. store result score @s bs.interaction.id run scoreboard players add #counter bs.interaction.id 1 +execute store result storage bs:ctx y int 1 run scoreboard players get @s bs.interaction.id + +return run function bs.interaction:register/utils/register_listener with storage bs:ctx diff --git a/datapacks/Bookshelf/data/bs.interaction/predicate/check_id.json b/datapacks/Bookshelf/data/bs.interaction/predicate/check_id.json new file mode 100644 index 000000000..219f15474 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/predicate/check_id.json @@ -0,0 +1,18 @@ +{ + "condition": "minecraft:entity_scores", + "entity": "this", + "scores": { + "bs.interaction.id": { + "min": { + "type": "minecraft:storage", + "storage": "bs:ctx", + "path": "y" + }, + "max": { + "type": "minecraft:storage", + "storage": "bs:ctx", + "path": "y" + } + } + } +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/callback/glow.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/callback/glow.json new file mode 100644 index 000000000..12f247bdc --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/callback/glow.json @@ -0,0 +1,5 @@ +{ + "values": [ + "bs.interaction:callback/glow" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/callback/none.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/callback/none.json new file mode 100644 index 000000000..9b5147128 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/callback/none.json @@ -0,0 +1,5 @@ +{ + "values": [ + "bs.interaction:callback/none" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/callback/unglow.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/callback/unglow.json new file mode 100644 index 000000000..d24bbd120 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/callback/unglow.json @@ -0,0 +1,5 @@ +{ + "values": [ + "bs.interaction:callback/unglow" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/clear_events.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/clear_events.json new file mode 100644 index 000000000..2d4e2c7a3 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/clear_events.json @@ -0,0 +1,20 @@ +{ + "__bookshelf__": { + "feature": true, + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#clear-events", + "authors": [ + "Aksiome" + ], + "created": { + "date": "2024/11/01", + "minecraft_version": "1.21.3" + }, + "updated": { + "date": "2024/11/01", + "minecraft_version": "1.21.3" + } + }, + "values": [ + "bs.interaction:clear_events/clear_events" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/exclusive_load.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/exclusive_load.json new file mode 100644 index 000000000..a5c9e84a6 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/exclusive_load.json @@ -0,0 +1,6 @@ +{ + "values": [ + "#minecraft:unload", + "#bs.interaction:load" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/help.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/help.json new file mode 100644 index 000000000..01402355e --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/help.json @@ -0,0 +1,5 @@ +{ + "values": [ + "bs.interaction:__help__" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/load.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/load.json new file mode 100644 index 000000000..4a6319cb7 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/load.json @@ -0,0 +1,5 @@ +{ + "values": [ + "bs.interaction:__load__" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/on_hover.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_hover.json new file mode 100644 index 000000000..f0275fcf6 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_hover.json @@ -0,0 +1,21 @@ +{ + "__bookshelf__": { + "feature": true, + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "minecraft_version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "minecraft_version": "1.21.3" + } + }, + "values": [ + "bs.interaction:register/hover" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/on_hover_enter.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_hover_enter.json new file mode 100644 index 000000000..730f82ed7 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_hover_enter.json @@ -0,0 +1,21 @@ +{ + "__bookshelf__": { + "feature": true, + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "minecraft_version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "minecraft_version": "1.21.3" + } + }, + "values": [ + "bs.interaction:register/hover_enter" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/on_hover_leave.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_hover_leave.json new file mode 100644 index 000000000..feb05552e --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_hover_leave.json @@ -0,0 +1,21 @@ +{ + "__bookshelf__": { + "feature": true, + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "minecraft_version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "minecraft_version": "1.21.3" + } + }, + "values": [ + "bs.interaction:register/hover_leave" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/on_left_click.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_left_click.json new file mode 100644 index 000000000..5bba183c3 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_left_click.json @@ -0,0 +1,21 @@ +{ + "__bookshelf__": { + "feature": true, + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "minecraft_version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "minecraft_version": "1.21.3" + } + }, + "values": [ + "bs.interaction:register/left_click" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/on_right_click.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_right_click.json new file mode 100644 index 000000000..3defc23a1 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/on_right_click.json @@ -0,0 +1,21 @@ +{ + "__bookshelf__": { + "feature": true, + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "minecraft_version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "minecraft_version": "1.21.3" + } + }, + "values": [ + "bs.interaction:register/right_click" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/tags/function/unload.json b/datapacks/Bookshelf/data/bs.interaction/tags/function/unload.json new file mode 100644 index 000000000..80650d138 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/tags/function/unload.json @@ -0,0 +1,5 @@ +{ + "values": [ + "bs.interaction:__unload__" + ] +} diff --git a/datapacks/Bookshelf/data/bs.interaction/test/__boot__.mcfunction b/datapacks/Bookshelf/data/bs.interaction/test/__boot__.mcfunction new file mode 100644 index 000000000..9c7b51a2b --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/test/__boot__.mcfunction @@ -0,0 +1,2 @@ +# @batch bs.interaction +# @beforebatch function #bs.interaction:exclusive_load diff --git a/datapacks/Bookshelf/data/bs.interaction/test/clear_events.mcfunction b/datapacks/Bookshelf/data/bs.interaction/test/clear_events.mcfunction new file mode 100644 index 000000000..2df40c575 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/test/clear_events.mcfunction @@ -0,0 +1,78 @@ +# @batch bs.interaction + +## === SETUP === + +summon minecraft:interaction ~.5 ~ ~.5 {Tags: ["bs.packtest","bs.packtest.executor"], width: 1.0, height: 2.0} +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_left_click { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_left_click { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_right_click { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_right_click { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover_enter { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover_enter { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover_leave { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover_leave { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover { run: "help", executor: "target" } +data modify storage bs:data packtest set value {with:{}} + +## === EXPECTED BEHAVIORS (CLEAR LEFT CLICK) === + +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result storage bs:data packtest.with.id int 1 run function #bs.interaction:on_left_click { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events with storage bs:data packtest +execute unless score #i bs.ctx matches 1 run fail "Clear events should clear a single event when using the id" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events { with: { type: "left_click" } } +execute unless score #i bs.ctx matches 2 run fail "Clear events should clear all events when using the type" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] if entity @s[tag=bs.interaction.listen_left_click] run fail "Interaction should stop listening to left_click events when they are cleared" + +## === EXPECTED BEHAVIORS (CLEAR RIGHT CLICK) === + +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result storage bs:data packtest.with.id int 1 run function #bs.interaction:on_right_click { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events with storage bs:data packtest +execute unless score #i bs.ctx matches 1 run fail "Clear events should clear a single event when using the id" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events { with: { type: "right_click" } } +execute unless score #i bs.ctx matches 2 run fail "Clear events should clear all events when using the type" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] if entity @s[tag=bs.interaction.listen_right_click] run fail "Interaction should stop listening to right_click events when they are cleared" + +## === EXPECTED BEHAVIORS (CLEAR HOVER ENTER) === + +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result storage bs:data packtest.with.id int 1 run function #bs.interaction:on_hover_enter { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events with storage bs:data packtest +execute unless score #i bs.ctx matches 1 run fail "Clear events should clear a single event when using the id" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events { with: { type: "hover_enter" } } +execute unless score #i bs.ctx matches 2 run fail "Clear events should clear all events when using the type" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] if entity @s[tag=bs.interaction.listen_hover_enter] run fail "Interaction should stop listening to hover_enter events when they are cleared" + +## === EXPECTED BEHAVIORS (CLEAR HOVER LEAVE) === + +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result storage bs:data packtest.with.id int 1 run function #bs.interaction:on_hover_leave { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events with storage bs:data packtest +execute unless score #i bs.ctx matches 1 run fail "Clear events should clear a single event when using the id" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events { with: { type: "hover_leave" } } +execute unless score #i bs.ctx matches 2 run fail "Clear events should clear all events when using the type" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] if entity @s[tag=bs.interaction.listen_hover_leave] run fail "Interaction should stop listening to hover_leave events when they are cleared" + +## === EXPECTED BEHAVIORS (CLEAR HOVER) === + +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result storage bs:data packtest.with.id int 1 run function #bs.interaction:on_hover { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events with storage bs:data packtest +execute unless score #i bs.ctx matches 1 run fail "Clear events should clear a single event when using the id" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events { with: { type: "hover" } } +execute unless score #i bs.ctx matches 2 run fail "Clear events should clear all events when using the type" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] if entity @s[tag=bs.interaction.listen_hover] run fail "Interaction should stop listening to hover events when they are cleared" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] if entity @s[tag=bs.interaction.is_hoverable] run fail "Interaction should stop listening to all hover events when they are cleared" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] if score @s bs.interaction.id matches 1.. run fail "Clear events should reset the interaction id when all events are cleared" + +## === EXPECTED BEHAVIORS (CLEAR ALL) === + +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_left_click { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_right_click { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover_enter { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover_leave { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover { run: "help", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events { with: {} } +execute unless score #i bs.ctx matches 5 run fail "Clear events should clear all events when using an empty object" + +## === EXPECTED BEHAVIORS (CLEAR NONE) === + +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #i bs.ctx run function #bs.interaction:clear_events { with: {} } +execute unless score #i bs.ctx matches 0 run fail "Clear events should return 0 when no events are registered" diff --git a/datapacks/Bookshelf/data/bs.interaction/test/on_hover.mcfunction b/datapacks/Bookshelf/data/bs.interaction/test/on_hover.mcfunction new file mode 100644 index 000000000..e414f0539 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/test/on_hover.mcfunction @@ -0,0 +1,60 @@ +# @batch bs.interaction +# @dummy + +## === SETUP === + +fill ~-1 ~-1 ~-1 ~1 ~1 ~1 minecraft:air replace minecraft:barrier +summon minecraft:interaction ~.5 ~ ~-.5 {Tags: ["bs.packtest","bs.packtest.executor"], width: 1.0, height: 2.0} +summon minecraft:interaction ~1.5 ~ ~.5 {Tags: ["bs.packtest","bs.packtest.trap"], width: 1.0, height: 2.0} +summon minecraft:interaction ~-.5 ~ ~.5 {Tags: ["bs.packtest","bs.packtest.trap"], width: 1.0, height: 2.0} +execute as @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,distance=..2,limit=4] run function #bs.interaction:on_hover { run: "tag @s add bs.packtest.source", executor: "source" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,distance=..2,limit=4] run function #bs.interaction:on_hover { run: "tag @s add bs.packtest.target", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,distance=..2,limit=4] run function #bs.interaction:on_hover { run: "tag @s add bs.packtest.interpreted", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: false } } +execute as @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,distance=..2,limit=4] run function #bs.interaction:on_hover { run: "tag @s add bs.packtest.lazy", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: true } } + +## === EXPECTED BEHAVIORS === + +await delay 1t +execute if entity @s[tag=bs.packtest.source] run fail "Callback should not run before the interaction is hovered" +tp @s ~.5 ~ ~.5 180 0 +await delay 1t +execute unless entity @s[tag=bs.packtest.source] run fail "Failed to run callback on source entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on target entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on the right interaction" + +tag @s remove bs.packtest.source +tag @e[distance=..2] remove bs.packtest.target +tag @e[distance=..2] remove bs.packtest.interpreted +tag @e[distance=..2] remove bs.packtest.lazy +await delay 1t + +execute unless entity @s[tag=bs.packtest.source] run fail "Callback should run continuously" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Callback should run continuously" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.interpreted,distance=..2] run fail "Callback should run continuously" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.lazy,distance=..2] run fail "Callback should run continuously" + +tag @e[distance=..2] remove bs.packtest.target +tag @e[distance=..2] remove bs.packtest.interpreted +tag @e[distance=..2] remove bs.packtest.lazy +tag @e[distance=..2] remove bs.packtest.executor +tag @s add bs.packtest.executor + +await delay 1t +execute unless entity @s[tag=bs.packtest.source] run fail "Failed to run callback on source entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on target entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" +execute unless entity @s[tag=bs.packtest.lazy] run fail "Failed to run callback using a lazy selector" + +## === UNEXPECTED INPUT THAT SHOULD RETURN AN ERROR === + +execute store result score #s bs.ctx run function #bs.interaction:on_hover { run: "", executor: "source" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when function is called on a non interaction entity" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_hover { run: "", executor: "target" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the command is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_hover { run: "help", executor: { selector: "¯\\_(ツ)_/¯" } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_hover { run: "help", executor: { selector: "@n[type=minecraft:allay,tag=bs.is_never_gonna_be_released]", lazy: false } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is interpreted and points to no entity" diff --git a/datapacks/Bookshelf/data/bs.interaction/test/on_hover_enter.mcfunction b/datapacks/Bookshelf/data/bs.interaction/test/on_hover_enter.mcfunction new file mode 100644 index 000000000..737f0d112 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/test/on_hover_enter.mcfunction @@ -0,0 +1,60 @@ +# @batch bs.interaction +# @dummy + +## === SETUP === + +fill ~-1 ~-1 ~-1 ~1 ~1 ~1 minecraft:air replace minecraft:barrier +summon minecraft:interaction ~.5 ~ ~-.5 {Tags: ["bs.packtest","bs.packtest.executor"], width: 1.0, height: 2.0} +summon minecraft:interaction ~1.5 ~ ~.5 {Tags: ["bs.packtest","bs.packtest.trap"], width: 1.0, height: 2.0} +summon minecraft:interaction ~-.5 ~ ~.5 {Tags: ["bs.packtest","bs.packtest.trap"], width: 1.0, height: 2.0} +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2,limit=4] run function #bs.interaction:on_hover_enter { run: "tag @s add bs.packtest.source", executor: "source" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2,limit=4] run function #bs.interaction:on_hover_enter { run: "tag @s add bs.packtest.target", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2,limit=4] run function #bs.interaction:on_hover_enter { run: "tag @s add bs.packtest.interpreted", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: false } } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2,limit=4] run function #bs.interaction:on_hover_enter { run: "tag @s add bs.packtest.lazy", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: true } } + +## === EXPECTED BEHAVIORS === + +await delay 2t +execute if entity @s[tag=bs.packtest.source] run fail "Callback should not run before the interaction is hovered" +tp @s ~.5 ~ ~.5 180 0 +await delay 2t +execute unless entity @s[tag=bs.packtest.source] run fail "Failed to run callback on source entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on target entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on the right interaction" + +tag @s remove bs.packtest.source +tag @e[distance=..2] remove bs.packtest.target +tag @e[distance=..2] remove bs.packtest.interpreted +tag @e[distance=..2] remove bs.packtest.lazy +await delay 2t + +execute if entity @s[tag=bs.packtest.source] run fail "Callback should run only once on enter" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Callback should run only once on enter" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.interpreted,distance=..2] run fail "Callback should run only once on enter" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.lazy,distance=..2] run fail "Callback should run only once on enter" + +tag @e[distance=..2] remove bs.packtest.executor +tag @s add bs.packtest.executor + +tp @s ~.5 ~ ~.5 0 0 +await delay 2t +tp @s ~.5 ~ ~.5 180 0 +await delay 2t +execute unless entity @s[tag=bs.packtest.source] run fail "Failed to run callback on source entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on target entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" +execute unless entity @s[tag=bs.packtest.lazy] run fail "Failed to run callback using a lazy selector" + +## === INPUT ERRORS === + +execute store result score #s bs.ctx run function #bs.interaction:on_hover_enter { run: "", executor: "source" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when function is called on a non interaction entity" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_hover_enter { run: "", executor: "target" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the command is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_hover_enter { run: "help", executor: { selector: "¯\\_(ツ)_/¯" } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_hover_enter { run: "help", executor: { selector: "@n[type=minecraft:allay,tag=bs.is_never_gonna_be_released]", lazy: false } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is interpreted and points to no entity" diff --git a/datapacks/Bookshelf/data/bs.interaction/test/on_hover_leave.mcfunction b/datapacks/Bookshelf/data/bs.interaction/test/on_hover_leave.mcfunction new file mode 100644 index 000000000..f813f2843 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/test/on_hover_leave.mcfunction @@ -0,0 +1,60 @@ +# @batch bs.interaction +# @dummy + +## === SETUP === + +fill ~-1 ~-1 ~-1 ~1 ~1 ~1 minecraft:air replace minecraft:barrier +summon minecraft:interaction ~.5 ~ ~1.5 {Tags: ["bs.packtest","bs.packtest.executor"], width: 1.0, height: 2.0} +summon minecraft:interaction ~1.5 ~ ~.5 {Tags: ["bs.packtest","bs.packtest.trap"], width: 1.0, height: 2.0} +summon minecraft:interaction ~-.5 ~ ~.5 {Tags: ["bs.packtest","bs.packtest.trap"], width: 1.0, height: 2.0} +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2,limit=4] run function #bs.interaction:on_hover_leave { run: "tag @s add bs.packtest.source", executor: "source" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2,limit=4] run function #bs.interaction:on_hover_leave { run: "tag @s add bs.packtest.target", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2,limit=4] run function #bs.interaction:on_hover_leave { run: "tag @s add bs.packtest.interpreted", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: false } } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2,limit=4] run function #bs.interaction:on_hover_leave { run: "tag @s add bs.packtest.lazy", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: true } } + +## === EXPECTED BEHAVIORS === + +await delay 1t +execute if entity @s[tag=bs.packtest.source] run fail "Callback should not run before the interaction is unhovered" +tp @s ~.5 ~ ~.5 180 0 +await delay 1t +execute unless entity @s[tag=bs.packtest.source] run fail "Failed to run callback on source entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on target entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on the right interaction" + +tag @s remove bs.packtest.source +tag @e[distance=..2] remove bs.packtest.target +tag @e[distance=..2] remove bs.packtest.interpreted +tag @e[distance=..2] remove bs.packtest.lazy +await delay 1t + +execute if entity @s[tag=bs.packtest.source] run fail "Callback should run only once on leave" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Callback should run only once on leave" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.interpreted,distance=..2] run fail "Callback should run only once on leave" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.lazy,distance=..2] run fail "Callback should run only once on leave" + +tag @e[distance=..2] remove bs.packtest.executor +tag @s add bs.packtest.executor + +tp @s ~.5 ~ ~.5 0 0 +await delay 1t +tp @s ~.5 ~ ~.5 180 0 +await delay 1t +execute unless entity @s[tag=bs.packtest.source] run fail "Failed to run callback on source entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on target entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=!bs.packtest.trap,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" +execute unless entity @s[tag=bs.packtest.lazy] run fail "Failed to run callback using a lazy selector" + +## === INPUT ERRORS === + +execute store result score #s bs.ctx run function #bs.interaction:on_hover_leave { run: "", executor: "source" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when function is called on a non interaction entity" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_hover_leave { run: "", executor: "target" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the command is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_hover_leave { run: "help", executor: { selector: "¯\\_(ツ)_/¯" } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_hover_leave { run: "help", executor: { selector: "@n[type=minecraft:allay,tag=bs.is_never_gonna_be_released]", lazy: false } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is interpreted and points to no entity" diff --git a/datapacks/Bookshelf/data/bs.interaction/test/on_hover_logout.mcfunction b/datapacks/Bookshelf/data/bs.interaction/test/on_hover_logout.mcfunction new file mode 100644 index 000000000..b212222b6 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/test/on_hover_logout.mcfunction @@ -0,0 +1,18 @@ +# @batch bs.interaction +# @dummy + +## === SETUP === +fill ~-1 ~-1 ~-1 ~1 ~1 ~1 minecraft:air replace minecraft:barrier +summon minecraft:interaction ~.5 ~ ~1.5 {Tags: ["bs.packtest"], width: 1.0, height: 2.0} +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover_enter { run: "scoreboard players add #packtest.interaction_hover_count bs.data 1", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_hover_leave { run: "scoreboard players remove #packtest.interaction_hover_count bs.data 1", executor: "target" } +scoreboard players set #packtest.interaction_hover_count bs.data 0 + +## === EXPECTED BEHAVIORS === + +execute positioned ~.5 ~ ~.5 run dummy on_hover_logout spawn +await delay 2t +assert score #packtest.interaction_hover_count bs.data matches 2 +dummy on_hover_logout leave +await delay 1t +assert score #packtest.interaction_hover_count bs.data matches 1 diff --git a/datapacks/Bookshelf/data/bs.interaction/test/on_hover_swap.mcfunction b/datapacks/Bookshelf/data/bs.interaction/test/on_hover_swap.mcfunction new file mode 100644 index 000000000..d00c15f4c --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/test/on_hover_swap.mcfunction @@ -0,0 +1,20 @@ +# @batch bs.interaction +# @dummy + +## === SETUP === + +fill ~-1 ~-1 ~-1 ~1 ~1 ~1 minecraft:air replace minecraft:barrier +summon minecraft:interaction ~ ~ ~1.5 {Tags: ["bs.packtest","bs.packtest.1"], width: 1.0, height: 2.0} +summon minecraft:interaction ~1 ~ ~1.5 {Tags: ["bs.packtest","bs.packtest.2"], width: 1.0, height: 2.0} +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..3,limit=2] run function #bs.interaction:on_hover_enter { run: "tag @s add bs.packtest.target", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..3,limit=2] run function #bs.interaction:on_hover_leave { run: "tag @s remove bs.packtest.target", executor: "target" } + +## === EXPECTED BEHAVIORS === + +tp @s ~.5 ~ ~.5 45 0 +await delay 2t +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest.1,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on target entity" +tp @s ~.5 ~ ~.5 -45 0 +await delay 2t +execute if entity @n[type=minecraft:interaction,tag=bs.packtest.1,tag=bs.packtest.target,distance=..2] run fail "Failed to swap hover to an other target entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest.2,tag=bs.packtest.target,distance=..2] run fail "Failed to swap hover to an other target entity" diff --git a/datapacks/Bookshelf/data/bs.interaction/test/on_left_click.mcfunction b/datapacks/Bookshelf/data/bs.interaction/test/on_left_click.mcfunction new file mode 100644 index 000000000..9f23e14a5 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/test/on_left_click.mcfunction @@ -0,0 +1,38 @@ +# @batch bs.interaction +# @dummy + +## === SETUP === + +summon minecraft:interaction ~.5 ~ ~.5 {Tags: ["bs.packtest","bs.packtest.executor"], width: 1.0, height: 2.0} +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_left_click { run: "tag @s add bs.packtest.source", executor: "source" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_left_click { run: "tag @s add bs.packtest.target", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_left_click { run: "tag @s add bs.packtest.interpreted", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: false } } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_left_click { run: "tag @s add bs.packtest.lazy", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: true } } + +## === EXPECTED BEHAVIORS === + +dummy @s attack @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] +execute unless entity @s[tag=bs.packtest.source] run fail "Failed to run callback on source entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on target entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" + +tag @e[distance=..2] remove bs.packtest.lazy +tag @e[distance=..2] remove bs.packtest.interpreted +tag @e[distance=..2] remove bs.packtest.executor +tag @s add bs.packtest.executor +dummy @s attack @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" +execute unless entity @s[tag=bs.packtest.lazy] run fail "Failed to run callback using a lazy selector" + +## === INPUT ERRORS === + +execute store result score #s bs.ctx run function #bs.interaction:on_left_click { run: "", executor: "source" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when function is called on a non interaction entity" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_left_click { run: "", executor: "target" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the command is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_left_click { run: "help", executor: { selector: "¯\\_(ツ)_/¯" } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_left_click { run: "help", executor: { selector: "@n[type=minecraft:allay,tag=bs.is_never_gonna_be_released]", lazy: false } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is interpreted and points to no entity" diff --git a/datapacks/Bookshelf/data/bs.interaction/test/on_right_click.mcfunction b/datapacks/Bookshelf/data/bs.interaction/test/on_right_click.mcfunction new file mode 100644 index 000000000..e0637dd59 --- /dev/null +++ b/datapacks/Bookshelf/data/bs.interaction/test/on_right_click.mcfunction @@ -0,0 +1,40 @@ +# @batch bs.interaction +# @dummy + +## === SETUP === + +summon minecraft:interaction ~.5 ~ ~.5 {Tags: ["bs.packtest","bs.packtest.executor"], width: 1.0, height: 2.0} +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_right_click { run: "tag @s add bs.packtest.source", executor: "source" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_right_click { run: "tag @s add bs.packtest.target", executor: "target" } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_right_click { run: "tag @s add bs.packtest.interpreted", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: false } } +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] run function #bs.interaction:on_right_click { run: "tag @s add bs.packtest.lazy", executor: { selector: "@n[tag=bs.packtest.executor,distance=..2]", lazy: true } } + +## === EXPECTED BEHAVIORS === + +dummy @s use entity @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] +advancement grant @s only bs.interaction:right_click +execute unless entity @s[tag=bs.packtest.source] run fail "Failed to run callback on source entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.target,distance=..2] run fail "Failed to run callback on target entity" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" + +tag @e[distance=..2] remove bs.packtest.lazy +tag @e[distance=..2] remove bs.packtest.interpreted +tag @e[distance=..2] remove bs.packtest.executor +tag @s add bs.packtest.executor +dummy @s use entity @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] +advancement grant @s only bs.interaction:right_click +execute unless entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.interpreted,distance=..2] run fail "Failed to run callback using an interpreted selector" +execute if entity @n[type=minecraft:interaction,tag=bs.packtest,tag=bs.packtest.lazy,distance=..2] run fail "Failed to run callback using a lazy selector" +execute unless entity @s[tag=bs.packtest.lazy] run fail "Failed to run callback using a lazy selector" + +## === INPUT ERRORS === + +execute store result score #s bs.ctx run function #bs.interaction:on_right_click { run: "", executor: "source" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when function is called on a non interaction entity" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_right_click { run: "", executor: "target" } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the command is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_right_click { run: "help", executor: { selector: "¯\\_(ツ)_/¯" } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is invalid" +execute as @n[type=minecraft:interaction,tag=bs.packtest,distance=..2] store result score #s bs.ctx run function #bs.interaction:on_right_click { run: "help", executor: { selector: "@n[type=minecraft:allay,tag=bs.is_never_gonna_be_released]", lazy: false } } +execute unless score #s bs.ctx matches 0 run fail "Failed to return an error when the selector is interpreted and points to no entity" diff --git a/datapacks/Bookshelf/data/minecraft/tags/function/load.json b/datapacks/Bookshelf/data/minecraft/tags/function/load.json index c18b6d908..2832ef1c4 100644 --- a/datapacks/Bookshelf/data/minecraft/tags/function/load.json +++ b/datapacks/Bookshelf/data/minecraft/tags/function/load.json @@ -32,6 +32,10 @@ "id": "#bs.id:load", "required": false }, + { + "id": "#bs.interaction:load", + "required": false + }, { "id": "#bs.link:load", "required": false diff --git a/datapacks/Bookshelf/data/minecraft/tags/function/unload.json b/datapacks/Bookshelf/data/minecraft/tags/function/unload.json index fad13aa62..c3facf413 100644 --- a/datapacks/Bookshelf/data/minecraft/tags/function/unload.json +++ b/datapacks/Bookshelf/data/minecraft/tags/function/unload.json @@ -32,6 +32,10 @@ "id": "#bs.id:unload", "required": false }, + { + "id": "#bs.interaction:unload", + "required": false + }, { "id": "#bs.link:unload", "required": false diff --git a/docs/modules.md b/docs/modules.md index 6aa455eff..c50f9e80d 100644 --- a/docs/modules.md +++ b/docs/modules.md @@ -25,6 +25,7 @@ modules/generate modules/health modules/hitbox modules/id +modules/interaction modules/link modules/math modules/move diff --git a/docs/modules/interaction.md b/docs/modules/interaction.md new file mode 100644 index 000000000..a746d48d0 --- /dev/null +++ b/docs/modules/interaction.md @@ -0,0 +1,292 @@ +# 🖱️ Interaction + +**`#bs.interaction:help`** + +Create and manage Graphical User Interfaces (GUIs) in Minecraft. + +```{epigraph} +"As far as the customer is concerned, the interface is the product." + +-- Jef Raskin +``` + +The Interaction API is a low-level API to create GUIs based on the [Interaction](https://minecraft.wiki/w/Interaction) entity. +This API is low level since the possible events are directly and manually bind to the interaction. +In this API, the interaction that listen to events is named **listener**. + +--- + +## 🔧 Functions + +You can find below all functions available in this API. + +--- + +### Clear events + +```{function} #bs.interaction:clear_events + +Clear events registered for the specified listener entity. + +:Inputs: + **Execution `as `**: Listener entity for which the events will be cleared. + + **Function Macro**: + :::{treeview} + - {nbt}`compound` **Arguments**: + - {nbt}`compound` **with**: Parameters to filter which events to clear. Clear all events if empty. + - {nbt}`string` **type**: Specify the type of events to clear. + - {nbt}`int` **id**: Specify the ID of events to clear. + ::: + +:Outputs: + **Return**: The number of events removed. + + **State**: The specified events for the listener entity will be removed. +``` + +*Clear hover events for the listener entity:* + +```mcfunction +summon minecraft:interaction ~ ~ ~ { Tags: ["bs.entity.interaction"], width: 1f, height: 1f } + +# Register hover events for the listener +execute as @n[tag=bs.entity.interaction] run function #bs.interaction:on_hover { run: "say Hovered", executor: "target" } + +# Clear hover events for the listener +execute as @n[tag=bs.entity.interaction] run function #bs.interaction:clear_events { with: { type: "hover" } } +``` + +> **Credits**: Aksiome, theogiraudet + +--- + +### On event + +:::::{tab-set} +::::{tab-item} Left click + +```{function} #bs.interaction:on_left_click + +Register a command to run when the left click is pressed on the current listener. +Each listener can respond to multiple events. + +:Inputs: + **Execution `as `**: Listener entity for which the event is registered. + + **Function macro**: + :::{treeview} + - {nbt}`compound` Arguments + - {nbt}`string` **run**: Command to execute upon left-click. + - {nbt}`string` {nbt}`compound` **executor**: Defines the entity on which the command will be executed. Can be either **"source"** for the player who performed the action or **"target"** for the listener entity itself. A compound can also be used to target other entities: + - {nbt}`string` **selector**: Specifies entities for the command execution (`execute as `). + - {nbt}`bool` **lazy**: Determines whether to resolve the selector immediately (`false`) or at runtime (`true`, default). If `false`, the selector must target only one entity, replacing the selector with that entity’s UUID. Useful for optimizing execution, especially when targeting graphical representations. If multiple entities are targeted, the first one is selected. + ::: + +:Outputs: + **Return**: The ID of the created event. + + **State**: The listener will trigger the event when left clicked. +``` +:::: +::::{tab-item} Right click + +```{function} #bs.interaction:on_right_click + +Register a command to run when the right click is pressed on the current listener. +Each listener can respond to multiple events. + +:Inputs: + **Execution `as `**: Listener entity for which the event is registered. + + **Function Macro**: + :::{treeview} + - {nbt}`compound` **Arguments**: + - {nbt}`string` **run**: Command to execute upon right-click. + - {nbt}`string` {nbt}`compound` **executor**: Defines the entity on which the command will be executed. Can be either **"source"** for the player who performed the action or **"target"** for the listener entity itself. A compound can also be used to target other entities: + - {nbt}`string` **selector**: Specifies entities for the command execution (`execute as `). + - {nbt}`bool` **lazy**: Determines whether to resolve the selector immediately (`false`) or at runtime (`true`, default). If `false`, the selector must target only one entity, replacing the selector with that entity’s UUID. Useful for optimizing execution, especially when targeting graphical representations. If multiple entities are targeted, the first one is selected. + ::: + +:Outputs: + **Return**: The ID of the created event. + + **State**: The listener will trigger the event when right clicked. +``` +:::: +::::{tab-item} Hover + +```{function} #bs.interaction:on_hover + +Register a command to run continuously while the player is hovering over the listener. +Each listener can respond to multiple events. + +:Inputs: + **Execution `as `**: Listener entity for which the event is registered. + + **Function Macro**: + :::{treeview} + - {nbt}`compound` **Arguments**: + - {nbt}`string` **run**: Command to execute while hovering over the listener. + - {nbt}`string` {nbt}`compound` **executor**: Defines the entity on which the command will be executed. Can be either **"source"** for the player who performed the action or **"target"** for the listener entity itself. A compound can also be used to target other entities: + - {nbt}`string` **selector**: Specifies entities for the command execution (`execute as `). + - {nbt}`bool` **lazy**: Determines whether to resolve the selector immediately (`false`) or at runtime (`true`, default). If `false`, the selector must target only one entity, replacing the selector with that entity’s UUID. Useful for optimizing execution, especially when targeting graphical representations. If multiple entities are targeted, the first one is selected. + ::: + +:Outputs: + **Return**: The ID of the created event. + + **State**: The listener will trigger the event continuously while hovered over. +``` +:::: +::::{tab-item} Enter hover + +```{function} #bs.interaction:on_hover_enter + +Register a command to run once when the player begins hovering over the listener. +Each listener can respond to multiple events. + +:Inputs: + **Execution `as `**: Listener entity for which the event is registered. + + **Function Macro**: + :::{treeview} + - {nbt}`compound` **Arguments**: + - {nbt}`string` **run**: Command to execute when hovering begins. + - {nbt}`string` {nbt}`compound` **executor**: Defines the entity on which the command will be executed. Can be either **"source"** for the player who performed the action or **"target"** for the listener entity itself. A compound can also be used to target other entities: + - {nbt}`string` **selector**: Specifies entities for the command execution (`execute as `). + - {nbt}`bool` **lazy**: Determines whether to resolve the selector immediately (`false`) or at runtime (`true`, default). If `false`, the selector must target only one entity, replacing the selector with that entity’s UUID. Useful for optimizing execution, especially when targeting graphical representations. If multiple entities are targeted, the first one is selected. + ::: + +:Outputs: + **Return**: The ID of the created event. + + **State**: The listener will trigger the event once upon hover entry. +``` +:::: +::::{tab-item} Leave hover + +```{function} #bs.interaction:on_hover_leave + +Register a command to run once when the player stops hovering over the listener. +Each listener can respond to multiple events. + +:Inputs: + **Execution `as `**: Listener entity for which the event is registered. + + **Function Macro**: + :::{treeview} + - {nbt}`compound` **Arguments**: + - {nbt}`string` **run**: Command to execute when hovering ends. + - {nbt}`string` {nbt}`compound` **executor**: Defines the entity on which the command will be executed. Can be either **"source"** for the player who performed the action or **"target"** for the listener entity itself. A compound can also be used to target other entities: + - {nbt}`string` **selector**: Specifies entities for the command execution (`execute as `). + - {nbt}`bool` **lazy**: Determines whether to resolve the selector immediately (`false`) or at runtime (`true`, default). If `false`, the selector must target only one entity, replacing the selector with that entity’s UUID. Useful for optimizing execution, especially when targeting graphical representations. If multiple entities are targeted, the first one is selected. + ::: + +:Outputs: + **Return**: The ID of the created event. + + **State**: The listener will trigger the event once upon hover exit. +``` + + +```{admonition} Edge case +:class: warning + +If a player logs out while hovering over the listener, the hover leave event will trigger on the executor. If the executor is the player, the event won’t be triggered again when they log back in. Be sure to account for this edge case and handle it appropriately when the player returns. +``` + +:::: +::::: + +*Glow the listener's icon while the listener is hovered and unglow it when it is not hovered anymore:* + +```mcfunction +summon minecraft:interaction ~ ~ ~ { Tags: ["bs.entity.interaction"], width: 1f, height: 1f } +summon block_display ~-.5 ~ ~-.5 { Tags: ["bs.entity.block_display"], width: 1f, height: 1f, block_state: { Name: "minecraft:slime_block" }} + +# Callback to glow the icon when the listener is hovered +execute as @n[tag=bs.entity.interaction] run function #bs.interaction:on_hover_enter { run: "function #bs.interaction:callback/glow", executor: { selector: "@e[tag=bs.entity.block_display]", lazy: false } } +# Callback to unglow the icon when the listener is not hovered anymore +execute as @n[tag=bs.entity.interaction] run function #bs.interaction:on_hover_leave { run: "function #bs.interaction:callback/unglow", executor: { selector: "@e[tag=bs.entity.block_display]", lazy: false } } +``` + +> **Credits**: Aksiome, theogiraudet + +--- + +## 🏷️ Entity Tags + +You can find below all tags available in this API. + +--- + +### Listen a specific event? + +:::::{tab-set} +::::{tab-item} Right click + +**`bs.interaction.listen_right_click`** + + +Determine if the current listener listen to right click interaction. +:::: +::::{tab-item} Left click + +**`bs.interaction.listen_left_click`** + +Determine if the current listener listen to left click interaction. +:::: +::::{tab-item} Hover + +**`bs.interaction.listen_hover`** + +Determine if the current listener listen to hover interaction. +:::: +::::{tab-item} Enter hover + +**`bs.interaction.listen_hover_enter`** + +Determine if the current listener listen to enter hover interaction. +:::: +::::{tab-item} Leave hover + +**`bs.interaction.listen_hover_leave`** + +Determine if the current listener listen to leave hover interaction. +:::: +::::: + +> **Credits**: theogiraudet + +--- + +### Is source? + +**`bs.interaction.source`** + +Usable only in the callback of an event. +Determine if the current entity is the source of the event. + +> **Credits**: theogiraudet + +--- + +### Is target? + +**`bs.interaction.target`** + +Usable only in the callback of an event. +Determine if the current entity is the target of the event. + +> **Credits**: theogiraudet + +--- + +
+ +**💬 Did it help you?** + +Feel free to leave your questions and feedbacks below! + +
diff --git a/generated/manifest.json b/generated/manifest.json index b79503111..14e56567d 100644 --- a/generated/manifest.json +++ b/generated/manifest.json @@ -1003,6 +1003,132 @@ } ] }, + { + "name": "bs.interaction", + "display_name": "Interaction", + "description": "A low-level API to create GUI based on Interaction entity by binding events to it.", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "module_path": "datapacks/Bookshelf/data/bs.interaction", + "weak_dependencies": [ + "bs.log" + ], + "features": [ + { + "name": "clear_events", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#clear-events", + "authors": [ + "Aksiome" + ], + "created": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + } + }, + { + "name": "on_hover", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + }, + { + "name": "on_hover_enter", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + }, + { + "name": "on_hover_leave", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + }, + { + "name": "on_left_click", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + }, + { + "name": "on_right_click", + "documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/interaction.html#on-event", + "authors": [ + "Aksiome", + "theogiraudet" + ], + "created": { + "date": "2024/03/30", + "version": "24w13a" + }, + "updated": { + "date": "2024/11/01", + "version": "1.21.3" + }, + "weak_dependencies": [ + "bs.log" + ] + } + ] + }, { "name": "bs.link", "display_name": "Link",