From 0e0a4cc0f21f4a331512c0c005f81f329fabf422 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 10 Feb 2021 23:43:34 +0000 Subject: [PATCH 1/4] Merge docs for 'Carpet Mod 1.4.26 for Minecraft 1.16.5 and Minecraft 21w06a' --- docs/scarpet/Full.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/scarpet/Full.md b/docs/scarpet/Full.md index bbc489de..6e63fd9f 100644 --- a/docs/scarpet/Full.md +++ b/docs/scarpet/Full.md @@ -1781,6 +1781,11 @@ When loaded (via `/script load` command, etc.), the game will run the content of `__config()` function, if present, which will be executed once. Loading the app will also bind specific events to the event system (check Events section for details). +If an app defines `__on_start()` function, it will be executed once before running anything else. For global scoped apps, +this is just after they are loaded, and for player scoped apps, before they are used first time by a player. +Unlike static code (written directly in the body of the app code), that always run once per app, this may run multiple times if +its a player app nd multiple players are on the server. + Unloading an app removes all of its state from the game, disables commands, removes bounded events, and saves its global state. If more cleanup is needed, one can define `__on_close()` function which will be executed when the module is unloaded, or server is closing or crashing. However, there is no need to do that @@ -4002,11 +4007,32 @@ Here is a list of events that are handled by default in scarpet. This list inclu to autoload them, but you can always add any function to any event (using `/script event` command) if it accepts required number of parameters. +## Meta-events + +These events are not controlled / triggered by the game per se, but are important for the flow of the apps, however for all +intent and purpose can be treated as regular events. Unlike regular events, they cannot be hooked up to with 'handle_event', +but the apps themselves need to have them defined as distinct function definitions, same they cannot be signalled. + +### `__on_start()` +Called once per app in its logical execution run. For `'global'` scope apps its executed right after the app is loaded. For +`'player'` scope apps, it is triggered once per player before the app can be used by that player. Since each player app acts +independently from other player apps, this is probably the best location to include some player specific initializations. Static +code (i.e. code typed directly in the app code that executes immediately, outside of function definitions), will only execute once +per app, regardless of scope, `'__on_start()'` allows to reliably call player specific initializations. + +### `__on_close()` + +Called once per app when the app is closing or reloading, right before the app is removed. +For player scoped apps, its called once per player. Scarpet app engine will attempt to call `'__on_close()'` even if +the system is closing down exceptionally. + + ## Built-in global events Global events will be handled once per app that is with `'global'` scope. With `player` scoped apps, each player instance is responsible independently from handling their events, so a global event may be executed multiple times for each player. + ### `__on_server_starts()` Event triggers after world is loaded and after all startup apps have started. It won't be triggered with `/reload`. From 6a43ee25c71f48baea8b7f89e2d3bd6f6babf78a Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 16 Feb 2021 11:03:05 -0400 Subject: [PATCH 2/4] fixes #712 --- .../UpdateStructureBlockC2SPacketMixin.java | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java b/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java index da3d391a..29298f17 100644 --- a/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java +++ b/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java @@ -1,6 +1,8 @@ package carpet.mixins; +import carpet.CarpetServer; import carpet.CarpetSettings; +import carpet.network.CarpetClient; import net.minecraft.network.PacketByteBuf; import net.minecraft.network.packet.c2s.play.UpdateStructureBlockC2SPacket; import net.minecraft.util.math.BlockPos; @@ -23,7 +25,7 @@ public class UpdateStructureBlockC2SPacketMixin { at = @At("TAIL") ) private void structureBlockLimitsRead(PacketByteBuf buf, CallbackInfo ci) { - if (buf.readableBytes() > 0) { + if (buf.readableBytes() == 6*4) { // This will throw an exception if carpet is not installed on client offset = new BlockPos(MathHelper.clamp(buf.readInt(), -CarpetSettings.structureBlockLimit, CarpetSettings.structureBlockLimit), MathHelper.clamp(buf.readInt(), -CarpetSettings.structureBlockLimit, CarpetSettings.structureBlockLimit), MathHelper.clamp(buf.readInt(), -CarpetSettings.structureBlockLimit, CarpetSettings.structureBlockLimit)); size = new BlockPos(MathHelper.clamp(buf.readInt(), 0, CarpetSettings.structureBlockLimit), MathHelper.clamp(buf.readInt(), 0, CarpetSettings.structureBlockLimit), MathHelper.clamp(buf.readInt(), 0, CarpetSettings.structureBlockLimit)); @@ -35,11 +37,15 @@ public class UpdateStructureBlockC2SPacketMixin { at = @At("TAIL") ) private void structureBlockLimitsWrite(PacketByteBuf buf, CallbackInfo ci) { - buf.writeInt(this.offset.getX()); - buf.writeInt(this.offset.getY()); - buf.writeInt(this.offset.getZ()); - buf.writeInt(this.size.getX()); - buf.writeInt(this.size.getY()); - buf.writeInt(this.size.getZ()); + //client method, only applicable if with carpet is on the server, or running locally + if (CarpetClient.isCarpet() || CarpetServer.minecraft_server != null) + { + buf.writeInt(this.offset.getX()); + buf.writeInt(this.offset.getY()); + buf.writeInt(this.offset.getZ()); + buf.writeInt(this.size.getX()); + buf.writeInt(this.size.getY()); + buf.writeInt(this.size.getZ()); + } } } From 5b1ef770097259e61d340f24ebbc57629aa9955f Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 16 Feb 2021 11:08:54 -0400 Subject: [PATCH 3/4] only when necessary really --- .../java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java b/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java index 29298f17..74a36526 100644 --- a/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java +++ b/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java @@ -38,7 +38,7 @@ public class UpdateStructureBlockC2SPacketMixin { ) private void structureBlockLimitsWrite(PacketByteBuf buf, CallbackInfo ci) { //client method, only applicable if with carpet is on the server, or running locally - if (CarpetClient.isCarpet() || CarpetServer.minecraft_server != null) + if (CarpetSettings.structureBlockLimit >= 128 && (CarpetClient.isCarpet() || CarpetServer.minecraft_server != null)) { buf.writeInt(this.offset.getX()); buf.writeInt(this.offset.getY()); From df7a4a6681bd2c23fbcefabed87e3d591b2ba6a3 Mon Sep 17 00:00:00 2001 From: gnembon Date: Wed, 17 Feb 2021 03:09:41 -0400 Subject: [PATCH 4/4] applying altrisi's observations. --- src/main/java/carpet/CarpetSettings.java | 2 +- .../java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/carpet/CarpetSettings.java b/src/main/java/carpet/CarpetSettings.java index f77a1a2f..40fdb082 100644 --- a/src/main/java/carpet/CarpetSettings.java +++ b/src/main/java/carpet/CarpetSettings.java @@ -819,7 +819,7 @@ public class CarpetSettings "'structureBlockOutlineDistance' may be required for", "correct rendering of long structures."}, options = {"48", "96", "192", "256"}, - category = {CREATIVE, CLIENT}, + category = CREATIVE, validate = StructureBlockLimitValidator.class, strict = false ) diff --git a/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java b/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java index 74a36526..b7177773 100644 --- a/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java +++ b/src/main/java/carpet/mixins/UpdateStructureBlockC2SPacketMixin.java @@ -38,7 +38,7 @@ public class UpdateStructureBlockC2SPacketMixin { ) private void structureBlockLimitsWrite(PacketByteBuf buf, CallbackInfo ci) { //client method, only applicable if with carpet is on the server, or running locally - if (CarpetSettings.structureBlockLimit >= 128 && (CarpetClient.isCarpet() || CarpetServer.minecraft_server != null)) + if (CarpetSettings.structureBlockLimit >= 128) { buf.writeInt(this.offset.getX()); buf.writeInt(this.offset.getY());