fix: citizen AI and combat improvements#11641
fix: citizen AI and combat improvements#11641ZeOs360 wants to merge 2 commits intoldtteam:version/mainfrom
Conversation
ThreatTable - dead entities were remaining in the list without an isAlive() check, causing memory leaks and index shifting during combat. removeIf and reference-based index recovery have been added to addThreat(). getCapability - LazyOptional.of() was being called on every invocation. It has been cached as a field and is now invalidated in setRemoved(). callForHelp - this.blockPosition() was being called on every comparison in the sort comparator. It is now pre-fetched as selfPos. checkIfValidDamageSource - Although addPlayer() is server-side, it was also running on the client side. !level.isClientSide has been added. BasicStateMachine - DateTimeFormatter was being created separately for each instance. It has been made static final.
In order for this pull request to be merged, make sure you test whether your changes work.If the changes are working as intended, remove the https://github.com/ldtteam/minecolonies/labels/undefined label from the pull request. Contributors, please review this pull request! |
|
Did you use AI to aid you in this PR? |
| final ThreatTableEntry currentTarget = (currentTargetIndex >= 0 && currentTargetIndex < threatList.size()) | ||
| ? threatList.get(currentTargetIndex) : null; | ||
| threatList.removeIf(entry -> !entry.getEntity().isAlive()); | ||
| currentTargetIndex = currentTarget != null ? Math.max(0, threatList.indexOf(currentTarget)) : 0; |
There was a problem hiding this comment.
it is intentionally not checking the full list on threat being added as threat added occurs very frequently, instead sanity checks like is alive are done when retrieving a new target.
There was a problem hiding this comment.
thanks for the context I'll revert the changes.
I used AI for analysis. The ThreatTable change was a mistake I didn't verify it against the existing design intent. |
getCapability - LazyOptional.of() was being called on every invocation. It has been cached as a field and is now invalidated in setRemoved().
callForHelp - this.blockPosition() was being called on every comparison in the sort comparator. It is now pre-fetched as selfPos.
checkIfValidDamageSource - Although addPlayer() is server-side, it was also running on the client side. !level.isClientSide has been added.
BasicStateMachine - DateTimeFormatter was being created separately for each instance. It has been made static final.
Closes #
Closes #
Changes proposed in this pull request
Review please