Skip to content
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

✨ feat: add a new bs.string module #283

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bd06af0
creation of `bs.string`
aure31 Nov 30, 2024
8c69154
add the concat feature
aure31 Dec 27, 2024
9cc7a31
🐛 Fix move (#289)
aksiome Dec 21, 2024
cb9862a
🐛 Add missing blocks from latest Minecraft version in bs.block regist…
aksiome Dec 21, 2024
2f43498
🏷️ Dump to 2.2.1
aksiome Dec 21, 2024
5f64ab5
🐛 Fix creaking hitbox and improve tests to use packtest beta versions…
theogiraudet Dec 23, 2024
335fd3d
🏷️ Dump 2.2.2 (#295)
theogiraudet Dec 23, 2024
00cca8a
Beet rework (#285)
aksiome Dec 30, 2024
44f2c45
Update versions.json
aksiome Jan 5, 2025
580983a
Beet rework (#285)
aksiome Dec 30, 2024
4db63f9
creation of `bs.string`
aure31 Nov 30, 2024
555a606
Merge branch 'master' into pr/283
aksiome Jan 10, 2025
d9077fd
Merge branch 'master' of https://github.com/aure31/Bookshelf into pr/283
aksiome Jan 10, 2025
309928a
merge + changing the concat with the advice of aksiom
aure31 Jan 11, 2025
2b26144
to_number + to_string + lower_case + upper_case
aure31 Jan 11, 2025
69e6fe9
starting the docs file
aure31 Jan 11, 2025
aed388e
find function
aure31 Jan 12, 2025
b3ff5f1
fix some files and slighly modified find
aure31 Jan 13, 2025
f7a1f02
fixes metadata
aure31 Jan 13, 2025
0199d4b
maybe fixes the header
aure31 Jan 13, 2025
405012d
test + split + to list
aure31 Jan 15, 2025
3d9ad42
fix bugs with the split, adding the replace function and more test : )
aure31 Jan 15, 2025
8cc7109
fix of the aksiom review
aure31 Jan 17, 2025
d945eab
🔖 Update generated metadata
github-actions[bot] Jan 17, 2025
9896b61
Merge branch 'mcbookshelf:master' into master
aure31 Jan 20, 2025
ba5d1ac
🔖 Update generated metadata
github-actions[bot] Jan 20, 2025
6e80ee4
ajout des differente pour benificié du cache
aure31 Jan 25, 2025
3a03178
Merge branch 'mcbookshelf:master' into master
aure31 Jan 25, 2025
f98f2e5
fix for concat
aure31 Jan 25, 2025
dbb9ef1
add of the insert function
aure31 Jan 25, 2025
75c19ba
🔖 Update generated metadata
github-actions[bot] Jan 25, 2025
236c908
unsuccessful attempt to implement the precompute algo of the find fun…
aure31 Jan 25, 2025
2a10868
fix find function
aure31 Jan 26, 2025
cca563d
disable the inverse search for the find function because of the need …
aure31 Jan 26, 2025
fa0236d
fix find function
aure31 Jan 26, 2025
1c555e2
Merge branch 'mcbookshelf:master' into master
aure31 Jan 28, 2025
8c85be3
resolve all
aure31 Jan 28, 2025
20bcfa0
adding the new algo to the split function
aure31 Jan 28, 2025
e6625d6
make two row in one
aure31 Jan 28, 2025
0521187
fix bug + adding bs.log as weak depedencies
aure31 Feb 27, 2025
dc6bd3c
🔖 Update generated metadata
github-actions[bot] Feb 27, 2025
ca135cc
fix bugs and adding the algorithm to the replace function
aure31 Mar 1, 2025
c89efd4
adding reverse function and preventing corner case
aure31 Mar 1, 2025
567099a
avancement de la doc
aure31 Mar 1, 2025
1b6232e
doc fix + removed debug
aure31 Mar 2, 2025
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
2 changes: 2 additions & 0 deletions docs/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Bookshelf is designed with modularity in mind. Features that serve a common purp
## 🌟 Featured Modules

```{include} _templates/featured-modules.md

```

```{toctree}
Expand Down Expand Up @@ -39,6 +40,7 @@ modules/tree
modules/vector
modules/view
modules/xp
modules/string
```

```{toctree}
Expand Down
100 changes: 100 additions & 0 deletions docs/modules/string.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 🔠 String

**`#bs.string:help`**
Copy link
Member

Choose a reason for hiding this comment

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

We try to have a small description, a banner image, and a quote for our module. Nothing is mandatory except the description, but it's better with all of them

Copy link
Author

Choose a reason for hiding this comment

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

how you find the image for the module with a black and white variant

Copy link
Member

Choose a reason for hiding this comment

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

Either have a png with transparent background, or make 2 versions. If you don't really feel like doing some image design we'll try to do it (either Theo or me)


Copy link
Member

Choose a reason for hiding this comment

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

  • In the documentation a lot of sentences are missing their . at the end.
  • Verbs should be imperative. For example in uppercase/lowercase, Converts should be Convert instead.
  • In multiple examples the description does not have an uppercase at the start of the sentence.
  • Functions should be sorted in alphabetical order.
  • Storage inputs/outputs should use treeview (see other modules like block) if more than 1, and examples should also work this way. For example in replace:
    # avoid
    data modify storage bs:in string.replace.str set value "hello world"
    data modify storage bs:in string.replace.old set value "world"
    data modify storage bs:in string.replace.new set value "minecraft"
    
    # use instead to encourage people to use only the base path (string.replace) to override the whole compound and avoid unintended side effects when multiple pack use bookshelf
    data modify storage bs:in string.replace set value {str: "hello world", old: "world", new: "minecraaft"}

---

## 🔧 Functions

You can find below all functions available in this module.

---

### Concat

```{function} #bs.string:concat

Merges a list of strings together into one string

:Inputs:
**Storage `bs:in string.concat.list`**: {nbt}`string` The list of strings that will be merged.

:Outputs:
**Storage `bs:out string.concat`**: {nbt}`string` The merged string.
```

_Merged Hello and World:_

```mcfunction
data modify storage bs:in string.concat.list set value ["Hello ","World"]

function #bs.string:concat

tellraw @a [{"text":"The merged string is \""},{"storage":"bs:out","nbt":"string.concat"},{"text":"\""}]
```

> **Credits**: Aure31

---

### Uppercase / Lowercase

:::::{tab-set}
::::{tab-item} Upper

```{function} #bs.string:upper {type:<mode>}

Converts the text to uppercase

:Inputs:
**Storage `bs:in string.upper.str`**: {nbt}`string` The string to convert to uppercase

**Function Macro**:
:::{treeview}
- {nbt}`compound` Arguments
- {nbt}`string` **type** : the size of the character table (`fast` or `slow`)
:::

:Outputs:
**Strorage `bs:out string.upper`**: {nbt}`string` The uppercase string
```

_put hello world to uppercase:_

```mcfunction
data modify storage bs:in string.upper.str set value "hello world"

function #bs.string:upper {type:'fast'}

tellraw @a [{"text":"The uppercase string is \""},{"storage":"bs:out","nbt":"string.upper"},{"text":"\""}]
```

::::
::::{tab-item} Lower

```{function} #bs.string:lower {type:<mode>}

Converts the text to lowercase

:Inputs:
**Storage `bs:in string.lower.str`**: {nbt}`string` The string to convert to lowercase

**Function Macro**:
:::{treeview}
- {nbt}`compound` Arguments
- {nbt}`string` **type** : the size of the character table (`fast` or `slow`)
:::

:Outputs:
**Strorage `bs:out string.lower`**: {nbt}`string` The lowercase string
```

_put hello world to lowercase:_

```mcfunction
data modify storage bs:in string.lower.str set value "hello world"

function #bs.string:lower {type:'fast'}

tellraw @a [{"text":"The lowercase string is \""},{"storage":"bs:out","nbt":"string.upper"},{"text":"\""}]
```
179 changes: 179 additions & 0 deletions meta/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3334,6 +3334,185 @@
}
]
},
{
"id": "bs.string",
"name": "String",
"slug": "bookshelf-string",
"readme": "https://raw.githubusercontent.com/mcbookshelf/Bookshelf/refs/heads/master/modules/bs.string/README.md",
"description": "Get information about the system string effortlessly.",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html",
"kind": "data_pack",
"tags": [
"default"
],
"features": [
{
"id": "#bs.string:concat",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#concat",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/10",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/13",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:find",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#find",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/12",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/15",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:index_of",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#index-of",
"authors": [
"aure31"
],
"created": {
"date": "2024/10/27",
"minecraft_version": "1.21.3"
},
"updated": {
"date": "2025/01/13",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:insert",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#find",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/25",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/25",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:lower",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#case",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/11",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/13",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:replace",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#replace",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/15",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/15",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:split",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#split",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/15",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/15",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:to_list",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#to_list",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/15",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/15",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:to_number",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#to_number",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/11",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/15",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:to_string",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#to_string",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/11",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/15",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.string:upper",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/string.html#case",
"authors": [
"aure31"
],
"created": {
"date": "2025/01/11",
"minecraft_version": "1.21.4"
},
"updated": {
"date": "2025/01/13",
"minecraft_version": "1.21.4"
}
}
]
},
{
"id": "bs.time",
"name": "Time",
Expand Down
9 changes: 9 additions & 0 deletions modules/bs.string/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 🔠 Bookshelf String

This module allows you to easily manage string in Minecraft.

For more details and usage examples, check out the Bookshelf [documentation](https://docs.mcbookshelf.dev/en/latest/modules/string.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!
22 changes: 22 additions & 0 deletions modules/bs.string/data/bs.string/function/__load__.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ------------------------------------------------------------------------------------------------------------
# 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.
# ------------------------------------------------------------------------------------------------------------

scoreboard objectives add bs.data dummy [{"text":"BS ","color":"dark_gray"},{"text":"Data","color":"aqua"}]
scoreboard objectives add bs.out dummy [{"text":"BS ","color":"dark_gray"},{"text":"Output","color":"aqua"}]
scoreboard objectives add bs.ctx dummy [{"text":"BS ","color":"dark_gray"},{"text":"Ctx","color":"aqua"}]
scoreboard objectives add bs.const dummy [{"text":"BS ","color":"dark_gray"},{"text":"Const","color":"aqua"}]

#set constant
Copy link
Member

Choose a reason for hiding this comment

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

Not really consistent with other comments, we should always add a space after #. Also not sure this one is really needed since the code is self explanatory. We don't really have conventions for comments but i think it's best to be consistent across a module (like for example if you use uppercase at the start of comments use it everywhere)

scoreboard players set 8 bs.const 8
21 changes: 21 additions & 0 deletions modules/bs.string/data/bs.string/function/__unload__.mcfunction
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.
# ------------------------------------------------------------------------------------------------------------

scoreboard objectives remove bs.data
scoreboard objectives remove bs.out
scoreboard objectives remove bs.ctx

#data remove storage bs:in string
Copy link
Member

Choose a reason for hiding this comment

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

You should remove both input and outputs when unloading the module also the const score

data remove storage bs:data string
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
execute if score #n bs.ctx matches 2048.. run function bs.string:concat/combine/2048

Check failure on line 1 in modules/bs.string/data/bs.string/function/concat/binary.mcfunction

View workflow job for this annotation

GitHub Actions / 🔍 Check Modules

Missing header

Found invalid header in file: modules/bs.string/data/bs.string/function/concat/binary.mcfunction
execute if score #n bs.ctx matches 1024.. run function bs.string:concat/combine/1024
execute if score #n bs.ctx matches 512.. run function bs.string:concat/combine/512
execute if score #n bs.ctx matches 256.. run function bs.string:concat/combine/256
Copy link
Member

Choose a reason for hiding this comment

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

I've run some benchmarks because i was a bit afraid the size of these generated functions could also have an impact, and found out that the sweet spot for performances is 256. So we should remove everything above and let the function loop

execute if score #n bs.ctx matches 128.. run function bs.string:concat/combine/128
execute if score #n bs.ctx matches 64.. run function bs.string:concat/combine/64
say max
31 changes: 31 additions & 0 deletions modules/bs.string/data/bs.string/function/concat/concat.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ------------------------------------------------------------------------------------------------------------
# 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.
# ------------------------------------------------------------------------------------------------------------

# Modified from https://github.com/CMDred/StringLib/

data modify storage bs:ctx _.s.1 set from storage bs:ctx _.list[-1]
data remove storage bs:ctx _.list[-1]
execute store result score #n bs.ctx run data get storage bs:ctx _.list

# we dont need below 64 since it's already handled in a single cycle
execute if score #n bs.ctx matches 64.. run function bs.string:concat/binary
say Macros
# if stuff remains
execute store result storage bs:ctx x int 1 store result score #c bs.ctx run scoreboard players get #n bs.ctx
scoreboard players remove #c bs.ctx 1
# Which dispatch to call
execute store result storage bs:ctx y int 1 run scoreboard players operation #c bs.ctx /= 8 bs.const

execute if score #n bs.ctx matches 1.. run function bs.string:concat/macro with storage bs:ctx
Loading
Loading