def beet_default(ctx: Context): for lib in sorted(ctx.directory.glob("lib_*")): config = { "data_pack": { "load": [lib.name], }, "pipeline": ["demo.export_mcmeta"], } ctx.require(subproject(config)) with ctx.worker(bridge) as channel: # Request mcmeta files from the worker channel.send(None) final_mcmeta = JsonFile({ "pack": { "pack_format": 7, "description": "This is the root", }, "custom_data": 0, "libs": [], }) for mcmeta in channel: final_mcmeta.data["custom_data"] += mcmeta.data["custom_data"] final_mcmeta.data["libs"].append(mcmeta.data) ctx.data.mcmeta = final_mcmeta
def beet_default(ctx: Context): config = ctx.meta.get("render", {}) resource_pack = config.get("resource_pack") data_pack = config.get("data_pack") ctx.require(render(resource_pack, data_pack))
def base_data_pack(ctx: Context): ctx.data["minecraft:load"] = FunctionTag( {"values": ["#load:_private/load"]}) ctx.data["load:_private/load"] = FunctionTag({ "values": [ "#load:_private/init", { "id": "#load:pre_load", "required": False }, { "id": "#load:load", "required": False }, { "id": "#load:post_load", "required": False }, ] }) ctx.data["load:_private/init"] = FunctionTag( {"values": ["load:_private/init"]}) ctx.data["load:_private/init"] = Function([ "scoreboard objectives add load.status dummy", "scoreboard players reset * load.status", ]) ctx.data.function_tags.merge({ "load:pre_load": FunctionTag({"values": []}), "load:load": FunctionTag({"values": []}), "load:post_load": FunctionTag({"values": []}), })
def installation_advancement(ctx: Context, opts: InstallationAdvancementOptions): author_namespace = opts.author_namespace or normalize_string(ctx.project_author) project_namespace = opts.project_namespace or ctx.project_id project_advancement_path = ( opts.project_advancement_path or f"{author_namespace}:{project_namespace}/installed" ) skull_owner = opts.author_skull_owner or ctx.project_author if not author_namespace: raise ValueError( "Missing author namespace. Either author or author_namespace need to be configured" ) if not skull_owner: raise ValueError( "Missing skull owner. Either author or author_skull_owner need to be configured" ) ctx.data["global:root"] = create_root_advancement() ctx.data[f"global:{author_namespace}"] = create_author_advancement( ctx.project_author, opts.author_description, skull_owner ) ctx.data[project_advancement_path] = create_project_advancement( ctx.project_name, ctx.project_description, author_namespace, opts.icon )
def beet_default(ctx: Context): ctx.project_name = "demo" ctx.project_description = "The description of my project" ctx.project_author = "Example" ctx.project_version = "1.7.4" ctx.data["demo:foo"] = Function(ctx.template.render("foo.mcfunction"))
def beet_default(ctx: Context): ctx.project_name = "something_else" ctx.project_description = {"text": "bold description", "bold": True} ctx.project_author = "Fizzy" ctx.project_version = "1.2.3" ctx.data.description = ["override for ", {"text": "data pack", "color": "red"}]
def beet_default(ctx: Context): config = ctx.meta.get("babelbox", {}) load = config.get("load", ()) dialect = config.get("dialect") filename_prefix = config.get("filename_prefix", False) ctx.require(babelbox(load, dialect, filename_prefix))
def beet_default(ctx: Context): ctx.require(plugin1) ctx.require(plugin1(commands=["say inline options"])) ctx.require(plugin3) ctx.require(plugin3(commands=["say blah"])) preset = plugin5(foo=1, bar=2)(something=42) ctx.require(preset(hello="world"))
def add_greeting(ctx: Context): ctx.require(add_greeting_translations) greeting_count = ctx.meta["greeting_count"] ctx.data["greeting:hello"] = Function( ['tellraw @a {"translate": "greeting.hello"}'] * greeting_count, tags=["minecraft:load"], )
def add_greeting(ctx: Context): ctx.assets["minecraft:en_us"] = Language({"greeting.hello": "hello"}) ctx.assets["minecraft:fr_fr"] = Language({"greeting.hello": "bonjour"}) ctx.data["greeting:hello"] = Function( ['tellraw @a {"translate": "greeting.hello"}'] * 5, tags=["minecraft:load"], )
def beet_default(ctx: Context): config = ProjectConfig(data_pack={"load": ["src"]}).resolve(ctx.directory) ctx.require( ProjectBuilder( Project( config, resolved_cache=ctx.cache, resolved_worker_pool=WorkerPool(resolved_handle=ctx.worker), )))
def beet_default(ctx: Context): ctx.require(other) with ctx.worker(thing) as channel: channel.send(2) channel.send(3) for name, function in channel: ctx.data[name] = function
def scoreboard(ctx: Context, opts: ScoreboardOptions): """Plugin that adds generated scoreboards to the data pack.""" if scoreboard_data := ctx.meta.get("generate_scoreboard"): commands = [ f"scoreboard objectives add {name} {criterion}" for name, criterion in scoreboard_data.items() ] ctx.generate(opts.function, Function(commands, prepend_tags=list(opts.tags))) scoreboard_data.clear()
def add_greeting(ctx: Context): i18n = ctx.inject(Internationalization) i18n.set("greeting.hello", en_us="hello", fr_fr="bonjour") greeting_count = ctx.meta["greeting_count"] ctx.data["greeting:hello"] = Function( ['tellraw @a {"translate": "greeting.hello"}'] * greeting_count, tags=["minecraft:load"], )
def other(ctx: Context): with ctx.worker(thing) as channel: channel.send(4) yield ctx.data["demo:function_count"] = Function( [f"say {len(ctx.data.functions)}"]) for name, function in channel: ctx.data[name] = function
def livereload(ctx: Context): link_manager = ctx.inject(LinkManager) if not link_manager.data_pack or not ctx.data: return data = create_livereload_data_pack() livereload_path = data.save(link_manager.data_pack) link_manager.dirty.append(str(livereload_path)) with ctx.worker(livereload_server) as channel: channel.send((link_manager.minecraft, livereload_path))
def beet_default(ctx: Context): ctx.data["basic3:hello"] = Function(["say dirt blinking"], tags=["minecraft:load"]) image = Image.new("RGB", (16, 32), "green") d = ImageDraw.Draw(image) d.rectangle([0, 16, 16, 32], fill="yellow") ctx.assets["minecraft:block/dirt"] = Texture( image, mcmeta={"animation": { "frametime": 20 }})
def handle_content(ctx: Context, node: TreeNode[str], function: Function, n: int): if node.root: ctx.generate(Function([f"function {node.parent}"], tags=["minecraft:tick"])) function.lines.append(f"scoreboard players add #index temp 1") if node.partition(n): function.lines.append( f"execute if score #index temp matches {node.range} run function {node.children}" ) else: function.lines.append( f"execute if score #index temp matches {node.range} run say {node.value}" )
def beet_default(ctx: Context): ctx.require("beet.contrib.inline_function") ctx.require("beet.contrib.inline_function_tag") ctx.data["demo:hello"] = ctx.template.render_file( Function(""" function #demo:thing #!function "demo:implementation_detail" #!tag "demo:thing" say this is an implementation detail #!endfunction """))
def plugin1(ctx: Context): ctx.require(plugin2) for i in range(5): with ctx.generate[f"part{i}"].push(): loop = ctx.generate( "{short_hash}", render=Function(source_path=ctx.directory / "main.mcfunction"), hash=i, count=i + 1, ) ctx.generate("init", render=Function(["function {{ loop }}"]), loop=loop)
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", "pack.mcmeta": ctx.directory / "pack.mcmeta", }, resource_pack={ "assets/minecraft": ctx.directory / "src", "assets/other/sounds.json": ctx.directory / "src/sounds.json", "not_in_schema.txt": ctx.directory / "pack.mcmeta", }, ) )
def beet_default(ctx: Context): function_path = ctx.cache.generated.directory / "foo.mcfunction" if not function_path.is_file(): function_path.write_text("say hello\n") ctx.data["demo:foo"] = Function(source_path=function_path)
def beet_default(ctx: Context): ctx.assets["minecraft:block/basic2/funky_model"] = Model( source_path=ctx.directory / "funky_model.json" ) ctx.assets["minecraft:block/stone"] = Model( { "parent": "block/basic2/funky_model", "textures": { "foo": "minecraft:block/stone", "bar": "minecraft:block/dirt", }, } ) ctx.assets["minecraft:stone"] = Blockstate( {"variants": {"": [{"model": "minecraft:block/stone"}]}} )
def lectern(ctx: Context, opts: LecternOptions): """Plugin that handles markdown files with lectern.""" document = ctx.inject(Document) for pattern in opts.load: for path in ctx.directory.glob(pattern): document.load(path) for arguments in opts.scripts: result = subprocess.run( arguments, cwd=ctx.directory, check=True, stdout=subprocess.PIPE, ) document.add_text(result.stdout.decode()) yield if opts.snapshot: with document.markdown_serializer.use_flat_format(opts.snapshot_flat): document.save( ctx.directory / opts.snapshot, ctx.directory / opts.external_files if opts.external_files else None, )
def beet_default(ctx: Context): ctx.assets.language_config["aaaa"] = { "name": "AAAA name", "region": "AAAA region", "bidirectional": False, } ctx.assets["minecraft:aaaa"] = Language({"menu.singleplayer": "AAAA"})
def beet_default(ctx: Context): if ctx.worker.long_lived: raise ErrorMessage( f'The "{__name__}" plugin should only be used for one-shot builds.' ) with config_error_handler("(stdin)"): data = json.load(sys.stdin) config = ProjectConfig.parse_obj(data).resolve(ctx.directory) ctx.require( ProjectBuilder( Project( resolved_config=config, resolved_cache=ctx.cache, resolved_worker_pool=WorkerPool(resolved_handle=ctx.worker), )))
def beet_default(ctx: Context): ctx.require(add_function("demo:foo")) with ctx.override(message="world", number=9): ctx.require(add_function("demo:bar")) ctx.require(add_function("demo:after"))
def add_greeting_translations(ctx: Context): ctx.meta["greeting_translations"] = cast(JsonDict, {}) yield for key, translations in ctx.meta["greeting_translations"].items(): for code, value in translations.items(): ctx.assets.languages.merge( {f"minecraft:{code}": Language({f"greeting.{key}": value})})
def beet_default(ctx: Context): ctx.require("beet.contrib.inline_function_tag") ctx.generate(render=Function(["say {{ 6 * 7 }}"])) ctx.generate("foo", render=Function(source_path="foo.mcfunction"), message="hello") ctx.require(plugin1) with ctx.override(generate_namespace="other"): ctx.generate["thing"]( render=Function( ['#!include "foo.mcfunction"'], tags=[ctx.generate(FunctionTag())], ), message="world", )
def beet_default(ctx: Context): # Add the necessary boilerplate to the data pack. # This could also be done by merging a base data pack embedded inside the package. ctx.require(base_data_pack) # Grab the Lantern Load configuration. # The id defaults to the project name and the version to the project version. config = ctx.meta.get("lantern_load", cast(JsonDict, {})) id = config.get("id", ctx.project_id) version = config.get("version", ctx.project_version) dependencies = config.get("dependencies", cast(JsonDict, {})) # Populate the #load:load tag with the dependencies followed by the pack's # own load function. load_tag_values = [ *({"id": f"#{dep}:load", "required": False} for dep in dependencies), f"{id}:load", ] ctx.data.function_tags.setdefault("load:load", FunctionTag()).add(f"#{id}:load") ctx.data[f"{id}:load"] = FunctionTag({"values": load_tag_values}) # Generate and join version checks for all the dependencies. # Currently this only matches a major version number against a fixed value or a range. version_checks = " ".join( f"if score {dep}.major load.status matches {version}" for dep, version in dependencies.items() ) prefix = f"execute {version_checks} run " if version_checks else "" # Implement the load function by first showing a message if there are any missing dependency # and then setting the pack's own version before calling the pack's init tag. ctx.data[f"{id}:load"] = Function( [ *( f"execute unless score {dep}.major load.status matches {version} run say {id}: missing dependency {dep}=={version}" for dep, version in dependencies.items() ), f"{prefix}scoreboard players set {id}.major load.status {version}", f"execute if score {id}.major load.status matches {version} run function #{id}:init", ] )