Skip to content

Commit

Permalink
Merge branch 'main' of github.com:moxvallix/moxlib
Browse files Browse the repository at this point in the history
  • Loading branch information
moxvallix committed Mar 31, 2023
2 parents a0bdd30 + e7d58f5 commit c31fc0d
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 3 deletions.
1 change: 1 addition & 0 deletions data/moxlib/functions/api/data/array/slice.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
execute unless data storage moxlib:data/private {lock:true} run function moxlib:data/array/slice/init
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function moxlib:math/string_to_integer/init
3 changes: 3 additions & 0 deletions data/moxlib/functions/api/verify.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
data modify storage moxlib:api/verify output set value true

schedule function moxlib:verify/cleanup 1t
3 changes: 2 additions & 1 deletion data/moxlib/functions/data/_objectives.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ scoreboard objectives add moxlib.data.get dummy
scoreboard objectives add moxlib.data.set dummy
scoreboard objectives add moxlib.data.collect dummy
scoreboard objectives add moxlib.data.compare dummy
scoreboard objectives add moxlib.data.paginate dummy
scoreboard objectives add moxlib.data.paginate dummy
function moxlib:data/array/_objectives
1 change: 1 addition & 0 deletions data/moxlib/functions/data/array/_objectives.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scoreboard objectives add moxlib.data.array.slice dummy
8 changes: 8 additions & 0 deletions data/moxlib/functions/data/array/slice/cleanup.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
data remove storage moxlib:api/data/array/slice target
data remove storage moxlib:api/data/array/slice start
data remove storage moxlib:api/data/array/slice end

execute if data storage moxlib:api/data/array/slice {success:false} run data remove storage moxlib:api/data/array/slice output

execute unless data storage moxlib:api/data/array/slice {success:false} run data remove storage moxlib:api/data/array/slice error
execute unless data storage moxlib:api/data/array/slice {success:false} run data modify storage moxlib:api/data/array/slice success set value true
7 changes: 7 additions & 0 deletions data/moxlib/functions/data/array/slice/init.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function moxlib:data/common/setup
function moxlib:data/array/slice/setup

execute unless data storage moxlib:api/data/array/slice {success:false} run function moxlib:data/array/slice/loop

function moxlib:data/array/slice/cleanup
function moxlib:data/common/cleanup
4 changes: 4 additions & 0 deletions data/moxlib/functions/data/array/slice/loop.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
execute if score $index moxlib.data.array.slice >= $start moxlib.data.array.slice if score $index moxlib.data.array.slice < $end moxlib.data.array.slice run data modify storage moxlib:api/data/array/slice output append from storage moxlib:api/data/array/slice target[0]
data remove storage moxlib:api/data/array/slice target[0]
scoreboard players add $index moxlib.data.array.slice 1
execute if score $index moxlib.data.array.slice < $end moxlib.data.array.slice if data storage moxlib:api/data/array/slice target[0] run function moxlib:data/array/slice/loop
11 changes: 11 additions & 0 deletions data/moxlib/functions/data/array/slice/setup.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data remove storage moxlib:api/data/array/slice success

data modify storage moxlib:api/data/array/slice output set value []
scoreboard players set $index moxlib.data.array.slice 0
execute store result score $start moxlib.data.array.slice run data get storage moxlib:api/data/array/slice start
execute store result score $end moxlib.data.array.slice run data get storage moxlib:api/data/array/slice end
execute unless score $start moxlib.data.array.slice matches 0.. run scoreboard players set $start moxlib.data.array.slice 0
execute unless score $end moxlib.data.array.slice matches 1.. unless data storage moxlib:api/data/array/slice end run scoreboard players set $end moxlib.data.array.slice 2147483647

execute if score $start moxlib.data.array.slice > $end moxlib.data.array.slice run data modify storage moxlib:api/data/array/slice success set value false
execute if score $start moxlib.data.array.slice > $end moxlib.data.array.slice run data modify storage moxlib:api/data/array/slice error set value "End cannot be less than start"
3 changes: 2 additions & 1 deletion data/moxlib/functions/math/_objectives.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ scoreboard objectives add moxlib.api.math.random dummy
scoreboard objectives add moxlib.api.math.power dummy
scoreboard objectives add moxlib.api.math.misc.fish dummy

scoreboard objectives add moxlib.math.array_to_integer dummy
scoreboard objectives add moxlib.math.array_to_integer dummy
scoreboard objectives add moxlib.math.string_to_integer dummy
14 changes: 14 additions & 0 deletions data/moxlib/functions/math/string_to_integer/init.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
data modify storage moxlib:api/math/string_to_integer success set value true

data modify storage moxlib:api/string/to_array target set from storage moxlib:api/math/string_to_integer target
function moxlib:api/string/to_array

data modify storage moxlib:api/math/array_to_integer target set value []
execute unless data storage moxlib:api/string/to_array output[0] run data modify storage moxlib:api/math/string_to_integer success set value false
execute if data storage moxlib:api/string/to_array output[0] run function moxlib:math/string_to_integer/iterate

execute if data storage moxlib:api/math/string_to_integer {success:true} run function moxlib:api/math/array_to_integer

data modify storage moxlib:api/math/string_to_integer output set from storage moxlib:api/math/array_to_integer output
execute if data storage moxlib:api/math/string_to_integer {success:false} run data remove storage moxlib:api/math/string_to_integer output
data remove storage moxlib:api/math/string_to_integer target
22 changes: 22 additions & 0 deletions data/moxlib/functions/math/string_to_integer/iterate.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
data modify storage moxlib:math/string_to_integer digit set from storage moxlib:api/string/to_array output[0]

scoreboard players set $digit moxlib.math.string_to_integer -1

execute if data storage moxlib:math/string_to_integer {digit:"0"} run scoreboard players set $digit moxlib.math.string_to_integer 0
execute if data storage moxlib:math/string_to_integer {digit:"1"} run scoreboard players set $digit moxlib.math.string_to_integer 1
execute if data storage moxlib:math/string_to_integer {digit:"2"} run scoreboard players set $digit moxlib.math.string_to_integer 2
execute if data storage moxlib:math/string_to_integer {digit:"3"} run scoreboard players set $digit moxlib.math.string_to_integer 3
execute if data storage moxlib:math/string_to_integer {digit:"4"} run scoreboard players set $digit moxlib.math.string_to_integer 4
execute if data storage moxlib:math/string_to_integer {digit:"5"} run scoreboard players set $digit moxlib.math.string_to_integer 5
execute if data storage moxlib:math/string_to_integer {digit:"6"} run scoreboard players set $digit moxlib.math.string_to_integer 6
execute if data storage moxlib:math/string_to_integer {digit:"7"} run scoreboard players set $digit moxlib.math.string_to_integer 7
execute if data storage moxlib:math/string_to_integer {digit:"8"} run scoreboard players set $digit moxlib.math.string_to_integer 8
execute if data storage moxlib:math/string_to_integer {digit:"9"} run scoreboard players set $digit moxlib.math.string_to_integer 9

execute if score $digit moxlib.math.string_to_integer matches -1 run data modify storage moxlib:api/math/string_to_integer success set value false
execute store result storage moxlib:math/string_to_integer digit byte 1 run scoreboard players get $digit moxlib.math.string_to_integer
execute if data storage moxlib:api/math/string_to_integer {success:true} run data modify storage moxlib:api/math/array_to_integer target append from storage moxlib:math/string_to_integer digit

data remove storage moxlib:api/string/to_array output[0]

execute if data storage moxlib:api/string/to_array output[0] if data storage moxlib:api/math/string_to_integer {success:true} run function moxlib:math/string_to_integer/iterate
3 changes: 2 additions & 1 deletion data/moxlib/functions/spec/data/_perform.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ function moxlib:spec/data/compare_same
function moxlib:spec/data/get
function moxlib:spec/data/includes
function moxlib:spec/data/not_includes
function moxlib:spec/data/set
function moxlib:spec/data/set
function moxlib:spec/data/array/_perform
1 change: 1 addition & 0 deletions data/moxlib/functions/spec/data/array/_perform.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
function moxlib:spec/data/array/slice
67 changes: 67 additions & 0 deletions data/moxlib/functions/spec/data/array/slice.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
data modify storage moxlib:api/data/array/slice target set value [1,2,3,4,5,6,7,8,9]

function moxlib:api/data/array/slice

data modify storage moxlib:test/it describes set value "An array sliced with no start or end"
data modify storage moxlib:test/it expects set value [1,2,3,4,5,6,7,8,9]
data modify storage moxlib:test/it receives set from storage moxlib:api/data/array/slice output

function moxlib:api/test/perform

data modify storage moxlib:api/data/array/slice target set value [1,2,3,4,5,6,7,8,9]
data modify storage moxlib:api/data/array/slice start set value 2

function moxlib:api/data/array/slice

data modify storage moxlib:test/it describes set value "An array sliced with no end"
data modify storage moxlib:test/it expects set value [3,4,5,6,7,8,9]
data modify storage moxlib:test/it receives set from storage moxlib:api/data/array/slice output

function moxlib:api/test/perform

data modify storage moxlib:api/data/array/slice target set value [1,2,3,4,5,6,7,8,9]
data modify storage moxlib:api/data/array/slice end set value 7

function moxlib:api/data/array/slice

data modify storage moxlib:test/it describes set value "An array sliced with no start"
data modify storage moxlib:test/it expects set value [1,2,3,4,5,6,7]
data modify storage moxlib:test/it receives set from storage moxlib:api/data/array/slice output

function moxlib:api/test/perform

data modify storage moxlib:api/data/array/slice target set value [1,2,3,4,5,6,7,8,9]
data modify storage moxlib:api/data/array/slice start set value 4
data modify storage moxlib:api/data/array/slice end set value 7

function moxlib:api/data/array/slice

data modify storage moxlib:test/it describes set value "A slice operation"
data modify storage moxlib:test/it expects set value [5,6,7]
data modify storage moxlib:test/it receives set from storage moxlib:api/data/array/slice output

function moxlib:api/test/perform

data modify storage moxlib:api/data/array/slice target set value [1,2,3,4,5,6,7,8,9]
data modify storage moxlib:api/data/array/slice start set value 4
data modify storage moxlib:api/data/array/slice end set value 4

function moxlib:api/data/array/slice

data modify storage moxlib:test/it describes set value "A slice operation with zero magnitude"
data modify storage moxlib:test/it expects set value []
data modify storage moxlib:test/it receives set from storage moxlib:api/data/array/slice output

function moxlib:api/test/perform

data modify storage moxlib:api/data/array/slice target set value [1,2,3,4,5,6,7,8,9]
data modify storage moxlib:api/data/array/slice start set value 4
data modify storage moxlib:api/data/array/slice end set value 2

function moxlib:api/data/array/slice

data modify storage moxlib:test/it describes set value "A slice operation with the end less than the start"
data modify storage moxlib:test/it expects set value {success:0b,error:"End cannot be less than start"}
data modify storage moxlib:test/it receives set from storage moxlib:api/data/array/slice {}

function moxlib:api/test/perform
1 change: 1 addition & 0 deletions data/moxlib/functions/verify/cleanup.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data remove storage moxlib:api/verify output

0 comments on commit c31fc0d

Please sign in to comment.