Skip to content

Add SpawnerPlayerSearchEvent#9614

Closed
TreemanKing wants to merge 1 commit into
PaperMC:masterfrom
TreemanKing:PreSpawnerSearchEvent-
Closed

Add SpawnerPlayerSearchEvent#9614
TreemanKing wants to merge 1 commit into
PaperMC:masterfrom
TreemanKing:PreSpawnerSearchEvent-

Conversation

@TreemanKing
Copy link
Copy Markdown
Contributor

Hopefully second try is the charm. With the feedback of lynxplay from my previous pull, I created a new Event which would act before the Spawner searches for nearby spawners.

This would:
a) allow to remove specific players from specific spawners in regards to their activation
b) allow spawners to skip player searching for n ticks (as specified by the backoff cooldown)
c) completely exclude players from affecting spawning on spawners.

I was also going to add NotNulls to the event but I wasn't sure so your feedback would be highly appreciated!

@TreemanKing TreemanKing requested a review from a team as a code owner August 16, 2023 02:08
Copy link
Copy Markdown
Member

@Warriorrrr Warriorrrr left a comment

Choose a reason for hiding this comment

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

PR looks good aside from a few small comments.

Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1006-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1006-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1005-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1005-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1005-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1006-PreSpawnerSearchEvent.patch Outdated
@Lulu13022002
Copy link
Copy Markdown
Contributor

I forgot to say that in the review, but you need the notnull/nullable annotations in the API otherwise the test will fail

Comment thread patches/server/1005-PreSpawnerSearchEvent.patch Outdated
@TreemanKing
Copy link
Copy Markdown
Contributor Author

TreemanKing commented Aug 24, 2023

I believe all of the above should be resolved. If someone could please check this, that would be great!

Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1005-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1005-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1005-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0426-PreSpawnerSearchEvent.patch Outdated
Copy link
Copy Markdown
Contributor

@lynxplay lynxplay left a comment

Choose a reason for hiding this comment

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

Generally really nice work 👍 a few annotations left but beyond that good and ready for testing/review.

Comment thread patches/api/0439-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0439-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0439-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1027-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1027-PreSpawnerSearchEvent.patch Outdated
@TreemanKing TreemanKing requested a review from lynxplay August 28, 2023 15:28
@TreemanKing TreemanKing force-pushed the PreSpawnerSearchEvent- branch from 4866c6f to e1bbe47 Compare August 28, 2023 16:41
Comment thread patches/api/0440-PreSpawnerSearchEvent.patch Outdated
@TreemanKing TreemanKing requested a review from lynxplay September 1, 2023 15:55
@TreemanKing TreemanKing force-pushed the PreSpawnerSearchEvent- branch from 3f77a5c to a90e989 Compare September 1, 2023 16:14
Copy link
Copy Markdown
Contributor

@lynxplay lynxplay left a comment

Choose a reason for hiding this comment

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

Looks good to me, I'll test the PR later today when I make it back home.
The comments can be resolved by the merger or you in time, but should not prevent the PR from being merged 👍

Comment thread patches/api/0440-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0440-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0440-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0440-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/api/0440-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1030-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1030-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1030-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1030-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1030-PreSpawnerSearchEvent.patch Outdated
Comment thread patches/server/1030-PreSpawnerSearchEvent.patch Outdated
Copy link
Copy Markdown
Contributor

@lynxplay lynxplay left a comment

Choose a reason for hiding this comment

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

After testing, seems to work well.
However, I am a bit bleh about the naming of the event after thinking about it.
It isn't really pre-search, the "heavy" searching logic is still executed.
The backoff ticks can prevent that, but the event is not really pre- anything.

@TreemanKing
Copy link
Copy Markdown
Contributor Author

TreemanKing commented Sep 6, 2023

After testing, seems to work well.
However, I am a bit bleh about the naming of the event after thinking about it.
It isn't really pre-search, the "heavy" searching logic is still executed.
The backoff ticks can prevent that, but the event is not really pre- anything.

Yep, more I coded, the more I thought maybe it should just be called "SpawnerSearchEvent".
Edit: Updated all instances to "SpawnerSearchEvent"

@TreemanKing TreemanKing changed the title PreSpawnerSearchEvent Add SpawnerSearchEvent Sep 6, 2023
Comment thread patches/api/0440-SpawnerSearchEvent.patch Outdated
Comment thread patches/api/0440-SpawnerSearchEvent.patch
Comment thread patches/api/0440-SpawnerSearchEvent.patch Outdated
@TreemanKing
Copy link
Copy Markdown
Contributor Author

Should I move the event to Block instead of Entity as well?

@Lulu13022002
Copy link
Copy Markdown
Contributor

It's a little bit tricky since the base spawner is used by the spawner block but also by the minecart spawner, i don't mind that whatever you chose but i think people are more used to see a spawner block

@Leguan16
Copy link
Copy Markdown
Contributor

Leguan16 commented Sep 7, 2023

What is the general opinion on this one:
https://discord.com/channels/289587909051416579/555469074080202765/1148993218885718076
(adding Cancelable which defaults to DENY)

@TreemanKing TreemanKing force-pushed the PreSpawnerSearchEvent- branch from 9db392a to 68c2c80 Compare September 7, 2023 11:11
@lynxplay
Copy link
Copy Markdown
Contributor

lynxplay commented Sep 7, 2023

Again, i don't know if we have a precedent for this.
Issue isn't really setCancelled(true), issue is setCancelled(false).

Does it use DEFAULT or ALLOW ?
Its a bit meh

@TreemanKing
Copy link
Copy Markdown
Contributor Author

Anything else I need to do or is this just awaiting reviews?

@lynxplay
Copy link
Copy Markdown
Contributor

At least from my end, I just need to find time to give this a final review and testing 👍

@TreemanKing TreemanKing force-pushed the PreSpawnerSearchEvent- branch from 68c2c80 to 266f239 Compare October 5, 2023 14:28
@TreemanKing
Copy link
Copy Markdown
Contributor Author

TreemanKing commented Oct 5, 2023

Having a second thought, maybe calling it SpawnerPlayerSearchEvent is more accurate with the event. Thoughts?

Copy link
Copy Markdown
Contributor

@lynxplay lynxplay left a comment

Choose a reason for hiding this comment

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

After some thought with MM about this, I think we have to rethink a bit how we want to handle the backoff ticks.

Mostly for the following scenario:
Plugin developer A sets the backoff ticks to 20.
Plugin developer A expects the spawner to start searching again in 20 ticks.
Server owner B set a tick delay for mob spawners in the paper world config to 20 ticks.
This means that every 20 ticks the spawner will attempt to search, only decrementing the backoff ticks every 20 ticks, leading to a total of 400 ticks before backoff ticks reaches 0.

Plugin developer A wants to avoid this, but is undable to do so because the tick delay is not exposed right now in the API so computing how long the backoff should be is not possible.

An alternative here would be to count down tickDelay and backoff ticks at the same time.
That way plugin developer A can set the backoff ticks to, lets say 20.
If the tick delay is e.g. 30, after 30 ticks the spawner would search again directly.

This way the plugin developer does not have to deal in spawner ticks but in world ticks, which should be a much more reliable/easy unit as it is not affected by the unaccessible tick delay.

+import java.util.Collections;
+
+/**
+ * Represents an event that is fired before a mob spawner attempts to search
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The javadocs need updating, the event is called after players have been searched.

Comment thread patches/server/1032-Optimise-nearby-player-retrieval.patch Outdated
@TreemanKing TreemanKing changed the title Add SpawnerSearchEvent Add SpawnerPlayerSearchEvent Oct 11, 2023
@Leguan16
Copy link
Copy Markdown
Contributor

does the Spawner search Players? Might rename it to SpawnerSearchPlayerEvent?

@TreemanKing TreemanKing force-pushed the PreSpawnerSearchEvent- branch 2 times, most recently from e1d2866 to cae67ff Compare November 10, 2023 04:32
+ */
+ @NotNull
+ public Result getSearchResult() {
+ return Preconditions.checkNotNull(this.searchResult, "Result cannot be null");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is not really needed, we are already checking the value to not be null in the setter.

Comment thread patches/api/0446-Add-SpawnerPlayerSearchEvent.patch Outdated
if (spawnCount <= 0 || maxNearbyEntities <= 0) return; // Paper - Ignore impossible spawn tick
// Paper start - Configurable mob spawner tick rate
- if (spawnDelay > 0 && --tickDelay > 0) return;
+ if (spawnDelay > 0 && --tickDelay > 0 && --backoffTicks > 0) return; // Paper
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe my brain is fired here, but this would fail to reduce the backoff ticks if the tick delay is <= 0 after its decrementation.

If my server has a tick delay configure of 0, --backoffTicks > 0 is never evaluated.

Comment thread patches/server/1047-Add-SpawnerPlayerSearchEvent.patch Outdated
@TreemanKing TreemanKing force-pushed the PreSpawnerSearchEvent- branch from cae67ff to 4775ae0 Compare November 12, 2023 03:07
@TreemanKing TreemanKing requested a review from lynxplay November 28, 2023 02:06
public int requiredPlayerRange = 16;
public int spawnRange = 4;
private int tickDelay = 0; // Paper
+ private int backoffTicks = 0; // Paper
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Machine and I discussed this yesterday but wouldn't it make sense to "merge" backoffTicks with tickDelay ?

The tickDelay variable does pretty much the exact same.
We'd save ourself a field here by this.tickDelay = Math.max(this.tickDelay, event.getBackoffTicks()) instead.

Passing the current backoff ticks to the event seems, in retrospective, kind of useless ? given the event is only called when those reach 0, I don't think there is much value here.

@TreemanKing TreemanKing closed this Jun 4, 2024
@TreemanKing TreemanKing force-pushed the PreSpawnerSearchEvent- branch from 4775ae0 to 4f13be9 Compare June 4, 2024 11:32
@TreemanKing TreemanKing reopened this Jun 4, 2024
@kennytv kennytv added the pre-softspoon: never rebased Pre-hardfork pull requests that were not re-opened with the new main branch label Mar 23, 2025
@kennytv kennytv deleted the branch PaperMC:master March 23, 2025 19:15
@kennytv kennytv closed this Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pre-softspoon: never rebased Pre-hardfork pull requests that were not re-opened with the new main branch pre-softspoon

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

7 participants