mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-29 20:09:17 +00:00
60 lines
3.4 KiB
Diff
60 lines
3.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Thu, 23 May 2024 21:28:02 +0800
|
|
Subject: [PATCH] Tracking Optimize: Reduce expensive iteration
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
index c564136c9304b0cf9aef22dba2fc3a53a1d7f30b..65b9af55c1137caee60159808f759d3d5c6fd2de 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
@@ -1157,6 +1157,9 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
return;
|
|
}
|
|
// Leaf end - petal
|
|
+
|
|
+ if (net.minecraft.server.MinecraftServer.getServer().getPlayerList().players.isEmpty()) return; // Leaf - Don't update since the server is empty
|
|
+
|
|
for (TrackedEntity tracker : this.entityMap.values()) {
|
|
// update tracker entry
|
|
tracker.updatePlayers(tracker.entity.getPlayersInTrackRange());
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
index f45cf9c7c2d67fafee6bb5409ffc975dc0d3b133..07fb29f9bb5a3a4c1dd7d9e9cd9dbbdb62f07d5d 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
|
|
@@ -439,7 +439,7 @@ public class ServerEntity {
|
|
// Leaf end - petal
|
|
}
|
|
|
|
- set.clear();
|
|
+ ((LivingEntity) this.entity).getAttributes().clearDirtyAttributes(); // Leaf
|
|
}
|
|
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
|
|
index 97a9fa03011dd8f524319924d07cd98d93c88f64..3aaeac724b4ddef3a00cbd61dba3fddcbd008664 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/ai/attributes/AttributeMap.java
|
|
@@ -24,7 +24,7 @@ public class AttributeMap {
|
|
// Leaf start - Use thread-safe collection
|
|
// Gale start - Lithium - replace AI attributes with optimized collections
|
|
private final Map<Attribute, AttributeInstance> attributes = com.google.common.collect.Maps.newConcurrentMap();
|
|
- private final Set<AttributeInstance> dirtyAttributes = com.google.common.collect.Sets.newConcurrentHashSet();
|
|
+ private Set<AttributeInstance> dirtyAttributes = com.google.common.collect.Sets.newConcurrentHashSet(); // Leaf - no final
|
|
// Gale end - Lithium - replace AI attributes with optimized collections
|
|
// Leaf end - Use thread-safe collection
|
|
private final AttributeSupplier supplier;
|
|
@@ -53,6 +53,12 @@ public class AttributeMap {
|
|
return this.dirtyAttributes;
|
|
}
|
|
|
|
+ // Leaf start - Reduce expensive clear() iteration
|
|
+ public void clearDirtyAttributes() {
|
|
+ this.dirtyAttributes = com.google.common.collect.Sets.newConcurrentHashSet();
|
|
+ }
|
|
+ // Leaf end - Reduce expensive clear() iteration
|
|
+
|
|
public Collection<AttributeInstance> getSyncableAttributes() {
|
|
return this.attributes.values().stream().filter(attribute -> attribute.getAttribute().isClientSyncable() && (entity == null || entity.shouldSendAttribute(attribute.getAttribute()))).collect(Collectors.toList()); // Purpur
|
|
}
|