Initial commit

This commit is contained in:
Alan O'Cull 2023-07-03 00:36:55 -04:00
commit 7a1f3b0441
4 changed files with 85 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
loot_randomizer/loot_tables/
loot_randomizer/*.zip
mcrecipescrambler/
build/

22
build.cmd Normal file
View File

@ -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

View File

@ -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 <seed>"')
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))

1
prep.cmd Normal file
View File

@ -0,0 +1 @@
git clone https://gitlab.com/UltraWelfare/mcrecipescrambler.git