Skip to content

Commit f2682d8

Browse files
authored
optimize attribute and cleanup entity tracker (#548)
* optimize attribute * compile fix * redo async tracker * rename id * refactor * fix comment * reduce call * fix entity removal * rename * fix * fix ctx * unnecessary * rebuild patches * fix immediately remove closes: #555 * wrap
1 parent 1144cbc commit f2682d8

File tree

42 files changed

+1018
-855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1018
-855
lines changed

build-data/leaf.at

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
protected net.minecraft.world.entity.Entity dimensions
44
protected-f net.minecraft.world.level.block.state.BlockBehaviour$BlockStateBase$Cache largeCollisionShape
55
public net.minecraft.core.Direction VALUES
6+
public net.minecraft.network.protocol.game.ClientboundUpdateAttributesPacket <init>(ILjava/util/List;)V
67
public net.minecraft.server.level.ServerChunkCache fullChunks
7-
public net.minecraft.server.level.ServerEntity sendDirtyEntityData()V
88
public net.minecraft.server.players.PlayerList SEND_PLAYER_INFO_INTERVAL
99
public net.minecraft.util.Mth SIN
1010
public net.minecraft.world.entity.Entity blockPosition
1111
public net.minecraft.world.entity.Entity markHurt()V
1212
public net.minecraft.world.entity.Entity position
1313
public net.minecraft.world.entity.Entity updateInWaterStateAndDoWaterCurrentPushing()V
1414
public net.minecraft.world.entity.LivingEntity canGlide()Z
15+
public net.minecraft.world.entity.ai.attributes.AttributeMap attributes
1516
public net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities lineOfSightTest
1617
public net.minecraft.world.entity.ai.memory.NearestVisibleLivingEntities nearbyEntities
1718
public net.minecraft.world.entity.decoration.ArmorStand noTickEquipmentDirty

leaf-server/minecraft-patches/features/0050-Replace-AI-attributes-with-optimized-collections.patch

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ As part of: Lithium (https://github.com/CaffeineMC/lithium)
1313
Licensed under: LGPL-3.0 (https://www.gnu.org/licenses/lgpl-3.0.html)
1414

1515
diff --git a/net/minecraft/world/entity/ai/attributes/AttributeMap.java b/net/minecraft/world/entity/ai/attributes/AttributeMap.java
16-
index 7dd8c1c8e27410854ce1ee90defc607c2710b5a2..0ac398b8b10aae5e67a797b2991c66874003f282 100644
16+
index be0fceea10755bb1a0a0cea4749f45e122bfa771..a65ba1712d55d23abdbb192f13ffb972be308e84 100644
1717
--- a/net/minecraft/world/entity/ai/attributes/AttributeMap.java
1818
+++ b/net/minecraft/world/entity/ai/attributes/AttributeMap.java
1919
@@ -14,9 +14,11 @@ import net.minecraft.core.Holder;
2020
import net.minecraft.resources.ResourceLocation;
2121

2222
public class AttributeMap {
23-
- private final Map<Holder<Attribute>, AttributeInstance> attributes = new Object2ObjectOpenHashMap<>();
23+
- public final Map<Holder<Attribute>, AttributeInstance> attributes = new Object2ObjectOpenHashMap<>();
2424
- private final Set<AttributeInstance> attributesToSync = new ObjectOpenHashSet<>();
2525
- private final Set<AttributeInstance> attributesToUpdate = new ObjectOpenHashSet<>();
2626
+ // Gale start - Lithium - replace AI attributes with optimized collections
27-
+ private final Map<Holder<Attribute>, AttributeInstance> attributes = new it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap<>(0);
27+
+ public final Map<Holder<Attribute>, AttributeInstance> attributes = new it.unimi.dsi.fastutil.objects.Reference2ReferenceOpenHashMap<>(0);
2828
+ private final Set<AttributeInstance> attributesToSync = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(0);
2929
+ private final Set<AttributeInstance> attributesToUpdate = new it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet<>(0);
3030
+ // Gale end - Lithium - replace AI attributes with optimized collections

leaf-server/minecraft-patches/features/0169-Dont-send-useless-entity-packets.patch

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,33 @@ Original license: MIT
99
Original project: https://github.com/PurpurMC/Purpur
1010

1111
diff --git a/net/minecraft/server/level/ServerEntity.java b/net/minecraft/server/level/ServerEntity.java
12-
index d605c4da4475fdc47a6d0c90fbca2713fc9d8fef..0dee18df07c979da6125a4e7a955343e44d67ac2 100644
12+
index db16e1e66807a3dbbff8200d93734c9b38140e6f..61a9d3012eb7a8bfdd3867606cd1b144f6170de2 100644
1313
--- a/net/minecraft/server/level/ServerEntity.java
1414
+++ b/net/minecraft/server/level/ServerEntity.java
15-
@@ -225,6 +225,8 @@ public class ServerEntity {
15+
@@ -195,11 +195,12 @@ public class ServerEntity {
16+
long l1 = this.positionCodec.encodeY(vec3);
17+
long l2 = this.positionCodec.encodeZ(vec3);
18+
boolean flag5 = l < -32768L || l > 32767L || l1 < -32768L || l1 > 32767L || l2 < -32768L || l2 > 32767L;
19+
+ boolean onGroundChanged = this.wasOnGround != this.entity.onGround(); // Purpur - Dont send useless entity packets
20+
if (this.forceStateResync || this.entity.getRequiresPrecisePosition() // Paper - fix desync when a player is added to the tracker
21+
|| flag5
22+
|| this.teleportDelay > 400
23+
|| this.wasRiding
24+
- || this.wasOnGround != this.entity.onGround()) {
25+
+ || onGroundChanged) { // Purpur - Dont send useless entity packets
26+
this.wasOnGround = this.entity.onGround();
27+
this.teleportDelay = 0;
28+
packet = ClientboundEntityPositionSyncPacket.of(this.entity);
29+
@@ -225,6 +226,8 @@ public class ServerEntity {
1630
}
1731
// Gale end - Airplane - better checking for useless move packets
1832

19-
+ if (org.dreeam.leaf.config.modules.opt.ReduceUselessPackets.reduceUselessEntityMovePackets && isUselessMoveEntityPacket(packet)) packet = null; // Purpur - Dont send useless entity packets
33+
+ if (org.dreeam.leaf.config.modules.opt.ReduceUselessPackets.reduceUselessEntityMovePackets && !onGroundChanged && isUselessMoveEntityPacket(packet)) packet = null; // Purpur - Dont send useless entity packets
2034
+
2135
if (this.entity.hasImpulse || this.trackDelta || this.entity instanceof LivingEntity && ((LivingEntity)this.entity).isFallFlying()) {
2236
Vec3 deltaMovement = this.entity.getDeltaMovement();
2337
if (deltaMovement != this.lastSentMovement) { // SparklyPaper start - skip distanceToSqr call in ServerEntity#sendChanges if the delta movement hasn't changed
24-
@@ -308,6 +310,21 @@ public class ServerEntity {
38+
@@ -308,6 +311,21 @@ public class ServerEntity {
2539
);
2640
}
2741

0 commit comments

Comments
 (0)