Skip to content

Commit

Permalink
Merge branch '1.3.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestOfLight committed Dec 22, 2024
2 parents 77cbd5a + c531a8f commit 71f56ff
Show file tree
Hide file tree
Showing 31 changed files with 1,310 additions and 129 deletions.
2 changes: 2 additions & 0 deletions Canopy [BP]/entities/probe.json
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@
]
}
},
// Pale Gardens - whenever it gets added to the official docs

// Plains
{
"event": "canopy:plains",
Expand Down
4 changes: 2 additions & 2 deletions Canopy [BP]/manifest.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"format_version": 2,
"header": {
"name": "Canopy [BP] v1.3.6",
"name": "Canopy [BP] v1.3.7",
"description": "Technical informatics & features addon by §aForestOfLight§r.",
"uuid": "7f6b23df-a583-476b-b0e4-87457e65f7c0",
"min_engine_version": [1, 21, 50],
"version": [1, 3, 6]
"version": [1, 3, 7]
},
"modules": [
{
Expand Down
11 changes: 8 additions & 3 deletions Canopy [BP]/scripts/lib/canopy/Command.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { world, system } from '@minecraft/server';
import IPC from 'lib/ipc/ipc';
import ArgumentParser from './ArgumentParser';
import Rule from './Rule';

Expand Down Expand Up @@ -82,8 +83,12 @@ class Command {

runCallback(sender, args) {
if (this.#extensionName) {
// console.warn(`[Canopy] Sending ${this.#extensionName} command callback: '${this.#name} ${JSON.stringify(args)}'`);
world.getDimension('overworld').runCommandAsync(`scriptevent canopyExtension:commandCallbackRequest ${this.#extensionName} "${sender?.name}" ${this.#name} ${JSON.stringify(args)}`);
// console.warn(`[Canopy] Sending ${this.#extensionName} command callback from ${sender?.name}: '${this.#name} ${JSON.stringify(args)}'`);
IPC.send(`canopyExtension:${this.#extensionName}:commandCallbackRequest`, {
commandName: this.#name,
senderName: sender?.name,
args: args
});
return;
}
this.#callback(sender, args);
Expand Down Expand Up @@ -138,7 +143,7 @@ class Command {
}

static broadcastPrefix() {
world.getDimension('overworld').runCommandAsync(`scriptevent canopyExtension:commandPrefix ${Command.prefix}`);
IPC.send('canopy:commandPrefix', Command.prefix);
}
}

Expand Down
35 changes: 11 additions & 24 deletions Canopy [BP]/scripts/lib/canopy/Rule.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { world, system } from '@minecraft/server';
import { world } from '@minecraft/server';
import IPC from "lib/ipc/ipc";

const rules = {};

Expand All @@ -19,7 +20,8 @@ class Rule {
this.#extensionName = extensionName;
if (Rule.exists(identifier)) {
throw new Error(`Rule with identifier '${identifier}' already exists.`);
} rules[identifier] = this;
}
rules[identifier] = this;
}

getCategory() {
Expand Down Expand Up @@ -48,30 +50,14 @@ class Rule {

async getValue() {
if (this.#extensionName) {
try {
world.getDimension('overworld').runCommandAsync(`scriptevent canopyExtension:ruleValueRequest ${this.#extensionName} ${this.#identifier}`);
const result = await new Promise((resolve, reject) => {
system.afterEvents.scriptEventReceive.subscribe((event) => this.recieveRuleValue(event, resolve), { namespaces: ['canopyExtension'] });
});
return this.parseString(result);
} catch (error) {
throw new Error(`[Canopy] [Rule] Error getting value for ${this.#identifier}: ${error}`);
}
// console.warn(`[Canopy] [Rule] Attempting to get value for ${this.#identifier} from extension ${this.#extensionName}.`);
return await IPC.invoke(`canopyExtension:${this.#extensionName}:ruleValueRequest`, { ruleID: this.#identifier }).then(result => {
// console.warn(`[Canopy] [Rule] Received value for ${this.#identifier} from extension ${this.#extensionName}: ${result}`);
return result;
});
}
return this.parseString(world.getDynamicProperty(this.#identifier));
}

async recieveRuleValue(scriptEventReceive, resolve) {
if (scriptEventReceive.id !== 'canopyExtension:ruleValueResponse' || scriptEventReceive.sourceType !== 'Server') return;
const splitMessage = scriptEventReceive.message.split(' ');
const extensionName = splitMessage[0];
if (extensionName !== this.#extensionName) return;
const ruleID = splitMessage[1];
if (ruleID !== this.#identifier) return;
const value = splitMessage[2];
// console.warn(`[Canopy] Received rule value: ${extensionName}:${ruleID} ${value}`);
resolve(value);
}

parseString(value) {
try {
Expand All @@ -80,11 +66,12 @@ class Rule {
if (value === 'undefined') return undefined;
if (value === 'NaN') return NaN;
}
return null;
}

setValue(value) {
if (this.#extensionName) {
world.getDimension('overworld').runCommandAsync(`scriptevent canopyExtension:ruleValueSet ${this.#extensionName} ${this.#identifier} ${value}`);
IPC.send(`canopyExtension:${this.#extensionName}:ruleValueSet`, { extensionName: this.#extensionName, ruleID: this.#identifier, value: value });
} else {
world.setDynamicProperty(this.#identifier, value);
}
Expand Down
16 changes: 3 additions & 13 deletions Canopy [BP]/scripts/lib/canopy/registry/CommandRegistry.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { system } from "@minecraft/server";
import IPC from 'lib/ipc/ipc';
import Command from "../Command";

system.afterEvents.scriptEventReceive.subscribe((event) => {
if (event.sourceType !== 'Server' || event.id !== 'canopyExtension:registerCommand') return;
const message = event.message;
const extensionName = message.split(' ')[0];
let cmdData;
try {
cmdData = JSON.parse(message.slice(extensionName.length + 1));
} catch (error) {
console.warn(`[CommandRegistry] Failed to parse command data: ${error}, ${event.message}`);
}
if (!cmdData) return;
IPC.on('canopyExtension:registerCommand', (cmdData) => {
if (typeof cmdData.description === 'string')
cmdData.description = { text: cmdData.description };
for (const helpEntry of cmdData.helpEntries) {
Expand All @@ -20,4 +10,4 @@ system.afterEvents.scriptEventReceive.subscribe((event) => {
}
new Command(cmdData);
// console.warn(`[Canopy] Registered command: ${cmdData.extensionName}:${cmdData.name}`);
}, { namespaces: ['canopyExtension']});
});
16 changes: 3 additions & 13 deletions Canopy [BP]/scripts/lib/canopy/registry/RuleRegistry.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import { system } from "@minecraft/server";
import IPC from "lib/ipc/ipc";
import Rule from "../Rule";

system.afterEvents.scriptEventReceive.subscribe((event) => {
if (event.sourceType !== 'Server' || event.id !== 'canopyExtension:registerRule') return;
const message = event.message;
const extensionName = message.split(' ')[0];
let ruleData;
try {
ruleData = JSON.parse(message.slice(extensionName.length + 1));
} catch (error) {
console.warn(`[RuleRegistry] Failed to parse rule data: ${error}, ${event.message}`);
}
if (!ruleData) return;
IPC.on('canopyExtension:registerRule', (ruleData) => {
if (typeof ruleData.description === 'string')
ruleData.description = { text: ruleData.description };
new Rule(ruleData);
// console.warn(`[Canopy] Registered rule: ${ruleData.extensionName}:${ruleData.identifier}`);
}, { namespaces: ['canopyExtension']});
});
74 changes: 74 additions & 0 deletions Canopy [BP]/scripts/lib/ipc/ipc.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @license
* MIT License
*
* Copyright (c) 2024 OmniacDev
*
* 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.
*/
declare namespace IPC {
class Connection {
private readonly _from;
private readonly _to;
private readonly _enc;
private readonly _terminators;
private MAYBE_ENCRYPT;
private MAYBE_DECRYPT;
get from(): string;
get to(): string;
constructor(from: string, to: string, encryption: string | false);
terminate(notify?: boolean): void;
send(channel: string, ...args: any[]): void;
invoke(channel: string, ...args: any[]): Promise<any>;
on(channel: string, listener: (...args: any[]) => void): () => void;
once(channel: string, listener: (...args: any[]) => void): () => void;
handle(channel: string, listener: (...args: any[]) => any): () => void;
}
class ConnectionManager {
private readonly _id;
private readonly _enc_map;
private readonly _con_map;
private readonly _enc_force;
private MAYBE_ENCRYPT;
private MAYBE_DECRYPT;
get id(): string;
constructor(id: string, force_encryption?: boolean);
connect(to: string, encrypted?: boolean, timeout?: number): Promise<Connection>;
send(channel: string, ...args: any[]): void;
invoke(channel: string, ...args: any[]): Promise<any>[];
on(channel: string, listener: (...args: any[]) => void): () => void;
once(channel: string, listener: (...args: any[]) => void): () => void;
handle(channel: string, listener: (...args: any[]) => any): () => void;
}
/** Sends a message with `args` to `channel` */
function send(channel: string, ...args: any[]): void;
/** Sends an `invoke` message through IPC, and expects a result asynchronously. */
function invoke(channel: string, ...args: any[]): Promise<any>;
/** Listens to `channel`. When a new message arrives, `listener` will be called with `listener(args)`. */
function on(channel: string, listener: (...args: any[]) => void): () => void;
/** Listens to `channel` once. When a new message arrives, `listener` will be called with `listener(args)`, and then removed. */
function once(channel: string, listener: (...args: any[]) => void): () => void;
/** Adds a handler for an `invoke` IPC. This handler will be called whenever `invoke(channel, ...args)` is called */
function handle(channel: string, listener: (...args: any[]) => any): () => void;
}
export default IPC;
export declare namespace NET {
function emit(namespace: string, event: string, channel: string, args: any[]): Generator<void, void, void>;
function listen(namespace: string, event: string, channel: string, callback: (args: any[]) => Generator<void, void, void>): () => void;
}
Loading

0 comments on commit 71f56ff

Please sign in to comment.