Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/smithed_libraries/packs/interaction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<p align="center">
<img width='50%' src="https://github.com/TheNuclearNexus/smithed/blob/master/public/official_smithed_library.png?raw=true">
</p>

# Interaction

This library serves to enable easier usage of interaction entities as well as enabling custom addons to this usage.

## Usage
[Documentation](https://docs.smithed.dev/libraries/interaction/)
## Downloading
You can download it from [here](https://smithed.net/packs/interaction)
or<br/>
You can build it from source using [beet](https://github.com/mcbeet/beet)

### Building
```
$ pip install beet mecha
$ git clone https://github.com/Smithed-MC/Libraries
$ cd Libraries/interaction

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the wrong relative path, should be Libraries/src/smithed_libraries/packs/interaction or just Libraries looking at the next command

$ beet -s 'meta.libraries = ["interaction"]'
```
21 changes: 21 additions & 0 deletions src/smithed_libraries/packs/interaction/beet.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
extend: "@smithed_libraries/common.yaml"

id: smithed.interaction
name: Smithed Interaction
version: "1.0.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure about the version, no others libs have a major version set to 1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other open new Lib PR is using a 1 major version 😁
But for a more serious answer, I consider the summit version the 0 major version (and I dont believe in 0 versioning :P)

description: Interaction Library for Smithed
author: runcows

data_pack:
name: Smithed Interaction
load:
data/smithed.interaction/modules: modules

require:
- bolt

meta:
bolt:
entrypoint: ["*"]
mecha:
formatting: minify
80 changes: 80 additions & 0 deletions src/smithed_libraries/packs/interaction/modules/core.bolt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ---------------------------------------------------- #
# -------------------- --------------------- #
# --------------- CORE --------------- #
# -------------------- --------------------- #
# ---------------------------------------------------- #
function smithed.interaction:impl/technical/load:
raw # core
scoreboard objectives add smithed.interaction.temp dummy

for action in [
{"type": "interaction", "trigger": "minecraft:player_interacted_with_entity", "data_location": "on_right_click", "on": "target"},
{"type": "attack", "trigger": "minecraft:player_hurt_entity", "data_location": "on_left_click", "on": "attacker"}
]:
ADV_LOC = "smithed.interaction:impl/" + action['type']
DATA_LOC = "data.smithed_interaction." + action['data_location']
CMD_LOC = DATA_LOC + ".command"
FUNC_LOC = DATA_LOC + ".function"
SHORTCUT_LOC = DATA_LOC + ".custom"
TIMESTAMP = action['type'] + ".timestamp"

advancement ADV_LOC:
criteria:
requirement:
trigger: action['trigger']
conditions:
entity:
type: "minecraft:entity_properties"
entity: "this"
predicate:
"minecraft:entity_type": "minecraft:interaction"
"minecraft:entity_tags":
all_of:
- "smithed.interaction"
rewards:
function: ADV_LOC

def try_action(type: str, command_to_try: str, nbt_location: str, fail_text: str):
scoreboard players set #success smithed.interaction.temp 0
with entity @s DATA_LOC:
scoreboard players set #success smithed.interaction.temp 1
raw command_to_try
if score #success smithed.interaction.temp matches 0 tellraw @p[tag=smithed.interaction.player] [
{text:"", color:"red"}, f"Interaction's {type} failed: ",
{text:"\"",color:"aqua"}, {entity:"@s",nbt: nbt_location, interpret:true, color:"green"},
{text:"\"",color:"aqua"}, (" " + fail_text)
]

function ADV_LOC:
advancement revoke @s only ADV_LOC
store result score #current_gametime smithed.interaction.temp run time query gametime
tag @s add smithed.interaction.player
# CONSIDER LATER: Do we want to macro in the players entity interaction range?
# | This is probably not worth, but it does make this feel incomplete
as @e[tag=smithed.interaction, type=interaction, distance=..16] if data entity @s action['type'] function ~/process:
store result score #check_gametime smithed.interaction.temp run data get entity @s TIMESTAMP
unless score #check_gametime smithed.interaction.temp = #current_gametime smithed.interaction.temp run return run data remove entity @s action['type']
raw f"execute on {action['on']} unless entity @s[tag=smithed.interaction.player] run return fail"
if data entity @s SHORTCUT_LOC at @s function ~/try_shortcut:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why a specific action has to be made here for the sit functionality, can't we use the function action to do the same thing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i now understand that it's a syntax thing, but it would be more clear that it's just a nice function tag like #smithed.interaction:custom/sit instead of #smithed.interaction:event/on_right_click/custom/sit

just a personal opinion at this point, i don't care if it's one or the other

try_action(
Comment thread
edayot marked this conversation as resolved.
"custom shortcut",
"$function #smithed.interaction:event/on_right_click/custom/$(custom)",
SHORTCUT_LOC,
"is not a valid shortcut. Cannot contain characters not valid in a function path!"
)
if data entity @s FUNC_LOC at @s function ~/try_function:
try_action(
"function",
"$function $(function)",
FUNC_LOC,
"is not a valid function location!"
)
if data entity @s CMD_LOC at @s function ~/try_command:
try_action(
"command",
"$$(command)",
CMD_LOC,
"is not a valid command!"
)
data remove entity @s action['type']
tag @s remove smithed.interaction.player
80 changes: 80 additions & 0 deletions src/smithed_libraries/packs/interaction/modules/sit.bolt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# --------------------------------------------------- #
# -------------------- -------------------- #
# --------------- SIT --------------- #
# -------------------- -------------------- #
# --------------------------------------------------- #
function smithed.interaction:impl/custom/sit:
# Functions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs the # @public macro for the version check, since it's in a function tag

AT_HEIGHT = ~/at_height
SEC = ~/sec
TICK = ~/tick

# Predicates
HAS_TEMP_ID = ~/has_temp_id
HAS_PASSENGER = ~/has_passenger

predicate HAS_PASSENGER {
"type":"minecraft:entity_properties",
"entity":"this",
"predicate":{
"minecraft:passenger":{}
}
}
predicate HAS_TEMP_ID {
"type": "minecraft:int_value_check",
"value": {
"type": "minecraft:score",
"target": {"type": "minecraft:fixed","name": "#temp"},
"score": "smithed.interaction.sittable_id"
},
"test": {
"type": "minecraft:score",
"target": "this",
"score": "smithed.interaction.sittable_id"
}
}

append function_tag smithed.interaction:event/on_right_click/custom/sit {"values":[(~/)]}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the function tag at the top of the function definition, so it's clear that this is called in a function tag

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also don't forget to use the prefixed calls function tag for the version check

# Follow
if data entity @s data.smithed_interaction.on_right_click{height:"follow"} return:
tag @s add smithed.interaction.sittable_interaction.follow
unless score @s smithed.interaction.sittable_id matches -2147483648..2147483647 store result score @s smithed.interaction.sittable_id run scoreboard players add #next smithed.interaction.sittable_id 1
store result score #temp smithed.interaction.sittable_id run scoreboard players get @s smithed.interaction.sittable_id
unless entity @e[tag=smithed.interaction.sittable_display.follow,type=item_display,distance=..0.001,predicate=(HAS_TEMP_ID)] summon item_display:
scoreboard players operation @s smithed.interaction.sittable_id = #temp smithed.interaction.sittable_id
tag @s add smithed.interaction.sittable_display
tag @s add smithed.interaction.sittable_display.follow
ride @p[tag=smithed.interaction.player] dismount
ride @p[tag=smithed.interaction.player] mount @s

# Normal
store result storage smithed.interaction:temp sitting.height double 0.5 run data get entity @s height
data modify storage smithed.interaction:temp sitting.height set from entity @s data.smithed_interaction.on_right_click.height

with storage smithed.interaction:temp sitting:
raw f"$execute positioned ~ ~$(height) ~ run function {AT_HEIGHT}"
function AT_HEIGHT:
kill @e[tag=smithed.interaction.sittable_display,distance=..0.01,type=item_display,predicate=!(HAS_PASSENGER)]
unless entity @e[tag=smithed.interaction.sittable_display,distance=..0.01,type=item_display] summon item_display:
tag @s add smithed.interaction.sittable_display
ride @p[tag=smithed.interaction.player] dismount
ride @p[tag=smithed.interaction.player] mount @s

## Helpers :D
append function smithed.interaction:impl/technical/load:
raw # custom : sit
scoreboard objectives add smithed.interaction.sittable_id dummy
scoreboard players add #next smithed.interaction.sittable_id 0
schedule function SEC 1t

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to add theses function to the beet config in the meta.smithed.versioning.scheduled_paths

this way when two version of the lib are loaded at the same time, they can cancel the scheduled function by themself

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just found that crafter don't use it, i'm going to update it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Im confused on this one, because I dont think any of the libraries use this

@edayot edayot Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they do, because, the default value of the list is impl/technical/tick, most libs use this as the tick function, but the interaction lib doesn't

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit harder than i thought, i'm going to check myself and suggest an edit

schedule function TICK 1t

function SEC:
schedule function ~/ 20t
kill @e[tag=smithed.interaction.sittable_display,type=item_display,predicate=!(HAS_PASSENGER)]

function TICK:
schedule function ~/ 1t
as @e[tag=smithed.interaction.sittable_display.follow,type=item_display] at @s:
store result score #temp smithed.interaction.sittable_id run scoreboard players get @s smithed.interaction.sittable_id
unless entity @e[tag=smithed.interaction.sittable_interaction.follow,type=interaction,distance=..0.001,predicate=(HAS_TEMP_ID)]:
tp @s @n[tag=smithed.interaction.sittable_interaction.follow,type=interaction,predicate=(HAS_TEMP_ID)]
Binary file added src/smithed_libraries/packs/interaction/pack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading