diff --git a/patches/server/0006-Leaves-Protocol-Core.patch b/patches/server/0006-Leaves-Protocol-Core.patch index f1117006..120ad19b 100644 --- a/patches/server/0006-Leaves-Protocol-Core.patch +++ b/patches/server/0006-Leaves-Protocol-Core.patch @@ -120,7 +120,7 @@ index 0000000000000000000000000000000000000000..64a1d25973b032e8cab64bbffa6824a1 +} diff --git a/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java b/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java new file mode 100644 -index 0000000000000000000000000000000000000000..eb8bec80870bbe8a6b6aea324376485875a30d00 +index 0000000000000000000000000000000000000000..3c738e1cfc3f9aef1e9684aa3a076cf677df1120 --- /dev/null +++ b/src/main/java/top/leavesmc/leaves/protocol/core/LeavesProtocolManager.java @@ -0,0 +1,292 @@ @@ -279,7 +279,7 @@ index 0000000000000000000000000000000000000000..eb8bec80870bbe8a6b6aea3243764858 + if (receiver.ignoreId() || receiver.payloadId().equals(payload.id().getPath()) || + ArrayUtils.contains(receiver.payloadIds(), payload.id().getPath())) { + try { -+ map.get(receiver).invoke(player, payload); ++ map.get(receiver).invoke(null, player, payload); + } catch (InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } @@ -305,7 +305,7 @@ index 0000000000000000000000000000000000000000..eb8bec80870bbe8a6b6aea3243764858 + if (!PLAYER_JOIN.isEmpty()) { + try { + for (Method method : PLAYER_JOIN) { -+ method.invoke(player); ++ method.invoke(null, player); + } + } catch (InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); @@ -317,7 +317,7 @@ index 0000000000000000000000000000000000000000..eb8bec80870bbe8a6b6aea3243764858 + if (!PLAYER_LEAVE.isEmpty()) { + try { + for (Method method : PLAYER_LEAVE) { -+ method.invoke(player); ++ method.invoke(null, player); + } + } catch (InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); @@ -343,7 +343,7 @@ index 0000000000000000000000000000000000000000..eb8bec80870bbe8a6b6aea3243764858 + if (register.ignoreId() || register.channelId().equals(channel) || + ArrayUtils.contains(register.channelIds(), channel)) { + try { -+ MINECRAFT_REGISTER.get(register).invoke(player); ++ MINECRAFT_REGISTER.get(register).invoke(null, player); + } catch (InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } diff --git a/patches/server/0045-Jade-Protocol.patch b/patches/server/0045-Jade-Protocol.patch index e6567a93..09d57126 100644 --- a/patches/server/0045-Jade-Protocol.patch +++ b/patches/server/0045-Jade-Protocol.patch @@ -20,10 +20,10 @@ index 4aeab90e778629c355189dfe79c39c4b21f5f5ac..fe8c9b7e7956837829b4fe3eb449b2c0 diff --git a/src/main/java/top/leavesmc/leaves/protocol/JadeProtocol.java b/src/main/java/top/leavesmc/leaves/protocol/JadeProtocol.java new file mode 100644 -index 0000000000000000000000000000000000000000..713a3c2b29de57ad47ffe1f0c591ba9164b8c5ff +index 0000000000000000000000000000000000000000..b0af99ba7bc27c27890b78cb6c370fa0c86e16f8 --- /dev/null +++ b/src/main/java/top/leavesmc/leaves/protocol/JadeProtocol.java -@@ -0,0 +1,617 @@ +@@ -0,0 +1,622 @@ +package top.leavesmc.leaves.protocol; + +import com.google.common.cache.Cache; @@ -326,14 +326,14 @@ index 0000000000000000000000000000000000000000..713a3c2b29de57ad47ffe1f0c591ba91 + } + + MinecraftServer server = MinecraftServer.getServer(); -+ Level world = player.level(); -+ boolean showDetails = payload.showDetails; -+ Entity entity = world.getEntity(payload.entityId); -+ if (entity == null || player.distanceToSqr(entity) > MAX_DISTANCE_SQR) { -+ return; -+ } -+ + server.execute(() -> { ++ Level world = player.level(); ++ boolean showDetails = payload.showDetails; ++ Entity entity = world.getEntity(payload.entityId); ++ if (entity == null || player.distanceToSqr(entity) > MAX_DISTANCE_SQR) { ++ return; ++ } ++ + var providers = entityDataProviders.get(entity); + if (providers.isEmpty()) { + return; @@ -412,18 +412,21 @@ index 0000000000000000000000000000000000000000..713a3c2b29de57ad47ffe1f0c591ba91 + void saveData(CompoundTag data, ServerPlayer player, Level world, T object, boolean showDetails); + } + -+ public record RequestEntityPayload(boolean showDetails, int entityId) implements CustomPacketPayload { ++ public record RequestEntityPayload(boolean showDetails, int entityId, float hitX, float hitY, float hitZ) implements CustomPacketPayload { + + private static final ResourceLocation PACKET_REQUEST_ENTITY = JadeProtocol.id("request_entity"); + + public RequestEntityPayload(ResourceLocation id, FriendlyByteBuf buf) { -+ this(buf.readBoolean(), buf.readInt()); ++ this(buf.readBoolean(), buf.readVarInt(), buf.readFloat(), buf.readFloat(), buf.readFloat()); + } + + @Override + public void write(FriendlyByteBuf buf) { + buf.writeBoolean(showDetails); + buf.writeInt(entityId); ++ buf.writeFloat(hitX); ++ buf.writeFloat(hitY); ++ buf.writeFloat(hitZ); + } + + @Override @@ -433,18 +436,20 @@ index 0000000000000000000000000000000000000000..713a3c2b29de57ad47ffe1f0c591ba91 + } + } + -+ public record RequestTilePayload(boolean showDetails, BlockHitResult hitResult) implements CustomPacketPayload { ++ public record RequestTilePayload(boolean showDetails, BlockHitResult hitResult, int blockState, ItemStack fakeBlock) implements CustomPacketPayload { + + private static final ResourceLocation PACKET_REQUEST_TILE = JadeProtocol.id("request_tile"); + + public RequestTilePayload(ResourceLocation id, FriendlyByteBuf buf) { -+ this(buf.readBoolean(), buf.readBlockHitResult()); ++ this(buf.readBoolean(), buf.readBlockHitResult(), buf.readVarInt(), buf.readItem()); + } + + @Override + public void write(FriendlyByteBuf buf) { + buf.writeBoolean(showDetails); + buf.writeBlockHitResult(hitResult); ++ buf.writeVarInt(blockState); ++ buf.writeItem(fakeBlock); + } + + @Override diff --git a/patches/server/0067-Leaves-carpet-support.patch b/patches/server/0067-Leaves-carpet-support.patch index c2cb9afb..8c1a30db 100644 --- a/patches/server/0067-Leaves-carpet-support.patch +++ b/patches/server/0067-Leaves-carpet-support.patch @@ -28,10 +28,10 @@ index 7a1fae214f7ed5c664459665f43011c84e6b6259..79e3e4ae09d29134219485800d8d9efc public static boolean creativeNoClip = false; diff --git a/src/main/java/top/leavesmc/leaves/protocol/CarpetServerProtocol.java b/src/main/java/top/leavesmc/leaves/protocol/CarpetServerProtocol.java new file mode 100644 -index 0000000000000000000000000000000000000000..ee51971365431be1f564e9e204e4beee85799fc2 +index 0000000000000000000000000000000000000000..207bbbdf462d12f39273eee1b1552477be35346f --- /dev/null +++ b/src/main/java/top/leavesmc/leaves/protocol/CarpetServerProtocol.java -@@ -0,0 +1,109 @@ +@@ -0,0 +1,106 @@ +package top.leavesmc.leaves.protocol; + +import net.minecraft.nbt.CompoundTag; @@ -58,9 +58,8 @@ index 0000000000000000000000000000000000000000..ee51971365431be1f564e9e204e4beee + + private static final ResourceLocation HELLO_ID = CarpetServerProtocol.id("hello"); + -+ private static final int HI = 69; -+ private static final int HELLO = 420; -+ private static final int DATA = 1; ++ private static final String HI = "69"; ++ private static final String HELLO = "420"; + + @Contract("_ -> new") + public static @NotNull ResourceLocation id(String path) { @@ -70,16 +69,20 @@ index 0000000000000000000000000000000000000000..ee51971365431be1f564e9e204e4beee + @ProtocolHandler.PlayerJoin + public static void onPlayerJoin(ServerPlayer player) { + if (LeavesConfig.leavesCarpetSupport) { -+ ProtocolUtils.sendPayloadPacket(player, new CarpetHelloPayload(HI, VERSION, new CompoundTag())); ++ CompoundTag data = new CompoundTag(); ++ data.putString(HI, VERSION); ++ ProtocolUtils.sendPayloadPacket(player, new CarpetPayload(data)); + } + } + -+ @ProtocolHandler.PayloadReceiver(payload = CarpetHelloPayload.class, payloadId = "hello") -+ private static void handleHello(@NotNull ServerPlayer player, @NotNull CarpetHelloPayload payload) { ++ @ProtocolHandler.PayloadReceiver(payload = CarpetPayload.class, payloadId = "hello") ++ private static void handleHello(@NotNull ServerPlayer player, @NotNull CarpetServerProtocol.CarpetPayload payload) { + if (LeavesConfig.leavesCarpetSupport) { -+ if (payload.helloId == HELLO) { -+ LeavesLogger.LOGGER.info("Player " + player.getScoreboardName() + " joined with carpet " + payload.version); -+ ProtocolUtils.sendPayloadPacket(player, HELLO_ID, CarpetRules::write); ++ if (payload.nbt.contains(HELLO)) { ++ LeavesLogger.LOGGER.info("Player " + player.getScoreboardName() + " joined with carpet " + payload.nbt.getString(HELLO)); ++ CompoundTag data = new CompoundTag(); ++ CarpetRules.write(data); ++ ProtocolUtils.sendPayloadPacket(player, new CarpetPayload(data)); + } + } + } @@ -88,15 +91,11 @@ index 0000000000000000000000000000000000000000..ee51971365431be1f564e9e204e4beee + + private static final Map rules = new HashMap<>(); + -+ public static void write(@NotNull FriendlyByteBuf buf) { -+ buf.writeVarInt(DATA); -+ ++ public static void write(@NotNull CompoundTag tag) { + CompoundTag rulesNbt = new CompoundTag(); + rules.values().forEach(rule -> rule.writeNBT(rulesNbt)); + -+ CompoundTag tag = new CompoundTag(); + tag.put("Rules", rulesNbt); -+ buf.writeNbt(tag); + } + + public static void register(CarpetRule rule) { @@ -121,16 +120,14 @@ index 0000000000000000000000000000000000000000..ee51971365431be1f564e9e204e4beee + } + } + -+ public record CarpetHelloPayload(int helloId, String version, CompoundTag nbt) implements CustomPacketPayload { ++ public record CarpetPayload(CompoundTag nbt) implements CustomPacketPayload { + -+ public CarpetHelloPayload(ResourceLocation location, FriendlyByteBuf buf) { -+ this(buf.readVarInt(), buf.readUtf(64), buf.readNbt()); ++ public CarpetPayload(ResourceLocation location, FriendlyByteBuf buf) { ++ this(buf.readNbt()); + } + + @Override + public void write(FriendlyByteBuf buf) { -+ buf.writeVarInt(helloId); -+ buf.writeUtf(version); + buf.writeNbt(nbt); + } +