Skip to content
This repository was archived by the owner on May 19, 2026. It is now read-only.
Merged
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
53 changes: 0 additions & 53 deletions assets/datalib/font/datalib.json

This file was deleted.

31 changes: 31 additions & 0 deletions data/datalib/function/api/gamerule/get.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# datalib:api/gamerule/get [MACRO]
# Reads a custom gamerule value from storage into datalib:output gamerule.
#
# INPUT (macro args via `with storage datalib:input {}`):
# $(rule) — rule name string (must match the name used in set)
#
# OUTPUT:
# datalib:output gamerule — the stored value string, or absent if never set
#
# EXAMPLE:
# data modify storage datalib:input rule set value "pvp_enabled"
# function datalib:api/gamerule/get with storage datalib:input {}
# # read: data get storage datalib:output gamerule

execute unless function datalib:debug/tools/utils/check_all run return 0

# Normalize key (spaces → underscores, lowercase)
data modify storage stringlib:input replace.String set from storage datalib:input rule
data modify storage stringlib:input replace.Find set value " "
data modify storage stringlib:input replace.Replace set value "_"
function stringlib:util/replace
data modify storage datalib:input _gamerule_norm set from storage stringlib:output replace
data remove storage stringlib:input replace

# Read from engine storage
data remove storage datalib:output gamerule
function datalib:api/gamerule/internal/read with storage datalib:input {}

$tellraw @a[tag=datalib.debug] ["",{"text":"[DL] ","color":"#00AAAA","bold":true},{"text":"gamerule/get ","color":"aqua"},{"text":" → ","color":"#555555"},{"text":"$(_gamerule_norm)","color":"white"},{"text":" = ","color":"#555555"},{"storage":"datalib:output","nbt":"gamerule","color":"green"}]

data remove storage datalib:input _gamerule_norm
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# datalib:api/gamerule/internal/call_on_false [MACRO]
# Calls the gr_on_false callback. Called by dispatch only.
$function $(gr_on_false)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# datalib:api/gamerule/internal/call_on_true [MACRO]
# Calls the gr_on_true callback. Called by dispatch only.
$function $(gr_on_true)
19 changes: 19 additions & 0 deletions data/datalib/function/api/gamerule/internal/dispatch.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# datalib:api/gamerule/internal/dispatch
# Evaluates the value and calls the appropriate callback function.
# Called exclusively by datalib:api/gamerule/set — do NOT call directly.
#
# INPUT (storage datalib:input):
# value — raw value string: "true", "false", or numeric string
# gr_on_true — (optional) function to call when value is "true"
# gr_on_false — (optional) function to call when value is "false"
# gr_on_value — (optional) function to call for numeric match
# gr_matches — (optional) scoreboard range string, e.g. "5..10"

# ── Boolean: true ────────────────────────────────────────────────────────────
execute if data storage datalib:input {value:"true"} if data storage datalib:input gr_on_true run return run function datalib:api/gamerule/internal/call_on_true with storage datalib:input {}

# ── Boolean: false ───────────────────────────────────────────────────────────
execute if data storage datalib:input {value:"false"} if data storage datalib:input gr_on_false run return run function datalib:api/gamerule/internal/call_on_false with storage datalib:input {}

# ── Numeric with explicit matches range ──────────────────────────────────────
execute if data storage datalib:input gr_on_value if data storage datalib:input gr_matches run function datalib:api/gamerule/internal/numeric_check with storage datalib:input {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# datalib:api/gamerule/internal/numeric_check [MACRO]
# Converts value string to score, checks against gr_matches range, calls gr_on_value.
# Called exclusively by dispatch — do NOT call directly.
#
# INPUT (macro args via `with storage datalib:input {}`):
# $(value) — numeric value string, e.g. "10"
# $(gr_matches) — scoreboard range string, e.g. "5..10" or "1.."
# $(gr_on_value) — function to call if score is in range

$scoreboard players set #dl_gamerule_scratch dl.gamerule $(value)
$execute if score #dl_gamerule_scratch dl.gamerule matches $(gr_matches) run function $(gr_on_value)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# datalib:api/gamerule/internal/persist [MACRO]
# Writes the normalized rule name + value into datalib:engine gamerules compound.
# Called exclusively by datalib:api/gamerule/set — do NOT call directly.
#
# INPUT (macro args via `with storage datalib:input {}`):
# $(_gamerule_norm) — normalized rule name (spaces → underscores, lowercase)
# $(value) — value string

$data modify storage datalib:engine gamerules.$(_gamerule_norm) set value "$(value)"
4 changes: 4 additions & 0 deletions data/datalib/function/api/gamerule/internal/read.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# datalib:api/gamerule/internal/read [MACRO]
# Reads gamerule value from engine storage into output.
# Called by get only.
$execute if data storage datalib:engine gamerules.$(_gamerule_norm) run data modify storage datalib:output gamerule set from storage datalib:engine gamerules.$(_gamerule_norm)
4 changes: 4 additions & 0 deletions data/datalib/function/api/gamerule/internal/remove.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# datalib:api/gamerule/internal/remove [MACRO]
# Removes a single gamerule key from engine storage.
# Called by reset only.
$data remove storage datalib:engine gamerules.$(_gamerule_norm)
26 changes: 26 additions & 0 deletions data/datalib/function/api/gamerule/reset.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# datalib:api/gamerule/reset [MACRO]
# Removes a custom gamerule from engine storage entirely.
# Does NOT touch vanilla /gamerule — this is for datalib-tracked rules only.
#
# INPUT (macro args via `with storage datalib:input {}`):
# $(rule) — rule name string
#
# EXAMPLE:
# data modify storage datalib:input rule set value "pvp_enabled"
# function datalib:api/gamerule/reset with storage datalib:input {}

execute unless function datalib:debug/tools/utils/check_all run return 0

# Normalize
data modify storage stringlib:input replace.String set from storage datalib:input rule
data modify storage stringlib:input replace.Find set value " "
data modify storage stringlib:input replace.Replace set value "_"
function stringlib:util/replace
data modify storage datalib:input _gamerule_norm set from storage stringlib:output replace
data remove storage stringlib:input replace

function datalib:api/gamerule/internal/remove with storage datalib:input {}

$tellraw @a[tag=datalib.debug] ["",{"text":"[DL] ","color":"#00AAAA","bold":true},{"text":"gamerule/reset ","color":"aqua"},{"text":" → ","color":"#555555"},{"text":"$(_gamerule_norm)","color":"gray","italic":true},{"text":" removed","color":"gray"}]

data remove storage datalib:input _gamerule_norm
46 changes: 46 additions & 0 deletions data/datalib/function/api/gamerule/set.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# datalib:api/gamerule/set [MACRO]
# Sets a custom gamerule value, persists it in storage, and dispatches
# a callback function when the value matches a defined condition.
#
# INPUT (macro args via `with storage datalib:input {}`):
# $(rule) — rule name string, e.g. "pvp_enabled"
# $(value) — value string: "true", "false", or a number string e.g. "10"
#
# OPTIONAL storage keys (set before calling, removed after):
# datalib:input gr_on_true — function to call when value is "true"
# datalib:input gr_on_false — function to call when value is "false"
# datalib:input gr_on_value — function to call for any numeric match
# datalib:input gr_matches — scoreboard range string, e.g. "5..10" (used with gr_on_value)
#
# EXAMPLE:
# data modify storage datalib:input rule set value "pvp_enabled"
# data modify storage datalib:input value set value "true"
# data modify storage datalib:input gr_on_true set value "mypack:pvp/enable"
# data modify storage datalib:input gr_on_false set value "mypack:pvp/disable"
# function datalib:api/gamerule/set with storage datalib:input {}
#
# RETURN: 1 on success, 0 on guard failure.

execute unless function datalib:debug/tools/utils/check_all run return 0

# ── Normalize rule name: spaces → underscores via StringLib ──────────────────
data modify storage stringlib:input replace.String set from storage datalib:input rule
data modify storage stringlib:input replace.Find set value " "
data modify storage stringlib:input replace.Replace set value "_"
function stringlib:util/replace
data modify storage datalib:input _gamerule_norm set from storage stringlib:output replace
data remove storage stringlib:input replace

# ── Persist value in engine storage ──────────────────────────────────────────
function datalib:api/gamerule/internal/persist with storage datalib:input {}

# ── Dispatch callbacks ────────────────────────────────────────────────────────
function datalib:api/gamerule/internal/dispatch with storage datalib:input {}

# ── Debug log ─────────────────────────────────────────────────────────────────
$tellraw @a[tag=datalib.debug] ["",{"text":"[DL] ","color":"#00AAAA","bold":true},{"text":"gamerule/set ","color":"aqua"},{"text":" → ","color":"#555555"},{"text":"$(_gamerule_norm)","color":"white"},{"text":" = ","color":"#555555"},{"text":"$(value)","color":"green"}]

# ── Cleanup ───────────────────────────────────────────────────────────────────
data remove storage datalib:input _gamerule_norm

return 1
3 changes: 3 additions & 0 deletions data/dl_load/function/load/scoreboards.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ execute unless score #dl.log_level dl.log_level matches 0.. run scoreboard playe
# Config scoreboard — fast integer config values (no storage lookup needed)
scoreboard objectives add datalib.config dummy

# Gamerule module — scratch scoreboard for numeric range checks
scoreboard objectives add dl.gamerule dummy

# State scoreboard — per-player state machine (0=idle 1=combat 2=menu ...)
scoreboard objectives add datalib.state dummy

Expand Down
Loading