Skip to content

Commit 535acae

Browse files
committed
fix recipe loading and a lot of resource loading issues
1 parent 06cd37e commit 535acae

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

src/components/barrel_recipe.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ def format_barrel_recipe_from_data(context: Context, buffer: List[str], data: An
2222
input_fluid_div = input_item_div = output_fluid_div = output_item_div = duration = """"""
2323

2424
if 'input_item' in data:
25-
in_path, in_name = crafting_recipe.format_ingredient(context, data['input_item']['ingredient'])
26-
in_count = data['input_item']['count'] if 'count' in data['input_item'] else 1
25+
in_item = data['input_item']
26+
in_path, in_name = crafting_recipe.format_ingredient(context, in_item if 'ingredient' not in in_item else in_item['ingredient'])
27+
in_count = in_item['count'] if 'count' in in_item else 1
2728
input_item_div = make_icon(in_name, in_path, 1, crafting_recipe.format_count(in_count))
2829
if 'output_item' in data:
2930
out_path, out_name, out_count = crafting_recipe.format_item_stack(context, data['output_item'])

src/components/crafting_recipe.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ def format_crafting_recipe_from_data(context: Context, buffer: List[str], identi
3737
return format_crafting_recipe_from_data(context, buffer, identifier, data['recipe'])
3838
elif recipe_type == 'tfc:advanced_shaped_crafting':
3939
data['type'] = 'minecraft:crafting_shaped'
40-
util.require('stack' in data['result'], 'Advanced shaped crafting with complex modifiers: \'%s\'' % data['result'])
41-
data['result'] = data['result']['stack'] # Discard modifiers
40+
stack = util.anyof(data['result'], 'stack', 'id')
41+
util.require(stack is not None, 'Advanced shaped crafting with complex modifiers: \'%s\'' % data['result'])
42+
data['result'] = stack # Discard modifiers
4243
return format_crafting_recipe_from_data(context, buffer, identifier, data)
4344
elif recipe_type == 'tfc:advanced_shapeless_crafting':
4445
data['type'] = 'minecraft:crafting_shapeless'
45-
util.require('stack' in data['result'], 'Advanced shapeless crafting with complex modifiers: \'%s\'' % data['result'])
46-
data['result'] = data['result']['stack'] # Discard modifiers
46+
stack = util.anyof(data['result'], 'stack', 'id')
47+
util.require(stack is not None, 'Advanced shapeless crafting with complex modifiers: \'%s\'' % data['result'])
48+
data['result'] = stack # Discard modifiers
4749
return format_crafting_recipe_from_data(context, buffer, identifier, data)
4850
else:
4951
raise util.error('Unknown crafting recipe type: %s for recipe %s' % (recipe_type, identifier))
@@ -87,7 +89,7 @@ def format_crafting_recipe_from_data(context: Context, buffer: List[str], identi
8789
))
8890

8991

90-
def format_ingredient(context: Context, data: Any) -> Tuple[str, str]:
92+
def format_ingredient(context: Context, data: Any) -> Tuple[str, str | None]:
9193
if 'item' in data:
9294
return item_loader.get_item_image(context, data['item'])
9395
elif 'tag' in data:
@@ -99,14 +101,27 @@ def format_ingredient(context: Context, data: Any) -> Tuple[str, str]:
99101
elif 'type' in data and data['type'] == 'tfc:fluid_item':
100102
util.require(data['fluid_ingredient']['ingredient'] == 'minecraft:water', 'Unknown `tfc:fluid_item` ingredient: \'%s\'' % data)
101103
return item_loader.get_item_image(context, 'minecraft:water_bucket')
104+
elif 'type' in data and data['type'] == 'tfc:fluid_content':
105+
util.require(data['fluid']['fluid'] == 'minecraft:water', 'Unknown `tfc:fluid_content` ingredient: \'%s\'' % data)
106+
return item_loader.get_item_image(context, 'minecraft:water_bucket')
107+
elif 'type' in data and data['type'] == 'tfc:and':
108+
csvstring = ''
109+
for i in data['children']:
110+
if 'item' in i:
111+
csvstring += ',' + str(i['item'])
112+
return item_loader.get_item_image(context, csvstring)
102113
elif isinstance(data, List):
103114
csvstring = ''
104115
for i in data:
105116
if 'item' in i:
106117
csvstring += ',' + str(i['item'])
107118
return item_loader.get_item_image(context, csvstring)
108119
else:
109-
util.error('Unsupported ingredient: %s' % data)
120+
util.error('Unsupported ingredient: %s' % str(data))
121+
122+
def format_sized_ingredient(context: Context, data: Any) -> Tuple[Tuple[str, str | Any], int]:
123+
ing = format_ingredient(context, data)
124+
return ing, 1 if 'count' not in data else data['count']
110125

111126
def format_item_stack(context: Context, data: Any) -> Tuple[str, str, int]:
112127
if 'modifiers' in data and 'stack' in data:

src/components/misc_recipe.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def format_misc_recipe(context: Context, buffer: List[str], identifier: str):
2323
elif recipe_type == 'tfc:loom':
2424
# 1.18 uses an ingredient with 'input_count' parameter
2525
# 1.20 uses an item stack ingredient with 'ingredient' and 'count' fields
26-
if 'ingredient' in data and 'input_count' in data:
27-
format_misc_recipe_from_data(context, buffer, identifier, data, in_count=data['input_count'])
26+
# 1.21 changed the 'ingredient' field to 'item'
27+
if 'ingredient' in data:
28+
count = data['input_count'] if 'input_count' in data else data['ingredient']['count'] if 'count' in data['ingredient'] else 1
29+
format_misc_recipe_from_data(context, buffer, identifier, data, in_count=count)
2830
elif 'ingredient' in data and 'ingredient' in data['ingredient'] and 'count' in data['ingredient']:
2931
ing = data['ingredient']
3032
format_misc_recipe_from_data(context, buffer, identifier, data, ingredient=ing['ingredient'], in_count=ing['count'])

src/loader.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ def __init__(self, tfc_dir: str, output_dir: str, use_mcmeta: bool, use_addons:
1515
self.tfc_dir = tfc_dir
1616
self.output_dir = output_dir
1717

18-
self.loaders = [('tfc', ('tfc', 'forge', 'minecraft'), self.load_from_tfc)]
18+
self.loaders = [('tfc', ('tfc', 'forge', 'minecraft', 'c'), self.load_from_tfc)]
1919
self.domains = ['tfc']
2020
if use_mcmeta:
2121
self.loaders += [
22-
('forge', ('forge', 'minecraft'), mcmeta.load_from_forge),
22+
('forge', ('forge', 'minecraft', 'c'), mcmeta.load_from_forge),
2323
('minecraft', ('minecraft',), mcmeta.load_from_mc)
2424
]
2525
self.domains += ['forge', 'minecraft']
@@ -84,9 +84,10 @@ def load_resource(self, path: str, resource_type: str, resource_root: str, resou
8484

8585
def load_from_tfc(self, path: str, reader):
8686
try:
87-
path = util.path_join(self.tfc_dir, 'src/main/resources', path)
87+
base_path = path
88+
path = util.path_join(self.tfc_dir, 'src/main/resources', base_path)
8889
if not os.path.exists(path):
89-
path = util.path_join(self.tfc_dir, 'src/generated/resources', path)
90+
path = util.path_join(self.tfc_dir, 'src/generated/resources', base_path)
9091
if path.endswith('.png'):
9192
with open(path, 'rb') as f:
9293
return reader(f)

src/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ def resource_location(path: str) -> str:
1414
return 'minecraft:%s' % path
1515
return path
1616

17+
def anyof(dict, *args):
18+
for arg in args:
19+
if arg in dict:
20+
return dict[arg]
21+
error('None of %s in %s' % (str(args), str(dict)))
22+
return None
23+
1724
def walk(path: str):
1825
if os.path.isfile(path):
1926
yield path

0 commit comments

Comments
 (0)