@occultus/core - v2.0.0-beta.4
    Preparing search index...

    @occultus/core - v2.0.0-beta.4

    Occultus SDK - Core

    这是 Occultus SDK(Script Development Kit)的核心脚本部件

    我们需要使用 Node.js 以及其对应的包管理工具来获取 Occultus SDK。

    我们推荐使用 pnpm,Occultus SDK 的包管理工具就是 pnpm。

    如果你的计算机上没有安装,请访问 https://nodejs.org/ 下载并安装 Node.js。

    接着根据你使用的包管理工具选择适合的命令进行初始化:

    npm init
    pnpm init
    yarn init

    接着根据你使用的包管理工具选择适合的命令进行安装:

    npm install @occultus/core
    pnpm add @occultus/core
    yarn add @occultus/core

    你也可以直接从 Codeberg 下载我们打包好的依赖文件,并手动添加到你的项目中。

    使用 ModInitializer 类来初始化你的模组:

    // 对于直接获取依赖文件的开发者,请使用相对路径而非模块名
    import { ModInitializer } from '@occultus/core';

    // 使用静态方法初始化模组
    const initializer = ModInitializer.initialize(
    "test", // 模组ID
    "Occultus SDK Test", // 模组名称
    "1.14.514", // 模组版本
    (arg) => { // 初始化回调
    console.log("Occultus SDK Test Mod has been initialized!");
    }
    );
    // 获取模组ID
    const modId = initializer.getModId();

    // 获取模组名称
    const modName = initializer.getModName();

    // 获取模组版本
    const version = initializer.getVersion();

    一般情况下,注册表应当由各个 API 实现具体功能,这里只有最基础的类型约定

    使用 ModManager 类管理注册表:

    import { ModManager, Registries } from '@occultus/core';

    // 添加注册表
    ModManager.addRegistry(registry);

    // 获取注册表
    const registry = ModManager.getRegistry("registry_id");

    使用 ModMessageServer 类处理模组间通信:

    import { ModMessageServer } from '@occultus/core';

    const messageServer = new ModMessageServer();

    // 定义消息处理器
    messageServer.defineMessage("custom_message", (event) => {
    console.log(`Received message: ${event.message}`);
    });

    // 发送消息
    messageServer.postMessage("custom_message", "data");

    打包脚本时,你需要一个支持将依赖递归打包进输出文件的脚本打包器,例如 Esbuild。

    Occultus SDK 的核心脚本组件(即本包)支持任意可以运行 Script API v2.0.0+ 的游戏版本,包括:

    • 1.21.90;
    • 1.21.100;
    • 1.21.110;
    • 以及更多……

    注意:本包理论上可以在部分更旧的版本上运作,但未进行测试,一些接口也可能会失效。

    本项目使用 MIT License 授权:

    The MIT License (MIT)
    
    Copyright © 2025 CTN Studios
    
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.