9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00
Files
LeavesMC/leaves-server/minecraft-patches/features/0003-Leaves-Protocol-Core.patch
violetc d5c9306a7f 1.21.4 (#413)
* init 1.21.4, and boom!

* build change, but weight not work

* just work

* Build changes, and delete timings

* Fix API patches (#406)

* Fix API patches

* merge

---------

Co-authored-by: violetc <58360096+s-yh-china@users.noreply.github.com>

* 0006/0129

* 0009/0129

* 0011/0129

* 0018/0129

* 0030/0129

* 0035/0129

* 0043/0129

* 0048/0129

* 0049/0129

* 0057/0129

* 0065/0129

* 0086/0129 (#408)

* 0072/0129

* 0080/0129

* Readd patch infos

* 0086/0129

* Delete applied patches

* 0087/0129

* 0091/0129

* 0097/0129

* 0101/0129

* 102/129

* 0107/0129

* 0112/0129

* 0118/0129

* 0129/0129, 100% patched

* fix some

* server work

* Protocol... (#409)

* Jade v7

* Fix changed part for Jade

* Formatting imports, add Lms Paster protocol

* REI payloads 5/8

* Add REI support, remove unnecessary content in Jade

* Rename

* Make jade better

* Make action work

* fix action jar

* Fix some protocol

* Fix bot action, and entity tickCount

* Fix Warden GameEventListener register on load

* Fix extra Raider drop

* Fix grindstone overstacking

* Update Paper, and some doc

* Merge

* [ci skip] Update Action

---------

Co-authored-by: Lumine1909 <133463833+Lumine1909@users.noreply.github.com>
2025-02-14 23:55:46 +08:00

95 lines
5.6 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Sun, 2 Feb 2025 13:08:32 +0800
Subject: [PATCH] Leaves Protocol Core
diff --git a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
index fb263fa1f30a7dfcb7ec2656abfb38e5fe88eac9..7e19dfe90a63ff26f03b95891dacb7360bba5a3c 100644
--- a/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
+++ b/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
@@ -40,13 +40,23 @@ 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) {
+ buffer.writeResourceLocation(payload.id());
+ payload.write(buffer);
+ 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/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 5dfdf76c8de5eda9a02f9a5fa1c3bada8ec7dcde..bde8ddadd3930100d1e31e630f809e77d6a70dac 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -1744,6 +1744,8 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
profilerFiller.popPush("server gui refresh");
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleTick(); // Leaves - protocol
+
for (int i = 0; i < this.tickables.size(); i++) {
this.tickables.get(i).run();
}
diff --git a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
index e71c1a564e5d4ac43460f89879ff709ee685706f..46ffae71b5119c7c4527a21b19c8e822f4d87114 100644
--- a/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerCommonPacketListenerImpl.java
@@ -136,6 +136,12 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
@Override
public void handleCustomPayload(ServerboundCustomPayloadPacket packet) {
+ // Leaves start - protocol
+ if (packet.payload() instanceof org.leavesmc.leaves.protocol.core.LeavesCustomPayload<?> leavesPayload) {
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePayload(player, leavesPayload);
+ }
+ // Leaves end - protocol
+
// CraftBukkit start
// Paper start - Brand support
if (packet.payload() instanceof net.minecraft.network.protocol.common.custom.BrandPayload(String brand)) {
@@ -154,6 +160,7 @@ public abstract class ServerCommonPacketListenerImpl implements ServerCommonPack
String channels = payload.toString(com.google.common.base.Charsets.UTF_8);
for (String channel : channels.split("\0")) {
this.getCraftPlayer().addChannel(channel);
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handleMinecraftRegister(channel, player); // Leaves - protocol
}
} catch (Exception ex) {
ServerGamePacketListenerImpl.LOGGER.error("Couldn't register custom payload", ex);
diff --git a/net/minecraft/server/players/PlayerList.java b/net/minecraft/server/players/PlayerList.java
index 03feaf0adb8ee87e33744a4615dc2507a02f92d7..31d145e2368ee935235f8e88278dcaea0c72f2c0 100644
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -330,6 +330,8 @@ public abstract class PlayerList {
return;
}
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerJoin(player); // Leaves - protocol
+
final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage();
if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure
@@ -500,6 +502,7 @@ public abstract class PlayerList {
return this.remove(player, net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? player.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(player.getDisplayName())));
}
public net.kyori.adventure.text.Component remove(ServerPlayer player, net.kyori.adventure.text.Component leaveMessage) {
+ org.leavesmc.leaves.protocol.core.LeavesProtocolManager.handlePlayerLeave(player); // Leaves - protocol
// Paper end - Fix kick event leave message not being sent
ServerLevel serverLevel = player.serverLevel();
player.awardStat(Stats.LEAVE_GAME);