Skip to content

Commit

Permalink
And more protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yh-china committed Jun 28, 2024
1 parent 0596dee commit a4f9ea5
Show file tree
Hide file tree
Showing 56 changed files with 43 additions and 24 deletions.
16 changes: 8 additions & 8 deletions patches/server/0006-Leaves-Server-Config-And-Command.patch
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ index 459f47244bdfeab63b5f16d780b0291d36310de8..a872421bc3e67fdcc929f104f4b085fb
.withRequiredArg()
diff --git a/src/main/java/org/leavesmc/leaves/LeavesConfig.java b/src/main/java/org/leavesmc/leaves/LeavesConfig.java
new file mode 100644
index 0000000000000000000000000000000000000000..9405d8ff041434a1fce98f744c51b22032889078
index 0000000000000000000000000000000000000000..afe13ae207eaa294e3299f15874d28df3a55e32d
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/LeavesConfig.java
@@ -0,0 +1,888 @@
Expand Down Expand Up @@ -116,8 +116,8 @@ index 0000000000000000000000000000000000000000..9405d8ff041434a1fce98f744c51b220
+import org.leavesmc.leaves.protocol.CarpetServerProtocol.CarpetRule;
+import org.leavesmc.leaves.protocol.CarpetServerProtocol.CarpetRules;
+
+//import org.leavesmc.leaves.protocol.bladeren.BladerenProtocol.LeavesFeatureSet; // Leaves - remove protocol temporarily
+//import org.leavesmc.leaves.protocol.bladeren.BladerenProtocol.LeavesFeature; // Leaves - remove protocol temporarily
+import org.leavesmc.leaves.protocol.bladeren.BladerenProtocol.LeavesFeatureSet;
+import org.leavesmc.leaves.protocol.bladeren.BladerenProtocol.LeavesFeature;
+
+public final class LeavesConfig {
+
Expand Down Expand Up @@ -295,7 +295,7 @@ index 0000000000000000000000000000000000000000..9405d8ff041434a1fce98f744c51b220
+ private static class RNGFishingVerify extends ConfigVerify.BooleanConfigVerify {
+ @Override
+ public String check(Boolean old, Boolean value) {
+// LeavesFeatureSet.register(LeavesFeature.of("rng_fishing", value)); // Leaves - remove protocol temporarily
+ LeavesFeatureSet.register(LeavesFeature.of("rng_fishing", value));
+ return null;
+ }
+ }
Expand Down Expand Up @@ -407,7 +407,7 @@ index 0000000000000000000000000000000000000000..9405d8ff041434a1fce98f744c51b220
+ private static class UseVanillaRandomVerify extends ConfigVerify.BooleanConfigVerify {
+ @Override
+ public String check(Boolean old, Boolean value) {
+// LeavesFeatureSet.register(LeavesFeature.of("use_vanilla_random", value)); // Leaves - remove protocol temporarily
+ LeavesFeatureSet.register(LeavesFeature.of("use_vanilla_random", value));
+ return null;
+ }
+ }
Expand Down Expand Up @@ -459,7 +459,7 @@ index 0000000000000000000000000000000000000000..9405d8ff041434a1fce98f744c51b220
+ private static class LavaRiptideVerify extends ConfigVerify.BooleanConfigVerify {
+ @Override
+ public String check(Boolean old, Boolean value) {
+// LeavesFeatureSet.register(LeavesFeature.of("lava_riptide", value)); // Leaves - remove protocol temporarily
+ LeavesFeatureSet.register(LeavesFeature.of("lava_riptide", value));
+ return null;
+ }
+ }
Expand Down Expand Up @@ -733,7 +733,7 @@ index 0000000000000000000000000000000000000000..9405d8ff041434a1fce98f744c51b220
+ private static class MSPTSyncVerify extends ConfigVerify.BooleanConfigVerify {
+ @Override
+ public String check(Boolean old, Boolean value) {
+// LeavesFeatureSet.register(LeavesFeature.of("mspt_sync", value)); // Leaves - remove protocol temporarily
+ LeavesFeatureSet.register(LeavesFeature.of("mspt_sync", value));
+ return null;
+ }
+ }
Expand Down Expand Up @@ -765,7 +765,7 @@ index 0000000000000000000000000000000000000000..9405d8ff041434a1fce98f744c51b220
+ @Override
+ public String check(Boolean old, Boolean value) {
+ if (value) {
+// org.leavesmc.leaves.protocol.syncmatica.SyncmaticaProtocol.init(); // Leaves - remove protocol temporarily
+ org.leavesmc.leaves.protocol.syncmatica.SyncmaticaProtocol.init();
+ }
+ return null;
+ }
Expand Down
14 changes: 12 additions & 2 deletions patches/server/0055-Syncmatica-Protocol.patch
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ index bef88d547aefa9c5b701aa91ffc58114309a7db7..51a1be78de7a794d13b64db6958977e2
if (this.ackBlockChangesUpTo > -1) {
diff --git a/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java
new file mode 100644
index 0000000000000000000000000000000000000000..a0c385dcd1b040521512e1125e7ff7aefcbd9d64
index 0000000000000000000000000000000000000000..8c0fd40a89681ef71d9dd2ad63d858e1aad82ceb
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/syncmatica/CommunicationManager.java
@@ -0,0 +1,387 @@
@@ -0,0 +1,397 @@
+package org.leavesmc.leaves.protocol.syncmatica;
+
+import com.mojang.authlib.GameProfile;
Expand All @@ -44,6 +44,7 @@ index 0000000000000000000000000000000000000000..a0c385dcd1b040521512e1125e7ff7ae
+import net.minecraft.world.level.block.Mirror;
+import net.minecraft.world.level.block.Rotation;
+import org.jetbrains.annotations.NotNull;
+import org.leavesmc.leaves.LeavesConfig;
+import org.leavesmc.leaves.protocol.core.LeavesProtocol;
+import org.leavesmc.leaves.protocol.core.LeavesProtocolManager;
+import org.leavesmc.leaves.protocol.core.ProtocolHandler;
Expand Down Expand Up @@ -100,6 +101,9 @@ index 0000000000000000000000000000000000000000..a0c385dcd1b040521512e1125e7ff7ae
+
+ @ProtocolHandler.PlayerJoin
+ public static void onPlayerJoin(ServerPlayer player) {
+ if (!LeavesConfig.syncmaticaProtocol) {
+ return;
+ }
+ final ExchangeTarget newPlayer = player.connection.exchangeTarget;
+ final VersionHandshakeServer hi = new VersionHandshakeServer(newPlayer);
+ playerMap.put(newPlayer, player);
Expand All @@ -110,6 +114,9 @@ index 0000000000000000000000000000000000000000..a0c385dcd1b040521512e1125e7ff7ae
+
+ @ProtocolHandler.PlayerLeave
+ public static void onPlayerLeave(ServerPlayer player) {
+ if (!LeavesConfig.syncmaticaProtocol) {
+ return;
+ }
+ final ExchangeTarget oldPlayer = player.connection.exchangeTarget;
+ final Collection<Exchange> potentialMessageTarget = oldPlayer.getExchanges();
+ if (potentialMessageTarget != null) {
Expand All @@ -124,6 +131,9 @@ index 0000000000000000000000000000000000000000..a0c385dcd1b040521512e1125e7ff7ae
+
+ @ProtocolHandler.PayloadReceiver(payload = LeavesProtocolManager.LeavesPayload.class, ignoreId = true)
+ public static void onPacketGet(ServerPlayer player, LeavesProtocolManager.LeavesPayload payload) {
+ if (!LeavesConfig.syncmaticaProtocol) {
+ return;
+ }
+ onPacket(player.connection.exchangeTarget, payload.id(), payload.data());
+ }
+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ Subject: [PATCH] Bladeren Protocol

diff --git a/src/main/java/org/leavesmc/leaves/protocol/bladeren/BladerenProtocol.java b/src/main/java/org/leavesmc/leaves/protocol/bladeren/BladerenProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..a91011c7a2c56646053bb9d158ff0c265c658c00
index 0000000000000000000000000000000000000000..4d9285d69724e8600fd7a3f9a6c31ecd579de6ad
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/bladeren/BladerenProtocol.java
@@ -0,0 +1,145 @@
@@ -0,0 +1,150 @@
+package org.leavesmc.leaves.protocol.bladeren;
+
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerPlayer;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+import org.leavesmc.leaves.LeavesConfig;
+import org.leavesmc.leaves.LeavesLogger;
+import org.leavesmc.leaves.protocol.core.LeavesCustomPayload;
+import org.leavesmc.leaves.protocol.core.LeavesProtocol;
+import org.leavesmc.leaves.protocol.core.ProtocolHandler;
+import org.leavesmc.leaves.protocol.core.ProtocolUtils;
Expand Down Expand Up @@ -50,6 +51,8 @@ index 0000000000000000000000000000000000000000..a91011c7a2c56646053bb9d158ff0c26
+ String clientVersion = payload.version;
+ CompoundTag tag = payload.nbt;
+
+ LeavesLogger.LOGGER.info("Player " + player.getScoreboardName() + " joined with bladeren " + clientVersion);
+
+ if (tag != null) {
+ CompoundTag featureNbt = tag.getCompound("Features");
+ for (String name : featureNbt.getAllKeys()) {
Expand Down Expand Up @@ -117,8 +120,9 @@ index 0000000000000000000000000000000000000000..a91011c7a2c56646053bb9d158ff0c26
+ }
+ }
+
+ public record BladerenFeatureModifyPayload(String name, CompoundTag nbt) implements CustomPacketPayload {
+ public record BladerenFeatureModifyPayload(String name, CompoundTag nbt) implements LeavesCustomPayload<BladerenFeatureModifyPayload> {
+
+ @New
+ public BladerenFeatureModifyPayload(ResourceLocation location, FriendlyByteBuf buf) {
+ this(buf.readUtf(), buf.readNbt());
+ }
Expand All @@ -136,8 +140,9 @@ index 0000000000000000000000000000000000000000..a91011c7a2c56646053bb9d158ff0c26
+ }
+ }
+
+ public record BladerenHelloPayload(String version, CompoundTag nbt) implements CustomPacketPayload {
+ public record BladerenHelloPayload(String version, CompoundTag nbt) implements LeavesCustomPayload<BladerenHelloPayload> {
+
+ @New
+ public BladerenHelloPayload(ResourceLocation location, @NotNull FriendlyByteBuf buf) {
+ this(buf.readUtf(64), buf.readNbt());
+ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Subject: [PATCH] Bladeren mspt sync protocol

diff --git a/src/main/java/org/leavesmc/leaves/protocol/bladeren/MsptSyncProtocol.java b/src/main/java/org/leavesmc/leaves/protocol/bladeren/MsptSyncProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..cf909f22f0860e6f56a86510dfcbd949a4c1fc32
index 0000000000000000000000000000000000000000..8bbcb87cf327ac3b85b8134231a23cb6092c5afb
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/bladeren/MsptSyncProtocol.java
@@ -0,0 +1,73 @@
@@ -0,0 +1,77 @@
+package org.leavesmc.leaves.protocol.bladeren;
+
+import net.minecraft.resources.ResourceLocation;
Expand All @@ -25,6 +25,7 @@ index 0000000000000000000000000000000000000000..cf909f22f0860e6f56a86510dfcbd949
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.OptionalDouble;
+
+@LeavesProtocol(namespace = "bladeren")
+public class MsptSyncProtocol {
Expand All @@ -43,7 +44,7 @@ index 0000000000000000000000000000000000000000..cf909f22f0860e6f56a86510dfcbd949
+ @ProtocolHandler.Init
+ public static void init() {
+ BladerenProtocol.registerFeature("mspt_sync", (player, compoundTag) -> {
+ if (compoundTag.getString("Value").equals("true")) {
+ if (compoundTag.getString("Value").equals("true")) {
+ onPlayerSubmit(player);
+ } else {
+ onPlayerLoggedOut(player);
Expand All @@ -67,12 +68,15 @@ index 0000000000000000000000000000000000000000..cf909f22f0860e6f56a86510dfcbd949
+
+ MinecraftServer server = MinecraftServer.getServer();
+ if (server.getTickCount() % LeavesConfig.msptSyncTickInterval == 0) {
+ double mspt = Arrays.stream(server.getTickTimesNanos()).average().getAsDouble() * 1.0E-6D;
+ double tps = 1000.0D / Math.max(mspt, 50);
+ players.forEach(player -> ProtocolUtils.sendPayloadPacket(player, MSPT_SYNC, buf -> {
+ buf.writeDouble(mspt);
+ buf.writeDouble(tps);
+ }));
+ OptionalDouble msptArr = Arrays.stream(server.getTickTimesNanos()).average();
+ if (msptArr.isPresent()) {
+ double mspt = msptArr.getAsDouble() * 1.0E-6D;
+ double tps = 1000.0D / Math.max(mspt, 50);
+ players.forEach(player -> ProtocolUtils.sendPayloadPacket(player, MSPT_SYNC, buf -> {
+ buf.writeDouble(mspt);
+ buf.writeDouble(tps);
+ }));
+ }
+ }
+ }
+ }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a4f9ea5

Please sign in to comment.