Skip to content

v0.14.0

Compare
Choose a tag to compare
@github-actions github-actions released this 05 Feb 16:17
· 34 commits to main since this release

Feature

  • Operations now return lazy sources (6832b91)
a = 5 + obj["@s"] / 2
# $2384k242hd495_2 bolt.expr.temp (generated name)
# does not emit any command yet

print(a.is_lazy()) # True

obj["$value"] = obj["$b"] * a
# expanded on expression while it's lazy.
# might produce repeated commands if "a" switches
# to early evaluation later on.

a.evaluate()
# triggers early evaluation of "a".
# commands are inserted where "a" was originally evaluated.

print(a.is_lazy()) # False

obj["$value2"] = a # copies "a"
  • Support dicts, lists, arrays and union types as data source types (1097f5f)
class Item(TypedDict): # from the typing module
    id: str
    Count: Byte # from nbtlib
    tag: dict[str, Any]

hotbar = storage.hotbar[list[Item]]
first_item = hotbar[0]
first_item.Count = obj["$count"]
# execute store result storage ... hotbar[0].Count byte 1 run scoreboard players get ...
first_item.id = 5
# "Int" does not match "String"

hotbar.append({id: "stone"})
# "{id: String}" is missing required key "Count" of type "Byte"

hotbar[0].merge({x:5})
# "{x: Int}" has extra key "x" not present in "Item"

hotbar = [1, 2, 3]
# Elements of "list[Int]" and "list[Item]" are not compatible
# "Int" is not a compound type with fixed keys and is not compatible with "Item"

message = storage.msg[str | list[str]]

message = ["hello", "world"]
# fine
message = "hello world"
# fine
message = [{a: "b"}, {b: 5}]
# "list[{a: String} | {b: Int}]" is not compatible with "String | list[String]"
  • Numeric literal casting (9874ca9)
storage.pos[list[Double]] = [43, 0, 5]
# [43.0d, 0.0d, 5.0d]

storage.item[Item] = {id: "glass", Count: 5, tag: {}}
# {id: "glass", Count: 5b, tag: {}}

storage.flag[Byte] = 128
# raises an exception because 128 can't be represented as Byte.

storage.number[Byte | Long] = 4 # can't cast when write type is a union
# "Int" is not compatible with "Byte | Long"

storage.number[Byte | None] = 4 # only if it's optional
# 4b
  • Separate data source interfaces for each nbt type (dbe9a74)
storage.msg[str] - 1
# TypeError: unsupported operand type(s) for -: 'DataSource' and 'int'

storage.value[int].oops
# TypeError: Data source of type 'Int' does not have named keys

storage.c[dict[str, Any]][0]
# TypeError: Data source of type 'dict[String, typing.Any]' object is not indexable

storage.arr[list[int]]({a: 0})
# TypeError: Data source of type 'list[Int]' does not support compound matching

Fix

  • Only cast numeric nbt types (86d49b1)