From bdca48734a884020991b56cf7bfe726e572606e0 Mon Sep 17 00:00:00 2001 From: hayanesuru Date: Fri, 22 Aug 2025 18:40:21 +0900 Subject: [PATCH] cleanup --- .../0282-optimize-goal-selector.patch | 6 ++- ...> 0290-counting-chunk-section-fluid.patch} | 40 +++++++++---------- 2 files changed, 24 insertions(+), 22 deletions(-) rename leaf-server/minecraft-patches/features/{0290-optimize-fluid.patch => 0290-counting-chunk-section-fluid.patch} (79%) diff --git a/leaf-server/minecraft-patches/features/0282-optimize-goal-selector.patch b/leaf-server/minecraft-patches/features/0282-optimize-goal-selector.patch index a9f208fe..a2ce63af 100644 --- a/leaf-server/minecraft-patches/features/0282-optimize-goal-selector.patch +++ b/leaf-server/minecraft-patches/features/0282-optimize-goal-selector.patch @@ -22,7 +22,7 @@ index f54bbe2e65b18f214266769c7a64144baafa9a58..40d53e4469a71b33949ee2bd7b01783d } } diff --git a/net/minecraft/world/entity/ai/goal/GoalSelector.java b/net/minecraft/world/entity/ai/goal/GoalSelector.java -index 653c58c7637c46c8b46a5082f671324a2221d431..f8e99ec950373fe5d3c178751bcc6e8dd9d9fb02 100644 +index 653c58c7637c46c8b46a5082f671324a2221d431..5148bed6cc991afc6f0e3de34bc19703295262e3 100644 --- a/net/minecraft/world/entity/ai/goal/GoalSelector.java +++ b/net/minecraft/world/entity/ai/goal/GoalSelector.java @@ -20,10 +20,11 @@ public class GoalSelector { @@ -66,13 +66,14 @@ index 653c58c7637c46c8b46a5082f671324a2221d431..f8e99ec950373fe5d3c178751bcc6e8d if (wrappedGoal.getGoal() == goal && wrappedGoal.isRunning()) { wrappedGoal.stop(); } -@@ -80,37 +91,79 @@ public class GoalSelector { +@@ -80,37 +91,81 @@ public class GoalSelector { } public void tick() { - for (WrappedGoal wrappedGoal : this.availableGoals) { - if (wrappedGoal.isRunning() && (goalContainsAnyFlags(wrappedGoal, this.goalTypes) || !wrappedGoal.canContinueToUse())) { // Paper - Perf: optimize goal types by removing streams - wrappedGoal.stop(); ++ // Leaf start - optimize goal selector + final org.dreeam.leaf.util.map.BinaryGoalSet availableGoals = this.availableGoals; + final WrappedGoal[] elements = availableGoals.elements(); + final long disabled = this.goalTypes.getBackingSet(); @@ -152,6 +153,7 @@ index 653c58c7637c46c8b46a5082f671324a2221d431..f8e99ec950373fe5d3c178751bcc6e8d } + goal.start(); } ++ // Leaf end - optimize goal selector this.tickRunningGoals(true); } diff --git a/leaf-server/minecraft-patches/features/0290-optimize-fluid.patch b/leaf-server/minecraft-patches/features/0290-counting-chunk-section-fluid.patch similarity index 79% rename from leaf-server/minecraft-patches/features/0290-optimize-fluid.patch rename to leaf-server/minecraft-patches/features/0290-counting-chunk-section-fluid.patch index 1df097de..3e4aa27a 100644 --- a/leaf-server/minecraft-patches/features/0290-optimize-fluid.patch +++ b/leaf-server/minecraft-patches/features/0290-counting-chunk-section-fluid.patch @@ -1,37 +1,37 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: hayanesuru Date: Sat, 9 Aug 2025 15:12:14 +0900 -Subject: [PATCH] optimize fluid +Subject: [PATCH] counting chunk section fluid diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java -index 498a9c1590ec3bc4a2b3d5bead899aeb37b56cdf..27a02bbabdb8ddc750a2aeb3901bd6783cbb873a 100644 +index 498a9c1590ec3bc4a2b3d5bead899aeb37b56cdf..2ec44cbd781426b4c8983f47665fe0aac1b4f214 100644 --- a/net/minecraft/world/level/Level.java +++ b/net/minecraft/world/level/Level.java @@ -1432,6 +1432,14 @@ public abstract class Level implements LevelAccessor, UUIDLookup, AutoCl } } -+ // Leaf start ++ // Leaf start - counting chunk section fluid + @Nullable + public final FluidState getFluidStateIfLoadedUnchecked(final int x, final int y, final int z) { + LevelChunk chunkAt = ((ServerLevel) this).chunkSource.fullChunksNonSync.get(ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(x >> 4, z >> 4)); + return chunkAt == null ? null : chunkAt.getFluidStateFinal(x, y, z); + } -+ // Leaf end ++ // Leaf end - counting chunk section fluid + public boolean isBrightOutside() { return !this.dimensionType().hasFixedTime() && this.skyDarken < 4; } diff --git a/net/minecraft/world/level/chunk/LevelChunk.java b/net/minecraft/world/level/chunk/LevelChunk.java -index 6a70665e9b8bc767ba316ada542178634e090afa..0ee94459c1995ddd7e8b469088827b873dab3fe0 100644 +index 6a70665e9b8bc767ba316ada542178634e090afa..37fac4d3d0a84eea314203086c7706be85847d27 100644 --- a/net/minecraft/world/level/chunk/LevelChunk.java +++ b/net/minecraft/world/level/chunk/LevelChunk.java @@ -330,6 +330,21 @@ public class LevelChunk extends ChunkAccess implements ca.spottedleaf.moonrise.p // Leaf end - optimize LevelChunk#getBlockStateFinal } -+ // Leaf start ++ // Leaf start - counting chunk section fluid + public FluidState getFluidStateFinal(final int x, final int y, final int z) { + final int sectionIndex = (y >> 4) - this.minSection; + if (sectionIndex < 0 || sectionIndex >= this.sections.length) { @@ -44,21 +44,21 @@ index 6a70665e9b8bc767ba316ada542178634e090afa..0ee94459c1995ddd7e8b469088827b87 + return section.states.get((y & 15) << 8 | (z & 15) << 4 | x & 15).getFluidState(); + } + } -+ // Leaf end ++ // Leaf end - counting chunk section fluid + @Override public BlockState getBlockState(BlockPos pos) { if (true) { diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java -index df717c545472006b99532280c38c1fbef12bcf82..938b664a7a8189188c4ae3991b50a966cb715718 100644 +index df717c545472006b99532280c38c1fbef12bcf82..72f80b7dfa640daf4ae3ba4339945f1400004c45 100644 --- a/net/minecraft/world/level/chunk/LevelChunkSection.java +++ b/net/minecraft/world/level/chunk/LevelChunkSection.java @@ -21,6 +21,8 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_ short nonEmptyBlockCount; // Paper - package private private short tickingBlockCount; private short tickingFluidCount; -+ public short waterFluidCount; // Leaf -+ public short lavaFluidCount; // Leaf ++ public short waterFluidCount; // Leaf - counting chunk section fluid ++ public short lavaFluidCount; // Leaf - counting chunk section fluid public final PalettedContainer states; private PalettedContainer> biomes; // CraftBukkit - read/write @@ -66,8 +66,8 @@ index df717c545472006b99532280c38c1fbef12bcf82..938b664a7a8189188c4ae3991b50a966 this.nonEmptyBlockCount = section.nonEmptyBlockCount; this.tickingBlockCount = section.tickingBlockCount; this.tickingFluidCount = section.tickingFluidCount; -+ this.waterFluidCount = section.waterFluidCount; // Leaf -+ this.lavaFluidCount = section.lavaFluidCount; // Leaf ++ this.waterFluidCount = section.waterFluidCount; // Leaf - counting chunk section fluid ++ this.lavaFluidCount = section.lavaFluidCount; // Leaf - counting chunk section fluid this.states = section.states.copy(); this.biomes = section.biomes.copy(); } @@ -75,7 +75,7 @@ index df717c545472006b99532280c38c1fbef12bcf82..938b664a7a8189188c4ae3991b50a966 if (blockState.isRandomlyTicking()) { this.tickingBlockCount--; } -+ // Leaf start ++ // Leaf start - counting chunk section fluid + final int flags = blockState.tagFlag; + if ((flags & org.dreeam.leaf.util.BlockMasks.WATER) != 0) { + this.waterFluidCount--; @@ -83,7 +83,7 @@ index df717c545472006b99532280c38c1fbef12bcf82..938b664a7a8189188c4ae3991b50a966 + if ((flags & org.dreeam.leaf.util.BlockMasks.LAVA) != 0) { + this.lavaFluidCount--; + } -+ // Leaf end ++ // Leaf end - counting chunk section fluid } if (!!fluidState.isRandomlyTicking()) { // Paper - block counting @@ -91,7 +91,7 @@ index df717c545472006b99532280c38c1fbef12bcf82..938b664a7a8189188c4ae3991b50a966 if (state.isRandomlyTicking()) { this.tickingBlockCount++; } -+ // Leaf start ++ // Leaf start - counting chunk section fluid + final int flags = state.tagFlag; + if ((flags & org.dreeam.leaf.util.BlockMasks.WATER) != 0) { + this.waterFluidCount++; @@ -99,7 +99,7 @@ index df717c545472006b99532280c38c1fbef12bcf82..938b664a7a8189188c4ae3991b50a966 + if ((flags & org.dreeam.leaf.util.BlockMasks.LAVA) != 0) { + this.lavaFluidCount++; + } -+ // Leaf end ++ // Leaf end - counting chunk section fluid } if (!!fluidState1.isRandomlyTicking()) { // Paper - block counting @@ -107,8 +107,8 @@ index df717c545472006b99532280c38c1fbef12bcf82..938b664a7a8189188c4ae3991b50a966 this.nonEmptyBlockCount = (short)0; this.tickingBlockCount = (short)0; this.tickingFluidCount = (short)0; -+ this.waterFluidCount = (short)0; // Leaf -+ this.lavaFluidCount = (short)0; // Leaf ++ this.waterFluidCount = (short)0; // Leaf - counting chunk section fluid ++ this.lavaFluidCount = (short)0; // Leaf - counting chunk section fluid this.specialCollidingBlocks = (short)0; this.tickingBlocks.clear(); @@ -116,7 +116,7 @@ index df717c545472006b99532280c38c1fbef12bcf82..938b664a7a8189188c4ae3991b50a966 tickingBlocks.add(raw[i]); } } -+ // Leaf start ++ // Leaf start - counting chunk section fluid + final int flags = state.tagFlag; + if ((flags & org.dreeam.leaf.util.BlockMasks.WATER) != 0) { + this.waterFluidCount += (short)paletteCount; @@ -124,7 +124,7 @@ index df717c545472006b99532280c38c1fbef12bcf82..938b664a7a8189188c4ae3991b50a966 + if ((flags & org.dreeam.leaf.util.BlockMasks.LAVA) != 0) { + this.lavaFluidCount += (short)paletteCount; + } -+ // Leaf end ++ // Leaf end - counting chunk section fluid final FluidState fluid = state.getFluidState();