9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-22 08:29:28 +00:00

Updated Upstream (Leaves) & Add back Jade protocol support

This commit is contained in:
Dreeam
2024-06-05 20:28:50 +08:00
parent daa098084e
commit 44da3463cb
52 changed files with 2424 additions and 1030 deletions

View File

@@ -6,7 +6,7 @@ Subject: [PATCH] Leaves: Server Utils
Original license: GPLv3
Original project: https://github.com/LeavesMC/Leaves
Commit: 87bfa2d2bbc597c8351ec8776b14c5a6166ed01c
Commit: 6951bdc2153bcb14aa64787ab007fa39fee7c007
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index b152cf0c89e735470ea61b4bb0d88f3467f1a8d0..1da09a313f73c35be5b1b46da6b489a599f745f4 100644

View File

@@ -8,7 +8,7 @@ TODO - Dreeam: Configurable leaves protocol listening
Original license: GPLv3
Original project: https://github.com/LeavesMC/Leaves
Commit: 87bfa2d2bbc597c8351ec8776b14c5a6166ed01c
Commit: 6951bdc2153bcb14aa64787ab007fa39fee7c007
diff --git a/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java b/src/main/java/net/minecraft/network/protocol/common/custom/CustomPacketPayload.java
index 663b3b12d9a7cdc04b7f86ccfe6bc6fcfd5028bc..a58ad6f41fc0eacf020e9ab6c8e5f7dfc4977f8d 100644
@@ -98,7 +98,7 @@ index 2e98c6598e589b498991c745058db3c0efb9cbf6..0d65a53b23c82cbc4539afd28c52b5fd
org.purpurmc.purpur.task.BossBarTask.removeFromAll(entityplayer.getBukkitEntity()); // Purpur
ServerLevel worldserver = entityplayer.serverLevel();
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 97890866386b382e131e624011ad16cce413a752..a5a7a5fc506c0ca094f37d26b2b27192d09a0a66 100644
index a3e90368e1e34c08508a54fc8c279f12b2bf763e..88bc9033981662e8ba62b833eac2a0301ab504da 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -485,6 +485,7 @@ public final class CraftServer implements Server {
@@ -117,6 +117,30 @@ index 97890866386b382e131e624011ad16cce413a752..a5a7a5fc506c0ca094f37d26b2b27192
int pollCount = 0;
diff --git a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
new file mode 100644
index 0000000000000000000000000000000000000000..c852b3a8d31bc73d32aef215e4d3a82aa1fd8f19
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
@@ -0,0 +1,18 @@
+package org.dreeam.leaf.config.modules.network;
+
+import org.dreeam.leaf.config.ConfigInfo;
+import org.dreeam.leaf.config.EnumConfigCategory;
+import org.dreeam.leaf.config.IConfigModule;
+
+public class ProtocolSupport implements IConfigModule {
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.NETWORK;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "protocol_support";
+ }
+}
diff --git a/src/main/java/org/leavesmc/leaves/protocol/core/LeavesCustomPayload.java b/src/main/java/org/leavesmc/leaves/protocol/core/LeavesCustomPayload.java
new file mode 100644
index 0000000000000000000000000000000000000000..243a8d77d67b9634d6442b60e481d18831367a74
@@ -610,23 +634,29 @@ index 0000000000000000000000000000000000000000..f9dc0a60ca4287e5ec91dd3fc1ae315e
+}
diff --git a/src/main/java/org/leavesmc/leaves/protocol/core/ProtocolUtils.java b/src/main/java/org/leavesmc/leaves/protocol/core/ProtocolUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..562f3d515679965571597945e8682712e1e1f0b9
index 0000000000000000000000000000000000000000..f54381eec7ec0ffde39e87b39b16e02d3ed1b419
--- /dev/null
+++ b/src/main/java/org/leavesmc/leaves/protocol/core/ProtocolUtils.java
@@ -0,0 +1,37 @@
@@ -0,0 +1,47 @@
+package org.leavesmc.leaves.protocol.core;
+
+import io.netty.buffer.ByteBuf;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.RegistryFriendlyByteBuf;
+import net.minecraft.network.protocol.common.ClientboundCustomPayloadPacket;
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerPlayer;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+public class ProtocolUtils {
+
+ private static final Function<ByteBuf, RegistryFriendlyByteBuf> bufDecorator = RegistryFriendlyByteBuf.decorator(MinecraftServer.getServer().registryAccess());
+
+ public static void sendEmptyPayloadPacket(ServerPlayer player, ResourceLocation id) {
+ player.connection.send(new ClientboundCustomPayloadPacket(new LeavesProtocolManager.EmptyPayload(id)));
+ }
@@ -650,4 +680,8 @@ index 0000000000000000000000000000000000000000..562f3d515679965571597945e8682712
+ public static void sendPayloadPacket(ServerPlayer player, CustomPacketPayload payload) {
+ player.connection.send(new ClientboundCustomPayloadPacket(payload));
+ }
+
+ public static RegistryFriendlyByteBuf decorate(ByteBuf buf) {
+ return bufDecorator.apply(buf);
+ }
+}

File diff suppressed because it is too large Load Diff

View File

@@ -6,37 +6,22 @@ Subject: [PATCH] Leaves: Appleskin Protocol
Original license: GPLv3
Original project: https://github.com/LeavesMC/Leaves
Commit: 87bfa2d2bbc597c8351ec8776b14c5a6166ed01c
Commit: 6951bdc2153bcb14aa64787ab007fa39fee7c007
This patch is Powered by AppleSkin (https://github.com/squeek502/AppleSkin)
diff --git a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
new file mode 100644
index 0000000000000000000000000000000000000000..1181ffae40b86a4212e199814d3e07e641a5a1f2
--- /dev/null
index b63d87d0593d116b0c5ee835dc4372f1b5542453..ef23577faaf7948d7a9b1def4d56506eab19cc80 100644
--- a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
+++ b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
@@ -0,0 +1,21 @@
+package org.dreeam.leaf.config.modules.network;
+
+import org.dreeam.leaf.config.ConfigInfo;
+import org.dreeam.leaf.config.EnumConfigCategory;
+import org.dreeam.leaf.config.IConfigModule;
+
+public class ProtocolSupport implements IConfigModule {
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.NETWORK;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "protocol_support";
+ }
@@ -18,4 +18,7 @@ public class ProtocolSupport implements IConfigModule {
@ConfigInfo(baseName = "jade-protocol")
public static boolean jadeProtocol = false;
+
+ @ConfigInfo(baseName = "appleskin-protocol")
+ public static boolean appleskinProtocol = false;
+}
}
diff --git a/src/main/java/org/leavesmc/leaves/protocol/AppleSkinProtocol.java b/src/main/java/org/leavesmc/leaves/protocol/AppleSkinProtocol.java
new file mode 100644
index 0000000000000000000000000000000000000000..c496c97c99cd352c2566731d3017cf1b14ee74ec

View File

@@ -6,7 +6,7 @@ Subject: [PATCH] Leaves: Xaero Map Protocol
Original license: GPLv3
Original project: https://github.com/LeavesMC/Leaves
Commit: 87bfa2d2bbc597c8351ec8776b14c5a6166ed01c
Commit: 6951bdc2153bcb14aa64787ab007fa39fee7c007
This patch is Powered by Xaero Map
@@ -23,7 +23,7 @@ index 0d65a53b23c82cbc4539afd28c52b5fd2d2ff5b4..c410f781371a87ecc2849144c747a6ac
// CraftBukkit start - handle player weather
// entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.START_RAINING, 0.0F));
diff --git a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
index 1181ffae40b86a4212e199814d3e07e641a5a1f2..be8474a514e7b9bdacd7cc89d8d3e8b3bc3eb709 100644
index ef23577faaf7948d7a9b1def4d56506eab19cc80..c9736e79387d785a67d6ebe71df6553eeaf2b41d 100644
--- a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
+++ b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
@@ -4,6 +4,8 @@ import org.dreeam.leaf.config.ConfigInfo;
@@ -35,7 +35,7 @@ index 1181ffae40b86a4212e199814d3e07e641a5a1f2..be8474a514e7b9bdacd7cc89d8d3e8b3
public class ProtocolSupport implements IConfigModule {
@Override
@@ -18,4 +20,9 @@ public class ProtocolSupport implements IConfigModule {
@@ -21,4 +23,9 @@ public class ProtocolSupport implements IConfigModule {
@ConfigInfo(baseName = "appleskin-protocol")
public static boolean appleskinProtocol = false;

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Chat Image protocol
This patch is Powered by ChatImage (https://github.com/kitUIN/ChatImage)
diff --git a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
index be8474a514e7b9bdacd7cc89d8d3e8b3bc3eb709..9324ca1f1abd2343b2f1eaec019e84428f01c626 100644
index c9736e79387d785a67d6ebe71df6553eeaf2b41d..53ae1ecb7acf8e9d8b9b1c50d5a483008b303a66 100644
--- a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
+++ b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
@@ -21,6 +21,9 @@ public class ProtocolSupport implements IConfigModule {
@@ -24,6 +24,9 @@ public class ProtocolSupport implements IConfigModule {
@ConfigInfo(baseName = "appleskin-protocol")
public static boolean appleskinProtocol = false;

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Asteor Bar protocol
This patch is Powered by AsteorBar (https://github.com/afoxxvi/AsteorBarMod)
diff --git a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
index 9324ca1f1abd2343b2f1eaec019e84428f01c626..45c422b993e254fd892bfd6f47a074f1e9688714 100644
index 53ae1ecb7acf8e9d8b9b1c50d5a483008b303a66..b91f0ae28f044ceed0b9db46669a4cca2d47cb2d 100644
--- a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
+++ b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
@@ -21,6 +21,9 @@ public class ProtocolSupport implements IConfigModule {
@@ -24,6 +24,9 @@ public class ProtocolSupport implements IConfigModule {
@ConfigInfo(baseName = "appleskin-protocol")
public static boolean appleskinProtocol = false;

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Leaves: Disable moved wrongly threshold
Original license: GPLv3
Original project: https://github.com/LeavesMC/Leaves
Commit: 87bfa2d2bbc597c8351ec8776b14c5a6166ed01c
Commit: 6951bdc2153bcb14aa64787ab007fa39fee7c007
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index d107cd93a6d43f060a7bcfc4a3ee0c82c51bc9b9..cc9c30b8555e0509162a82c4a01de9fc51ba59af 100644
index 2461fdfe02dc2252178e442f54ef4f584ba75cf8..a0abb0182aa6166b1d2702aa9964132889dc9d86 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -589,7 +589,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl

View File

@@ -6,7 +6,7 @@ Subject: [PATCH] Leaves: Fix vehicle teleport by end gateway
Original license: GPLv3
Original project: https://github.com/LeavesMC/Leaves
Commit: 87bfa2d2bbc597c8351ec8776b14c5a6166ed01c
Commit: 6951bdc2153bcb14aa64787ab007fa39fee7c007
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/TheEndGatewayBlockEntity.java
index 0e58011d22536051a18388c2d45fd1a30c2f5ffd..2910af920a746f90529f94038922e2a9e6ad3bc1 100644

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Faster Random for xaeroMapServerID generation
diff --git a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
index 8378bab717088b832888be69618f13ba6dd44273..58c2745563b482e9147afa168de72c3ee7a79f0b 100644
index b91f0ae28f044ceed0b9db46669a4cca2d47cb2d..8c71281004649e23adb6609a66ab4951b280c517 100644
--- a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
+++ b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
@@ -4,7 +4,7 @@ import org.dreeam.leaf.config.ConfigInfo;
@@ -17,7 +17,7 @@ index 8378bab717088b832888be69618f13ba6dd44273..58c2745563b482e9147afa168de72c3e
public class ProtocolSupport implements IConfigModule {
@@ -30,5 +30,5 @@ public class ProtocolSupport implements IConfigModule {
@@ -33,5 +33,5 @@ public class ProtocolSupport implements IConfigModule {
@ConfigInfo(baseName = "xaero-map-protocol")
public static boolean xaeroMapProtocol = false;
@ConfigInfo(baseName = "xaero-map-server-id")

View File

@@ -15,7 +15,7 @@ This patch was ported downstream from the Petal fork.
Makes most pathfinding-related work happen asynchronously
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index 3a153b7f1092c2d4ac6e0115f611d60907619a40..8ba2d0884114abd7dd3ff8d6e8a9a86e171bc2c0 100644
index 965a92f9a8e8efada117d208290271bc94b23db7..f82c85a09004448350611e406f1a373b2a07f9ec 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -303,6 +303,7 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Targeti

View File

@@ -193,7 +193,7 @@ index 4f91107f9ae42f96c060c310596db9aa869a8dbc..faad96f04af2e368f0276ade417dd1ba
public boolean visible = true;
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
index f1e4ed6f62472737a534fc457aa483d0725e92e3..7c303c4f1996139a0a5401a66413a58a10edbf55 100644
index cb2683c7e090a8d040b581bc95a0505998f17f43..539934a75df64e7accf4829d8d4b075833bb5bc9 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
@@ -295,7 +295,11 @@ public class ServerEntity {

View File

@@ -38,7 +38,7 @@ index 81dd0aa6a90fd9dda9e7752f85b9cf4568e3b575..7d04ff88e6352147e0c00266bd5d251f
LivingEntity entityliving1 = deadEntity.getLastHurtByMob();
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
index 1a2ef85cd8a62824b23f4212a5e2a70ce89e344f..8c36a75dbd60b61337ba5c1b061f8c6c2648c4ca 100644
index 184b69dc39749734f8176d3f3c2bf9f690a099f0..852cd20583d2c783c58ae19d0fa84ec834fe40e9 100644
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
@@ -82,7 +82,18 @@ public class LevelChunk extends ChunkAccess {

View File

@@ -22,7 +22,7 @@ index 9c6f5b55b1f1376fa75e216cd366ee47c79fafc4..7762c8186035fdf60e11d9f1844516b6
static RandomSource createThreadSafe() {
return new ThreadSafeLegacyRandomSource(RandomSupport.generateUniqueSeed());
diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java
index e971ef13754402f3de118ea24cb9f83b564cd65e..749fa63c641c1cb54445c85721c795355ffae123 100644
index 25e93a0a58b0ecf02f2669fc8f01ef2f2f938dc7..a50c6d59cfd6286b4ab2f70b2918ba845f04bf94 100644
--- a/src/main/java/net/minecraft/world/level/Level.java
+++ b/src/main/java/net/minecraft/world/level/Level.java
@@ -128,6 +128,7 @@ public abstract class Level implements LevelAccessor, AutoCloseable {

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Fix sprint glitch
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index d55d869f0a389d58d001e59e26b1b5912b5c94a8..919b71af99edfed2240bacfd288fcd210398f49a 100644
index d4cee0133f8e7df5321b00cf97bb7f43b1d198bc..f1c0ca7baa6297813c5e5deeaf6ad698086ffddb 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -1451,7 +1451,8 @@ public abstract class LivingEntity extends Entity implements Attackable {

View File

@@ -10,7 +10,7 @@ Add Pufferfish DAB support for Camel, Sniffer
https://github.com/pufferfish-gg/Pufferfish/issues/83
diff --git a/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java b/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java
index 063dde771ade593a29481f14b8f44a0f72f15953..e658456676aba19861d301d009f61a3b5cb078da 100644
index 877fe6312051f2669360b85c0caded7b47f04866..17c0e7fc08621d30bc8398a5063f9dbb9d917f57 100644
--- a/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java
+++ b/src/main/java/net/minecraft/world/entity/animal/armadillo/Armadillo.java
@@ -128,8 +128,10 @@ public class Armadillo extends Animal {

View File

@@ -97,7 +97,7 @@ index da026533b15a1981000e73bba6c5209c13de28dc..96d2077abd0112f2b2b8c4678447afbf
return this.level().purpurConfig.frogBreedingTicks;
}
diff --git a/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java b/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java
index e6861fd5f9817ec54294976f0e93952baa387773..2fe21d0d8807365610ef4f7346874e08e7342886 100644
index 45f92d8fd06027f1487e24987c3fb9a389f619a9..f484f399f2b93e86b24de7393d86eae900b5a98b 100644
--- a/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java
+++ b/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java
@@ -95,6 +95,23 @@ public class Tadpole extends AbstractFish {

View File

@@ -16,7 +16,7 @@ now is just updating dirty map/decoration data.
When no bukkit renderers are added to the map, we also re-use the same packet for all players who are tracking it which avoids a lot of work.
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
index 7c303c4f1996139a0a5401a66413a58a10edbf55..bed271712d4040983340ad001c20eaf07b0838a0 100644
index 539934a75df64e7accf4829d8d4b075833bb5bc9..1aba5405b4b452c9972288f941e861d60331d8b9 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
@@ -120,27 +120,40 @@ public class ServerEntity {

View File

@@ -6,7 +6,7 @@ Subject: [PATCH] Fix MC-2025
Mojang issues: https://bugs.mojang.com/browse/MC-2025
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 1da09a313f73c35be5b1b46da6b489a599f745f4..a1af147bdf54a5001a8c65c97f309a2a4ec71567 100644
index fd937544baae6835e1826a686676dcbfa58aca33..add6e68926cda8fc94fb6b37c3da20046b8c7346 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2628,6 +2628,16 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess

View File

@@ -9,7 +9,7 @@ AFK command & command cooldown
AFK title message
diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
index 00a9348b4585d9e69364e0d1ac88a59f43ebeee6..21f1b80794e2234c7fe34959ca03190617659bb0 100644
index 95c84e0f83d056ee080061cd495c95a328814469..a5784aa215522c4666139a8eac3711c966cc7cb1 100644
--- a/src/main/java/net/minecraft/commands/Commands.java
+++ b/src/main/java/net/minecraft/commands/Commands.java
@@ -250,6 +250,7 @@ public class Commands {
@@ -44,7 +44,7 @@ index 9b97d5ca67c0e53f318a54465708e21ae906e994..0e772d847d9a9b4000bcb9547f07663f
} else {
getBukkitEntity().setPlayerListName(prefix + scoreboardName + suffix, true);
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 01fe83e04ed8ce8d91dad5feffe164346fa8a13e..4300ba74bd91e3229c8721d4b2c160eaa9f8a456 100644
index a0abb0182aa6166b1d2702aa9964132889dc9d86..2c630eddcacee445f44beeefa842e90aff75c0a6 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2254,8 +2254,34 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Block log4j rce exploit in chat
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index 7830e21dce33ad389441227d728750606dcd3c56..e49bd9ab6c77ecb9da60d973e97448a2f4c78492 100644
index 2c630eddcacee445f44beeefa842e90aff75c0a6..ea1383691d57bfe9da958b6071bdb936fed322d6 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -2444,6 +2444,8 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl

View File

@@ -1,978 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: violetc <58360096+s-yh-china@users.noreply.github.com>
Date: Sat, 3 Dec 2022 08:57:15 +0800
Subject: [PATCH] Leaves: Jade Protocol
Original license: GPLv3
Original project: https://github.com/LeavesMC/Leaves
This patch is Powered by Jade (https://github.com/Snownee/Jade)
diff --git a/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java b/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java
index e6861fd5f9817ec54294976f0e93952baa387773..45f92d8fd06027f1487e24987c3fb9a389f619a9 100644
--- a/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java
+++ b/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java
@@ -290,7 +290,7 @@ public class Tadpole extends AbstractFish {
}
- private int getTicksLeftUntilAdult() {
+ public int getTicksLeftUntilAdult() { // Leaves - private -> public
return Math.max(0, Tadpole.ticksToBeFrog - this.age);
}
diff --git a/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.java b/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.java
index fca0131b9a90ac026a24cf579b17928c19173f3f..f8d0a8ea39cd90a9b45ff97e32e0e7224ddd8808 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData.java
@@ -68,7 +68,7 @@ public class TrialSpawnerData {
});
public final Set<UUID> detectedPlayers;
public final Set<UUID> currentMobs;
- protected long cooldownEndsAt;
+ public long cooldownEndsAt; // Leaves - protected -> public
protected long nextMobSpawnsAt;
protected int totalMobsSpawned;
public Optional<SpawnData> nextSpawnData;
diff --git a/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
new file mode 100644
index 0000000000000000000000000000000000000000..b63d87d0593d116b0c5ee835dc4372f1b5542453
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/network/ProtocolSupport.java
@@ -0,0 +1,21 @@
+package org.dreeam.leaf.config.modules.network;
+
+import org.dreeam.leaf.config.ConfigInfo;
+import org.dreeam.leaf.config.EnumConfigCategory;
+import org.dreeam.leaf.config.IConfigModule;
+
+public class ProtocolSupport implements IConfigModule {
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.NETWORK;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "protocol_support";
+ }
+
+ @ConfigInfo(baseName = "jade-protocol")
+ public static boolean jadeProtocol = false;
+}
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..561a8c33eaf1d961b4d8442bbab8c1ed9eef619c
--- /dev/null
+++ b/src/main/java/top/leavesmc/leaves/protocol/JadeProtocol.java
@@ -0,0 +1,909 @@
+package top.leavesmc.leaves.protocol;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Multimap;
+import com.mojang.authlib.GameProfile;
+import it.unimi.dsi.fastutil.objects.Object2IntLinkedOpenHashMap;
+import net.minecraft.core.BlockPos;
+import net.minecraft.core.Direction;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.nbt.CompoundTag;
+import net.minecraft.nbt.ListTag;
+import net.minecraft.network.FriendlyByteBuf;
+import net.minecraft.network.chat.CommonComponents;
+import net.minecraft.network.chat.Component;
+import net.minecraft.network.chat.MutableComponent;
+import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.server.players.GameProfileCache;
+import net.minecraft.world.Container;
+import net.minecraft.world.LockCode;
+import net.minecraft.world.MenuProvider;
+import net.minecraft.world.Nameable;
+import net.minecraft.world.RandomizableContainer;
+import net.minecraft.world.effect.MobEffectCategory;
+import net.minecraft.world.effect.MobEffectInstance;
+import net.minecraft.world.entity.AgeableMob;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.LivingEntity;
+import net.minecraft.world.entity.OwnableEntity;
+import net.minecraft.world.entity.animal.Animal;
+import net.minecraft.world.entity.animal.Chicken;
+import net.minecraft.world.entity.animal.allay.Allay;
+import net.minecraft.world.entity.animal.frog.Tadpole;
+import net.minecraft.world.entity.animal.horse.AbstractHorse;
+import net.minecraft.world.entity.boss.EnderDragonPart;
+import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
+import net.minecraft.world.entity.monster.ZombieVillager;
+import net.minecraft.world.entity.vehicle.ContainerEntity;
+import net.minecraft.world.inventory.PlayerEnderChestContainer;
+import net.minecraft.world.item.Item;
+import net.minecraft.world.item.ItemStack;
+import net.minecraft.world.item.Items;
+import net.minecraft.world.level.BaseCommandBlock;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.level.block.CalibratedSculkSensorBlock;
+import net.minecraft.world.level.block.ChestBlock;
+import net.minecraft.world.level.block.entity.AbstractFurnaceBlockEntity;
+import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
+import net.minecraft.world.level.block.entity.BeehiveBlockEntity;
+import net.minecraft.world.level.block.entity.BlockEntity;
+import net.minecraft.world.level.block.entity.BrewingStandBlockEntity;
+import net.minecraft.world.level.block.entity.CalibratedSculkSensorBlockEntity;
+import net.minecraft.world.level.block.entity.CampfireBlockEntity;
+import net.minecraft.world.level.block.entity.ChestBlockEntity;
+import net.minecraft.world.level.block.entity.ChiseledBookShelfBlockEntity;
+import net.minecraft.world.level.block.entity.CommandBlockEntity;
+import net.minecraft.world.level.block.entity.ComparatorBlockEntity;
+import net.minecraft.world.level.block.entity.EnderChestBlockEntity;
+import net.minecraft.world.level.block.entity.HopperBlockEntity;
+import net.minecraft.world.level.block.entity.JukeboxBlockEntity;
+import net.minecraft.world.level.block.entity.LecternBlockEntity;
+import net.minecraft.world.level.block.entity.TrialSpawnerBlockEntity;
+import net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData;
+import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+import net.minecraft.world.phys.BlockHitResult;
+import org.jetbrains.annotations.Contract;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import top.leavesmc.leaves.protocol.core.LeavesProtocol;
+import top.leavesmc.leaves.protocol.core.ProtocolHandler;
+import top.leavesmc.leaves.protocol.core.ProtocolUtils;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Objects;
+import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+@LeavesProtocol(namespace = "jade")
+public class JadeProtocol {
+
+ public static final String PROTOCOL_ID = "jade";
+
+ // send
+ public static final ResourceLocation PACKET_SERVER_PING = id("server_ping");
+ public static final ResourceLocation PACKET_RECEIVE_DATA = id("receive_data");
+
+ private static final HierarchyLookup<IJadeDataProvider<Entity>> entityDataProviders = new HierarchyLookup<>(Entity.class);
+ private static final HierarchyLookup<IJadeDataProvider<BlockEntity>> tileDataProviders = new HierarchyLookup<>(BlockEntity.class);
+
+ private static final HierarchyLookup<IServerExtensionProvider<Entity, ItemStack>> entityItemProviders = new HierarchyLookup<>(Entity.class);
+ private static final HierarchyLookup<IServerExtensionProvider<BlockEntity, ItemStack>> tileItemProviders = new HierarchyLookup<>(BlockEntity.class);
+
+ public static final Cache<Object, ItemCollector<?>> targetCache = CacheBuilder.newBuilder().weakKeys().expireAfterAccess(60, TimeUnit.SECONDS).build();
+
+ public static final int MAX_DISTANCE_SQR = 900;
+
+ @Contract("_ -> new")
+ public static @NotNull ResourceLocation id(String path) {
+ return new ResourceLocation(PROTOCOL_ID, path);
+ }
+
+ @ProtocolHandler.Init
+ public static void init() {
+ entityItemProviders.register(Entity.class, (player, world, target) -> {
+ if (target instanceof ContainerEntity containerEntity && containerEntity.getLootTable() != null) {
+ return List.of();
+ }
+
+ ItemCollector<?> itemCollector;
+ try {
+ itemCollector = targetCache.get(target, () -> {
+ if (target instanceof AbstractHorse) {
+ return new ItemCollector<>(new ItemIterator.ContainerItemIterator(o -> {
+ if (o instanceof AbstractHorse horse) {
+ return horse.inventory;
+ }
+ return null;
+ }, 2));
+ }
+ return ItemCollector.EMPTY;
+ });
+ } catch (ExecutionException e) {
+ return null;
+ }
+
+ if (itemCollector == ItemCollector.EMPTY) {
+ return null;
+ }
+ return itemCollector.update(target, world.getGameTime());
+ });
+
+ tileItemProviders.register(CampfireBlockEntity.class, (player, world, target) -> {
+ CampfireBlockEntity campfire = (CampfireBlockEntity) target;
+ List<ItemStack> list = Lists.newArrayList();
+ for (int i = 0; i < campfire.cookingTime.length; i++) {
+ ItemStack stack = campfire.getItems().get(i);
+ if (stack.isEmpty()) {
+ continue;
+ }
+ stack = stack.copy();
+ stack.getOrCreateTag().putInt("jade:cooking", campfire.cookingTime[i] - campfire.cookingProgress[i]);
+ list.add(stack);
+ }
+ return List.of(new ViewGroup<>(list));
+ });
+ tileItemProviders.register(BlockEntity.class, (player, world, target) -> {
+ if (target instanceof RandomizableContainer te && te.getLootTable() != null) {
+ return List.of();
+ }
+
+ if (!player.isCreative() && !player.isSpectator() && target instanceof BaseContainerBlockEntity te) {
+ if (te.lockKey != LockCode.NO_LOCK) {
+ return List.of();
+ }
+ }
+ if (target instanceof EnderChestBlockEntity) {
+ PlayerEnderChestContainer inventory = player.getEnderChestInventory();
+ return new ItemCollector<>(new ItemIterator.ContainerItemIterator(0)).update(inventory, world.getGameTime());
+ }
+ ItemCollector<?> itemCollector;
+ try {
+ itemCollector = targetCache.get(target, () -> {
+ if (target instanceof Container) {
+ if (target instanceof ChestBlockEntity) {
+ return new ItemCollector<>(new ItemIterator.ContainerItemIterator(o -> {
+ if (o instanceof ChestBlockEntity be) {
+ if (be.getBlockState().getBlock() instanceof ChestBlock chestBlock) {
+ Container compound = ChestBlock.getContainer(chestBlock, be.getBlockState(), world, be.getBlockPos(), false);
+ if (compound != null) {
+ return compound;
+ }
+ }
+ return be;
+ }
+ return null;
+ }, 0));
+ }
+ return new ItemCollector<>(new ItemIterator.ContainerItemIterator(0));
+ }
+ return ItemCollector.EMPTY;
+ });
+ } catch (ExecutionException e) {
+ return null;
+ }
+
+ if (itemCollector == ItemCollector.EMPTY) {
+ return null;
+ }
+ return itemCollector.update(target, world.getGameTime());
+ });
+
+ entityDataProviders.register(OwnableEntity.class, ((data, player, world, entity, showDetails) -> {
+ UUID ownerUUID = ((OwnableEntity) entity).getOwnerUUID();
+ if (ownerUUID != null) {
+ GameProfileCache cache = MinecraftServer.getServer().getProfileCache();
+ if (cache != null) {
+ cache.get(ownerUUID).map(GameProfile::getName).ifPresent(name -> data.putString("OwnerName", name));
+ }
+ }
+ }));
+ entityDataProviders.register(LivingEntity.class, ((data, player, world, entity, showDetails) -> {
+ LivingEntity living = (LivingEntity) entity;
+ Collection<MobEffectInstance> effects = living.getActiveEffects();
+ if (effects.isEmpty()) {
+ return;
+ }
+ ListTag list = new ListTag();
+ for (MobEffectInstance effect : effects) {
+ CompoundTag compound = new CompoundTag();
+ compound.putString("Name", Component.Serializer.toJson(getEffectName(effect)));
+ if (effect.isInfiniteDuration()) {
+ compound.putBoolean("Infinite", true);
+ } else {
+ compound.putInt("Duration", effect.getDuration());
+ }
+ compound.putBoolean("Bad", effect.getEffect().getCategory() == MobEffectCategory.HARMFUL);
+ list.add(compound);
+ }
+ data.put("StatusEffects", list);
+ }));
+ entityDataProviders.register(AgeableMob.class, ((data, player, world, entity, showDetails) -> {
+ int time = -((AgeableMob) entity).getAge();
+ if (time > 0) {
+ data.putInt("GrowingTime", time);
+ }
+ }));
+ entityDataProviders.register(Tadpole.class, ((data, player, world, entity, showDetails) -> {
+ int time = ((Tadpole) entity).getTicksLeftUntilAdult();
+ if (time > 0) {
+ data.putInt("GrowingTime", time);
+ }
+ }));
+ entityDataProviders.register(Animal.class, ((data, player, world, entity, showDetails) -> {
+ int time = ((Animal) entity).getAge();
+ if (time > 0) {
+ data.putInt("BreedingCD", time);
+ }
+ }));
+ entityDataProviders.register(Allay.class, ((data, player, world, entity, showDetails) -> {
+ int time = 0;
+ Allay allay = (Allay) entity;
+ if (allay.duplicationCooldown > 0 && allay.duplicationCooldown < Integer.MAX_VALUE) {
+ time = (int) allay.duplicationCooldown;
+ }
+ if (time > 0) {
+ data.putInt("BreedingCD", time);
+ }
+ }));
+ entityDataProviders.register(Chicken.class, ((data, player, world, entity, showDetails) -> {
+ data.putInt("NextEggIn", ((Chicken) entity).eggTime);
+ }));
+ entityDataProviders.register(Entity.class, ((tag, player, world, object, showDetails) -> {
+ for (var provider : entityItemProviders.get(object)) {
+ var groups = provider.getGroups(player, world, object);
+ if (groups == null) {
+ continue;
+ }
+ if (ViewGroup.saveList(tag, "JadeItemStorage", groups, item -> {
+ CompoundTag itemTag = new CompoundTag();
+ int count = item.getCount();
+ if (count > 64) {
+ item.setCount(1);
+ }
+ item.save(itemTag);
+ if (count > 64) {
+ itemTag.putInt("NewCount", count);
+ item.setCount(count);
+ }
+ return itemTag;
+ })) {
+ tag.putString("JadeItemStorageUid", "minecraft:item_storage");
+ }
+ break;
+ }
+ }));
+ entityDataProviders.register(ZombieVillager.class, (data, player, world, object, showDetails) -> {
+ ZombieVillager entity = (ZombieVillager) object;
+ if (entity.villagerConversionTime > 0) {
+ data.putInt("ConversionTime", entity.villagerConversionTime);
+ }
+ });
+
+ tileDataProviders.register(BrewingStandBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ if (object instanceof BrewingStandBlockEntity brewingStand) {
+ CompoundTag compound = new CompoundTag();
+ compound.putInt("Time", brewingStand.brewTime);
+ compound.putInt("Fuel", brewingStand.fuel);
+ data.put("BrewingStand", compound);
+ }
+ }));
+ tileDataProviders.register(BeehiveBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ data.getAllKeys().clear();
+ BeehiveBlockEntity beehive = (BeehiveBlockEntity) object;
+ data.putByte("Bees", (byte) beehive.getOccupantCount());
+ data.putBoolean("Full", beehive.isFull());
+ }));
+ tileDataProviders.register(CommandBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ if (!player.canUseGameMasterBlocks()) {
+ return;
+ }
+ BaseCommandBlock logic = ((CommandBlockEntity) object).getCommandBlock();
+ String command = logic.getCommand();
+ if (command.isEmpty()) {
+ return;
+ }
+ if (command.length() > 40) {
+ command = command.substring(0, 37) + "...";
+ }
+ data.putString("Command", command);
+ }));
+ tileDataProviders.register(JukeboxBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ if (object instanceof JukeboxBlockEntity jukebox) {
+ ItemStack stack = jukebox.getTheItem();
+ if (!stack.isEmpty()) {
+ data.put("Record", stack.save(new CompoundTag()));
+ }
+ }
+ }));
+ tileDataProviders.register(LecternBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ ItemStack stack = ((LecternBlockEntity) object).getBook();
+ if (!stack.isEmpty()) {
+ if (stack.hasCustomHoverName() || stack.getItem() != Items.WRITABLE_BOOK) {
+ data.put("Book", stack.save(new CompoundTag()));
+ }
+ }
+ }));
+ tileDataProviders.register(ComparatorBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ data.putInt("Signal", ((ComparatorBlockEntity) object).getOutputSignal());
+ }));
+ tileDataProviders.register(HopperBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ BlockState state = object.getBlockState();
+ if (state.hasProperty(BlockStateProperties.ENABLED) && !state.getValue(BlockStateProperties.ENABLED)) {
+ data.putBoolean("HopperLocked", true);
+ }
+ }));
+ tileDataProviders.register(AbstractFurnaceBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ AbstractFurnaceBlockEntity furnace = (AbstractFurnaceBlockEntity) object;
+ ListTag items = new ListTag();
+ for (int i = 0; i < 3; i++) {
+ items.add(furnace.getItem(i).save(new CompoundTag()));
+ }
+ data.put("furnace", items);
+ CompoundTag furnaceTag = furnace.saveWithoutMetadata();
+ data.putInt("progress", furnaceTag.getInt("CookTime"));
+ data.putInt("total", furnaceTag.getInt("CookTimeTotal"));
+ }));
+ tileDataProviders.register(BlockEntity.class, ((data, player, world, object, showDetails) -> {
+ if (object instanceof Nameable nameable) {
+ Component name = null;
+ if (nameable instanceof ChestBlockEntity chestBlock) {
+ MenuProvider menuProvider = chestBlock.getBlockState().getMenuProvider(world, chestBlock.getBlockPos());
+ if (menuProvider != null) {
+ name = menuProvider.getDisplayName();
+ }
+ } else if (nameable.hasCustomName()) {
+ name = nameable.getDisplayName();
+ }
+
+ if (name != null) {
+ data.putString("givenName", Component.Serializer.toJson(name));
+ }
+ }
+ }));
+ tileDataProviders.register(ChiseledBookShelfBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ ChiseledBookShelfBlockEntity bookShelf = (ChiseledBookShelfBlockEntity) object;
+ if (!bookShelf.isEmpty()) {
+ data.put("Bookshelf", bookShelf.saveWithoutMetadata());
+ }
+ }));
+ tileDataProviders.register(BlockEntity.class, ((tag, player, world, object, showDetails) -> {
+ if (object instanceof AbstractFurnaceBlockEntity) {
+ return;
+ }
+
+ for (var provider : tileItemProviders.get(object)) {
+ var groups = provider.getGroups(player, world, object);
+ if (groups == null) {
+ continue;
+ }
+
+ if (ViewGroup.saveList(tag, "JadeItemStorage", groups, item -> {
+ CompoundTag itemTag = new CompoundTag();
+ int count = item.getCount();
+ if (count > 64) {
+ item.setCount(1);
+ }
+ item.save(itemTag);
+ if (count > 64) {
+ itemTag.putInt("NewCount", count);
+ item.setCount(count);
+ }
+ return itemTag;
+ })) {
+ tag.putString("JadeItemStorageUid", "minecraft:item_storage");
+ } else if (object instanceof RandomizableContainer containerEntity && containerEntity.getLootTable() != null) {
+ tag.putBoolean("Loot", true);
+ } else if (!player.isCreative() && !player.isSpectator() && object instanceof BaseContainerBlockEntity te) {
+ if (te.lockKey != LockCode.NO_LOCK) {
+ tag.putBoolean("Locked", true);
+ }
+ }
+ break;
+ }
+ }));
+ tileDataProviders.register(TrialSpawnerBlockEntity.class, (data, player, world, object, showDetails) -> {
+ TrialSpawnerBlockEntity spawner = (TrialSpawnerBlockEntity) object;
+ TrialSpawnerData spawnerData = spawner.getTrialSpawner().getData();
+ if (spawner.getTrialSpawner().canSpawnInLevel(world) && world.getGameTime() < spawnerData.cooldownEndsAt) {
+ data.putInt("Cooldown", (int) (spawnerData.cooldownEndsAt - world.getGameTime()));
+ }
+ });
+ tileDataProviders.register(CalibratedSculkSensorBlockEntity.class, ((data, player, world, object, showDetails) -> {
+ Direction direction = object.getBlockState().getValue(CalibratedSculkSensorBlock.FACING).getOpposite();
+ int signal = world.getSignal(object.getBlockPos().relative(direction), direction);
+ data.putInt("Signal", signal);
+ }));
+ }
+
+ @ProtocolHandler.PlayerJoin
+ public static void onPlayerJoin(ServerPlayer player) {
+ if (org.dreeam.leaf.config.modules.network.ProtocolSupport.jadeProtocol) {
+ ProtocolUtils.sendPayloadPacket(player, PACKET_SERVER_PING, buf -> buf.writeUtf("{}"));
+ }
+ }
+
+ @ProtocolHandler.PayloadReceiver(payload = RequestEntityPayload.class, payloadId = "request_entity")
+ public static void requestEntityData(ServerPlayer player, RequestEntityPayload payload) {
+ if (!org.dreeam.leaf.config.modules.network.ProtocolSupport.jadeProtocol) {
+ return;
+ }
+
+ MinecraftServer server = MinecraftServer.getServer();
+ 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;
+ }
+ if (payload.partIndex >= 0 && entity instanceof EnderDragon dragon) {
+ EnderDragonPart[] parts = dragon.getSubEntities();
+ if (payload.partIndex < parts.length) {
+ entity = parts[payload.partIndex];
+ }
+ }
+
+ var providers = entityDataProviders.get(entity);
+ if (providers.isEmpty()) {
+ return;
+ }
+
+ CompoundTag tag = new CompoundTag();
+ for (IJadeDataProvider<Entity> provider : providers) {
+ try {
+ provider.saveData(tag, player, world, entity, showDetails);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ tag.putInt("WailaEntityID", entity.getId());
+
+ ProtocolUtils.sendPayloadPacket(player, PACKET_RECEIVE_DATA, buf -> buf.writeNbt(tag));
+ });
+ }
+
+ @ProtocolHandler.PayloadReceiver(payload = RequestTilePayload.class, payloadId = "request_tile")
+ public static void requestTileData(ServerPlayer player, RequestTilePayload payload) {
+ if (!org.dreeam.leaf.config.modules.network.ProtocolSupport.jadeProtocol) {
+ return;
+ }
+
+ MinecraftServer server = MinecraftServer.getServer();
+ boolean showDetails = payload.showDetails;
+ BlockHitResult result = payload.hitResult;
+ BlockPos pos = result.getBlockPos();
+ Level world = player.level();
+ if (pos.distSqr(player.blockPosition()) > MAX_DISTANCE_SQR || !world.isLoaded(pos)) {
+ return;
+ }
+
+ server.execute(() -> {
+ BlockEntity tile = world.getBlockEntity(pos);
+ if (tile == null) return;
+
+ List<IJadeDataProvider<BlockEntity>> providers = tileDataProviders.get(tile);
+ if (providers.isEmpty()) {
+ return;
+ }
+
+ CompoundTag tag = new CompoundTag();
+ for (IJadeDataProvider<BlockEntity> provider : providers) {
+ try {
+ provider.saveData(tag, player, world, tile, showDetails);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ tag.putInt("x", pos.getX());
+ tag.putInt("y", pos.getY());
+ tag.putInt("z", pos.getZ());
+ tag.putString("id", BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(tile.getType()).toString());
+
+ ProtocolUtils.sendPayloadPacket(player, PACKET_RECEIVE_DATA, buf -> buf.writeNbt(tag));
+ });
+ }
+
+ @ProtocolHandler.ReloadServer
+ public static void onServerReload() {
+ if (org.dreeam.leaf.config.modules.network.ProtocolSupport.jadeProtocol) {
+ enableAllPlayer();
+ }
+ }
+
+ public static void enableAllPlayer() {
+ for (ServerPlayer player : MinecraftServer.getServer().getPlayerList().players) {
+ onPlayerJoin(player);
+ }
+ }
+
+ public record RequestEntityPayload(boolean showDetails, int entityId, int partIndex, 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.readVarInt(), buf.readVarInt(), buf.readFloat(), buf.readFloat(), buf.readFloat());
+ }
+
+ @Override
+ public void write(FriendlyByteBuf buf) {
+ buf.writeBoolean(showDetails);
+ buf.writeVarInt(entityId);
+ buf.writeVarInt(partIndex);
+ buf.writeFloat(hitX);
+ buf.writeFloat(hitY);
+ buf.writeFloat(hitZ);
+ }
+
+ @Override
+ @NotNull
+ public ResourceLocation id() {
+ return PACKET_REQUEST_ENTITY;
+ }
+ }
+
+ 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(), buf.readVarInt(), buf.readItem());
+ }
+
+ @Override
+ public void write(FriendlyByteBuf buf) {
+ buf.writeBoolean(showDetails);
+ buf.writeBlockHitResult(hitResult);
+ buf.writeVarInt(blockState);
+ buf.writeItem(fakeBlock);
+ }
+
+ @Override
+ @NotNull
+ public ResourceLocation id() {
+ return PACKET_REQUEST_TILE;
+ }
+ }
+
+ // Power by Jade
+
+ public static Component getEffectName(MobEffectInstance mobEffectInstance) {
+ MutableComponent mutableComponent = mobEffectInstance.getEffect().getDisplayName().copy();
+ if (mobEffectInstance.getAmplifier() >= 1 && mobEffectInstance.getAmplifier() <= 9) {
+ mutableComponent.append(CommonComponents.SPACE).append(Component.translatable("enchantment.level." + (mobEffectInstance.getAmplifier() + 1)));
+ }
+ return mutableComponent;
+ }
+
+ public interface IJadeProvider {
+ }
+
+ public interface IJadeDataProvider<T> {
+ void saveData(CompoundTag data, ServerPlayer player, Level world, T object, boolean showDetails);
+ }
+
+ public interface IServerExtensionProvider<IN, OUT> {
+ List<ViewGroup<OUT>> getGroups(ServerPlayer player, Level world, IN target);
+ }
+
+ public static class ItemCollector<T> {
+ public static final int MAX_SIZE = 54;
+ public static final ItemCollector<?> EMPTY = new ItemCollector<>(null);
+ private static final Predicate<ItemStack> NON_EMPTY = stack -> {
+ if (stack.isEmpty()) {
+ return false;
+ }
+ CompoundTag tag = stack.getTag();
+ if (tag != null && tag.contains("CustomModelData")) {
+ for (String key : stack.getTag().getAllKeys()) {
+ if (key.toLowerCase(Locale.ENGLISH).endsWith("clear") && stack.getTag().getBoolean(key)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ };
+ private final Object2IntLinkedOpenHashMap<ItemDefinition> items = new Object2IntLinkedOpenHashMap<>();
+ private final ItemIterator<T> iterator;
+ public long version;
+ public long lastTimeFinished;
+ public List<ViewGroup<ItemStack>> mergedResult;
+
+ public ItemCollector(ItemIterator<T> iterator) {
+ this.iterator = iterator;
+ }
+
+ public List<ViewGroup<ItemStack>> update(Object target, long gameTime) {
+ if (iterator == null) {
+ return null;
+ }
+ T container = iterator.find(target);
+ if (container == null) {
+ return null;
+ }
+ long currentVersion = iterator.getVersion(container);
+ if (mergedResult != null && iterator.isFinished()) {
+ if (version == currentVersion) {
+ return mergedResult; // content not changed
+ }
+ if (lastTimeFinished + 5 > gameTime) {
+ return mergedResult; // avoid update too frequently
+ }
+ iterator.reset();
+ }
+ AtomicInteger count = new AtomicInteger();
+ iterator.populate(container).forEach(stack -> {
+ count.incrementAndGet();
+ if (NON_EMPTY.test(stack)) {
+ ItemDefinition def = new ItemDefinition(stack);
+ items.addTo(def, stack.getCount());
+ }
+ });
+ iterator.afterPopulate(count.get());
+ if (mergedResult != null && !iterator.isFinished()) {
+ updateCollectingProgress(mergedResult.get(0));
+ return mergedResult;
+ }
+ List<ItemStack> partialResult = items.object2IntEntrySet().stream().limit(54).map(entry -> {
+ ItemDefinition def = entry.getKey();
+ return def.toStack(entry.getIntValue());
+ }).toList();
+ List<ViewGroup<ItemStack>> groups = List.of(updateCollectingProgress(new ViewGroup<>(partialResult)));
+ if (iterator.isFinished()) {
+ mergedResult = groups;
+ version = currentVersion;
+ lastTimeFinished = gameTime;
+ items.clear();
+ }
+ return groups;
+ }
+
+ protected ViewGroup<ItemStack> updateCollectingProgress(ViewGroup<ItemStack> group) {
+ float progress = iterator.getCollectingProgress();
+ CompoundTag data = group.getExtraData();
+ if (Float.isNaN(progress)) {
+ progress = 0;
+ }
+ if (progress >= 1) {
+ data.remove("Collecting");
+ } else {
+ data.putFloat("Collecting", progress);
+ }
+ return group;
+ }
+
+ public record ItemDefinition(Item item, @Nullable CompoundTag tag) {
+ ItemDefinition(ItemStack stack) {
+ this(stack.getItem(), stack.getTag());
+ }
+
+ public ItemStack toStack(int count) {
+ ItemStack stack = new ItemStack(item);
+ stack.setCount(count);
+ stack.setTag(tag);
+ return stack;
+ }
+ }
+ }
+
+ public static abstract class ItemIterator<T> {
+ public static final AtomicLong version = new AtomicLong();
+ protected final Function<Object, @Nullable T> containerFinder;
+ protected final int fromIndex;
+ protected boolean finished;
+ protected int currentIndex;
+
+ protected ItemIterator(Function<Object, @Nullable T> containerFinder, int fromIndex) {
+ this.containerFinder = containerFinder;
+ this.currentIndex = this.fromIndex = fromIndex;
+ }
+
+ public @Nullable T find(Object target) {
+ return containerFinder.apply(target);
+ }
+
+ public final boolean isFinished() {
+ return finished;
+ }
+
+ public long getVersion(T container) {
+ return version.getAndIncrement();
+ }
+
+ public abstract Stream<ItemStack> populate(T container);
+
+ public void reset() {
+ currentIndex = fromIndex;
+ finished = false;
+ }
+
+ public void afterPopulate(int count) {
+ currentIndex += count;
+ if (count == 0 || currentIndex >= 10000) {
+ finished = true;
+ }
+ }
+
+ public float getCollectingProgress() {
+ return Float.NaN;
+ }
+
+ public static abstract class SlottedItemIterator<T> extends ItemIterator<T> {
+ protected float progress;
+
+ public SlottedItemIterator(Function<Object, @Nullable T> containerFinder, int fromIndex) {
+ super(containerFinder, fromIndex);
+ }
+
+ protected abstract int getSlotCount(T container);
+
+ protected abstract ItemStack getItemInSlot(T container, int slot);
+
+ @Override
+ public Stream<ItemStack> populate(T container) {
+ int slotCount = getSlotCount(container);
+ int toIndex = currentIndex + ItemCollector.MAX_SIZE * 2;
+ if (toIndex >= slotCount) {
+ toIndex = slotCount;
+ finished = true;
+ }
+ progress = (float) (currentIndex - fromIndex) / (slotCount - fromIndex);
+ return IntStream.range(currentIndex, toIndex).mapToObj(slot -> getItemInSlot(container, slot));
+ }
+
+ @Override
+ public float getCollectingProgress() {
+ return progress;
+ }
+ }
+
+ public static class ContainerItemIterator extends SlottedItemIterator<Container> {
+ public ContainerItemIterator(int fromIndex) {
+ this(Container.class::cast, fromIndex);
+ }
+
+ public ContainerItemIterator(Function<Object, @Nullable Container> containerFinder, int fromIndex) {
+ super(containerFinder, fromIndex);
+ }
+
+ @Override
+ protected int getSlotCount(Container container) {
+ return container.getContainerSize();
+ }
+
+ @Override
+ protected ItemStack getItemInSlot(Container container, int slot) {
+ return container.getItem(slot);
+ }
+ }
+ }
+
+ public static class ViewGroup<T> {
+
+ public final List<T> views;
+ @Nullable
+ public String id;
+ @Nullable
+ protected CompoundTag extraData;
+
+ public ViewGroup(List<T> views) {
+ this.views = views;
+ }
+
+ public void save(CompoundTag tag, Function<T, CompoundTag> writer) {
+ ListTag list = new ListTag();
+ for (var view : views) {
+ list.add(writer.apply(view));
+ }
+ tag.put("Views", list);
+ if (id != null) {
+ tag.putString("Id", id);
+ }
+ if (extraData != null) {
+ tag.put("Data", extraData);
+ }
+ }
+
+ public static <T> boolean saveList(CompoundTag tag, String key, List<ViewGroup<T>> groups, Function<T, CompoundTag> writer) {
+ if (groups == null || groups.isEmpty()) {
+ return false;
+ }
+
+ ListTag groupList = new ListTag();
+ for (ViewGroup<T> group : groups) {
+ if (group.views.isEmpty()) {
+ continue;
+ }
+ CompoundTag groupTag = new CompoundTag();
+ group.save(groupTag, writer);
+ groupList.add(groupTag);
+ }
+ if (!groupList.isEmpty()) {
+ tag.put(key, groupList);
+ return true;
+ }
+ return false;
+ }
+
+ public CompoundTag getExtraData() {
+ if (extraData == null) {
+ extraData = new CompoundTag();
+ }
+ return extraData;
+ }
+ }
+
+ public static class HierarchyLookup<T> {
+
+ private final Class<?> baseClass;
+ private final Cache<Class<?>, List<T>> resultCache = CacheBuilder.newBuilder().build();
+ private final boolean singleton;
+ private ListMultimap<Class<?>, T> objects = ArrayListMultimap.create();
+
+ public HierarchyLookup(Class<?> baseClass) {
+ this(baseClass, false);
+ }
+
+ public HierarchyLookup(Class<?> baseClass, boolean singleton) {
+ this.baseClass = baseClass;
+ this.singleton = singleton;
+ }
+
+ public void register(Class<?> clazz, T provider) {
+ Objects.requireNonNull(clazz);
+ objects.put(clazz, provider);
+ }
+
+ public List<T> get(Object obj) {
+ if (obj == null) {
+ return List.of();
+ }
+ return get(obj.getClass());
+ }
+
+ public List<T> get(Class<?> clazz) {
+ try {
+ return resultCache.get(clazz, () -> {
+ List<T> list = Lists.newArrayList();
+ getInternal(clazz, list);
+ if (singleton && !list.isEmpty()) {
+ return ImmutableList.of(list.get(0));
+ }
+ return list;
+ });
+ } catch (ExecutionException e) {
+ e.printStackTrace();
+ }
+ return List.of();
+ }
+
+ private void getInternal(Class<?> clazz, List<T> list) {
+ if (clazz != baseClass && clazz != Object.class) {
+ getInternal(clazz.getSuperclass(), list);
+ }
+ list.addAll(objects.get(clazz));
+ }
+
+ public Multimap<Class<?>, T> getObjects() {
+ return objects;
+ }
+ }
+}