56 lines
2.2 KiB
Python
56 lines
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""把 44 个食物物品分到独立分页 dn_sa_food(食物),材料保留 dn_sa"""
|
||
import os, json, csv
|
||
|
||
BASE = r'e:\MCStudioDownload\work\3027246179@qq.com\Cpp\AddOn\309c2d420bc84ee986db9cdd070ff02a'
|
||
DROP = {'box_of_nails', 'box_of_paperclips', 'box_of_screws', 'gunpowder_bottle', 'rope',
|
||
'water_bottle', 'water_bottle2', 'blank', 'empty_glass_bottle', 'falsh_lights',
|
||
'cellphone', 'jerry_can', 'dirty_water_bottle'}
|
||
|
||
# 材料集合(63)
|
||
mats = set()
|
||
with open(os.path.join(BASE, '_sa_materials.csv'), encoding='utf-8-sig') as f:
|
||
for row in csv.reader(f):
|
||
if row and row[1].endswith('.png') and row[0].isdigit() and row[1][:-4] not in DROP:
|
||
mats.add(row[1][:-4])
|
||
|
||
BEHDIR = os.path.join(BASE, 'behavior_pack_kcH4M5u0/netease_items_beh')
|
||
food_count, mat_count = 0, 0
|
||
for fn in sorted(os.listdir(BEHDIR)):
|
||
if not fn.endswith('.json'):
|
||
continue
|
||
name = fn[len('dn_sa_'):-5]
|
||
p = os.path.join(BEHDIR, fn)
|
||
d = json.load(open(p, encoding='utf-8'))
|
||
if name in mats:
|
||
mat_count += 1 # 材料,保持 dn_sa
|
||
else:
|
||
d['minecraft:item']['description']['category'] = 'dn_sa_food'
|
||
json.dump(d, open(p, 'w', encoding='utf-8'), ensure_ascii=False, indent=4)
|
||
food_count += 1
|
||
print('食物 category 改为 dn_sa_food:', food_count, '| 材料保持 dn_sa:', mat_count)
|
||
|
||
# tab.json 添加食物分页
|
||
TP = os.path.join(BASE, 'behavior_pack_kcH4M5u0/netease_tab/tab.json')
|
||
t = json.load(open(TP, encoding='utf-8'))
|
||
t['category'].append({
|
||
'name': 'dn_sa_food',
|
||
'labelText': 'dn_sa:tab_food',
|
||
'icon': 'textures/items/burger'
|
||
})
|
||
json.dump(t, open(TP, 'w', encoding='utf-8'), ensure_ascii=False, indent=4)
|
||
print('tab.json 分页数:', len(t['category']))
|
||
|
||
# lang 添加分页标题
|
||
LP = os.path.join(BASE, 'resource_pack_t7eJjrxY/texts/zh_CN.lang')
|
||
lang = open(LP, encoding='utf-8').read()
|
||
if 'dn_sa:tab_food=' not in lang:
|
||
open(LP, 'a', encoding='utf-8').write('\ndn_sa:tab_food=食物\n')
|
||
print('lang 添加: dn_sa:tab_food=食物')
|
||
else:
|
||
print('lang 已有 tab_food')
|
||
|
||
# 验证
|
||
beh = [f for f in os.listdir(BEHDIR) if f.endswith('.json')]
|
||
print('beh json 总数:', len(beh))
|