From 7a1f3b0441d23b2cdd8ced8bf195378d0036a641 Mon Sep 17 00:00:00 2001 From: Alan O Date: Mon, 3 Jul 2023 00:36:55 -0400 Subject: [PATCH] Initial commit --- .gitignore | 4 +++ build.cmd | 22 ++++++++++++++ loot_randomizer/randomize.py | 58 ++++++++++++++++++++++++++++++++++++ prep.cmd | 1 + 4 files changed, 85 insertions(+) create mode 100644 .gitignore create mode 100644 build.cmd create mode 100644 loot_randomizer/randomize.py create mode 100644 prep.cmd diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d871d17 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +loot_randomizer/loot_tables/ +loot_randomizer/*.zip +mcrecipescrambler/ +build/ \ No newline at end of file diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000..414c04f --- /dev/null +++ b/build.cmd @@ -0,0 +1,22 @@ +REM https://gitlab.com/UltraWelfare/mcrecipescrambler + +cd .\mcrecipescrambler\ +python .\scrambler.py .\out.zip +cd ..\loot_randomizer\ +python randomize.py +cd .. + +REM Wait for files to be generated (since it's writing asynchronously?) +timeout 1 + +REM make corresponding directory and unzip files into it, first loot tables, then recipes +mkdir .\build\%1\ +"C:\Program Files\7-Zip\7z.exe" x loot_randomizer\random_loot.zip -o.\build\%1\ -r -y +"C:\Program Files\7-Zip\7z.exe" x mcrecipescrambler\out.zip -o.\build\%1\ -r -y + +REM now, zip everything up into a file, and delete remains +"C:\Program Files\7-Zip\7z.exe" a -tzip .\build\%1.zip .\build\%1\* +rmdir /s /q .\build\%1 +del .\mcrecipescrambler\out.zip + +REM "C:\Program Files\7-Zip\7z.exe" a -tzip BoneJuice.zip BoneJuice \ No newline at end of file diff --git a/loot_randomizer/randomize.py b/loot_randomizer/randomize.py new file mode 100644 index 0000000..37bcd43 --- /dev/null +++ b/loot_randomizer/randomize.py @@ -0,0 +1,58 @@ +import os +import random +import io +import zipfile +import json +import sys + +if len(sys.argv) >= 2: + try: + seed = int(sys.argv[1]) + except Exception: + print('The seed "{}" is not an integer.'.format(sys.argv[1])) + exit() + random.seed(seed) + datapack_name = 'random_loot_{}'.format(seed) + datapack_desc = 'Loot Table Randomizer, Seed: {}'.format(seed) +else: + print('If you want to use a specific randomizer seed integer, use: "python randomize.py "') + datapack_name = 'random_loot' + datapack_desc = 'Loot Table Randomizer' + +datapack_filename = datapack_name + '.zip' + +print('Generating datapack...') + +file_list = [] +remaining = [] + +for dirpath, dirnames, filenames in os.walk('loot_tables'): + for filename in filenames: + file_list.append(os.path.join(dirpath, filename)) + remaining.append(os.path.join(dirpath, filename)) + +file_dict = {} + +for file in file_list: + i = random.randint(0, len(remaining)-1) + file_dict[file] = remaining[i] + del remaining[i] + +zipbytes = io.BytesIO() +zip = zipfile.ZipFile(zipbytes, 'w', zipfile.ZIP_DEFLATED, False) + +for from_file in file_dict: + with open(from_file) as file: + contents = file.read() + + zip.writestr(os.path.join('data/minecraft/', file_dict[from_file]), contents) + +zip.writestr('pack.mcmeta', json.dumps({'pack':{'pack_format':1, 'description':datapack_desc}}, indent=4)) +zip.writestr('data/minecraft/tags/functions/load.json', json.dumps({'values':['{}:reset'.format(datapack_name)]})) +zip.writestr('data/{}/functions/reset.mcfunction'.format(datapack_name), 'tellraw @a ["",{"text":"Loot table randomizer by SethBling","color":"green"}]') + +zip.close() +with open(datapack_filename, 'wb') as file: + file.write(zipbytes.getvalue()) + +print('Created datapack "{}"'.format(datapack_filename)) \ No newline at end of file diff --git a/prep.cmd b/prep.cmd new file mode 100644 index 0000000..d293ebf --- /dev/null +++ b/prep.cmd @@ -0,0 +1 @@ +git clone https://gitlab.com/UltraWelfare/mcrecipescrambler.git \ No newline at end of file