-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbabel.py
More file actions
92 lines (74 loc) · 4.18 KB
/
babel.py
File metadata and controls
92 lines (74 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# By Joseph "JiFish" Fowler. All rights reserved.
import argparse
import sys
import os
from build_datapack import buildDatapack
from minecraft_extract import extractFilesFromJar
from config import loadAndValidateYaml
def chance_calculation(config):
chance_tattered = ((1 - config['copy-of-copy-chance']) * (1 - config['copy-of-original-chance']) * (1 - config['original-chance'])) * 100
chance_coc = ((config['copy-of-copy-chance']) * (1 - config['copy-of-original-chance']) * (1 - config['original-chance'])) * 100
chance_coo = ((config['copy-of-original-chance']) * (1 - config['original-chance'])) * 100
chance_o = config['original-chance'] * 100
chance_total = chance_tattered + chance_coc + chance_coo + chance_o
print(f"Real chances calculation (applying chances sequentially):")
print(f"Tattered chance: {chance_tattered:.1f}%")
print(f"Copy of copy chance: {chance_coc:.1f}%")
print(f"Copy of orginal chance: {chance_coo:.1f}%")
print(f"Orginal chance: {chance_o:.1f}%")
print(f"Total: {chance_total:.1f}%")
isCompiled = getattr(sys, 'frozen', False)
version = "v2.3%s" % (' (Windows)' if isCompiled else '')
minecraft_version = "1.21.11"
parser = argparse.ArgumentParser()
parser.add_argument('filename', help='Optional config filename. (default: %(default)s)', nargs='?', default='config.yaml')
parser.add_argument('-v', '--version', action='version', version=version)
parser.add_argument('-i', '--indent', action='store_true', help="Indent output json files. Overrides config field.")
parser.add_argument('-m', '-t', '--metabox', action='store_true', help="Add test loot tables. Overrides config field.")
parser.add_argument('-a', '--append-version', action='store_true', help="Append babel version number to output filename.")
parser.add_argument('-c', '--chance-calc', action='store_true', help="Calculate real chances of various book generations and exit.")
if isCompiled:
parser.add_argument('-!', '--no-wait', action='store_true',
help="Don't wait for user input when finished.")
parser.add_argument('-d', '--debug', action='store_true', help=argparse.SUPPRESS)
# Handle windows style help arg
if len(sys.argv) == 2 and sys.argv[1] == '/?':
sys.argv[1] = '--help'
args = parser.parse_args()
print("")
print("░█▀▄░█▀█░█▀▄░█▀▀░█░░░░░█▀▄░█▀█░█▀█░█░█░░░█░░░█▀█░█▀█░▀█▀")
print("░█▀▄░█▀█░█▀▄░█▀▀░█░░░░░█▀▄░█░█░█░█░█▀▄░░░█░░░█░█░█░█░░█░")
print("░▀▀░░▀░▀░▀▀░░▀▀▀░▀▀▀░░░▀▀░░▀▀▀░▀▀▀░▀░▀░░░▀▀▀░▀▀▀░▀▀▀░░▀░ " + version)
print('By JiFish. email: %s' % 'ku.oc.hsifij@eoj'[::-1])
print('Mastodon: https://social.jifish.co.uk/@joe')
print('Github: https://github.com/JiFish/babel')
print("")
print("Using configuration: %s.\n" % args.filename)
try:
config = loadAndValidateYaml(args.filename)
if args.chance_calc:
chance_calculation(config)
else:
# args that overrides config fields
if args.indent:
config['indent-output'] = True
if args.metabox:
config['add-metabox'] = True
# Append version alters 'output-filename'
if args.append_version:
filename, extension = os.path.splitext(config['output-filename'])
config['output-filename'] = filename + '_' + version + extension
extractFilesFromJar(minecraft_version, config['add-lost-libraries'])
print("Building data pack...")
buildDatapack(config, version, f"data_extracted/{minecraft_version}")
print("Data pack build complete!\n\nCopy %s to your world's 'datapacks' directory." % config['output-filename'])
except Exception as e:
print("\nBUILD FAILED!")
print(str(e))
if not isCompiled or args.debug:
from traceback import print_exc
print("\nDetails:")
print_exc()
finally:
if isCompiled and not args.no_wait:
input("\nPress ENTER or close this window.")