From 91fb8c4b8955f8b3b43697dc43709466e090d504 Mon Sep 17 00:00:00 2001 From: DARUK SHOCK Date: Sat, 5 Apr 2025 15:50:51 +0200 Subject: [PATCH] Created the creative loot tables plugin --- beet/contrib/creative_loot_tables.py | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 beet/contrib/creative_loot_tables.py diff --git a/beet/contrib/creative_loot_tables.py b/beet/contrib/creative_loot_tables.py new file mode 100644 index 00000000..cda5869a --- /dev/null +++ b/beet/contrib/creative_loot_tables.py @@ -0,0 +1,30 @@ +"""Plugin that automates the creation of the creative loot table""" +# IMPORTANT : this plugin is meant to be used with the mod https://modrinth.com/mod/creative-loot-tables +# USAGE: in your beet.json file, specify a regex at meta.creative_loot_tables.pattern +# any loot table with an ID matching with this regex will be put in the creative loot table. + +from beet import Context, LootTable +from re import Pattern +import re + +def beet_default(ctx: Context) -> None: + + # get the pattern + meta: dict = ctx.meta + pattern: str = meta.get("creative_loot_tables", {}).get("pattern") + if pattern is None: + return + regex: Pattern = re.compile(pattern) + + # search + loot_tables: list[str] = [id for id in ctx.data.loot_tables if regex.match(id)] + + # no match found + if len(loot_tables) == 0: + return + + # output the loot table + creative_loot_table: dict = { + "pools": [{"rolls": 1, "entries": [{"type": "loot_table", "value": loot_table}] } for loot_table in loot_tables] + } + ctx.generate("creative_loot_tables:creative_loot_table", LootTable(creative_loot_table)) \ No newline at end of file