|
4 | 4 |
|
5 | 5 |
|
6 | 6 | def convert(_dir, version, edition ='pc'): |
7 | | - fp = open(os.path.join(_dir, 'dataPaths.json')) |
8 | | - datapaths = json.load(fp) |
9 | | - fp.close() |
| 7 | + with open(os.path.join(_dir, 'dataPaths.json')) as f: |
| 8 | + datapaths = json.load(f) |
10 | 9 | data = _grabdata(_dir, datapaths[edition][version]) |
11 | 10 | ret = {} |
12 | | - if 'blocks' in data: |
13 | | - ret['blocks'] = _by_id(data['blocks']) |
14 | | - ret['blocks_name'] = _by_name(data['blocks']) |
15 | | - ret['blocks_list'] = data['blocks'] |
16 | | - if 'items' in data: |
17 | | - ret['items'] = _by_id(data['items']) |
18 | | - ret['items_name'] = _by_name(data['items']) |
19 | | - ret['items_list'] = data['items'] |
20 | | - if 'biomes' in data: |
21 | | - ret['biomes'] = _by_id(data['biomes']) |
22 | | - ret['biomes_list'] = data['biomes'] |
23 | | - if 'recipes' in data: |
24 | | - ret['recipes'] = data['recipes'] |
25 | | - if 'instruments' in data: |
26 | | - ret['instruments'] = _by_id(data['instruments']) |
27 | | - ret['instruments_list'] = data['instruments'] |
28 | | - if 'materials' in data: |
29 | | - ret['materials'] = data['materials'] |
| 11 | + for datum in ('recipes', 'materials', 'protocol', 'version', |
| 12 | + 'blockCollisionShapes', 'protocolComments'): |
| 13 | + if datum in data: |
| 14 | + ret[datum] = data[datum] |
| 15 | + for datum in ('blocks', 'items', 'windows', 'effects', 'particles', |
| 16 | + 'biomes', 'instruments', 'enchantments', 'foods'): |
| 17 | + if datum in data: |
| 18 | + ret[datum] = _by_id(data[datum]) |
| 19 | + ret[f"{datum}_name"] = _by_name(data[datum]) |
| 20 | + ret[f"{datum}_list"] = data[datum] |
30 | 21 | if 'entities' in data: |
31 | 22 | ret['mobs'] = _by_id(_filter('type', 'mob', data['entities'])) |
32 | 23 | ret['objects'] = _by_id(_filter('type', 'object', data['entities'])) |
33 | 24 | ret['entities_name'] = _by_name(data['entities']) |
34 | 25 | ret['entities_list'] = data['entities'] |
35 | | - if 'protocol' in data: |
36 | | - ret['protocol'] = data['protocol'] |
37 | | - if 'windows' in data: |
38 | | - ret['windows'] = _by_id(data['windows']) |
39 | | - ret['windows_name'] = _by_name(data['windows']) |
40 | | - ret['windows_list'] = data['windows'] |
41 | | - if 'effects' in data: |
42 | | - ret['effects'] = _by_id(data['effects']) |
43 | | - ret['effects_name'] = _by_name(data['effects']) |
44 | | - ret['effects_list'] = data['effects'] |
45 | | - if 'version' in data: |
46 | | - ret['version'] = data['version'] |
47 | | - if 'particles' in data: |
48 | | - ret['particles'] = _by_id(data['particles']) |
49 | | - ret['particles_name'] = _by_name(data['particles']) |
50 | | - ret['particles_list'] = data['particles'] |
| 26 | + |
51 | 27 |
|
52 | 28 | def find_item_or_block(find): |
53 | 29 | if isinstance(find, int): # by id |
|
0 commit comments