Skip to content

Commit

Permalink
test: update operation_nbt_type
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWii committed Jan 23, 2024
1 parent 3d0c760 commit c2b27d4
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
46 changes: 45 additions & 1 deletion examples/operation_nbt_type/src/main.mcfunction
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from bolt_expressions import Scoreboard, Data
from nbtlib import Byte, Short, Int, Long, Float, Double
from typing import Any

obj = Scoreboard("obj")
temp = Data.storage("demo")
Expand Down Expand Up @@ -35,4 +37,46 @@ say temp.c will be scaled and converted to a double (preserve precision)
temp.bar = temp.c / 10

say force temp.c to be truncated
temp.bar = Data.cast(temp.c / 10, "int")
temp.bar = Data.cast(temp.c / 10, "int")


say score is casted to int
temp.value = obj["@s"]
say score is casted to double
temp.value = obj["@s"] / 10

temp.value[Byte] = obj["@s"]

temp.value[Double] = (temp.x1 * 100 + temp.x2 * 100) / 200


say casting to byte before appending to list
temp.value[Byte] = obj['$value']
temp.list.append(temp.value)

say or use Data.cast
temp.list.append(Data.cast(obj['$value'], Byte))


x = temp.x[Double]

say casts y to double
x = temp.y

say only copies the value
x = temp.y[Double]


z = temp.z[Double]

say no cast
x = z

x = z[Any]
say casts z to double

say no cast (type of x is temporarely overwritten)
x[Any] = temp.arbitrary

say casts to a double
x = temp.arbitrary
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,30 @@ execute store result storage demo bar double 0.1 run data get storage demo c 1
say force temp.c to be truncated
execute store result storage bolt.expr:temp 2384k242hd495_10 int 0.1 run data get storage demo c 1
data modify storage demo bar set from storage bolt.expr:temp 2384k242hd495_10
say score is casted to int
execute store result storage demo value int 1 run scoreboard players get @s obj
say score is casted to double
execute store result storage demo value double 0.1 run scoreboard players get @s obj
execute store result storage demo value byte 1 run scoreboard players get @s obj
execute store result score $i0 bolt.expr.temp run data get storage demo x1 100
execute store result score $i1 bolt.expr.temp run data get storage demo x2 100
scoreboard players operation $i0 bolt.expr.temp += $i1 bolt.expr.temp
execute store result storage demo value double 0.005 run scoreboard players get $i0 bolt.expr.temp
say casting to byte before appending to list
execute store result storage demo value byte 1 run scoreboard players get $value obj
data modify storage demo list append from storage demo value
say or use Data.cast
execute store result storage bolt.expr:temp 2384k242hd495_11 byte 1 run scoreboard players get $value obj
data modify storage demo list append from storage bolt.expr:temp 2384k242hd495_11
say casts y to double
execute store result storage demo x double 1 run data get storage demo y 1
say only copies the value
data modify storage demo x set from storage demo y
say no cast
data modify storage demo x set from storage demo z
execute store result storage demo x double 1 run data get storage demo z 1
say casts z to double
say no cast (type of x is temporarely overwritten)
data modify storage demo x set from storage demo arbitrary
say casts to a double
execute store result storage demo x double 1 run data get storage demo arbitrary 1

0 comments on commit c2b27d4

Please sign in to comment.