Skip to content

Commit

Permalink
Player head management plugin (#888)
Browse files Browse the repository at this point in the history
* Merge branch 'ver/1.16' of https://github.com/Bloo-dev/lib_player_heads into ver/1.16

* Merge pull request #1 from Luexa/enhance-code-and-examples

Enhance code and examples (version 1.1)

* Recursive json-dict key retrieval

* Dirty existing skin data gathering

This is a very very gross and terribly code implementation to extract existing skin data into a cache file. This code was half to learn how to interact with mecha AST rules. Most of this commit's changes *will* be reverted or overwritten in a later commit

* Dirty skin download to source

A quick-and-dirty utility script to process the texture url data from the previous commit and interactively download and name each skin file. This script will be deleted in a future commit but is included here so it can be retrieved by git at a future date if needed

* Custom container for skin textures

Creates and registers a custom container on the datapack object for skin textures, allowing them to be auto-mounted to the pack object upon load

* Use bind() to process Skin objects

- adds PIL (pillow) as dependancy
- serializes skin images immediately on load to prepare for hash comparison

* Bind the Skin container to a custom mecha rule processor

* Structural pattern matching on AST

First attempt to match the ast structure of the SkullOwner nbt compound. Ran into issues where the ast stores ordered entries, but we want to match unordered.

* Evaluate ast to libnbt dict for robust syntax matching

Matches the following cases of SkullOwner:
```SkullOwner:$texture
SkullOwner:{Value:"$texture"}
SkullOwner:{Value:"$texture",Name:"foo",Signature:"bar"}
SkullOwner:{Name:"foo",Properties:{textures:[{Value:"$texture",Signature:"bar"}]}}```,
with each additional field functioning as optional if needed

* mineskin_upload function for api calls

* trims unneeded data from skin texture url

* Use provided random uuid from mineskin

Apparently, the uuid no longer *must* be unique for the skin to work, but for safety we'll keep using a unique uuid since one is already provided by mineskin.

* Save skin cache out when finished

* Prompt the user for an API token if needed for submitting new skin textures

* cached uuid is list of ints

* Output uuid is array, not string

* Untested ratelimited request resubmit

* Use traceback diagnostics to report invalid textures and unhandled cases

* Log unused cache entries

* Store NbtTransformer in `ctx.inject` so it can be used on loot_tables

* Apply ast rule to snbt within advancements and loot tables

* [WIP] Usable Diagnostics on LootTables

* Cleanup diagnostic printing.

* Fix diagnostics on json files with multiple lines needing subs

Since we're faking database entries, the lookup key for loottables needs to be unique, which it cant be when one file has two strings needing parsing. Instead we use an enumerated resource location

* Spring cleaning

* Update heart-canisters to new shortcuts

* Fix typos

* substitutions in lib_player_heads registry

Also updates mecha to fix a bug with raising diagnostics within subcommands

* Missing skin texture for compilation errors

uses mecha's `yield Diagnostic` magic syntax to both raise errors and return a valid ast, which gets a magenta/black missing-texture

* Pass proper location for lib_player_heads invalid skin names

* Remove unused name field in skin_cache

* Fix skin value subs for other structural cases

* Error if GH Action needs to upload skin

* REVERTABLE: GH Action Test Case

* REVERTABLE: Enale GH Action on test branch

* Allow processing of list-root item modifiers

* REVERTABLE: Fix gh action skin test typo

* Escape newlines in nbt from loot-tables, so mecha parses them right

* Try raising exception to quit gh action

* Try systemexit exception for gh action

* Try sys.exit for gh action

* Comment

* Revert "REVERTABLE: GH Action Test Case"

This reverts commit 11a74ba.

Revert "REVERTABLE: Fix gh action skin test typo"

This reverts commit 3a25f69.

Revert "REVERTABLE: Enale GH Action on test branch"

This reverts commit fdf3ad0.

* Eliminate many #type:ignore with better type annotations

* Support un-prefixed item modifier functions

* small typo

* Apply substitutions to all modules - first pass

* Delete skin_downloader.py

* Record parent_module on new skins

* Cache record of any skins from other modules

* Increment patch on non-native skin reference diff

* Output wraps the build pipeline

Moves gm4.output to use its exit phase instead, this allows all other plugins to process their exit phases first, doing things like cleaning up extra file containers or saving important data

* Configure mecha to keep comments

* Sub-modules properly record nonnative references

* Clarify metallurgy mould naming

* Initial commit

* Metallurgy skins cleanup

* Disable unused thoriub_brass substitution

* Experimental lib_player_heads versioning warnings

* Revert "Experimental lib_player_heads versioning warnings"

This reverts commit ac60b4d.

This functionality would be better served in some hypothetical linting checker rather than here; additionally, this should ideally belong to the library files itself, not the player head management tool. For now, the maintainers will need to keep in mind that skin file changes should accompany lib_player_heads registry edits

* Baryte lump typo

* Update init.mcfunction

* Cleanup unused OLD textures and correct some typos

* Update mecha version to add 1.20 command tree support

* Legacy loot_table

* Update skin_cache.json

---------

Co-authored-by: Bloo-dev <[email protected]>
  • Loading branch information
SpecialBuilder32 and Bloo-dev authored Sep 7, 2023
1 parent c0ca619 commit dd1ddc7
Show file tree
Hide file tree
Showing 241 changed files with 1,844 additions and 387 deletions.
9 changes: 8 additions & 1 deletion beet-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ pipeline:
- gm4.plugins.manifest.write_meta
- broadcast: 'gm4_*'
extend: 'beet.yaml'
require:
- gm4.plugins.output.release
- gm4.plugins.player_heads
pipeline:
- gm4.plugins.manifest.write_updates
- gm4.plugins.manifest.write_credits
- require: [beet.contrib.copy_files]
meta: {copy_files: {data_pack: {LICENSE.md: "../LICENSE.md"}}}
- gm4.plugins.readme_generator
- gm4.plugins.write_mcmeta
- gm4.plugins.output.release
meta:
mecha:
formatting:
layout: preserve
nbt_compact: True

meta:
autosave:
Expand Down
9 changes: 8 additions & 1 deletion beet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ pipeline:
- gm4.plugins.manifest.create
- broadcast: 'gm4_*'
extend: 'beet.yaml'
require:
- gm4.plugins.output
- gm4.plugins.player_heads
pipeline:
- gm4.plugins.write_mcmeta
- gm4.plugins.output
meta:
mecha:
layout: preserve
nbt_compact: True
cmd_compact: True
21 changes: 17 additions & 4 deletions gm4/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,24 @@ def dev(ctx: click.Context, project: Project, modules: tuple[str], watch: bool,
config = {
"broadcast": modules,
"extend": "beet.yaml",
"require": ["beet.contrib.livereload"] if reload else [],
"require": [
"gm4.plugins.output",
"beet.contrib.livereload",
"gm4.plugins.player_heads"
] if reload else [
"gm4.plugins.output",
"gm4.plugins.player_heads"
],
"pipeline": [
"gm4.plugins.write_mcmeta",
"gm4.plugins.output"
]
"gm4.plugins.write_mcmeta"
],
"meta": {
"mecha" : {
"formatting":{
"layout": "preserve",
"nbt_compact": True,
"cmd_compact": True
} } }
}
project.config_overrides = [
f"pipeline[] = {json.dumps(config)}",
Expand Down
14 changes: 12 additions & 2 deletions gm4/plugins/manifest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from beet import Context, TextFile
from beet import Context, TextFile, JsonFile
from pathlib import Path
from typing import Any
from functools import cache
Expand Down Expand Up @@ -97,6 +97,7 @@ def update_patch(ctx: Context):
release_dir = Path('release') / version
manifest_file = release_dir / "meta.json"
logger = parent_logger.getChild("update_patch")
skin_cache = JsonFile(source_path="gm4/skin_cache.json").data

modules = ctx.cache["gm4_manifest"].json["modules"]

Expand All @@ -119,7 +120,16 @@ def update_patch(ctx: Context):
deps = _traverse_includes(id) | {"base"}
deps_dirs = [element for sublist in [[f"{d}/data", f"{d}/*py"] for d in deps] for element in sublist]

diff = run(["git", "diff", last_commit, "--shortstat", "--", f"{id}/data", f"{id}/*.py"] + deps_dirs) if last_commit else True
# add watches to skins this module uses from other modules. NOTE this could be done in a more extendable way in the future, rather than "hardcoded"
skin_dep_dirs: list[str] = []
for skin_ref in skin_cache["nonnative_references"].get(id, []):
d = skin_cache["skins"][skin_ref]["parent_module"]
ns, path = skin_ref.split(":")
skin_dep_dirs.append(f"{d}/data/{ns}/skins/{path}.png")

watch_dirs = deps_dirs+skin_dep_dirs

diff = run(["git", "diff", last_commit, "--shortstat", "--", f"{id}/data", f"{id}/*.py"] + watch_dirs) if last_commit else True

if not diff and released:
# No changes were made, keep the same patch version
Expand Down
11 changes: 6 additions & 5 deletions gm4/plugins/output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from beet import Context
from pathlib import Path
from bolt import Module
import os
import json
import requests
Expand All @@ -18,12 +17,13 @@
USER_AGENT = "Gamemode4Dev/GM4_Datapacks/release-pipeline ([email protected])"

def beet_default(ctx: Context):
"""Saves the datapack to the ./out folder."""
"""Saves the datapack to the ./out folder in it's exit phase.
Should be first in pipeline to properly wrap all other plugins cleanup phases"""
version = os.getenv("VERSION", "1.20")
out_dir = Path("out")

ctx.data[Module].clear() # manually cleanup bolt modules

yield # wait for exit phase, after other plugins cleanup
ctx.data.save(
path=out_dir / f"{ctx.project_id}_{version.replace('.', '_')}",
overwrite=True,
Expand All @@ -33,6 +33,7 @@ def beet_default(ctx: Context):
def release(ctx: Context):
"""
Saves the zipped datapack and metadata to the ./release/{version} folder.
Should be first in pipeline to properly wrap all other plugins cleanup phases
If the module has the `version` and `meta.modrinth.project_id` fields, and
`BEET_MODRINTH_TOKEN` environment variable is set, will try to publish a
Expand All @@ -46,7 +47,7 @@ def release(ctx: Context):
release_dir = Path("release") / version_dir
file_name = f"{ctx.project_id}_{version_dir.replace('.', '_')}.zip"

ctx.data[Module].clear() # manually cleanup bolt modules
yield # wait for exit phase, after other plugins cleanup

ctx.data.save(
path=release_dir / file_name,
Expand Down
Loading

0 comments on commit dd1ddc7

Please sign in to comment.