Skip to content

entity activation: use kd-tree for players and dedup entities#528

Open
hayanesuru wants to merge 3 commits into
Winds-Studio:ver/1.21.11from
hayanesuru:4-entity-activation
Open

entity activation: use kd-tree for players and dedup entities#528
hayanesuru wants to merge 3 commits into
Winds-Studio:ver/1.21.11from
hayanesuru:4-entity-activation

Conversation

@hayanesuru
Copy link
Copy Markdown
Collaborator

No description provided.

@hayanesuru hayanesuru changed the title Optimize entity activation optimize entity activation Oct 10, 2025
@hayanesuru hayanesuru changed the title optimize entity activation dedup and use kd-tree in entity activation Jan 10, 2026
@hayanesuru hayanesuru changed the base branch from ver/1.21.8 to ver/1.21.11 February 1, 2026 14:06
@hayanesuru hayanesuru changed the title dedup and use kd-tree in entity activation entity activation: use kd-tree for players and dedup entities Feb 1, 2026
@hayanesuru hayanesuru added type: feature Pull request for adding new features status: docs update required Config changed, needs the PR author or team member to update docs labels Feb 1, 2026
@Dreeam-qwq Dreeam-qwq added type: optimization Pull request for optimization and removed type: feature Pull request for adding new features labels Mar 25, 2026
@hayanesuru hayanesuru force-pushed the 4-entity-activation branch 3 times, most recently from 99c8a9c to 7e32352 Compare March 30, 2026 02:29
@hayanesuru hayanesuru added the type: fix Pull request for fixing bug label Mar 30, 2026
@hayanesuru hayanesuru force-pushed the 4-entity-activation branch from 7e32352 to 5f16578 Compare April 9, 2026 14:06
Copy link
Copy Markdown
Member

@Dreeam-qwq Dreeam-qwq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we added a more efficient activation range impl here, do we still need to optimize the original activation range impl?

And I think we don't need to build K-D Tree 3D if the dab is disabled.

}

- return (int) Math.min(Integer.MAX_VALUE, Math.max(1, Math.round(wakeUpDuration * wakeUpDurationRandom.nextGaussian(1, deviation))));
+ return (int) Math.min(Integer.MAX_VALUE, Math.max(1, Math.round(wakeUpDuration * (1.0 + deviation * entity.random.nextGaussian())))); // Leaf - optimize entity activation
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move this change to the original patch Variable-entity-wake-up-duration.patch, since there is an existing patch in Leaf, no need to use another patch to make this kind of changes.

Comment thread leaf-server/minecraft-patches/features/0324-optimize-entity-activation.patch Outdated
: dx * dx + dy * dy;
}

public boolean isEmpty() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's a method that may be used in the future, you can add a comment to note that.

Comment thread leaf-server/minecraft-patches/features/0324-optimize-entity-activation.patch Outdated
+ (dontEnableIfInWater || entity.getType().is(net.minecraft.tags.EntityTypeTags.CAN_BREATHE_UNDER_WATER) || !entity.isInWater())) { // Leaf - Option for dontEnableIfInWater
+ int distSq = (int) player.distanceToSqr(entity);
+ a = distSq > startSq ?
+ Math.min(maxPriority, Math.max((int) (distSq * scale), 1)) :
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you changed original impl from "int + shift" to "double + scale"?

- entity.activatedPriority = 1;
+ a = 1;
}
+ entity.activatedPriority = reset.add(entity.getId()) ? a : Math.min(a, entity.activatedPriority);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmmm, I think using IntOpenHashSet here is slower than using a boolean to handle the reset in the original impl?

@hayanesuru hayanesuru removed the type: fix Pull request for fixing bug label May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: docs update required Config changed, needs the PR author or team member to update docs type: optimization Pull request for optimization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants