diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml
index bff96b25..cedfc8c4 100644
--- a/.github/workflows/build-pr.yml
+++ b/.github/workflows/build-pr.yml
@@ -32,14 +32,10 @@ jobs:
run: ./gradlew -Dorg.gradle.jvmargs="${{ env.GRAALVM_ARGS }}" applyAllPatches --stacktrace --no-daemon
- name: Create MojmapPaperclipJar
run: ./gradlew -Dorg.gradle.jvmargs="${{ env.GRAALVM_ARGS }}" createMojmapPaperclipJar --stacktrace --no-daemon
- - name: Create ReobfPaperclipJar
- run: ./gradlew -Dorg.gradle.jvmargs="${{ env.GRAALVM_ARGS }}" -Dpaperweight.debug=true createReobfPaperclipJar --stacktrace --no-daemon
- name: Rename Paperclip JARs
run: |
mv leaf-server/build/libs/leaf-paperclip-1.21.4-R0.1-SNAPSHOT-mojmap.jar ./leaf-1.21.4-mojmap.jar
- mv leaf-server/build/libs/leaf-paperclip-1.21.4-R0.1-SNAPSHOT-reobf.jar ./leaf-1.21.4-reobf.jar
-
- name: Upload Leaf as build artifact
uses: actions/upload-artifact@main
with:
diff --git a/README.md b/README.md
index 7408a0ad..b2f4b456 100644
--- a/README.md
+++ b/README.md
@@ -118,7 +118,7 @@ If these excellent projects hadn't appeared, Leaf wouldn't have become great.
• Matter
• Luminol
• Nitori
- • Moonrise
+ • Moonrise (during 1.21.1)
diff --git a/gradle.properties b/gradle.properties
index 5b05a454..54766034 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -2,7 +2,7 @@ group=cn.dreeam.leaf
mcVersion=1.21.4
version=1.21.4-R0.1-SNAPSHOT
-galeCommit=7af959b540632e53031b437ca99b254d126fb48c
+galeCommit=119ea5b00abb21109606d9c75e80a79db37c3603
org.gradle.configuration-cache=true
org.gradle.caching=true
diff --git a/leaf-server/minecraft-patches/features/0134-Slight-optimizations-to-VarInt.patch b/leaf-server/minecraft-patches/features/0134-Slightly-optimized-VarInt-write.patch
similarity index 84%
rename from leaf-server/minecraft-patches/features/0134-Slight-optimizations-to-VarInt.patch
rename to leaf-server/minecraft-patches/features/0134-Slightly-optimized-VarInt-write.patch
index e7a6a588..9c6641fa 100644
--- a/leaf-server/minecraft-patches/features/0134-Slight-optimizations-to-VarInt.patch
+++ b/leaf-server/minecraft-patches/features/0134-Slightly-optimized-VarInt-write.patch
@@ -1,18 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06
Date: Mon, 24 Feb 2025 21:11:09 +0100
-Subject: [PATCH] Slight optimizations to VarInt
+Subject: [PATCH] Slightly optimized VarInt#write
+Use switch case instead of if-else for branches. It makes it able to use
+tableswitch instruction for better efficiency.
diff --git a/net/minecraft/network/VarInt.java b/net/minecraft/network/VarInt.java
-index 6f8dd31582f0e1d3a71acc7a142c1f4ec0539d9e..043db53ee627ac13e3a952c8d5beba5065ecbb48 100644
+index 6f8dd31582f0e1d3a71acc7a142c1f4ec0539d9e..4c9095995e8515c61d54f1c056be35a12a138ef3 100644
--- a/net/minecraft/network/VarInt.java
+++ b/net/minecraft/network/VarInt.java
-@@ -51,35 +51,41 @@ public class VarInt {
- }
+@@ -52,35 +52,44 @@ public class VarInt {
public static ByteBuf write(ByteBuf buffer, int value) {
-- // Gale start - Velocity - optimized VarInt#write
+ // Gale start - Velocity - optimized VarInt#write
- if ((value & 0xFFFFFF80) == 0) {
- buffer.writeByte(value);
- } else if ((value & 0xFFFFC000) == 0) {
@@ -41,7 +42,7 @@ index 6f8dd31582f0e1d3a71acc7a142c1f4ec0539d9e..043db53ee627ac13e3a952c8d5beba50
- | 0x80808080;
- buffer.writeInt(w);
- buffer.writeByte(value >>> 28);
-+ // Gale start - Velocity - optimized VarInt#write // Leaf - help JIT by using switch case
++ // Leaf start - Slightly optimized VarInt#write
+ int bytesNeeded = getByteSize(value);
+
+ switch (bytesNeeded) {
@@ -77,5 +78,8 @@ index 6f8dd31582f0e1d3a71acc7a142c1f4ec0539d9e..043db53ee627ac13e3a952c8d5beba50
+ buffer.writeByte(value >>> 28);
+ break;
}
++ // Leaf end - Slightly optimized VarInt#write
++
return buffer;
}
+
diff --git a/leaf-server/minecraft-patches/features/0135-Rewrite-ClientboundLightUpdatePacketData.patch b/leaf-server/minecraft-patches/features/0135-Rewrite-ClientboundLightUpdatePacketData.patch
index fc49511e..3f869283 100644
--- a/leaf-server/minecraft-patches/features/0135-Rewrite-ClientboundLightUpdatePacketData.patch
+++ b/leaf-server/minecraft-patches/features/0135-Rewrite-ClientboundLightUpdatePacketData.patch
@@ -5,24 +5,15 @@ Subject: [PATCH] Rewrite ClientboundLightUpdatePacketData
diff --git a/net/minecraft/network/protocol/game/ClientboundLightUpdatePacketData.java b/net/minecraft/network/protocol/game/ClientboundLightUpdatePacketData.java
-index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..2ef45811f3a3a763f389e8e6e9eeaf255cf668e6 100644
+index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..234280499fe1bc495bcdd4c3e144d1f99b7e6975 100644
--- a/net/minecraft/network/protocol/game/ClientboundLightUpdatePacketData.java
+++ b/net/minecraft/network/protocol/game/ClientboundLightUpdatePacketData.java
-@@ -1,8 +1,8 @@
- package net.minecraft.network.protocol.game;
-
--import com.google.common.collect.Lists;
- import io.netty.buffer.ByteBuf;
- import java.util.BitSet;
-+import java.util.Arrays;
- import java.util.List;
- import javax.annotation.Nullable;
- import net.minecraft.core.SectionPos;
-@@ -16,30 +16,109 @@ import net.minecraft.world.level.lighting.LevelLightEngine;
+@@ -16,30 +16,113 @@ import net.minecraft.world.level.lighting.LevelLightEngine;
public class ClientboundLightUpdatePacketData {
private static final StreamCodec DATA_LAYER_STREAM_CODEC = ByteBufCodecs.byteArray(2048);
+
++ // Leaf start - Rewrite ClientboundLightUpdatePacketData
+ // Static constants to avoid allocations
+ private static final byte[][] EMPTY_ARRAY = new byte[0][];
+
@@ -43,6 +34,7 @@ index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..2ef45811f3a3a763f389e8e6e9eeaf25
+ private final byte[][] blockUpdates;
+ private final int skyUpdateCount;
+ private final int blockUpdateCount;
++ // Leaf end - Rewrite ClientboundLightUpdatePacketData
public ClientboundLightUpdatePacketData(ChunkPos chunkPos, LevelLightEngine lightEngine, @Nullable BitSet skyLight, @Nullable BitSet blockLight) {
- this.skyYMask = new BitSet();
@@ -53,6 +45,7 @@ index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..2ef45811f3a3a763f389e8e6e9eeaf25
- this.blockUpdates = Lists.newArrayList();
-
- for (int i = 0; i < lightEngine.getLightSectionCount(); i++) {
++ // Leaf start - Rewrite ClientboundLightUpdatePacketData
+ int sectionCount = lightEngine.getLightSectionCount();
+
+ // Round up to nearest long boundary (64 bits) to prevent BitSet expansion
@@ -137,16 +130,18 @@ index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..2ef45811f3a3a763f389e8e6e9eeaf25
+
+ this.skyUpdateCount = skyCount;
+ this.blockUpdateCount = blockCount;
++ // Leaf end - Rewrite ClientboundLightUpdatePacketData
}
public ClientboundLightUpdatePacketData(FriendlyByteBuf buffer, int x, int z) {
-@@ -47,8 +126,28 @@ public class ClientboundLightUpdatePacketData {
+@@ -47,8 +130,30 @@ public class ClientboundLightUpdatePacketData {
this.blockYMask = buffer.readBitSet();
this.emptySkyYMask = buffer.readBitSet();
this.emptyBlockYMask = buffer.readBitSet();
- this.skyUpdates = buffer.readList(DATA_LAYER_STREAM_CODEC);
- this.blockUpdates = buffer.readList(DATA_LAYER_STREAM_CODEC);
+
++ // Leaf start - Rewrite ClientboundLightUpdatePacketData
+ // Read lists directly as arrays to avoid intermediate collections
+ List skyList = buffer.readList(DATA_LAYER_STREAM_CODEC);
+ List blockList = buffer.readList(DATA_LAYER_STREAM_CODEC);
@@ -168,10 +163,11 @@ index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..2ef45811f3a3a763f389e8e6e9eeaf25
+
+ this.skyUpdateCount = skySize;
+ this.blockUpdateCount = blockSize;
++ // Leaf end - Rewrite ClientboundLightUpdatePacketData
}
public void write(FriendlyByteBuf buffer) {
-@@ -56,25 +155,31 @@ public class ClientboundLightUpdatePacketData {
+@@ -56,25 +161,33 @@ public class ClientboundLightUpdatePacketData {
buffer.writeBitSet(this.blockYMask);
buffer.writeBitSet(this.emptySkyYMask);
buffer.writeBitSet(this.emptyBlockYMask);
@@ -190,6 +186,7 @@ index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..2ef45811f3a3a763f389e8e6e9eeaf25
- } else {
- skyLight.set(index);
- updates.add(dataLayerData.copy().getData());
++ // Leaf start - Rewrite ClientboundLightUpdatePacketData
+ // Avoid creating unnecessary objects when writing
+ if (this.skyUpdateCount > 0) {
+ // Use direct array access for efficiency
@@ -199,7 +196,7 @@ index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..2ef45811f3a3a763f389e8e6e9eeaf25
}
+ } else {
+ buffer.writeVarInt(0);
-+ }
+ }
+
+ if (this.blockUpdateCount > 0) {
+ // Use direct array access for efficiency
@@ -209,7 +206,8 @@ index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..2ef45811f3a3a763f389e8e6e9eeaf25
+ }
+ } else {
+ buffer.writeVarInt(0);
- }
++ }
++ // Leaf end - Rewrite ClientboundLightUpdatePacketData
}
+ // Getter methods
@@ -217,20 +215,20 @@ index a0b54f3a3d11e0f0f1cb806406a870ba36da8f07..2ef45811f3a3a763f389e8e6e9eeaf25
public BitSet getSkyYMask() {
return this.skyYMask;
}
-@@ -84,7 +189,7 @@ public class ClientboundLightUpdatePacketData {
+@@ -84,7 +197,7 @@ public class ClientboundLightUpdatePacketData {
}
public List getSkyUpdates() {
- return this.skyUpdates;
-+ return this.skyUpdateCount > 0 ? Arrays.asList(this.skyUpdates) : List.of();
++ return this.skyUpdateCount > 0 ? java.util.Arrays.asList(this.skyUpdates) : List.of(); // Leaf - Rewrite ClientboundLightUpdatePacketData
}
public BitSet getBlockYMask() {
-@@ -96,6 +201,6 @@ public class ClientboundLightUpdatePacketData {
+@@ -96,6 +209,6 @@ public class ClientboundLightUpdatePacketData {
}
public List getBlockUpdates() {
- return this.blockUpdates;
-+ return this.blockUpdateCount > 0 ? Arrays.asList(this.blockUpdates) : List.of();
++ return this.blockUpdateCount > 0 ? java.util.Arrays.asList(this.blockUpdates) : List.of(); // Leaf - Rewrite ClientboundLightUpdatePacketData
}
}
diff --git a/leaf-server/minecraft-patches/features/0136-Some-Optimizations-on-SerializableChunkData.patch b/leaf-server/minecraft-patches/features/0136-Some-Optimizations-on-SerializableChunkData.patch
index 71e5ed23..10c295fc 100644
--- a/leaf-server/minecraft-patches/features/0136-Some-Optimizations-on-SerializableChunkData.patch
+++ b/leaf-server/minecraft-patches/features/0136-Some-Optimizations-on-SerializableChunkData.patch
@@ -76,14 +76,3 @@ index 6b6aaeca14178b5b709e20ae13552d42217f15c0..c10ed10dd843bfa12be3f80a244cda94
CompoundTag compoundTag = packStructureData(
StructurePieceSerializationContext.fromLevel(level), pos, chunk.getAllStarts(), chunk.getAllReferences()
);
-@@ -605,8 +615,8 @@ public record SerializableChunkData(
- list,
- list2,
- list1,
-- compoundTag
-- , persistentDataContainer // CraftBukkit - persistentDataContainer
-+ compoundTag,
-+ persistentDataContainer // CraftBukkit - persistentDataContainer
- );
- }
- }