diff --git a/leaf-server/minecraft-patches/features/0063-Optimize-noise-generation.patch b/leaf-server/minecraft-patches/features/0063-Optimize-noise-generation.patch index cd8e34dd..852c8c7e 100644 --- a/leaf-server/minecraft-patches/features/0063-Optimize-noise-generation.patch +++ b/leaf-server/minecraft-patches/features/0063-Optimize-noise-generation.patch @@ -183,32 +183,26 @@ index fb11a2eea540d55e50eab59f9857ca5d99f556f8..dcc1a3f8b611c9f103b848db90b077b9 private double sampleWithDerivative(int gridX, int gridY, int gridZ, double deltaX, double deltaY, double deltaZ, double[] noiseValues) { diff --git a/net/minecraft/world/level/levelgen/synth/PerlinNoise.java b/net/minecraft/world/level/levelgen/synth/PerlinNoise.java -index da3c26fbad32d75d71f7e59c8c3341316a754756..797368070540d78981cfeef82f9820ae6ef4b676 100644 +index da3c26fbad32d75d71f7e59c8c3341316a754756..51975690f707c81a8dd8bdf1ce528aece7edcdf7 100644 --- a/net/minecraft/world/level/levelgen/synth/PerlinNoise.java +++ b/net/minecraft/world/level/levelgen/synth/PerlinNoise.java -@@ -26,6 +26,10 @@ public class PerlinNoise { +@@ -26,6 +26,7 @@ public class PerlinNoise { private final double lowestFreqValueFactor; private final double lowestFreqInputFactor; private final double maxValue; -+ // Gale start - C2ME - optimize noise generation -+ private final int octaveSamplersCount; -+ private final double [] amplitudesArray; -+ // Gale end - C2ME - optimize noise generation ++ private final double [] amplitudesArray; // Gale - C2ME - optimize noise generation @Deprecated public static PerlinNoise createLegacyForBlendedNoise(RandomSource random, IntStream octaves) { -@@ -127,6 +131,10 @@ public class PerlinNoise { +@@ -127,6 +128,7 @@ public class PerlinNoise { this.lowestFreqInputFactor = Math.pow(2.0, -i); this.lowestFreqValueFactor = Math.pow(2.0, size - 1) / (Math.pow(2.0, size) - 1.0); this.maxValue = this.edgeValue(2.0); -+ // Gale start - C2ME - optimize noise generation -+ this.octaveSamplersCount = this.noiseLevels.length; -+ this.amplitudesArray = this.amplitudes.toDoubleArray(); -+ // Gale end - C2ME - optimize noise generation ++ this.amplitudesArray = this.amplitudes.toDoubleArray(); // Gale - C2ME - optimize noise generation } protected double maxValue() { -@@ -138,7 +146,27 @@ public class PerlinNoise { +@@ -138,7 +140,28 @@ public class PerlinNoise { } public double getValue(double x, double y, double z) { @@ -218,10 +212,11 @@ index da3c26fbad32d75d71f7e59c8c3341316a754756..797368070540d78981cfeef82f9820ae + double e = this.lowestFreqInputFactor; + double f = this.lowestFreqValueFactor; + -+ for (int i = 0; i < this.octaveSamplersCount; ++i) { ++ final int length = this.noiseLevels.length; ++ ++ for (int i = 0; i < length; i++) { + ImprovedNoise perlinNoiseSampler = this.noiseLevels[i]; + if (perlinNoiseSampler != null) { -+ @SuppressWarnings("deprecation") + double g = perlinNoiseSampler.noise( + wrap(x * e), wrap(y * e), wrap(z * e), 0.0, 0.0 + ); @@ -237,7 +232,7 @@ index da3c26fbad32d75d71f7e59c8c3341316a754756..797368070540d78981cfeef82f9820ae } @Deprecated -@@ -187,7 +215,7 @@ public class PerlinNoise { +@@ -187,7 +210,7 @@ public class PerlinNoise { } public static double wrap(double value) { diff --git a/leaf-server/minecraft-patches/features/0268-Optimise-getEntities.patch b/leaf-server/minecraft-patches/features/0268-Optimise-getEntities.patch index 4500d418..1674ad53 100644 --- a/leaf-server/minecraft-patches/features/0268-Optimise-getEntities.patch +++ b/leaf-server/minecraft-patches/features/0268-Optimise-getEntities.patch @@ -1,18 +1,19 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Taiyou06 Date: Sat, 12 Jul 2025 02:00:43 +0200 -Subject: [PATCH] Optimise-getEntities +Subject: [PATCH] Optimise getEntities Co-authored by: Martijn Muijsers diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -index 7f508c50e451a0689218cd36e6ac993f87092c04..8c77623ca06139883b12690bdde3c79ce99f6049 100644 +index 7f508c50e451a0689218cd36e6ac993f87092c04..a6c1f450f32fa688b102140963fd5bfb6b4e6ddf 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -@@ -546,6 +546,14 @@ public final class ChunkEntitySlices { +@@ -546,6 +546,15 @@ public final class ChunkEntitySlices { final BasicEntityList[] entitiesBySection = this.entitiesBySection; ++ // Leaf start - Optimise getEntities + // Cache AABB fields to local variables to reduce field accesses inside the hot loop. + final double boxMinX = box.minX; + final double boxMinY = box.minY; @@ -24,7 +25,7 @@ index 7f508c50e451a0689218cd36e6ac993f87092c04..8c77623ca06139883b12690bdde3c79c for (int section = min; section <= max; ++section) { final BasicEntityList list = entitiesBySection[section - minSection]; -@@ -554,11 +562,18 @@ public final class ChunkEntitySlices { +@@ -554,11 +563,19 @@ public final class ChunkEntitySlices { } final Entity[] storage = list.storage; @@ -42,13 +43,15 @@ index 7f508c50e451a0689218cd36e6ac993f87092c04..8c77623ca06139883b12690bdde3c79c + // Inline AABB#intersects to avoid a method call and use the cached AABB fields. + final AABB entityBB = entity.getBoundingBox(); + if (entityBB.maxX <= boxMinX || entityBB.minX >= boxMaxX || entityBB.maxY <= boxMinY || entityBB.minY >= boxMaxY || entityBB.maxZ <= boxMinZ || entityBB.minZ >= boxMaxZ) { ++ // Leaf end - Optimise getEntities continue; } -@@ -585,19 +600,32 @@ public final class ChunkEntitySlices { +@@ -585,19 +602,34 @@ public final class ChunkEntitySlices { final BasicEntityList[] entitiesBySection = this.entitiesBySection; ++ // Leaf start - Optimise getEntities + // Cache AABB fields to local variables to reduce field accesses inside the hot loop. + final double boxMinX = box.minX; + final double boxMinY = box.minY; @@ -78,11 +81,12 @@ index 7f508c50e451a0689218cd36e6ac993f87092c04..8c77623ca06139883b12690bdde3c79c + // Inline AABB#intersects to avoid a method call and use the cached AABB fields. + final AABB entityBB = entity.getBoundingBox(); + if (entityBB.maxX <= boxMinX || entityBB.minX >= boxMaxX || entityBB.maxY <= boxMinY || entityBB.minY >= boxMaxY || entityBB.maxZ <= boxMinZ || entityBB.minZ >= boxMaxZ) { ++ // Leaf end - Optimise getEntities continue; } diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java -index 33dabdec3e62d766583ed2482a688d6001ae7e8f..152c85513b7c4c7df61747cfad977a617a80080e 100644 +index c63c2d1b6bd005eda12c8c1f7cec2a29856fed14..2107514e75b646d9af7471848252924206cbbb9b 100644 --- a/net/minecraft/world/entity/LivingEntity.java +++ b/net/minecraft/world/entity/LivingEntity.java @@ -2276,7 +2276,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin @@ -90,7 +94,7 @@ index 33dabdec3e62d766583ed2482a688d6001ae7e8f..152c85513b7c4c7df61747cfad977a61 @Override public boolean isAlive() { - return !this.isRemoved() && this.getHealth() > 0.0F && !this.dead; // Paper - Check this.dead -+ return !this.dead && !this.isRemoved() && this.getHealth() > 0.0F; // Paper - Check this.dead // Leaf - check the cheapest first ++ return !this.dead && !this.isRemoved() && this.getHealth() > 0.0F; // Paper - Check this.dead // Leaf - Optimise getEntities - check the cheapest first } public boolean isLookingAtMe(LivingEntity entity, double tolerance, boolean scaleByDistance, boolean visual, double... yValues) { diff --git a/leaf-server/minecraft-patches/features/0281-fix-temptation-lookups.patch b/leaf-server/minecraft-patches/features/0281-fix-temptation-lookups.patch index 760b8989..bf1b97b9 100644 --- a/leaf-server/minecraft-patches/features/0281-fix-temptation-lookups.patch +++ b/leaf-server/minecraft-patches/features/0281-fix-temptation-lookups.patch @@ -5,24 +5,10 @@ Subject: [PATCH] fix temptation lookups diff --git a/io/papermc/paper/entity/temptation/GlobalTemptationLookup.java b/io/papermc/paper/entity/temptation/GlobalTemptationLookup.java -index 5f5cdfc538ba9aa6666c019df6706015234d7bae..e7c0fd59b4b64b3e60887ddae63e2f1a4ddd752f 100644 +index 5f5cdfc538ba9aa6666c019df6706015234d7bae..2dfec8f6d0fe833e5f06cf2165ae14bf54cc7b84 100644 --- a/io/papermc/paper/entity/temptation/GlobalTemptationLookup.java +++ b/io/papermc/paper/entity/temptation/GlobalTemptationLookup.java -@@ -1,9 +1,12 @@ - package io.papermc.paper.entity.temptation; - --import java.util.ArrayList; - import java.util.BitSet; - import java.util.List; - import java.util.function.Predicate; -+ -+import it.unimi.dsi.fastutil.objects.ObjectArrays; -+import net.minecraft.server.level.ServerLevel; -+import net.minecraft.server.level.ServerPlayer; - import net.minecraft.tags.ItemTags; - import net.minecraft.world.entity.animal.HappyGhast; - import net.minecraft.world.entity.animal.armadillo.ArmadilloAi; -@@ -24,6 +27,7 @@ public class GlobalTemptationLookup { +@@ -24,6 +24,7 @@ public class GlobalTemptationLookup { public static final TemptationPredicate BEE_FOOD = register(stack -> stack.is(ItemTags.BEE_FOOD)); public static final TemptationPredicate CHICKEN_FOOD = register(stack -> stack.is(ItemTags.CHICKEN_FOOD)); public static final TemptationPredicate COW_FOOD = register(stack -> stack.is(ItemTags.COW_FOOD)); @@ -30,15 +16,15 @@ index 5f5cdfc538ba9aa6666c019df6706015234d7bae..e7c0fd59b4b64b3e60887ddae63e2f1a public static final TemptationPredicate PANDA_FOOD = register(stack -> stack.is(ItemTags.PANDA_FOOD)); public static final TemptationPredicate PIG_CARROT_ON_A_STICK = register(stack -> stack.is(Items.CARROT_ON_A_STICK)); public static final TemptationPredicate PIG = register(stack -> stack.is(ItemTags.PIG_FOOD)); -@@ -61,20 +65,34 @@ public class GlobalTemptationLookup { +@@ -61,20 +62,34 @@ public class GlobalTemptationLookup { return val; } - private final List precalculatedTemptItems = new ArrayList<>(); + private final BitSet[] precalculatedTemptItems; private final BitSet calculatedThisTick = new BitSet(); -+ private static final ServerPlayer[] EMPTY_PLAYERS = {}; -+ private ServerPlayer[] players = EMPTY_PLAYERS; ++ private static final net.minecraft.server.level.ServerPlayer[] EMPTY_PLAYERS = {}; ++ private net.minecraft.server.level.ServerPlayer[] players = EMPTY_PLAYERS; { - for (int i = 0; i < registeredPredicateCounter; i++) { @@ -50,7 +36,7 @@ index 5f5cdfc538ba9aa6666c019df6706015234d7bae..e7c0fd59b4b64b3e60887ddae63e2f1a } - public void reset() { -+ public void tick(final ServerLevel world) { ++ public void tick(final net.minecraft.server.level.ServerLevel world) { for (int i = 0; i < registeredPredicateCounter; i++) { - this.precalculatedTemptItems.get(i).clear(); + this.precalculatedTemptItems[i].clear(); @@ -58,20 +44,20 @@ index 5f5cdfc538ba9aa6666c019df6706015234d7bae..e7c0fd59b4b64b3e60887ddae63e2f1a + } + + int j = 0; -+ final ServerPlayer[] array = world.players().toArray(EMPTY_PLAYERS); ++ final net.minecraft.server.level.ServerPlayer[] array = world.players().toArray(EMPTY_PLAYERS); + for (int i = 0; i < array.length; i++) { -+ final ServerPlayer p = array[i]; ++ final net.minecraft.server.level.ServerPlayer p = array[i]; + if (!p.isSpectator() && p.isAlive()) { + array[j] = p; + j++; + } } - this.calculatedThisTick.clear(); -+ this.players = ObjectArrays.setLength(array, j); ++ this.players = it.unimi.dsi.fastutil.objects.ObjectArrays.setLength(array, j); } public boolean isCalculated(final int index) { -@@ -86,6 +104,10 @@ public class GlobalTemptationLookup { +@@ -86,6 +101,10 @@ public class GlobalTemptationLookup { } public BitSet getBitSet(final int index) { @@ -79,7 +65,7 @@ index 5f5cdfc538ba9aa6666c019df6706015234d7bae..e7c0fd59b4b64b3e60887ddae63e2f1a + return this.precalculatedTemptItems[index]; + } + -+ public ServerPlayer[] players() { ++ public net.minecraft.server.level.ServerPlayer[] players() { + return this.players; } }