Skip to content

Add Allies and additional rule API#13853

Open
Doc94 wants to merge 2 commits intoPaperMC:mainfrom
Doc94:feature/alliance
Open

Add Allies and additional rule API#13853
Doc94 wants to merge 2 commits intoPaperMC:mainfrom
Doc94:feature/alliance

Conversation

@Doc94
Copy link
Copy Markdown
Member

@Doc94 Doc94 commented May 2, 2026

Currently exists a "isAllies" method in NMS used for things like target/considerations in Entities, one rule of that is if two entities share a team then are allies, this API allow pass additional rules by Key, this its a good alternative for listen every time the Target Event or track Memory for entities who not use that event.

This allow things like.

player.getWorld().spawn(player.getLocation(), Warden.class, entity -> {
                        entity.addAdditionalAlliedRule(Key.key(TestPlugin.this, "rule_1"),target -> {
                            return target instanceof Player playerTarget && playerTarget.getInventory().getItemInMainHand().getType().name().contains("SWORD");
                        });
                        entity.addAdditionalAlliedRule(Key.key(TestPlugin.this, "rule_2"),target -> {
                            return target instanceof Player playerTarget && playerTarget.getInventory().getItemInMainHand().getType().name().contains("PICKAXE");
                        });
                    });

for

2026-05-02_11-00-58.mp4

@Doc94 Doc94 requested a review from a team as a code owner May 2, 2026 15:03
@github-project-automation github-project-automation Bot moved this to Awaiting review in Paper PR Queue May 2, 2026
@Doc94 Doc94 force-pushed the feature/alliance branch from 94ced07 to 5af1e7c Compare May 2, 2026 18:47
@yannicklamprecht
Copy link
Copy Markdown
Contributor

I would personally like to have the following.

player.getWorld().spawn(player.getLocation(), Warden.class, entity -> {
                        entity.addAdditionalAlliedRule(Key.of(plugin, "ignore_sword"), target -> {
                            return target instanceof Player playerTarget && playerTarget.getInventory().getItemInMainHand().getType().name().contains("SWORD");
                        });
                    });

So that you can remove the additional rule at any time using.

entity.removeAdditionalAlliedRule(Key.of(plugin, "ignore_sword"));

Advantages: Multiple plugins can declare and handle allies.
Dissadvantages: The whole logic would be O(n) instead of O(1)

@Doc94
Copy link
Copy Markdown
Member Author

Doc94 commented May 3, 2026

@yannicklamprecht sounds good, i make a change for allow that now... still require the user listen for remove/add entity for add the rule again when the entity was loaded (like when change dimension) but i feel its ok.

@Doc94 Doc94 force-pushed the feature/alliance branch from 3bb5e83 to 38bb337 Compare May 3, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Awaiting review

Development

Successfully merging this pull request may close these issues.

2 participants