9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-31 04:46:38 +00:00
Files
Leaf/leaf-server/minecraft-patches/features/0283-counting-chunk-section-fluid.patch
Dreeam d36ed6c316 Remove OP lock (#486)
Current implementation of OP lock is not an appropriate solution to prevent plugins that contain backdoor or malicious code. There are many ways to bypass this check to manipulate the OP list or permissions. The best way to prevent this kind of grief is to get plugins from valid and trustworthy places.
2025-08-31 23:53:19 -04:00

131 lines
6.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: hayanesuru <hayanesuru@outlook.jp>
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 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<Entity>, 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 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 - 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<BlockState> states;
private PalettedContainer<Holder<Biome>> 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();