From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: hayanesuru Date: Sat, 9 Aug 2025 15:12:14 +0900 Subject: [PATCH] counting chunk section fluid diff --git a/net/minecraft/world/level/Level.java b/net/minecraft/world/level/Level.java index 94c5ba01caf50416dbc7512e825fcf70b7baac03..e4d83ed875a159150e64e4745a03f61f6a909680 100644 --- a/net/minecraft/world/level/Level.java +++ b/net/minecraft/world/level/Level.java @@ -1433,6 +1433,14 @@ public abstract class Level implements LevelAccessor, UUIDLookup, AutoCl } } + // 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 - 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 a82049aabcdb64f4632c707ee1d48a885da4301a..56eead021e6c9b7b6aaea3e5301db7e6bff58ea1 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 - 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) { + 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 - 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..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 - counting chunk section fluid + public short lavaFluidCount; // Leaf - counting chunk section fluid 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 - counting chunk section fluid + this.lavaFluidCount = section.lavaFluidCount; // Leaf - counting chunk section fluid 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 - counting chunk section fluid + 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 - counting chunk section fluid } 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 - counting chunk section fluid + final int flags = state.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 - counting chunk section fluid } 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 - counting chunk section fluid + this.lavaFluidCount = (short)0; // Leaf - counting chunk section fluid 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 - counting chunk section fluid + 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 - counting chunk section fluid final FluidState fluid = state.getFluidState();