96 lines
3.7 KiB
Python
96 lines
3.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""将 8 个纯贴图医疗物品加入网易基岩版模组(与 _tmp/add_materials.py 同风格)"""
|
|
import os, json, shutil
|
|
|
|
ROOT = r'e:\MCStudioDownload\work\3027246179@qq.com\Cpp\AddOn\0aaaa4f2f16c46e8964025a5ab0ecc02'
|
|
BP = os.path.join(ROOT, 'behavior_pack_kcH4M5u0')
|
|
RP = os.path.join(ROOT, 'resource_pack_t7eJjrxY')
|
|
TEX_SRC = os.path.join(ROOT, '_sa_medical_textures')
|
|
|
|
# id, 中文名, 说明(tooltip)
|
|
ITEMS = [
|
|
('plaster', '创可贴', '医疗用品,用于轻度包扎治疗。'),
|
|
('splint', '夹板', '医疗用品,用于固定骨折部位。'),
|
|
('alcohol_wipes', '酒精湿巾', '医疗用品,用于消毒。'),
|
|
('blood_bag', '血袋', '医疗用品,用于输血补血。'),
|
|
('blood_bag_empty', '空血袋', '空的血袋,可用于采集血液。'),
|
|
('painkiller_pills', '止痛药丸', '口服止痛药,可缓解疼痛。'),
|
|
('stamina_boost_pills', '耐力增强药丸', '口服增强药,可提升耐力。'),
|
|
('tube', '管子', '医疗用品,用于输液。'),
|
|
]
|
|
|
|
# 1) 复制贴图
|
|
tex_dst = os.path.join(RP, 'textures', 'items')
|
|
for i, _, _ in ITEMS:
|
|
shutil.copyfile(os.path.join(TEX_SRC, i + '.png'), os.path.join(tex_dst, i + '.png'))
|
|
|
|
# 2) 行为包物品 json
|
|
for i, _, tip in ITEMS:
|
|
obj = {
|
|
"format_version": "1.10",
|
|
"minecraft:item": {
|
|
"components": {
|
|
"minecraft:max_stack_size": 64,
|
|
"netease:customtips": {"value": tip}
|
|
},
|
|
"description": {
|
|
"category": "dn_sa",
|
|
"identifier": "dn_sa:" + i
|
|
}
|
|
}
|
|
}
|
|
with open(os.path.join(BP, 'netease_items_beh', 'dn_sa_%s.json' % i), 'w', encoding='utf-8') as f:
|
|
json.dump(obj, f, ensure_ascii=False, indent=4)
|
|
|
|
# 3) 资源包物品 json
|
|
for i, _, _ in ITEMS:
|
|
obj = {
|
|
"format_version": "1.10",
|
|
"minecraft:item": {
|
|
"components": {"minecraft:icon": "dn_sa:" + i},
|
|
"description": {"identifier": "dn_sa:" + i}
|
|
}
|
|
}
|
|
with open(os.path.join(RP, 'netease_items_res', 'dn_sa_%s.json' % i), 'w', encoding='utf-8') as f:
|
|
json.dump(obj, f, ensure_ascii=False, indent=4)
|
|
|
|
# 4) item_texture.json 登记
|
|
itp = os.path.join(RP, 'textures', 'item_texture.json')
|
|
with open(itp, encoding='utf-8') as f:
|
|
data = json.load(f)
|
|
td = data['texture_data']
|
|
for i, _, _ in ITEMS:
|
|
td['dn_sa:' + i] = {"textures": "textures/items/" + i}
|
|
with open(itp, 'w', encoding='utf-8') as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=4)
|
|
|
|
# 5) group_config.json 新增医疗分组
|
|
gc = os.path.join(BP, 'netease_group', 'group_config.json')
|
|
with open(gc, encoding='utf-8') as f:
|
|
gdata = json.load(f)
|
|
names = [g['group_name'] for g in gdata['groups']]
|
|
if 'itemGroup.name.dn_sa_med' not in names:
|
|
gdata['groups'].append({
|
|
"group_name": "itemGroup.name.dn_sa_med",
|
|
"icon": "dn_sa:plaster",
|
|
"list": ["dn_sa:" + i for i, _, _ in ITEMS]
|
|
})
|
|
with open(gc, 'w', encoding='utf-8') as f:
|
|
json.dump(gdata, f, ensure_ascii=False, indent=2)
|
|
|
|
# 6) zh_CN.lang
|
|
lang = os.path.join(RP, 'texts', 'zh_CN.lang')
|
|
with open(lang, encoding='utf-8') as f:
|
|
lines = f.read().rstrip('\n').split('\n')
|
|
existing = set(l.split('=')[0] for l in lines if '=' in l)
|
|
add = []
|
|
if 'itemGroup.name.dn_sa_med' not in existing:
|
|
add.append('itemGroup.name.dn_sa_med=医疗用品')
|
|
for i, cn, _ in ITEMS:
|
|
k = 'item.dn_sa:%s.name' % i
|
|
if k not in existing:
|
|
add.append('%s=%s' % (k, cn))
|
|
with open(lang, 'w', encoding='utf-8') as f:
|
|
f.write('\n'.join(lines) + '\n\n' + '\n'.join(add) + '\n')
|
|
|
|
print('OK: %d items' % len(ITEMS)) |