def test_empty_with_image(): pack = ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="blue"))) assert pack assert pack == ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="blue"))) assert pack != ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="red"))) assert pack != ResourcePack(image=PngFile(Image.new("RGB", (16, 16), color="blue"))) assert dict(pack) == {}
def test_mcmeta_properties(): pack = ResourcePack() pack.description = "Something" pack.pack_format = 1 assert pack.mcmeta.content == { "pack": {"description": "Something", "pack_format": 1} }
def test_vanilla_shaders(snapshot: Any, minecraft_resource_pack: Path): pack = ResourcePack(path=minecraft_resource_pack) assert snapshot("json") == pack.shader_posts["minecraft:spider"].data assert snapshot( "json") == pack.shader_programs["minecraft:entity_outline"].data assert snapshot() == pack.fragment_shaders["minecraft:wobble"].text assert snapshot() == pack.vertex_shaders["minecraft:sobel"].text
def test_texture(snapshot: Any): image = Image.new("RGB", (64, 64)) d = ImageDraw.Draw(image) d.text((10, 10), "hello", fill="white") pack = ResourcePack("custom") pack["custom:hello"] = Texture(image) assert snapshot("resource_pack") == pack
def test_texture_mcmeta(snapshot: Any): image = Image.new("RGB", (64, 128)) d = ImageDraw.Draw(image) d.text((10, 10), "hello", fill="white") d.text((10, 74), "world", fill="white") pack = ResourcePack("custom") pack["custom:hello"] = Texture(image, mcmeta={"animation": {"frametime": 20}}) assert snapshot("resource_pack") == pack
def test_empty(): assert Document() == Document() assert Document().data == DataPack() assert Document().assets == ResourcePack() assert Document().get_text() == "" empty = "# Lectern snapshot\n\nThe data pack and resource pack are empty.\n" assert Document().get_markdown() == empty assert Document().get_markdown(emit_external_files=True) == (empty, {}) assert Document(text="Nothing to see here") == Document() assert Document(markdown="Nothing to see here") == Document()
def item_models(ctx: Context, opts: HatsOptions): """Create item models used for custom model data""" assets = ResourcePack() registry = HatRegistry.get(opts.cmd_id) overrides = [] for category, hats in registry.categories.items(): overrides += [ModelOverride(hat.cmd, hat.model_path(category)) for hat in hats] overrides = sorted(overrides, key=lambda o: o.cmd) item_head_name = opts.default_item_head.split(":")[1] item_inventory_name = opts.default_item_inventory.split(":")[1] assets.models[f"minecraft:item/{item_head_name}"] = Model( ctx.template.render(f"models/{item_head_name}.json", overrides=overrides) ) assets.models[f"minecraft:item/{item_inventory_name}"] = Model( ctx.template.render(f"models/{item_inventory_name}.json", overrides=overrides) ) return assets
def apply_directives( self, directives: Mapping[str, Directive], fragments: Iterable[Fragment], loaders: Iterable[FragmentLoader] = (), ) -> Tuple[ResourcePack, DataPack]: """Apply directives into a blank data pack and a blank resource pack.""" assets, data = ResourcePack(), DataPack() for fragment in fragments: for loader in loaders: fragment = loader(fragment, directives) if not fragment: break if fragment: directives[fragment.directive](fragment, assets, data) return assets, data
def __init__( self, assets: Optional[ResourcePack] = None, data: Optional[DataPack] = None, ): super().__init__() self.resolvers = [] self.assets = assets or ResourcePack() self.data = data or DataPack() self["data_pack"] = DataPackDirective() self["resource_pack"] = ResourcePackDirective() self["skip"] = SkipDirective() @self.add_resolver def _(self: DirectiveRegistry): for pack in [self.assets, self.data]: for file_type in pack.resolve_scope_map().values(): name = snake_case(file_type.__name__) self[name] = NamespacedResourceDirective(file_type)
def test_sounds(): pack = ResourcePack() pack["minecraft:block/note_block/banjo_1"] = Sound( b"abc", event="block.note_block.banjo", subtitle="foo" ) pack["minecraft:block/note_block/banjo_2"] = Sound( b"123", event="block.note_block.banjo", weight=2, pitch=1.1 ) config = { "block.note_block.banjo": { "sounds": [ "block/note_block/banjo_1", {"name": "block/note_block/banjo_2", "weight": 2, "pitch": 1.1}, ], "subtitle": "foo", } } assert pack["minecraft"].sound_config == SoundConfig(config)
def test_merge(snapshot: Any): p1 = ResourcePack("p1") p1["custom:red"] = Texture(Image.new("RGB", (32, 32), color="red")) p2 = ResourcePack("p2") p2["custom:green"] = Texture(Image.new("RGB", (32, 32), color="green")) blink = Image.new("RGB", (32, 64), color="blue") d = ImageDraw.Draw(blink) d.rectangle([0, 32, 32, 64], fill="white") p3 = ResourcePack("p3") p3["other:blue"] = Texture(blink, mcmeta={"animation": {"frametime": 20}}) p1.merge(p2) p1.merge(p3) assert snapshot("resource_pack") == p1
import pytest from PIL import Image, ImageDraw from beet import JsonFile, PngFile, ResourcePack, Texture def test_default(): assert ResourcePack() == ResourcePack() assert not ResourcePack() @pytest.mark.parametrize( # type: ignore "pack", [ ResourcePack("p1"), ResourcePack("p2", mcmeta=JsonFile({"pack": {"description": "world"}})), ResourcePack( "p3", mcmeta=JsonFile({"pack": {"description": "world", "pack_format": 42}}) ), ], ) def test_empty(snapshot: Any, pack: ResourcePack): assert snapshot("resource_pack") == pack assert not pack assert dict(pack) == {} def test_empty_with_image(): pack = ResourcePack(image=PngFile(Image.new("RGB", (32, 32), color="blue"))) assert pack
def test_default(): assert ResourcePack() == ResourcePack() assert not ResourcePack()
def __call__(self, fragment: Fragment, assets: ResourcePack, data: DataPack): assets.load(self.bundle_pack_fragment(fragment))
def test_vanilla_particles(snapshot: SnapshotFixture, minecraft_resource_pack: Path): pack = ResourcePack(path=minecraft_resource_pack) assert snapshot("json") == pack.particles["minecraft:end_rod"].data
def test_empty_namespaces(): pack = ResourcePack() assert not pack assert not pack["hello"] assert not pack["world"]
def test_vanilla_zip(minecraft_resource_pack: Path, tmp_path: Path): pack = ResourcePack(path=minecraft_resource_pack) zipped_pack = pack.save(tmp_path, zipped=True) assert ResourcePack(path=zipped_pack) == ResourcePack(path=zipped_pack)
def test_vanilla_compare(minecraft_resource_pack: Path): assert ResourcePack(path=minecraft_resource_pack) == ResourcePack( path=minecraft_resource_pack )
def load(self, path: Path) -> ResourcePack: return ignore_name(ResourcePack(path=path))
def dump(self, path: Path, value: ResourcePack): value.save(path, overwrite=True)
def load(self, path: Path) -> ResourcePack: return ResourcePack(path=next(path.iterdir()))
def test_resource_pack(): pack = ResourcePack() doc = Document(assets=pack) assert doc.assets is pack