Add SpawnerPlayerSearchEvent#9614
Conversation
Warriorrrr
left a comment
There was a problem hiding this comment.
PR looks good aside from a few small comments.
|
I forgot to say that in the review, but you need the notnull/nullable annotations in the API otherwise the test will fail |
|
I believe all of the above should be resolved. If someone could please check this, that would be great! |
lynxplay
left a comment
There was a problem hiding this comment.
Generally really nice work 👍 a few annotations left but beyond that good and ready for testing/review.
4866c6f to
e1bbe47
Compare
3f77a5c to
a90e989
Compare
lynxplay
left a comment
There was a problem hiding this comment.
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 👍
lynxplay
left a comment
There was a problem hiding this comment.
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". |
|
Should I move the event to Block instead of Entity as well? |
|
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 |
|
What is the general opinion on this one: |
9db392a to
68c2c80
Compare
|
Again, i don't know if we have a precedent for this. Does it use DEFAULT or ALLOW ? |
|
Anything else I need to do or is this just awaiting reviews? |
|
At least from my end, I just need to find time to give this a final review and testing 👍 |
68c2c80 to
266f239
Compare
|
Having a second thought, maybe calling it |
lynxplay
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
The javadocs need updating, the event is called after players have been searched.
|
does the Spawner search Players? Might rename it to |
e1d2866 to
cae67ff
Compare
| + */ | ||
| + @NotNull | ||
| + public Result getSearchResult() { | ||
| + return Preconditions.checkNotNull(this.searchResult, "Result cannot be null"); |
There was a problem hiding this comment.
This is not really needed, we are already checking the value to not be null in the setter.
| 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 |
There was a problem hiding this comment.
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.
cae67ff to
4775ae0
Compare
| public int requiredPlayerRange = 16; | ||
| public int spawnRange = 4; | ||
| private int tickDelay = 0; // Paper | ||
| + private int backoffTicks = 0; // Paper |
There was a problem hiding this comment.
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.
4775ae0 to
4f13be9
Compare
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!