This repository has been archived by the owner on Dec 27, 2023. It is now read-only.
generated from QuiltMC/quilt-template-mod
/
gen_recipes.py
executable file
·83 lines (66 loc) · 2.28 KB
/
gen_recipes.py
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
#! /usr/bin/env python3
# You didn't think I'd do it all by hand, did you?
import pathlib
import json
import copy
import itertools
TARGET_FOLDER = pathlib.Path('src/main/resources/data/tictaccursed/recipes/generated/')
BASE_RECIPE = {
"type": "minecraft:crafting_shaped",
"pattern": [],
"key": {},
"result": {
"item": None,
"count": 1
}
}
X_KEY = {
"item": "tictaccursed:cross"
}
O_KEY = {
"item": "tictaccursed:circle"
}
def main():
TARGET_FOLDER.mkdir(parents=True, exist_ok=True)
# Empty the folder
for file in TARGET_FOLDER.iterdir():
file.unlink()
for recipe in itertools.product(['X', 'O', ' '], repeat=9):
# Skip all empty recipes
if recipe.count(' ') == 9:
continue
# Determine the output
win_x = False
win_o = False
# Rows and columns
for i in range(3):
if (recipe[i*3] == recipe[i*3+1] == recipe[i*3+2] == "X") or (recipe[i] == recipe[i+3] == recipe[i+6] == "X"):
win_x = True
if (recipe[i*3] == recipe[i*3+1] == recipe[i*3+2] == "O") or (recipe[i] == recipe[i+3] == recipe[i+6] == "O"):
win_o = True
# Diagonals
if (recipe[0] == recipe[4] == recipe[8] == "X") or (recipe[2] == recipe[4] == recipe[6] == "X"):
win_x = True
if (recipe[0] == recipe[4] == recipe[8] == "O") or (recipe[2] == recipe[4] == recipe[6] == "O"):
win_o = True
# Set the output
output = "unknown"
if win_x and not win_o:
output = "cross"
if win_o and not win_x:
output = "circle"
# Create the recipe
recipe_string = ''.join(recipe)
new_recipe = copy.deepcopy(BASE_RECIPE)
new_recipe["pattern"] = [recipe_string[0:3], recipe_string[3:6], recipe_string[6:9]]
new_recipe["result"]["item"] = f"tictaccursed:{output}"
# Add the keys
if "X" in recipe_string:
new_recipe["key"]["X"] = X_KEY
if "O" in recipe_string:
new_recipe["key"]["O"] = O_KEY
# Write the recipe
with open(TARGET_FOLDER / f"{recipe_string.replace(' ', '.').lower()}.json", "w") as f:
json.dump(new_recipe, f, indent=4)
if __name__ == "__main__":
main()