From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Tue, 26 Sep 2023 19:00:41 +0800 Subject: [PATCH] Leaves: Protocol Core Original license: GPLv3 Original project: https://github.com/LeavesMC/Leaves Commit: 3187d77f57058a81bc04ce7eaac1224f58b03c25 diff --git a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java index fb263fa1f30a7dfcb7ec2656abfb38e5fe88eac9..56fd1ed7ccaf96e7eedea60fbdbf7f934939d563 100644 --- a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java +++ b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java @@ -40,13 +40,22 @@ public interface CustomPacketPayload { @Override public void encode(B buffer, CustomPacketPayload value) { + // Leaves start - protocol core + if (value instanceof org.leavesmc.leaves.protocol.core.LeavesCustomPayload payload) { + org.leavesmc.leaves.protocol.core.LeavesProtocolManager.encode(buffer, payload); + return; + } + // Leaves end - protocol core this.writeCap(buffer, value.type(), value); } @Override public CustomPacketPayload decode(B buffer) { ResourceLocation resourceLocation = buffer.readResourceLocation(); - return (CustomPacketPayload)this.findCodec(resourceLocation).decode(buffer); + // Leaves start - protocol core + var payload = org.leavesmc.leaves.protocol.core.LeavesProtocolManager.decode(resourceLocation, buffer); + return java.util.Objects.requireNonNullElseGet(payload, () -> this.findCodec(resourceLocation).decode(buffer)); + // Leaves end - protocol core } }; } diff --git a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java index 62b9d9486c15a1ec6527f786df4e9fc483390bcb..5384bbc6bb3dbe5481f9d8cb10282551a0f78ec1 100644 --- a/net/minecraft/network/protocol/common/custom/DiscardedPayload.java +++ b/net/minecraft/network/protocol/common/custom/DiscardedPayload.java @@ -4,12 +4,12 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.ResourceLocation; -public record DiscardedPayload(ResourceLocation id, byte[] data) implements CustomPacketPayload { // Paper - store data +public record DiscardedPayload(ResourceLocation id, byte @org.jetbrains.annotations.Nullable [] data) implements CustomPacketPayload { // Paper - store data // Leaves - nullable public static StreamCodec codec(ResourceLocation id, int maxSize) { return CustomPacketPayload.codec((value, output) -> { // Paper start // Always write data - output.writeBytes(value.data); + if (value.data != null) output.writeBytes(value.data); // Leaves - nullable }, buffer -> { int i = buffer.readableBytes(); if (i >= 0 && i <= maxSize) { diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java index cf958bb871137dc88a8c36be867f2192acba2687..2c50bde56da7174dcea828feedecb92c98347a45 100644 --- a/net/minecraft/server/MinecraftServer.java +++ b/net/minecraft/server/MinecraftServer.java @@ -1736,6 +1736,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop