Skip to content

✨ feat: add a new bs.components module #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion docs/_static/switcher.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
"version": "1.18",
"url": "https://docs.mcbookshelf.dev/en/1.18-1.1_spaghetti/"
}
]
]
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
675 changes: 675 additions & 0 deletions docs/modules/component.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions modules/bs.component/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 🏅 Bookshelf Component

This module provides a set of components that can be used to simplify the development of complex GUI in Minecraft.

For more details and usage examples, check out the Bookshelf [documentation](https://docs.mcbookshelf.dev/en/latest/modules/component.html).


## 📖 About Bookshelf

This module is part of the [Bookshelf Project](https://docs.mcbookshelf.dev/en/latest/index.html), a modular library datapack designed to simplify complex systems in Minecraft. Explore the full range of modules and discover how Bookshelf can simplify your Minecraft creations!
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# ------------------------------------------------------------------------------------------------------------
# Copyright (c) 2025 Gunivers
#
# This file is part of the Bookshelf project (https://github.com/mcbookshelf/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.
# ------------------------------------------------------------------------------------------------------------

# 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", "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 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
@@ -0,0 +1,27 @@
# ------------------------------------------------------------------------------------------------------------
# Copyright (c) 2025 Gunivers
#
# This file is part of the Bookshelf project (https://github.com/mcbookshelf/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.
# ------------------------------------------------------------------------------------------------------------

# 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", "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

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

# Create the button at the item display's position
execute as @n[tag=bs.component.item_display] at @s anchored feet positioned ^ ^ ^ run function bs.component:button/create_simple_button with storage bs:ctx _
tag @n[tag=bs.component.item_display] remove bs.component.item_display
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# ------------------------------------------------------------------------------------------------------------
# Copyright (c) 2025 Gunivers
#
# This file is part of the Bookshelf project (https://github.com/mcbookshelf/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.component.icon
$data modify storage bs.ctx _ set value { width: $(width), height: $(height), on_click: "$(on_click)", hover: "function #bs.interaction:callback/glow", hover_leave: "function #bs.interaction:callback/unglow" }
data modify storage bs.ctx _.hover set from storage bs.ctx _.with.hover
data modify storage bs.ctx _.hover_leave set from storage bs.ctx _.with.hover_leave
execute summon minecraft:interaction run function bs.component:button/setup_button with storage bs.ctx _
tag @s remove bs.component.icon
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ------------------------------------------------------------------------------------------------------------
# Copyright (c) 2025 Gunivers
#
# This file is part of the Bookshelf project (https://github.com/mcbookshelf/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 properties
$data merge entity @s {width: $(width), height: $(height), Tags: ["bs.component.button"]}

# Setup the click event
$function #bs.interaction:on_right_click { run: "$(on_click)", executor: "source" }

# Setup hover events for glow effect
$function #bs.interaction:on_hover { run: "$(hover)", executor: { selector: "@e[tag=bs.component.icon, limit=1]", lazy: false }}
$function #bs.interaction:on_hover_leave { run: "$(hover_leave)", executor: { selector: "@e[tag=bs.component.icon, limit=1]", lazy: false }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"__bookshelf__": {
"feature": true,
"documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/component.html#create-button",
"authors": [
"theogiraudet"
],
"created": {
"date": "2024/11/28",
"minecraft_version": "1.21.3"
}
},
"values": [
"bs.component:button/create_block_display_button"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"__bookshelf__": {
"feature": true,
"documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/component.html#create-button",
"authors": [
"theogiraudet"
],
"created": {
"date": "2024/11/28",
"minecraft_version": "1.21.3"
}
},
"values": [
"bs.component:button/create_item_display_button"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"__bookshelf__": {
"feature": true,
"documentation": "https://bookshelf.docs.gunivers.net/en/latest/modules/component.html#create-button",
"authors": [
"theogiraudet"
],
"created": {
"date": "2024/11/23",
"minecraft_version": "1.21.3"
}
},
"values": [
"bs.component:button/create_simple_button"
]
}
17 changes: 17 additions & 0 deletions modules/bs.component/module.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extend": "../config.json",
"data_pack": {
"name": "bs.component",
"load": "."
},
"meta": {
"name": "Component",
"slug": "bookshelf-component",
"description": "A set of components that can be used to simplify the development of complex GUI in Minecraft.",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/component.html",
"tags": ["runtime"],
"dependencies": [
"bs.interaction"
]
}
}
Loading