Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
theogiraudet committed Feb 25, 2025
1 parent cebb44f commit 132782f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Here are some of the key terms used throughout the documentation.
modules/bitwise
modules/block
modules/color
modules/component
modules/environment
modules/generation
modules/health
Expand Down
70 changes: 70 additions & 0 deletions docs/modules/component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 👆 Component

**`#bs.component:help`**

Create easily graphical components in Minecraft.

```{epigraph}
"About ten years ago, most push buttons went “3D”. Using shades of grey, they appear to pop out of the screen. This is not just to look cool: it’s important because 3D buttons afford pushing."
-- joel Spolsky
```

The Component API is a high-level API to create GUIs components.
This API use the Interaction API under the hood to create the components and the events.
You can so fallback on the Interaction API to create more complex components.

---

## 🔧 Functions

You can find below all functions available in this API.

---

### Clear Events

```{function} #bs.interaction:clear_events
Clear events registered for the specified interaction entity.
:Inputs:
**Execution `as <entity>`**: Interaction 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 interaction entity will be removed.
```

*Clear hover events for the interaction entity:*

```mcfunction
summon minecraft:interaction ~ ~ ~ { Tags: ["bs.entity.interaction"], width: 1f, height: 1f }
# Register hover events for the interaction
execute as @n[tag=bs.entity.interaction] run function #bs.interaction:on_hover { run: "say Hovered", executor: "target" }
# Clear hover events for the interaction
execute as @n[tag=bs.entity.interaction] run function #bs.interaction:clear_events { with: { type: "hover" } }
```

> **Credits**: theogiraudet
---

<div id="gs-comments" align=center>

**💬 Did it help you?**

Feel free to leave your questions and feedbacks below!

</div>
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# ------------------------------------------------------------------------------------------------------------

# Create the base properties
$data modify storage bs:ctx _ set value { width: $(width), height: $(height), on_click: "$(on_click)" , block_state: { Name: $(block), Properties: $(properties) }, Tags: ["bs.component.block_display"], transformation: { translation: [-0.5f, 0.5f, -0.5f]}, with: {}}
$data modify storage bs:ctx _ set value { width: $(width), height: $(height), on_click: "$(on_click)" , block_state: { Name: $(block), Properties: $(properties) }, Tags: ["bs.component.block_display", "smithed.entity", "smithed.strict"], transformation: { translation: [-0.5f, 0.5f, -0.5f]}, with: {}}
$data modify storage bs:ctx _ merge value $(with)
data modify storage bs:ctx _.with.hover set from storage bs:ctx _.hover
data modify storage bs:ctx _.with.hover_leave set from storage bs:ctx _.hover_leave

# Summon the item display
execute summon block_display run data modify entity @s {} merge from storage bs:ctx _

# Create the button at the item display's position
# Create the button at the block display's position
execute as @n[tag=bs.component.block_display] at @s anchored feet positioned ^ ^ ^ run function bs.component:button/create_simple_button with storage bs:ctx _
tag @n[tag=bs.component.block_display] remove bs.component.block_display
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# ------------------------------------------------------------------------------------------------------------

# Create the base properties
$data modify storage bs:ctx _ set value { width: $(width), height: $(height), on_click: "$(on_click)" , item: { id: $(item) }, Tags: ["bs.component.item_display"], transformation: { translation: [0f, 0.5f, 0f]}, with: {}}
$data modify storage bs:ctx _ set value { width: $(width), height: $(height), on_click: "$(on_click)" , item: { id: $(item) }, Tags: ["bs.component.item_display", "smithed.entity", "smithed.strict"], transformation: { translation: [0f, 0.5f, 0f]}, with: {}}
$data modify storage bs:ctx _ merge value $(with)
data modify storage bs:ctx _.with.hover set from storage bs:ctx _.hover
data modify storage bs:ctx _.with.hover_leave set from storage bs:ctx _.hover_leave
Expand Down

0 comments on commit 132782f

Please sign in to comment.