-
Bug
-
Resolution: Invalid
-
None
-
1.17.20.21 Beta, 1.17.2 Hotfix
-
None
-
Unconfirmed
-
Windows
You can have as many or as few JavaScript files as you want here (the name of the files doesn't matter) and they will all be run independently of each other!
This is JavaScript. The Scripting Documentation is supposed to tell me if "they will all be run independently of each other" means that, like being run in their own Web Workers, they will not block each other.
In Addition, like Web Workers, there should be API allows scripts to interact with each other.
I have tried to interact with another script running on the same side using events but it doesn't work. Listeners will be called only when the broadcast happens on the other side.
Broadcasting an event should cause all of listeners of this event to be called, no matter which side the listener is on! Even listeners in the same script should also be called. To decide whether the event should be handled by a listener or not is not API's business, just like UDP broadcasting.
// server-side listener const system = server.registerSystem(0, 0); system.initialize = function () { this.registerEventData("TestNamespace:test_event", { msg: "MyString" }); this.listenForEvent("TestNamespace:test_event", (event) => { const msg = this.createEventData("minecraft:display_chat_event"); msg.data.message = event.data.msg; this.broadcastEvent("minecraft:display_chat_event", msg) }) };
// client-side script const system = client.registerSystem(0, 0); system.initialize = function () { this.registerEventData("TestNamespace:test_event", { msg: "MyString" }); this.listenForEvent("minecraft:hit_result_changed", () => { const event = this.createEventData("TestNamespace:test_event"); event.data.msg = "from client"; this.broadcastEvent("TestNamespace:test_event", event) }) };
// server-side script const system = server.registerSystem(0, 0); system.initialize = function () { this.registerEventData("TestNamespace:test_event", { msg: "MyString" }) }; system.update = function () { const event = this.createEventData("TestNamespace:test_event"); event.data.msg = "from server"; this.broadcastEvent("TestNamespace:test_event", event) };