Skip to content
Closed
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
2 changes: 1 addition & 1 deletion beet/contrib/dbg.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def level_ranks(self) -> Dict[str, int]:

def render_preview(self, path: str, lineno: int) -> TextComponent:
"""Render the preview as a text component."""
function = self.ctx.data.functions[path]
function = self.ctx.data.function[path]
lines = function.text.splitlines()

preview_start = max(lineno - 1 - self.opts.preview_padding, 0)
Expand Down
4 changes: 2 additions & 2 deletions beet/contrib/hangman.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def hangman(ctx: Context, opts: HangmanOptions):
"""Plugin that provides indentation-based syntactic extensions for functions."""
logger.warning("Deprecated in favor of mecha (https://github.com/mcbeet/mecha).")

for path in ctx.data.functions.match(*opts.match):
function = ctx.data.functions[path]
for path in ctx.data.function.match(*opts.match):
function = ctx.data.function[path]
function.lines = list(
fold_hanging_commands(ctx, parse_lines(function.lines), path)
)
Expand Down
4 changes: 2 additions & 2 deletions beet/contrib/inline_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def _function_handler(self, path: str, op: str, caller: Any) -> str:
if op == "replace":
self.ctx.data[path] = function
elif op == "append":
self.ctx.data.functions.setdefault(path, Function()).append(function)
self.ctx.data.function.setdefault(path, Function()).append(function)
elif op == "prepend":
self.ctx.data.functions.setdefault(path, Function()).prepend(function)
self.ctx.data.function.setdefault(path, Function()).prepend(function)

return ""
4 changes: 2 additions & 2 deletions beet/contrib/vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ def __init__(
elif opts and opts.version:
self.minecraft_version = opts.version
elif ctx:
self.minecraft_version = f"{ctx.minecraft_version}.*"
self.minecraft_version = ctx.minecraft_version
else:
self.minecraft_version = f"{LATEST_MINECRAFT_VERSION}.*"
self.minecraft_version = LATEST_MINECRAFT_VERSION

def mount(
self,
Expand Down
2 changes: 1 addition & 1 deletion beet/library/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@

from .utils import list_extensions, list_origin_folders

LATEST_MINECRAFT_VERSION: str = "1.20"
LATEST_MINECRAFT_VERSION: str = "1.21"


T = TypeVar("T")
Expand Down
59 changes: 30 additions & 29 deletions beet/library/data_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
class Advancement(JsonFile):
"""Class representing an advancement."""

scope: ClassVar[Tuple[str, ...]] = ("advancements",)
scope: ClassVar[Tuple[str, ...]] = ("advancement",)
extension: ClassVar[str] = ".json"


Expand Down Expand Up @@ -96,7 +96,7 @@ class Function(TextFileBase[List[str]]):
tags: Optional[List[str]] = extra_field(default=None)
prepend_tags: Optional[List[str]] = extra_field(default=None)

scope: ClassVar[Tuple[str, ...]] = ("functions",)
scope: ClassVar[Tuple[str, ...]] = ("function",)
extension: ClassVar[str] = ".mcfunction"

lines: ClassVar[FileDeserialize[List[str]]] = FileDeserialize()
Expand Down Expand Up @@ -143,28 +143,28 @@ def bind(self, pack: "DataPack", path: str):
class ItemModifier(JsonFile):
"""Class representing an item modifier."""

scope: ClassVar[Tuple[str, ...]] = ("item_modifiers",)
scope: ClassVar[Tuple[str, ...]] = ("item_modifier",)
extension: ClassVar[str] = ".json"


class LootTable(JsonFile):
"""Class representing a loot table."""

scope: ClassVar[Tuple[str, ...]] = ("loot_tables",)
scope: ClassVar[Tuple[str, ...]] = ("loot_table",)
extension: ClassVar[str] = ".json"


class Predicate(JsonFile):
"""Class representing a predicate."""

scope: ClassVar[Tuple[str, ...]] = ("predicates",)
scope: ClassVar[Tuple[str, ...]] = ("predicate",)
extension: ClassVar[str] = ".json"


class Recipe(JsonFile):
"""Class representing a recipe."""

scope: ClassVar[Tuple[str, ...]] = ("recipes",)
scope: ClassVar[Tuple[str, ...]] = ("recipe",)
extension: ClassVar[str] = ".json"


Expand All @@ -174,19 +174,19 @@ class Structure(BinaryFileBase[StructureFileData]):

content: BinaryFileContent[StructureFileData] = None

scope: ClassVar[Tuple[str, ...]] = ("structures",)
scope: ClassVar[Tuple[str, ...]] = ("structure",)
extension: ClassVar[str] = ".nbt"

data: ClassVar[FileDeserialize[StructureFileData]] = FileDeserialize()

def from_bytes(self, content: bytes) -> StructureFileData:
with GzipFile(fileobj=io.BytesIO(content)) as fileobj:
return StructureFile.parse(fileobj).root
return StructureFile.parse(fileobj).root # type: ignore

def to_bytes(self, content: StructureFileData) -> bytes:
dst = io.BytesIO()
with GzipFile(fileobj=dst, mode="wb") as fileobj:
StructureFile(content).write(fileobj)
StructureFile(content).write(fileobj) # type: ignore
return dst.getvalue()


Expand Down Expand Up @@ -261,37 +261,37 @@ def default(cls) -> JsonDict:
class BlockTag(TagFile):
"""Class representing a block tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "blocks")
scope: ClassVar[Tuple[str, ...]] = ("tags", "block")


class EntityTypeTag(TagFile):
"""Class representing an entity tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "entity_types")
scope: ClassVar[Tuple[str, ...]] = ("tags", "entity_type")


class FluidTag(TagFile):
"""Class representing a fluid tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "fluids")
scope: ClassVar[Tuple[str, ...]] = ("tags", "fluid")


class FunctionTag(TagFile):
"""Class representing a function tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "functions")
scope: ClassVar[Tuple[str, ...]] = ("tags", "function")


class GameEventTag(TagFile):
"""Class representing a game event tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "game_events")
scope: ClassVar[Tuple[str, ...]] = ("tags", "game_event")


class ItemTag(TagFile):
"""Class representing an item tag."""

scope: ClassVar[Tuple[str, ...]] = ("tags", "items")
scope: ClassVar[Tuple[str, ...]] = ("tags", "item")


class ChatTypeTag(TagFile):
Expand All @@ -312,15 +312,15 @@ class DataPackNamespace(Namespace):
directory = "data"

# fmt: off
advancements: NamespacePin[Advancement] = NamespacePin(Advancement)
functions: NamespacePin[Function] = NamespacePin(Function)
item_modifiers: NamespacePin[ItemModifier] = NamespacePin(ItemModifier)
loot_tables: NamespacePin[LootTable] = NamespacePin(LootTable)
predicates: NamespacePin[Predicate] = NamespacePin(Predicate)
recipes: NamespacePin[Recipe] = NamespacePin(Recipe)
advancement: NamespacePin[Advancement] = NamespacePin(Advancement)
function: NamespacePin[Function] = NamespacePin(Function)
item_modifier: NamespacePin[ItemModifier] = NamespacePin(ItemModifier)
loot_table: NamespacePin[LootTable] = NamespacePin(LootTable)
predicate: NamespacePin[Predicate] = NamespacePin(Predicate)
recipe: NamespacePin[Recipe] = NamespacePin(Recipe)
trim_pattern: NamespacePin[TrimPattern] = NamespacePin(TrimPattern)
trim_material: NamespacePin[TrimMaterial] = NamespacePin(TrimMaterial)
structures: NamespacePin[Structure] = NamespacePin(Structure)
structure: NamespacePin[Structure] = NamespacePin(Structure)
chat_type: NamespacePin[ChatType] = NamespacePin(ChatType)
damage_type: NamespacePin[DamageType] = NamespacePin(DamageType)
banner_patterns: NamespacePin[BannerPattern] = NamespacePin(BannerPattern)
Expand Down Expand Up @@ -350,19 +350,20 @@ class DataPack(Pack[DataPackNamespace]):
(1, 18): 9,
(1, 19): 12,
(1, 20): 41,
(1, 21): 48,
}
latest_pack_format = pack_format_registry[split_version(LATEST_MINECRAFT_VERSION)]

# fmt: off
advancements: NamespaceProxyDescriptor[Advancement] = NamespaceProxyDescriptor(Advancement)
functions: NamespaceProxyDescriptor[Function] = NamespaceProxyDescriptor(Function)
item_modifiers: NamespaceProxyDescriptor[ItemModifier] = NamespaceProxyDescriptor(ItemModifier)
loot_tables: NamespaceProxyDescriptor[LootTable] = NamespaceProxyDescriptor(LootTable)
predicates: NamespaceProxyDescriptor[Predicate] = NamespaceProxyDescriptor(Predicate)
recipes: NamespaceProxyDescriptor[Recipe] = NamespaceProxyDescriptor(Recipe)
advancement: NamespaceProxyDescriptor[Advancement] = NamespaceProxyDescriptor(Advancement)
function: NamespaceProxyDescriptor[Function] = NamespaceProxyDescriptor(Function)
item_modifier: NamespaceProxyDescriptor[ItemModifier] = NamespaceProxyDescriptor(ItemModifier)
loot_table: NamespaceProxyDescriptor[LootTable] = NamespaceProxyDescriptor(LootTable)
predicate: NamespaceProxyDescriptor[Predicate] = NamespaceProxyDescriptor(Predicate)
recipe: NamespaceProxyDescriptor[Recipe] = NamespaceProxyDescriptor(Recipe)
trim_pattern: NamespaceProxyDescriptor[TrimPattern] = NamespaceProxyDescriptor(TrimPattern)
trim_material: NamespaceProxyDescriptor[TrimMaterial] = NamespaceProxyDescriptor(TrimMaterial)
structures: NamespaceProxyDescriptor[Structure] = NamespaceProxyDescriptor(Structure)
structure: NamespaceProxyDescriptor[Structure] = NamespaceProxyDescriptor(Structure)
chat_type: NamespaceProxyDescriptor[ChatType] = NamespaceProxyDescriptor(ChatType)
damage_type: NamespaceProxyDescriptor[DamageType] = NamespaceProxyDescriptor(DamageType)
banner_patterns: NamespaceProxyDescriptor[BannerPattern] = NamespaceProxyDescriptor(BannerPattern)
Expand Down
1 change: 1 addition & 0 deletions beet/library/resource_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ class ResourcePack(Pack[ResourcePackNamespace]):
(1, 18): 8,
(1, 19): 13,
(1, 20): 32,
(1, 21): 34,
}
latest_pack_format = pack_format_registry[split_version(LATEST_MINECRAFT_VERSION)]

Expand Down
34 changes: 17 additions & 17 deletions docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ pack == {
Namespace containers are also available through attribute access. This is usually the syntax you'll be looking for as it's a bit more readable and provides better autocompletion.

```{code-cell}
demo_namespace.functions["foo"] is demo_namespace[Function]["foo"]
demo_namespace.function["foo"] is demo_namespace[Function]["foo"]
```

You can even omit the container entirely when adding files to the namespace. The namespace will dispatch the file to the appropriate container automatically depending on its type.

```{code-cell}
demo_namespace["bar"] = Function(["say world"])
demo_namespace.functions
demo_namespace.function
```

### Resource locations
Expand All @@ -81,15 +81,15 @@ Data pack objects let you access files in a single lookup with proxies that expo
```{code-cell}
pack = DataPack()

pack.functions["demo:foo"] = Function()
pack.functions["demo:foo"] is pack["demo"].functions["foo"]
pack.function["demo:foo"] = Function()
pack.function["demo:foo"] is pack["demo"].function["foo"]
```

Proxy attributes are always in sync with the underlying namespaces. You can also omit the attribute when adding files to data packs. The data pack object will dispatch the file to the appropriate proxy depending on its type.

```{code-cell}
pack["demo:bar"] = Function()
pack.functions == {
pack.function == {
"demo:foo": Function(),
"demo:bar": Function(),
}
Expand Down Expand Up @@ -272,17 +272,17 @@ pack.match("d*")
```

```{code-cell}
pack["demo"].functions.match("f*")
pack["demo"].function.match("f*")
```

```{code-cell}
pack.functions.match("demo:*")
pack.function.match("demo:*")
```

You can specify multiple patterns. The exclamation mark lets you invert a pattern.

```{code-cell}
pack.functions.match("demo:*", "!demo:foo")
pack.function.match("demo:*", "!demo:foo")
```

## File handles
Expand Down Expand Up @@ -420,14 +420,14 @@ The files used in data packs and resource packs are derived from the core file h

```{code-cell}
pack = DataPack(path="../examples/load_basic/src")
pack.functions["demo:foo"]
pack.function["demo:foo"]
```

As you can see, when we load an unzipped data pack all the files remain in their unloaded state. The moment we start interacting with the content of the function `beet` will load the file automatically.

```{code-cell}
pack.functions["demo:foo"].lines.append("say bar")
pack.functions["demo:foo"]
pack.function["demo:foo"].lines.append("say bar")
pack.function["demo:foo"]
```

## The toolchain
Expand Down Expand Up @@ -457,11 +457,11 @@ out
└── greeting_data_pack
├── data
│ ├── greeting
│ │ └── functions
│ │ └── function
│ │ └── hello.mcfunction
│ └── minecraft
│ └── tags
│ └── functions
│ └── function
│ └── load.json
└── pack.mcmeta

Expand Down Expand Up @@ -518,11 +518,11 @@ out
└── greeting_data_pack
├── data
│ ├── greeting
│ │ └── functions
│ │ └── function
│ │ └── hello.mcfunction
│ └── minecraft
│ └── tags
│ └── functions
│ └── function
│ └── load.json
└── pack.mcmeta

Expand Down Expand Up @@ -558,11 +558,11 @@ out
├── greeting_data_pack
│ ├── data
│ │ ├── greeting
│ │ │ └── functions
│ │ │ └── function
│ │ │ └── hello.mcfunction
│ │ └── minecraft
│ │ └── tags
│ │ └── functions
│ │ └── function
│ │ └── load.json
│ └── pack.mcmeta
└── greeting_resource_pack
Expand Down
2 changes: 1 addition & 1 deletion examples/code_draft/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ def beet_default(ctx: Context):
draft.cache("demo", f"{message=}", zipped=True)
draft.data["demo:message"] = Function([f"say {message}"])

ctx.data.functions["demo:message"].lines *= 2
ctx.data.function["demo:message"].lines *= 2
4 changes: 2 additions & 2 deletions examples/code_mount/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@


def beet_default(ctx: Context):
ctx.data.mount("data/demo/functions", ctx.directory / "src")
ctx.data.mount("data/owo/functions/foo.mcfunction", ctx.directory / "src/thing.txt")
ctx.data.mount("data/demo/function", ctx.directory / "src")
ctx.data.mount("data/owo/function/foo.mcfunction", ctx.directory / "src/thing.txt")
ctx.data.mount("pack.mcmeta", ctx.directory / "pack.mcmeta")
ctx.assets.mount("assets/minecraft", ctx.directory / "src")
ctx.assets.mount("assets/other/sounds.json", ctx.directory / "src/sounds.json")
Expand Down
4 changes: 2 additions & 2 deletions examples/code_mount_load/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def beet_default(ctx: Context):
ctx.require(
load(
data_pack={
"data/demo/functions": ctx.directory / "src",
"data/owo/functions/foo.mcfunction": ctx.directory / "src/thing.txt",
"data/demo/function": ctx.directory / "src",
"data/owo/function/foo.mcfunction": ctx.directory / "src/thing.txt",
"pack.mcmeta": ctx.directory / "pack.mcmeta",
},
resource_pack={
Expand Down
2 changes: 1 addition & 1 deletion examples/code_sandbox/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def beet_default(ctx: Context):

def add_function(name: str):
def plugin(ctx: Context):
function_count = len(ctx.data.functions)
function_count = len(ctx.data.function)
last_function = ctx.meta.get("last_function")
ctx.data[name] = Function([f"say {function_count=} {last_function=}"])
ctx.meta["last_function"] = name
Expand Down
2 changes: 1 addition & 1 deletion examples/code_worker/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def other(ctx: Context):

yield

ctx.data["demo:function_count"] = Function([f"say {len(ctx.data.functions)}"])
ctx.data["demo:function_count"] = Function([f"say {len(ctx.data.function)}"])

for name, function in channel:
ctx.data[name] = function
Expand Down
2 changes: 1 addition & 1 deletion examples/load_broadcast_extend/libs/bar/beet.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
data_pack:
load:
data/bar/functions: "src"
data/bar/function: "src"
Loading