Skip to content

Commit

Permalink
Update beet to official 1.21 versions (Gamemode4Dev#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
misode authored Aug 14, 2024
1 parent 738cf07 commit fd51c5e
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 331 deletions.
2 changes: 1 addition & 1 deletion gm4/plugins/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def write_credits(ctx: Context):

def write_updates(ctx: Context):
"""Writes the module update commands to this module's init function."""
init = ctx.data.function.get(f"{ctx.project_id}:init", None)
init = ctx.data.functions.get(f"{ctx.project_id}:init", None)
if init is None:
return

Expand Down
4 changes: 2 additions & 2 deletions gm4/plugins/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def default_pack_icon(ctx: Context):

def gm4_root_advancement(ctx: Context):
"""Adds the root display advancement gm4:root, if the module has any display advancements"""
if len(ctx.data["gm4"].advancement.keys()) > 0:
ctx.data.advancement["gm4:root"] = Advancement(
if len(ctx.data["gm4"].advancements.keys()) > 0:
ctx.data.advancements["gm4:root"] = Advancement(
{
"display": {
"icon": {
Expand Down
6 changes: 3 additions & 3 deletions gm4/plugins/player_heads.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import Any, Callable, ClassVar

import requests
from beet import Context, FileDeserialize, JsonFile, PngFile
from beet import Context, FileDeserialize, JsonFile, PngFile, NamespaceFileScope
from mecha import Diagnostic, Mecha, MutatingReducer, rule
from mecha.ast import (
AstJsonObject,
Expand Down Expand Up @@ -43,7 +43,7 @@ def beet_default(ctx: Context):

class Skin(PngFile):
"""Class representing a skin texture file."""
scope: ClassVar[tuple[str, ...]] = ("skins",)
scope: ClassVar[NamespaceFileScope] = ("skins",)
extension: ClassVar[str] = ".png"
image: ClassVar[FileDeserialize[Image]] = FileDeserialize() # purely here to solve type-warnings on PIL images

Expand Down Expand Up @@ -135,7 +135,7 @@ def mineskin_upload(self, skin: Skin, filename: str) -> tuple[str|None, list[int
token = self.ctx.inject(MineskinAuthManager).token

buf = BytesIO()
skin.image.save(buf, format="PNG")
skin.image.save(buf, format="PNG") # type: ignore
res = requests.post(
url='https://api.mineskin.org/generate/upload',
data={"name":"GM4_Skin", "visibility":0},
Expand Down
8 changes: 4 additions & 4 deletions gm4/plugins/prefabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def structure_deep_rename(ctx: Context, find_namespace: str, repl_namespace: str
}))

# rename structure-file references
for s in ctx.data.structure:
blocks = ctx.data.structure[s].data["blocks"].snbt() # type: ignore ; nbtlib typing missing
for s in ctx.data.structures:
blocks = ctx.data.structures[s].data["blocks"].snbt() # type: ignore ; nbtlib typing missing
updated_blocks_data = re.sub(f"{find_namespace}:([a-z0-9_/]+)", f"{repl_namespace}:\\1", blocks) # type: ignore ; nbtlib typing missing
ctx.data.structure[s].serializer = repro_structure_to_bytes
ctx.data.structure[s].data["blocks"] = nbtlib.parse_nbt(updated_blocks_data) # type: ignore ; nbtlib typing missing
ctx.data.structures[s].serializer = repro_structure_to_bytes
ctx.data.structures[s].data["blocks"] = nbtlib.parse_nbt(updated_blocks_data) # type: ignore ; nbtlib typing missing
14 changes: 7 additions & 7 deletions gm4/plugins/test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from beet import Context, TextFile
from typing import ClassVar, Tuple
from beet import Context, TextFile, NamespaceFileScope
from typing import ClassVar
from mecha import Mecha


Expand All @@ -10,15 +10,15 @@ def load_tests(ctx: Context):
class TestFile(TextFile):
"""Class representing an test function."""

scope: ClassVar[Tuple[str, ...]] = ("test",)
scope: ClassVar[NamespaceFileScope] = ("test",)
extension: ClassVar[str] = ".mcfunction"


def strip_tests(ctx: Context):
for structure in ctx.data.structure.match("*:test_*", "*:test/*"):
del ctx.data.structure[structure]
for predicate in ctx.data.predicate.match("*:test_*", "*:test/*"):
del ctx.data.predicate[predicate]
for structure in ctx.data.structures.match("*:test_*", "*:test/*"):
del ctx.data.structures[structure]
for predicate in ctx.data.predicates.match("*:test_*", "*:test/*"):
del ctx.data.predicates[predicate]


def skip_mecha_lint(ctx: Context):
Expand Down
4 changes: 2 additions & 2 deletions gm4/plugins/upgrade_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def beet_default(ctx: Context, opts: UpgradePathsConfig):
score_holder = ctx.project_id.removeprefix('gm4_')
newest_version_with_upgrades = 0.0
for ns, direc in map(lambda a: a.split(':'), upgrade_paths_dirs):
upgrade_paths_tree = ctx.data[ns].function.generate_tree(direc)
upgrade_paths_tree = ctx.data[ns].functions.generate_tree(direc)
if upgrade_paths_tree:
newest_version_with_upgrades = max(newest_version_with_upgrades, max(map(float, upgrade_paths_tree.keys())))
for path in upgrade_paths_tree.keys():
Expand All @@ -42,6 +42,6 @@ def lib(ctx: Context):
if ver.patch is None:
ver.patch = 0 # when beet-dev is run, pipeline has no patch number record, but dev builds should still allow int conversion
ver_int = ver.int_rep()
ctx.data.function[f'{ctx.project_id}:load'].append(f'execute unless score {score_holder} gm4_earliest_version matches ..{ver_int} run scoreboard players set {score_holder} gm4_earliest_version {ver_int}')
ctx.data.functions[f'{ctx.project_id}:load'].append(f'execute unless score {score_holder} gm4_earliest_version matches ..{ver_int} run scoreboard players set {score_holder} gm4_earliest_version {ver_int}')

beet_default(ctx)
20 changes: 10 additions & 10 deletions gm4/plugins/versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def modules(ctx: Context, opts: VersioningConfig):
namespaced_function = f"{ctx.project_id}:{function}" if ":" not in function else function
lines.append(f"execute unless score {ctx.project_id} load.status matches {module_ver.major} run schedule clear {namespaced_function}")

ctx.data.function[f"{ctx.project_id}:load"] = Function(lines)
ctx.data.functions[f"{ctx.project_id}:load"] = Function(lines)

# load.json tag
ctx.data.function_tags["load:load"] = FunctionTag({
Expand All @@ -84,7 +84,7 @@ def modules(ctx: Context, opts: VersioningConfig):

# inject module load success checks (load.status 1..) into technical and display advancements
# advancements get score checks injected into every criteria
versioned_advancements(ctx, Version("X.X.X"), [a for a in ctx.data.advancement.keys() if not a=="gm4:root"], False)
versioned_advancements(ctx, Version("X.X.X"), [a for a in ctx.data.advancements.keys() if not a=="gm4:root"], False)

@configurable("gm4.versioning", validator=VersioningConfig)
def libraries(ctx: Context, opts: VersioningConfig):
Expand Down Expand Up @@ -120,7 +120,7 @@ def libraries(ctx: Context, opts: VersioningConfig):
lines.append(dep_check_line + f"{ctx.project_id}_minor load.status {lib_ver.minor}")
lines.append(dep_check_line + f"{ctx.project_id} load.status {lib_ver.major}")

ctx.data.function[f"{ctx.project_id}:enumerate"] = Function(lines)
ctx.data.functions[f"{ctx.project_id}:enumerate"] = Function(lines)

# resolve_load.mcfunction
lines = [f"execute if score {ctx.project_id} load.status matches {lib_ver.major} if score {ctx.project_id}_minor load.status matches {lib_ver.minor} run function {ctx.project_id}:load"]
Expand All @@ -129,7 +129,7 @@ def libraries(ctx: Context, opts: VersioningConfig):
lines.append(f"execute unless score {ctx.project_id} load.status matches {lib_ver.major} run schedule clear {ctx.project_id}:{func}")
lines.append(f"execute unless score {ctx.project_id}_minor load.status matches {lib_ver.minor} run schedule clear {ctx.project_id}:{func}")

ctx.data.function[f"{ctx.project_id}:resolve_load"] = Function(lines)
ctx.data.functions[f"{ctx.project_id}:resolve_load"] = Function(lines)

# load/tags {{ lib name }}.json
ctx.data.function_tags[f"load:{ctx.project_id}"] = FunctionTag({
Expand Down Expand Up @@ -175,7 +175,7 @@ def libraries(ctx: Context, opts: VersioningConfig):
))

# stamp version number and module bring packaged into into load.mcfunction
handle = ctx.data.function[f"{ctx.project_id}:load"]
handle = ctx.data.functions[f"{ctx.project_id}:load"]
handle.append([
"\n",
f"data modify storage gm4:log versions append value {{id:\"{ctx.project_id}\",module:\"{ctx.project_id.replace('gm4', 'lib')}\",version:\"{ctx.project_version}\",from:\"{ctx.cache['currently_building'].json.get('name', 'standalone')}\"}}"
Expand All @@ -199,15 +199,15 @@ def base(ctx: Context, opts: VersioningConfig):
f"execute unless score gm4 load.status matches {ver.major}.. run scoreboard players set gm4_minor load.status {ver.minor}",
f"execute unless score gm4 load.status matches {ver.major}.. run scoreboard players set gm4 load.status {ver.major}"
]
ctx.data.function[f"gm4:enumerate"] = Function(lines)
ctx.data.functions[f"gm4:enumerate"] = Function(lines)

# resolve_load.mcfunction
lines = f"execute if score gm4 load.status matches {ver.major} if score gm4_minor load.status matches {ver.minor} run function gm4:load"
ctx.data.function[f"gm4:resolve_load"] = Function(lines)
ctx.data.functions[f"gm4:resolve_load"] = Function(lines)

# resolve_post_load.mcfunction
lines = f"execute if score gm4 load.status matches {ver.major} if score gm4_minor load.status matches {ver.minor} run function gm4:post_load"
ctx.data.function[f"gm4:resolve_post_load"] = Function(lines)
ctx.data.functions[f"gm4:resolve_post_load"] = Function(lines)

versioned_advancements(ctx, ver, opts.extra_version_injections.advancements, strict=True) #type:ignore

Expand Down Expand Up @@ -266,9 +266,9 @@ def versioned_advancements(ctx: Context, ver: Version, targets: list[str], stric

for entry in targets:
if ":" in entry:
handle = ctx.data.advancement[entry]
handle = ctx.data.advancements[entry]
else:
handle = ctx.data.advancement[f"{ctx.project_id}:{entry}"]
handle = ctx.data.advancements[f"{ctx.project_id}:{entry}"]
for criteria in handle.data["criteria"].values():
player_conditions = criteria.setdefault("conditions", {}).setdefault("player", [])
if type(player_conditions) is dict:
Expand Down
10 changes: 5 additions & 5 deletions gm4_auto_crafting/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def beet_default(ctx: Context):

recipes: list[RecipeData] = []

for id, recipe in vanilla.data.recipe.items():
for id, recipe in vanilla.data.recipes.items():
name = id.split(':')[1]
contents = recipe.data
if contents["type"] == "minecraft:crafting_shaped":
Expand Down Expand Up @@ -490,14 +490,14 @@ def generate_custom_item_tag(ctx: Context, data: TagData) -> str:

# write the function that checks the predicates
fn_name = f"{NAMESPACE}:check_item_tags"
if fn_name not in ctx.data.function:
ctx.data.function[fn_name] = Function([
if fn_name not in ctx.data.functions:
ctx.data.functions[fn_name] = Function([
"# checks each slot for item tags",
"# @s = crafter armor stand\n# located at the center of the block",
"# run from gm4_custom_crafters-3.0:process_input/check_item_tags via #gm4_custom_crafters:custom_item_checks",
"",
])
ctx.data.function[fn_name].append(f"execute if predicate {NAMESPACE}:custom_item_tags/{name} run data modify storage gm4_custom_crafters:temp/crafter item.item_tags.{NAMESPACE}.{name} set value 1b")
ctx.data.functions[fn_name].append(f"execute if predicate {NAMESPACE}:custom_item_tags/{name} run data modify storage gm4_custom_crafters:temp/crafter item.item_tags.{NAMESPACE}.{name} set value 1b")

# create predicate file for the item tag check
json: Any = {"condition":"minecraft:entity_properties","entity":"this","predicate":{"equipment":{"mainhand":{"items": f"#{NAMESPACE}:{name}"}}}}
Expand Down Expand Up @@ -560,7 +560,7 @@ def on_length_leaf(value: int, path: str):
# if this slot_count has recipes that use tags, then create a function that doesn't check total_length
if recipes_using_tags:
path_uses_tags = f"{path}/uses_tags"
ctx.data.function[f"{NAMESPACE}:{path}/search"].append(f"execute if score $crafted gm4_crafting matches 0 run function {NAMESPACE}:{path_uses_tags}")
ctx.data.functions[f"{NAMESPACE}:{path}/search"].append(f"execute if score $crafted gm4_crafting matches 0 run function {NAMESPACE}:{path_uses_tags}")
generate_recipe_function(ctx, recipes_using_tags, path_uses_tags)

# create a search tree based on the slot_count
Expand Down
2 changes: 1 addition & 1 deletion gm4_disassemblers/generate_disassembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
def beet_default(ctx: Context):
"""Creates a loot table for dropping the 9 result items when disassembling an item."""
vanilla = ctx.inject(Vanilla)
recipes = vanilla.data.recipe
recipes = vanilla.data.recipes

for item, durability in ITEMS.items():
recipe = recipes[f"minecraft:{item}"].data
Expand Down
9 changes: 5 additions & 4 deletions gm4_guidebook/generate_guidebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
LootTable,
Model,
NamespaceContainer,
NamespaceFileScope,
PngFile,
Texture,
)
Expand Down Expand Up @@ -63,14 +64,14 @@ class Book(BaseModel):

class GuidebookPages(JsonFileBase[Book]):
"""defines a custom beet filetype for guidebook pages"""
scope: ClassVar[tuple[str, ...]] = ("guidebook",)
scope: ClassVar[NamespaceFileScope] = ("guidebook",)
extension: ClassVar[str] = ".json"
data: ClassVar[FileDeserialize[Book]] = FileDeserialize()
model = Book # tell beet to parse this file using the Book data model

class CustomCrafterRecipe(JsonFile):
"""defines a custom beet filetype for CC recipes"""
scope: ClassVar[tuple[str, ...]] = ("gm4_recipes",)
scope: ClassVar[NamespaceFileScope] = ("gm4_recipes",)
extension: ClassVar[str] = ".json"

# NOTE in the future, this can be moved to wherever we auto-generate CC recipes from
Expand Down Expand Up @@ -785,7 +786,7 @@ def loottable_to_display(loottable: str, ctx: Context) -> tuple[TextComponent, T
else:
item = f"minecraft.{item}"

loot = ctx.data.loot_table[loottable].data
loot = ctx.data.loot_tables[loottable].data

if len(loot["pools"]) > 1:
raise ValueError("Loot table has multiple pools")
Expand Down Expand Up @@ -1840,7 +1841,7 @@ def generate_display_advancement(book: Book, project_id: str) -> Advancement:
"""
Creates the function that is granted when a section is unlocked
"""
def generate_reward_function(section: Section, book_id: str, book_name: str, desc: str) -> Function:
def generate_reward_function(section: Section, book_id: str, book_name: str, desc: Optional[str]) -> Function:
# check if any module needs to be loaded
if section.enable and len(section.enable) > 0:
start = "execute"
Expand Down
2 changes: 1 addition & 1 deletion gm4_standard_crafting/generate_recipes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def beet_default(ctx: Context):

vanilla = ctx.inject(Vanilla)
item_tags = vanilla.mount("data/minecraft/tags/item").data.item_tags
recipes = vanilla.mount("data/minecraft/recipe").data.recipe
recipes = vanilla.mount("data/minecraft/recipe").data.recipes

def recursive_apply(items: list[str], dir: str, shape: list[str], output_count: int):
for item in items:
Expand Down
Loading

0 comments on commit fd51c5e

Please sign in to comment.