|
9 | 9 | def beet_default(ctx: Context): |
10 | 10 | yield |
11 | 11 |
|
12 | | - # edited item model definition - replaced head with player_head |
| 12 | + # edited item model definitions |
| 13 | + # - replaced head with player_head |
13 | 14 | backport(ctx.assets, 63, playerhead_models_1_21_5) |
| 15 | + # - added on_shelf |
| 16 | + backport(ctx.assets, 64, on_shelf_models_1_21_9) |
14 | 17 |
|
15 | 18 | # renamed gamerules |
16 | 19 | backport(ctx.data, 92, rename_gamerules) |
@@ -48,6 +51,30 @@ def recursive_replace(compound: dict[str,Any]): |
48 | 51 | recursive_replace(overlay.data) |
49 | 52 | return overlay |
50 | 53 |
|
| 54 | +def on_shelf_models_1_21_9(id: str, resource: NamespaceFile): |
| 55 | + if not isinstance(resource, ItemModel): |
| 56 | + return None |
| 57 | + |
| 58 | + def recursive_replace(compound: dict[str,Any]): |
| 59 | + for key, val in compound.items(): |
| 60 | + # recurse down the tree |
| 61 | + if key == "when": |
| 62 | + if isinstance(compound[key], list) and "on_shelf" in val: |
| 63 | + compound[key].remove("on_shelf") |
| 64 | + elif isinstance(compound[key], str) and val == "on_shelf": |
| 65 | + compound.pop(key) |
| 66 | + continue |
| 67 | + if isinstance(val, list): |
| 68 | + for subval in val: # type: ignore |
| 69 | + if isinstance(subval, dict): |
| 70 | + recursive_replace(subval) # type: ignore |
| 71 | + elif isinstance(val, dict): |
| 72 | + recursive_replace(val) # type: ignore |
| 73 | + |
| 74 | + overlay = resource.copy() |
| 75 | + recursive_replace(overlay.data) |
| 76 | + return overlay if overlay != resource else None |
| 77 | + |
51 | 78 |
|
52 | 79 | # Only gamerules that are actually used are replaced |
53 | 80 | GAMERULES_RENAMES = { |
|
0 commit comments