From 055ded17f0284194e676bc495ec1c28b8f2d5a67 Mon Sep 17 00:00:00 2001 From: Aksiome <54895777+aksiome@users.noreply.github.com> Date: Thu, 24 Oct 2024 18:52:21 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20argument=20to=20control=20out?= =?UTF-8?q?put=20scaling=20in=20noise=20matrix=20functions=20(#267)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fractal_noise_mat_2d.mcfunction | 3 ++- .../fractal_noise_mat_2d/xloop.mcfunction | 4 ++-- .../fractal_noise_mat_2d/yloop.mcfunction | 2 +- .../simplex_noise_mat_2d.mcfunction | 3 ++- .../simplex_noise_mat_2d/xloop.mcfunction | 4 ++-- .../simplex_noise_mat_2d/yloop.mcfunction | 2 +- .../noise/white_noise_mat_1d/loop.mcfunction | 4 ++-- .../white_noise_mat_1d.mcfunction | 5 ++++- .../white_noise_mat_2d.mcfunction | 3 +++ .../noise/white_noise_mat_2d/xloop.mcfunction | 4 ++-- .../noise/white_noise_mat_2d/yloop.mcfunction | 2 +- .../test/noise/white_noise_mat_1d.mcfunction | 4 ++-- .../test/noise/white_noise_mat_2d.mcfunction | 6 ++--- docs/modules/random.md | 22 ++++++++++++------- 14 files changed, 41 insertions(+), 27 deletions(-) diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/fractal_noise_mat_2d.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/fractal_noise_mat_2d.mcfunction index ab4e72e856..2f2c1bd4e6 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/fractal_noise_mat_2d.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/fractal_noise_mat_2d.mcfunction @@ -15,10 +15,11 @@ # Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/random.html#noise-generators # ------------------------------------------------------------------------------------------------------------ -data modify storage bs:ctx _ set value {octaves:4,persistence:.5,lacunarity:2.0,size:16} +data modify storage bs:ctx _ set value {octaves:4,persistence:.5,lacunarity:2.0,size:16,scale:1} $scoreboard players set #w bs.ctx $(width) $scoreboard players set #h bs.ctx $(height) $data modify storage bs:ctx _ merge value $(with) +execute store result storage bs:ctx _.scale double .000001 run data get storage bs:ctx _.scale 1000 execute store result score $random.fractal_noise_2d.octaves bs.in run data get storage bs:ctx _.octaves execute store result score $random.fractal_noise_2d.persistence bs.in run data get storage bs:ctx _.persistence 1000 diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/xloop.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/xloop.mcfunction index dd8c7597b1..09c38b366b 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/xloop.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/xloop.mcfunction @@ -16,8 +16,8 @@ # ------------------------------------------------------------------------------------------------------------ data modify storage bs:out random.fractal_noise_mat_2d[-1] append value 0f -execute store result storage bs:out random.fractal_noise_mat_2d[-1][-1] float .001 run function #bs.random:fractal_noise_2d +$execute store result storage bs:out random.fractal_noise_mat_2d[-1][-1] float $(scale) run function #bs.random:fractal_noise_2d execute store result score $random.fractal_noise_2d.x bs.in run scoreboard players add #x bs.ctx 1 scoreboard players operation $random.fractal_noise_2d.x bs.in *= #k bs.ctx -execute if score #x bs.ctx < #w bs.ctx run function bs.random:noise/fractal_noise_mat_2d/xloop +execute if score #x bs.ctx < #w bs.ctx run function bs.random:noise/fractal_noise_mat_2d/xloop with storage bs:ctx _ diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/yloop.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/yloop.mcfunction index 6188cdd779..6f22975129 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/yloop.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/fractal_noise_mat_2d/yloop.mcfunction @@ -17,7 +17,7 @@ execute store result score $random.fractal_noise_2d.x bs.in run scoreboard players set #x bs.ctx 0 data modify storage bs:out random.fractal_noise_mat_2d append value [] -function bs.random:noise/fractal_noise_mat_2d/xloop +function bs.random:noise/fractal_noise_mat_2d/xloop with storage bs:ctx _ execute store result score $random.fractal_noise_2d.y bs.in run scoreboard players add #y bs.ctx 1 scoreboard players operation $random.fractal_noise_2d.y bs.in *= #k bs.ctx diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/simplex_noise_mat_2d.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/simplex_noise_mat_2d.mcfunction index fa1520ed30..67a4d3ab14 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/simplex_noise_mat_2d.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/simplex_noise_mat_2d.mcfunction @@ -15,10 +15,11 @@ # Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/random.html#noise-generators # ------------------------------------------------------------------------------------------------------------ -data modify storage bs:ctx _ set value {size:16} +data modify storage bs:ctx _ set value {size:16,scale:1} $scoreboard players set #w bs.ctx $(width) $scoreboard players set #h bs.ctx $(height) $data modify storage bs:ctx _ merge value $(with) +execute store result storage bs:ctx _.scale double .000001 run data get storage bs:ctx _.scale 1000 execute if data storage bs:ctx _.seed store result score $random.simplex_noise_2d.seed bs.in run data get storage bs:ctx _.seed execute unless data storage bs:ctx _.seed store result score $random.simplex_noise_2d.seed bs.in run random value 1.. bs.random:simplex_noise_mat_2d diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/xloop.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/xloop.mcfunction index cee6a165e3..fc6a3db353 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/xloop.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/xloop.mcfunction @@ -16,8 +16,8 @@ # ------------------------------------------------------------------------------------------------------------ data modify storage bs:out random.simplex_noise_mat_2d[-1] append value 0f -execute store result storage bs:out random.simplex_noise_mat_2d[-1][-1] float .001 run function #bs.random:simplex_noise_2d +$execute store result storage bs:out random.simplex_noise_mat_2d[-1][-1] float $(scale) run function #bs.random:simplex_noise_2d execute store result score $random.simplex_noise_2d.x bs.in run scoreboard players add #x bs.ctx 1 scoreboard players operation $random.simplex_noise_2d.x bs.in *= #k bs.ctx -execute if score #x bs.ctx < #w bs.ctx run function bs.random:noise/simplex_noise_mat_2d/xloop +execute if score #x bs.ctx < #w bs.ctx run function bs.random:noise/simplex_noise_mat_2d/xloop with storage bs:ctx _ diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/yloop.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/yloop.mcfunction index d858e38b17..509a37138d 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/yloop.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/simplex_noise_mat_2d/yloop.mcfunction @@ -17,7 +17,7 @@ execute store result score $random.simplex_noise_2d.x bs.in run scoreboard players set #x bs.ctx 0 data modify storage bs:out random.simplex_noise_mat_2d append value [] -function bs.random:noise/simplex_noise_mat_2d/xloop +function bs.random:noise/simplex_noise_mat_2d/xloop with storage bs:ctx _ execute store result score $random.simplex_noise_2d.y bs.in run scoreboard players add #y bs.ctx 1 scoreboard players operation $random.simplex_noise_2d.y bs.in *= #k bs.ctx diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_1d/loop.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_1d/loop.mcfunction index 4e3c817da8..ea23245cf6 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_1d/loop.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_1d/loop.mcfunction @@ -17,5 +17,5 @@ scoreboard players remove #i bs.ctx 1 data modify storage bs:out random.white_noise_mat_1d append value 0f -execute store result storage bs:out random.white_noise_mat_1d[-1] float .001 run random value 1..1000 -execute if score #i bs.ctx matches 1.. run function bs.random:noise/white_noise_mat_1d/loop +$execute store result storage bs:out random.white_noise_mat_1d[-1] float $(scale) run random value 1..1000 +execute if score #i bs.ctx matches 1.. run function bs.random:noise/white_noise_mat_1d/loop with storage bs:ctx _ diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_1d/white_noise_mat_1d.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_1d/white_noise_mat_1d.mcfunction index 8f5b3d3197..7f23698946 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_1d/white_noise_mat_1d.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_1d/white_noise_mat_1d.mcfunction @@ -15,7 +15,10 @@ # Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/random.html#noise-generators # ------------------------------------------------------------------------------------------------------------ +data modify storage bs:ctx _ set value {scale:1} $scoreboard players set #i bs.ctx $(length) +$data modify storage bs:ctx _ merge value $(with) +execute store result storage bs:ctx _.scale double .000001 run data get storage bs:ctx _.scale 1000 data modify storage bs:out random.white_noise_mat_1d set value [] -execute if score #i bs.ctx matches 1.. run function bs.random:noise/white_noise_mat_1d/loop +execute if score #i bs.ctx matches 1.. run function bs.random:noise/white_noise_mat_1d/loop with storage bs:ctx _ diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/white_noise_mat_2d.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/white_noise_mat_2d.mcfunction index c427a885e6..992668c13d 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/white_noise_mat_2d.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/white_noise_mat_2d.mcfunction @@ -15,8 +15,11 @@ # Documentation of the feature: https://bookshelf.docs.gunivers.net/en/latest/modules/random.html#noise-generators # ------------------------------------------------------------------------------------------------------------ +data modify storage bs:ctx _ set value {scale:1} $scoreboard players set #w bs.ctx $(width) $scoreboard players set #h bs.ctx $(height) +$data modify storage bs:ctx _ merge value $(with) +execute store result storage bs:ctx _.scale double .000001 run data get storage bs:ctx _.scale 1000 scoreboard players set #y bs.ctx 0 data modify storage bs:out random.white_noise_mat_2d set value [] diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/xloop.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/xloop.mcfunction index d48f0c69c7..bab83ed2e3 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/xloop.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/xloop.mcfunction @@ -16,6 +16,6 @@ # ------------------------------------------------------------------------------------------------------------ data modify storage bs:out random.white_noise_mat_2d[-1] append value 0f -execute store result storage bs:out random.white_noise_mat_2d[-1][-1] float .001 run random value 1..1000 +$execute store result storage bs:out random.white_noise_mat_2d[-1][-1] float $(scale) run random value 1..1000 scoreboard players add #x bs.ctx 1 -execute if score #x bs.ctx < #w bs.ctx run function bs.random:noise/white_noise_mat_2d/xloop +execute if score #x bs.ctx < #w bs.ctx run function bs.random:noise/white_noise_mat_2d/xloop with storage bs:ctx _ diff --git a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/yloop.mcfunction b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/yloop.mcfunction index 6c0078593a..8771b54944 100644 --- a/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/yloop.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/function/noise/white_noise_mat_2d/yloop.mcfunction @@ -17,7 +17,7 @@ scoreboard players set #x bs.ctx 0 data modify storage bs:out random.white_noise_mat_2d append value [] -function bs.random:noise/white_noise_mat_2d/xloop +function bs.random:noise/white_noise_mat_2d/xloop with storage bs:ctx _ scoreboard players add #y bs.ctx 1 execute if score #y bs.ctx < #h bs.ctx run function bs.random:noise/white_noise_mat_2d/yloop diff --git a/datapacks/Bookshelf/data/bs.random/test/noise/white_noise_mat_1d.mcfunction b/datapacks/Bookshelf/data/bs.random/test/noise/white_noise_mat_1d.mcfunction index bb32c35c28..2e99ba246f 100644 --- a/datapacks/Bookshelf/data/bs.random/test/noise/white_noise_mat_1d.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/test/noise/white_noise_mat_1d.mcfunction @@ -1,11 +1,11 @@ # White noise 1d generates the right number of random values # @batch bs.random -function #bs.random:white_noise_mat_1d {length:0} +function #bs.random:white_noise_mat_1d {length:0,with:{}} execute store result score #n bs.ctx if data storage bs:out random.white_noise_mat_1d[] assert score #n bs.ctx matches 0 -function #bs.random:white_noise_mat_1d {length:5} +function #bs.random:white_noise_mat_1d {length:5,with:{}} execute store result score #n bs.ctx if data storage bs:out random.white_noise_mat_1d[] assert score #n bs.ctx matches 5 diff --git a/datapacks/Bookshelf/data/bs.random/test/noise/white_noise_mat_2d.mcfunction b/datapacks/Bookshelf/data/bs.random/test/noise/white_noise_mat_2d.mcfunction index 88f16c6685..65c0b724b4 100644 --- a/datapacks/Bookshelf/data/bs.random/test/noise/white_noise_mat_2d.mcfunction +++ b/datapacks/Bookshelf/data/bs.random/test/noise/white_noise_mat_2d.mcfunction @@ -1,15 +1,15 @@ # White noise 2d generates the right number of random values # @batch bs.random -function #bs.random:white_noise_mat_2d {width:0,height:8} +function #bs.random:white_noise_mat_2d {width:0,height:8,with:{}} execute store result score #n bs.ctx if data storage bs:out random.white_noise_mat_2d[] assert score #n bs.ctx matches 0 -function #bs.random:white_noise_mat_2d {width:8,height:0} +function #bs.random:white_noise_mat_2d {width:8,height:0,with:{}} execute store result score #n bs.ctx if data storage bs:out random.white_noise_mat_2d[] assert score #n bs.ctx matches 0 -function #bs.random:white_noise_mat_2d {width:3,height:2} +function #bs.random:white_noise_mat_2d {width:3,height:2,with:{}} execute store result score #n bs.ctx if data storage bs:out random.white_noise_mat_2d[] assert score #n bs.ctx matches 2 execute store result score #n bs.ctx if data storage bs:out random.white_noise_mat_2d[0][] diff --git a/docs/modules/random.md b/docs/modules/random.md index cb17d5a8d4..e03bf2379e 100644 --- a/docs/modules/random.md +++ b/docs/modules/random.md @@ -326,7 +326,7 @@ function #bs.random:fractal_noise_2d :::::{tab-set} ::::{tab-item} White noise 1D -```{function} #bs.random:white_noise_mat_1d {length:} +```{function} #bs.random:white_noise_mat_1d {length:,with:{}} Generates a 1-dimensional array of white noise values. @@ -335,17 +335,19 @@ Generates a 1-dimensional array of white noise values. :::{treeview} - {nbt}`compound` Arguments - {nbt}`int` **length**: Length of the array to generate. + - {nbt}`compound` **with**: + - {nbt}`number` **scale**: Scalar for the function's output (default: 1). ::: :Outputs: - **Storage `bs:out random.white_noise_mat_1d`**: {nbt}`list` Array of values between 0 and 1. + **Storage `bs:out random.white_noise_mat_1d`**: {nbt}`list` Array of values between 0 and {scale}. ``` *Generate 4 random values:* ```mcfunction # Generate random noise -function #bs.random:white_noise_mat_1d {length:4} +function #bs.random:white_noise_mat_1d {length:4,with:{}} # Display the result tellraw @a [{"text": "Noise: ", "color": "dark_gray"},{"nbt":"white_noise_mat_1d","storage":"bs:out", "color": "gold"}] @@ -354,7 +356,7 @@ tellraw @a [{"text": "Noise: ", "color": "dark_gray"},{"nbt":"white_noise_mat_1d :::: ::::{tab-item} White noise 2D -```{function} #bs.random:white_noise_mat_2d {width:,height:} +```{function} #bs.random:white_noise_mat_2d {width:,height:,with:{}} Generates a 2-dimensional array of white noise values. @@ -364,17 +366,19 @@ Generates a 2-dimensional array of white noise values. - {nbt}`compound` Arguments - {nbt}`int` **width**: Width of the array to generate. - {nbt}`int` **height**: Height of the array to generate. + - {nbt}`compound` **with**: + - {nbt}`number` **scale**: Scalar for the function's output (default: 1). ::: :Outputs: - **Storage `bs:out random.white_noise_mat_2d`**: {nbt}`list` 2D array of values between 0 and 1. + **Storage `bs:out random.white_noise_mat_2d`**: {nbt}`list` 2D array of values between 0 and {scale}. ``` *Generate a 4x4 random noise pattern:* ```mcfunction # Generate random noise -function #bs.random:white_noise_mat_2d {width:4,height:4} +function #bs.random:white_noise_mat_2d {width:4,height:4,with:{}} # Display the result tellraw @a [{"text": "Noise: ", "color": "dark_gray"},{"nbt":"white_noise_mat_2d","storage":"bs:out", "color": "gold"}] @@ -395,10 +399,11 @@ Generates a 2D simplex noise texture of size `width` by `height`. Simplex noise - {nbt}`compound` **with**: - {nbt}`int` **size**: Size of the noise "cell" (default: 16). Lower size means more detail. - {nbt}`int` **seed**: Seed for the noise generation, allowing for reproducibility (default: random). + - {nbt}`number` **scale**: Scalar for the function's output (default: 1). ::: :Outputs: - **Storage `bs:out random.simplex_noise_mat_2d`**: 2D array of values between -1 and 1. + **Storage `bs:out random.simplex_noise_mat_2d`**: 2D array of values between {-scale} and {scale}. ``` *Generate a 16×16 simplex noise pattern:* @@ -431,10 +436,11 @@ Generates a 2D fractal noise texture of size `width` by `height`. Fractal noise - {nbt}`int` **octaves**: Number of noise layers (default: 4). More octaves = more detail. - {nbt}`double` **persistence**: Contribution of each octave (default: 0.5). Higher means more detail. - {nbt}`double` **lacunarity**: Increase in frequency for each octave (default: 2.0). Higher means more rapid frequency increase. + - {nbt}`number` **scale**: Scalar for the function's output (default: 1). ::: :Outputs: - **Storage `bs:out random.fractal_noise_mat_2d`**: 2D array of values between -1 and 1. + **Storage `bs:out random.fractal_noise_mat_2d`**: 2D array of values between {-scale} and {scale}. ``` *Generate a 16×16 fractal noise pattern:*