mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-26 10:29:13 +00:00
Originally vanilla logic is to use stream, and Mojang switched it to Guava's Collections2 since 1.21.4. It is much faster than using stream or manually adding to a new ArrayList. Manually adding to a new ArrayList requires allocating a new object array. However, the Collections2 lazy handles filter condition on iteration, so much better.
60 lines
3.2 KiB
Diff
60 lines
3.2 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Sat, 23 Nov 2024 09:04:46 -0500
|
|
Subject: [PATCH] Cache random tick block status
|
|
|
|
|
|
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
index df717c545472006b99532280c38c1fbef12bcf82..36c033b0ee63dfc273d721fb4b614733e8fdef19 100644
|
|
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
@@ -21,6 +21,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
short nonEmptyBlockCount; // Paper - package private
|
|
private short tickingBlockCount;
|
|
private short tickingFluidCount;
|
|
+ private boolean isRandomlyTickingBlocksStatus; // Leaf - Cache random tick block status
|
|
public final PalettedContainer<BlockState> states;
|
|
private PalettedContainer<Holder<Biome>> biomes; // CraftBukkit - read/write
|
|
|
|
@@ -54,6 +55,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
this.tickingFluidCount = section.tickingFluidCount;
|
|
this.states = section.states.copy();
|
|
this.biomes = section.biomes.copy();
|
|
+ this.isRandomlyTickingBlocksStatus = this.tickingBlockCount > 0; // Leaf - Cache random tick block status
|
|
}
|
|
|
|
public LevelChunkSection(PalettedContainer<BlockState> states, PalettedContainer<Holder<Biome>> biomes) { // CraftBukkit - read/write
|
|
@@ -165,6 +167,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
}
|
|
|
|
this.updateBlockCallback(x, y, z, state, blockState); // Paper - block counting
|
|
+ this.isRandomlyTickingBlocksStatus = this.tickingBlockCount > 0; // Leaf - Cache random tick block status
|
|
|
|
return blockState;
|
|
}
|
|
@@ -178,7 +181,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
}
|
|
|
|
public boolean isRandomlyTickingBlocks() {
|
|
- return this.tickingBlockCount > 0;
|
|
+ return isRandomlyTickingBlocksStatus; // Leaf - Cache random tick block status
|
|
}
|
|
|
|
public boolean isRandomlyTickingFluids() {
|
|
@@ -193,6 +196,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
this.tickingFluidCount = (short)0;
|
|
this.specialCollidingBlocks = (short)0;
|
|
this.tickingBlocks.clear();
|
|
+ this.isRandomlyTickingBlocksStatus = false; // Leaf - Cache random tick block status
|
|
|
|
if (this.maybeHas((final BlockState state) -> !state.isAir())) {
|
|
final PalettedContainer.Data<BlockState> data = this.states.data;
|
|
@@ -226,6 +230,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
|
this.nonEmptyBlockCount += (short)paletteCount;
|
|
if (state.isRandomlyTicking()) {
|
|
this.tickingBlockCount += (short)paletteCount;
|
|
+ this.isRandomlyTickingBlocksStatus = this.tickingBlockCount > 0; // Leaf - Cache random tick block status
|
|
final short[] raw = coordinates.elements();
|
|
final int rawLen = raw.length;
|
|
|