|
1 | | -from beet import Context, subproject, Cache |
| 1 | +from beet import Context, subproject, Cache, Language, Function |
2 | 2 | from pathlib import Path |
3 | 3 | from typing import Any |
4 | 4 | from gm4.utils import CSV |
5 | 5 | from gm4.plugins.resource_pack import ContainerGuiOptions, GuiFont |
6 | 6 |
|
7 | 7 | def beet_default(ctx: Context): |
8 | 8 |
|
9 | | - trades_init = [] |
10 | | - trades_list = [] |
11 | | - trades_append = [] |
12 | | - |
13 | | - furniture_sets = {} |
| 9 | + trades_init: list[str] = [] |
| 10 | + trades_list: list[str] = [] |
| 11 | + trades_append: list[str] = [] |
| 12 | + |
| 13 | + furniture_sets: dict[str,CSV] = {} |
14 | 14 |
|
15 | 15 | for path in sorted(Path('gm4_furniture/raw_data/furniture_set').glob('*.csv')): |
16 | 16 | furniture_sets[path.stem] = CSV.from_file(path) |
17 | 17 |
|
18 | 18 | # loop through the different sheets, each sheet hold a different 'set_name' |
19 | 19 | # of furniture which need to be sorted in the furniture_station storage |
20 | | - for set_name,furniture_set in furniture_sets.items(): |
| 20 | + for set_name, furniture_set in furniture_sets.items(): |
21 | 21 |
|
22 | 22 | # call generate_trade_data to build the commands |
23 | 23 | new_trades_init,new_trades_list,new_trades_append = generate_trade_data(ctx, furniture_set, set_name) |
24 | 24 | # append the trade data to the total list |
25 | 25 | trades_init.append(new_trades_init) |
26 | | - trades_list.append(new_trades_list) |
| 26 | + trades_list += new_trades_list |
27 | 27 | trades_append.append(new_trades_append) |
28 | 28 |
|
29 | 29 | # read furniture data from this sheet, and then create the placement function |
30 | 30 | # and loot table for each furniture |
31 | 31 | generate_furniture_data(ctx, furniture_set, set_name) |
32 | 32 |
|
33 | | - |
34 | | - # build the trade data commands |
35 | | - trades_init = '\n'.join(trades_init) |
36 | | - trades_list = '\n'.join(trades_list) |
37 | | - trades_append = '\n'.join(trades_append) |
38 | | - # build the trade data function from crafting_template |
39 | | - subproject_config = { |
40 | | - "data_pack": { |
41 | | - "load": [ |
42 | | - { |
43 | | - f"data/gm4_furniture/function/generate_trades.mcfunction": "data/gm4_furniture/template/function/crafting_template.mcfunction", |
44 | | - } |
45 | | - ], |
46 | | - "render": { |
47 | | - "function": "*" |
48 | | - } |
49 | | - }, |
50 | | - "meta": { |
51 | | - "trades_init": trades_init, |
52 | | - "trades_list": trades_list, |
53 | | - "trades_append": trades_append, |
54 | | - } |
55 | | - } |
56 | | - |
57 | | - ctx.require(subproject(subproject_config)) |
58 | | - |
59 | | - |
60 | | - |
61 | | -def generate_trade_data(ctx, furniture_set, set_name): |
| 33 | + # generate trades function |
| 34 | + function_strings: list[str] = [ |
| 35 | + "# create storage to hold the trade data for furniture items in furniture station", |
| 36 | + "# @s = unspecified", |
| 37 | + "# at unspecified", |
| 38 | + "# run from init", |
| 39 | + "# generated by generate.py\n" |
| 40 | + ] |
| 41 | + for string in trades_init + trades_list + trades_append: |
| 42 | + function_strings.append(string) |
| 43 | + function_strings.append("\ndata remove storage gm4_furniture:temp new_trades") |
| 44 | + ctx.data.functions['gm4_furniture:generate_trades'] = Function(function_strings) |
| 45 | + |
| 46 | +def generate_trade_data(ctx: Context, furniture_set: CSV, set_name: str): |
62 | 47 |
|
63 | 48 | # create a command to make an empty storage called new_trades that holds the set_name name and tool cmd |
64 | 49 | new_trades_init = "data modify storage gm4_furniture:temp new_trades." + set_name + " set value {\"minecraft:item_model\":\"gm4_furniture:set_tool/" + set_name + "\",trades:[]}" |
65 | 50 |
|
66 | 51 | # iterate over the rows in the spreadsheet and add the trade data for each furniture to the storage |
67 | | - new_trades_list = [] |
| 52 | + new_trades_list: list[str] = [] |
68 | 53 | for row in furniture_set: |
69 | 54 | new_trades_list.append("data modify storage gm4_furniture:temp new_trades." + set_name + ".trades append value {cost:[{id:" + row['craft_item_1_id'] + ",count:" + row['craft_item_1_count'] + "b},{id:" + row['craft_item_2_id'] + ",count:" + row['craft_item_2_count'] + "b}],result:{furniture_id:\"" + set_name + "/" + row['technical_id'] + "\",count:" + row['craft_result_count'] + "}}") |
70 | | - new_trades_list = '\n'.join(new_trades_list) |
71 | 55 |
|
72 | 56 | # add command to append the main furniture_station storage with the newly created new_trades |
73 | 57 | new_trades_append = "data modify storage gm4_furniture:data furniture_station prepend from storage gm4_furniture:temp new_trades." + set_name |
74 | 58 |
|
75 | 59 | # return the created commands |
76 | 60 | return(new_trades_init,new_trades_list,new_trades_append) |
77 | 61 |
|
78 | | - |
79 | | - |
80 | | -def generate_furniture_data(ctx, furniture_set, set_name): |
| 62 | +def generate_furniture_data(ctx: Context, furniture_set: CSV, set_name: str): |
81 | 63 |
|
82 | 64 | # create furniture loot tables and placement functions for every furniture in this category |
83 | 65 | for row in furniture_set: |
@@ -121,7 +103,10 @@ def generate_furniture_data(ctx, furniture_set, set_name): |
121 | 103 | } |
122 | 104 |
|
123 | 105 | ctx.require(subproject(subproject_config)) |
124 | | - |
| 106 | + |
| 107 | + ctx.generate("gm4_translations:en_us", merge=Language({ |
| 108 | + f"block.gm4_furniture.{ set_name }.{ row['technical_id'] }": row['display_name'] |
| 109 | + })) |
125 | 110 |
|
126 | 111 | class FurnitureStationGui(ContainerGuiOptions): |
127 | 112 | container = "furniture_station" |
|
0 commit comments