2
0
Fork
You've already forked bridge-protocol
0
No description
  • TypeScript 54.3%
  • JavaScript 45.7%
Find a file
2024年11月17日 03:23:39 +00:00
.gitee Initial commit 2024年11月16日 02:21:58 +00:00
BridgeProtocol.js BridgeProtocol : 24.11.15 版本更新 2024年11月16日 02:53:58 +00:00
BridgeProtocol.ts BridgeProtocol : 24.11.15 版本更新 2024年11月16日 02:53:58 +00:00
LICENSE update LICENSE. 2024年11月16日 03:05:25 +00:00
README.en.md update README.en.md. 2024年11月16日 05:35:58 +00:00
README.md 更新 README.md 2024年11月17日 03:23:39 +00:00
纳西妲.gif 创建仓库基础信息 2024年11月16日 02:45:50 +00:00

BridgeProtocol

中文

Introduction

  • The Unified Push Protocol (hereinafter referred to as "the Protocol") is a communication protocol designed for Bedrock Edition games, aiming to standardize data exchange between multiple mod packs.
  • The protocol provides a set of flexible interfaces, allowing developers to easily integrate and expand features, achieving modular data pushing.

Basic Information

  • Protocol Version:
v1.0.4.24.11.15
  • Architecture Author:
aa剑侠
  • Protocol Author:
钛宇-星光阁
  • Release Date:
2024年11月14日
  • Contact Information:
1965304849@qq.com

Core Concepts

Data Type Definitions

  • JSON Value Type (JSONValue): Supports strings, booleans, numbers, JSON objects, and JSON arrays.
  • JSON Object (JSONObject): A collection of key-value pairs, where the value can be any JSON value type.
  • JSON Array (JSONArray): An array of JSON value types.
  • Game Object Type (GameObject): Includes entities, blocks, players, dimensions, or item stacks.
  • Transmission Data Type (TransmissionDataType): Supports JSON values, game objects, and their arrays.

Function Definitions

  • Export Function Type (ExportFunctionType): A function that accepts TransmissionDataType parameters and returns TransmissionDataType values.

Event Listeners

  • Event Listener Interface (EventListener): Used for subscribing to and unsubscribing from event listening.

Script Messages

  • Script Message Interface (ScriptMessage): Standardizes the message format when scripts are executed.

Feature Implementation

  • Protocol Interceptor Class (ProtocolInterceptors): Handles custom logic before and after function calls.
  • Unified Push Protocol (BridgeProtocol): The core class, managing project identifiers, function lists, interceptors, and descriptive information.

Helper Functions

  • Event Getter (eventGetter): Creates a Promise to wait for a specified event to occur.
  • Random Integer Generator (randomFloor): Generates a random integer within a specified range.
  • Simplified Serial Number Generator (BriefID): Generates a serial number based on timestamps and random numbers.

Precautions

  • This system is only a protocol and does not involve specific feature implementations.
  • Each feature should be implemented independently by each mod.
  • The push system only serves as a carrier for data pushing and does not involve data processing and storage.

Usage Instructions

Exporting Functions

Add/Update Features: Add or update functions to the feature list through the exportFunction method.

Calling Functions

Asynchronous Calling: Use the call method to asynchronously call functions and wait for results.

Data Conversion

Data Conversion Functions: Including dataToArray, dataToTransmitString, typeConversion, etc., used to convert server script event command messages into suitable transmission data types.

String Representation

Game Object String Representation: Including blockToString, entityToString, dimensionToString, etc., used to convert game objects into string form.

Usage Examples

Creating a Protocol Instance:

const bridge = new BridgeProtocol();

Exporting Module Functions:

< Format >
bridge.exportFunction(myFunction, "myFunctionName");
bridge.exportFunction(myFunction);
bridge.exportFunctions=[myFunction, "myFunctionName"];
bridge.exportFunctions=[myFunction];
bridge.exportFunctions=[
 [myFunction, "myFunctionName"],
 [myFunction, "myFunctionName"],
];
bridge.exportFunctions=[
 [myFunction],
 [myFunction],
];
< Example >
bridge.exportFunction((player: server.Player)=>{ player.sendMessage("Hello, World!"); }, "sayHello");

Calling Module Functions:

< Format >
bridge.call("myFunctionName", [arg1, arg2]);
< Example >
bridge.call("sayHello", [player]);

Using Protocol Interceptors:

bridge.protocolInterceptors.onCalled(func, functionName, parameters);
bridge.protocolInterceptors.onCalling(callback, functionName, parameters);

Future Directions

  • Support More Game Object Types: For example, support container data, item data, etc.
  • Support More Precise Duplex Communication: For example, call a specific mod pack's function.
  • Support Cross-Mod Call Acceleration Reasoning: For example, increase the priority for high-frequency called functions, prohibit unresponsive calls from being sent again at the call layer.
Bouncing Naxida