From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: hayanesuru Date: Sat, 9 Aug 2025 15:12:14 +0900 Subject: [PATCH] optimize fluid diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java index 498a9c1590ec3bc4a2b3d5bead899aeb37b56cdf..27a02bbabdb8ddc750a2aeb3901bd6783cbb873a 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 + @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 + 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 --- 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 + 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) { + return AIR_FLUIDSTATE; + } else { + LevelChunkSection section = this.sections[sectionIndex]; + if (section.waterFluidCount == 0 && section.lavaFluidCount == 0) { + return AIR_FLUIDSTATE; + } + return section.states.get((y & 15) << 8 | (z & 15) << 4 | x & 15).getFluidState(); + } + } + // Leaf end + @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..df94db4a21ecb9353b3fbadd19caecd0fb74ae8d 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 final PalettedContainer states; private PalettedContainer> biomes; // CraftBukkit - read/write @@ -52,6 +54,8 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_ this.nonEmptyBlockCount = section.nonEmptyBlockCount; this.tickingBlockCount = section.tickingBlockCount; this.tickingFluidCount = section.tickingFluidCount; + this.waterFluidCount = section.waterFluidCount; // Leaf + this.lavaFluidCount = section.lavaFluidCount; // Leaf this.states = section.states.copy(); this.biomes = section.biomes.copy(); } @@ -147,6 +151,15 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_ if (blockState.isRandomlyTicking()) { this.tickingBlockCount--; } + // Leaf start + final int flags = blockState.tagFlag; + if ((flags & org.dreeam.leaf.util.BlockMasks.WATER) != 0) { + this.waterFluidCount--; + } + if ((flags & org.dreeam.leaf.util.BlockMasks.LAVA) != 0) { + this.lavaFluidCount--; + } + // Leaf end } if (!!fluidState.isRandomlyTicking()) { // Paper - block counting @@ -158,6 +171,15 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_ if (state.isRandomlyTicking()) { this.tickingBlockCount++; } + // Leaf start + final int flags = blockState.tagFlag; + if ((flags & org.dreeam.leaf.util.BlockMasks.WATER) != 0) { + this.waterFluidCount++; + } + if ((flags & org.dreeam.leaf.util.BlockMasks.LAVA) != 0) { + this.lavaFluidCount++; + } + // Leaf end } if (!!fluidState1.isRandomlyTicking()) { // Paper - block counting @@ -191,6 +213,8 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_ this.nonEmptyBlockCount = (short)0; this.tickingBlockCount = (short)0; this.tickingFluidCount = (short)0; + this.waterFluidCount = (short)0; // Leaf + this.lavaFluidCount = (short)0; // Leaf this.specialCollidingBlocks = (short)0; this.tickingBlocks.clear(); @@ -238,6 +262,15 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_ tickingBlocks.add(raw[i]); } } + // Leaf start + final int flags = state.tagFlag; + if ((flags & org.dreeam.leaf.util.BlockMasks.WATER) != 0) { + this.waterFluidCount += (short)paletteCount; + } + if ((flags & org.dreeam.leaf.util.BlockMasks.LAVA) != 0) { + this.lavaFluidCount += (short)paletteCount; + } + // Leaf end final FluidState fluid = state.getFluidState();