import os

# 目标目录
TARGET_DIR = r"D:\Minrcraft Run1\versions\26.1.2-Fabric\resourcepacks\Featured 1.5\assets\minecraft\models\item\armor"

def process_files():
    print(f"目标目录: {TARGET_DIR}\n")

    if not os.path.exists(TARGET_DIR):
        print("[错误] 目录不存在！")
        return

    for filename in os.listdir(TARGET_DIR):
        if filename.endswith(".json") and "trim" in filename:
            file_path = os.path.join(TARGET_DIR, filename)
            print(f"正在处理: {filename}")

            parts = filename.split("_")
            
            if len(parts) < 3:
                print("  [跳过] 文件名结构异常")
                continue

            material = parts[2]
            print(f"  材料识别为: {material}")

            try:
                with open(file_path, "r", encoding="utf-8") as f:
                    content = f.read()

                # 删除 _材料
                content = content.replace(f"_{material}", "")

                # 替换路径
                content = content.replace(
                    "trims/items",
                    f"item/custom_overlay/{material}"
                )

                with open(file_path, "w", encoding="utf-8") as f:
                    f.write(content)

                print("  [完成] 修改成功\n")

            except Exception as e:
                print(f"  [错误] {e}\n")

if __name__ == "__main__":
    process_files()
    input("处理完成，按回车键退出...")  # 防止窗口关闭