9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-26 02:19:19 +00:00

Merge branch 'ver/1.21.4' of https://github.com/Winds-Studio/Leaf into ver/1.21.4

This commit is contained in:
Taiyou06
2025-03-13 10:31:47 +01:00
6 changed files with 30 additions and 43 deletions

View File

@@ -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:

View File

@@ -118,7 +118,7 @@ If these excellent projects hadn't appeared, Leaf wouldn't have become great.
<a href="https://github.com/plasmoapp/matter">Matter</a><br>
<a href="https://github.com/LuminolMC/Luminol">Luminol</a><br>
<a href="https://github.com/Gensokyo-Reimagined/Nitori">Nitori</a><br>
<a href="https://github.com/Tuinity/Moonrise">Moonrise</a><br>
<a href="https://github.com/Tuinity/Moonrise">Moonrise</a> (during 1.21.1)<br>
</p>
</details>

View File

@@ -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

View File

@@ -1,18 +1,19 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Taiyou06 <kaandindar21@gmail.com>
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;
}

View File

@@ -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<ByteBuf, byte[]> 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<byte[]> skyList = buffer.readList(DATA_LAYER_STREAM_CODEC);
+ List<byte[]> 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<byte[]> 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<byte[]> 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
}
}

View File

@@ -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
);
}
}