mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
[ci skip] cleanup
stage 2
This commit is contained in:
@@ -37,7 +37,7 @@ index dd2509996bfd08e8c3f9f2be042229eac6d7692d..a35e9fae8f8da0c42f0616c4f78dc396
|
||||
private static final byte CHUNK_TICKET_STAGE_NONE = 0;
|
||||
private static final byte CHUNK_TICKET_STAGE_LOADING = 1;
|
||||
diff --git a/net/minecraft/server/level/ChunkMap.java b/net/minecraft/server/level/ChunkMap.java
|
||||
index 5d9d233e3a568aa6297ed9c703fa450f98158602..08873993b3b75db325fe1f2b4ab1de73b3d05be4 100644
|
||||
index 5d9d233e3a568aa6297ed9c703fa450f98158602..4984e57d3b0806164111e79acfc82f6d9b27bfbf 100644
|
||||
--- a/net/minecraft/server/level/ChunkMap.java
|
||||
+++ b/net/minecraft/server/level/ChunkMap.java
|
||||
@@ -248,6 +248,15 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
||||
@@ -88,9 +88,9 @@ index 5d9d233e3a568aa6297ed9c703fa450f98158602..08873993b3b75db325fe1f2b4ab1de73
|
||||
this.lastTrackedChunk = chunk;
|
||||
|
||||
final ServerPlayer[] playersRaw = players.getRawDataUnchecked();
|
||||
+ // Leaf start - Multithreaded tracker
|
||||
+ final int playersLen = players.size(); // Ensure length won't change in the future tasks
|
||||
+
|
||||
+ // Leaf start - Multithreaded tracker
|
||||
+ if (org.dreeam.leaf.config.modules.async.MultithreadedTracker.enabled && org.dreeam.leaf.config.modules.async.MultithreadedTracker.compatModeEnabled) {
|
||||
+ final boolean isServerPlayer = this.entity instanceof ServerPlayer;
|
||||
+ final boolean isRealPlayer = isServerPlayer && ((ca.spottedleaf.moonrise.patches.chunk_system.player.ChunkSystemServerPlayer) this.entity).moonrise$isRealPlayer();
|
||||
|
||||
@@ -12,7 +12,7 @@ In non-strict test, this can give ~60-110% improvement (524ms on Paper, 204ms on
|
||||
under 625 villagers situation.
|
||||
|
||||
diff --git a/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java b/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java
|
||||
index b0c5e41fefc7c9adf1a61bd5b52861736657d37e..a887bb8ed2318d6ee39be350a1d0e7223ecf3ff5 100644
|
||||
index b0c5e41fefc7c9adf1a61bd5b52861736657d37e..d4d75a3f5d03533626417aaa3b0457ab98acea1c 100644
|
||||
--- a/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java
|
||||
+++ b/net/minecraft/world/entity/ai/sensing/NearestLivingEntitySensor.java
|
||||
@@ -13,17 +13,28 @@ import net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities;
|
||||
@@ -21,32 +21,32 @@ index b0c5e41fefc7c9adf1a61bd5b52861736657d37e..a887bb8ed2318d6ee39be350a1d0e722
|
||||
public class NearestLivingEntitySensor<T extends LivingEntity> extends Sensor<T> {
|
||||
+
|
||||
+ // Leaf start - Smart sort entities in NearestLivingEntitySensor
|
||||
+ private final org.dreeam.leaf.util.fastBitRadixSort sorter;
|
||||
+ // Leaf end - Smart sort entities in NearestLivingEntitySensor
|
||||
+ private final org.dreeam.leaf.util.FastBitRadixSort sorter;
|
||||
+
|
||||
+ public NearestLivingEntitySensor() {
|
||||
+ this.sorter = new org.dreeam.leaf.util.fastBitRadixSort();
|
||||
+ this.sorter = new org.dreeam.leaf.util.FastBitRadixSort();
|
||||
+ }
|
||||
+ // Leaf end - Smart sort entities in NearestLivingEntitySensor
|
||||
+
|
||||
@Override
|
||||
protected void doTick(ServerLevel level, T entity) {
|
||||
double attributeValue = entity.getAttributeValue(Attributes.FOLLOW_RANGE);
|
||||
+ double rangeSqr = attributeValue * attributeValue;
|
||||
AABB aabb = entity.getBoundingBox().inflate(attributeValue, attributeValue, attributeValue);
|
||||
- List<LivingEntity> entitiesOfClass = level.getEntitiesOfClass(
|
||||
- LivingEntity.class, aabb, matchableEntity -> matchableEntity != entity && matchableEntity.isAlive()
|
||||
- );
|
||||
- entitiesOfClass.sort(Comparator.comparingDouble(entity::distanceToSqr));
|
||||
+
|
||||
+ // Leaf start - Smart sort entities in NearestLivingEntitySensor
|
||||
+ double rangeSqr = attributeValue * attributeValue;
|
||||
+ List<LivingEntity> entities = level.getEntitiesOfClass(LivingEntity.class, aabb, e -> e != entity && e.isAlive() && entity.distanceToSqr(e) <= rangeSqr);
|
||||
+
|
||||
+ LivingEntity[] sorted = this.sorter.sort(entities, entity, LivingEntity.class);
|
||||
+ List<LivingEntity> sortedList = java.util.Arrays.asList(sorted);
|
||||
+
|
||||
Brain<?> brain = entity.getBrain();
|
||||
- brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, entitiesOfClass);
|
||||
- brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(level, entity, entitiesOfClass));
|
||||
+ brain.setMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES, sortedList);
|
||||
+ brain.setMemory(MemoryModuleType.NEAREST_VISIBLE_LIVING_ENTITIES, new NearestVisibleLivingEntities(level, entity, sortedList));
|
||||
+ // Leaf end - Smart sort entities in NearestLivingEntitySensor
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -158,7 +158,7 @@ index 14878690a88fd4de3e2c127086607e6c819c636c..64a8b50bfac66f75d8c87d9e6e4000dc
|
||||
// Paper start - PlayerChunkLoadEvent
|
||||
if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) {
|
||||
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
index b8ac6a9ba7b56ccd034757f7d135d272b8e69e90..e307e618775acb2052593e16d6ff2a5a9edbac4a 100644
|
||||
index b8ac6a9ba7b56ccd034757f7d135d272b8e69e90..6354a2cbcfe2b940e3c3a80b12b24c7f0f52c202 100644
|
||||
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
@@ -18,7 +18,7 @@ public class LevelChunkSection implements ca.spottedleaf.moonrise.patches.block_
|
||||
@@ -166,7 +166,7 @@ index b8ac6a9ba7b56ccd034757f7d135d272b8e69e90..e307e618775acb2052593e16d6ff2a5a
|
||||
public static final int SECTION_SIZE = 4096;
|
||||
public static final int BIOME_CONTAINER_BITS = 2;
|
||||
- short nonEmptyBlockCount; // Paper - package private
|
||||
+ volatile short nonEmptyBlockCount; // Paper - package private // Leaf - volatile
|
||||
+ volatile short nonEmptyBlockCount; // Paper - package private // Leaf - Async chunk send - volatile
|
||||
private short tickingBlockCount;
|
||||
private short tickingFluidCount;
|
||||
private boolean isRandomlyTickingBlocksStatus; // Leaf - Cache random tick block status
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.minecraft.world.entity.Entity;
|
||||
import java.lang.reflect.Array; // Required for Array.newInstance
|
||||
import java.util.List;
|
||||
|
||||
public class fastBitRadixSort {
|
||||
public class FastBitRadixSort {
|
||||
|
||||
private static final int SMALL_ARRAY_THRESHOLD = 2;
|
||||
private Entity[] entityBuffer = new Entity[0];
|
||||
Reference in New Issue
Block a user