Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rewrite] Custom Mobs #78

Merged
merged 11 commits into from
Aug 6, 2024

Conversation

JustAHuman-xD
Copy link
Collaborator

Testing Status

Currently this PR is not tested in any way, I need to do extensive testing

Description

This PR aims to rewrite the custom mob system (without any changes to the end functionality hopefully) to have improved performance, code readability and just cleanup in general.

Proposed generic changes

  • Added Utils#getNearbyPlayersInSurvival(Location, double, double, double) this method is just a utility since you had loops frequently that all did the same thing, filter down to players in survival, there is also an overloaded method with just one double if the radius on each axis is identical
  • Replaced various instanceof with instanceof casts
  • Changed some annotations to use @ParametersNonnullByDefault instead of a lot of @Nonnull annotations
  • Marking constants final
  • Removing unnecessary boxing or overloading
  • Re-arranging conditions and method calls to be more performant
  • Combining nested if statements
  • Switched to guard statements to avoid a ton of indentation

Proposed changes to CustomMob

  • Made the constructor protected since its an abstract class
  • Added SCANNED_CHUNKS a Set of ChunkPositions, and MOB_CACHE a map of CustomMob -> Set<UUID>
    • Added another EventHandler method to the register listener, it is the chunk load event, if the loaded chunks position is not in scanned chunks it will go through all of the entities and cache them if they are custom, it will only do this once per chunk
  • Added cacheEntity(Entity) and uncacheEntity(Entity) respectively
    • There is now a default in the onEntityDeath that calls uncacheEntity, and I have added the annotation @OverridingMethodsMustInvokeSuper and followed that in all the overriding methods as well to ensure that it is always called.
    • The spawn event now calls cacheEntity

Proposed changes to MobTicker

  • Replaced the getWorlds.getLivingEntities calls with an iteration over the MOB_CACHE in CustomMob

Proposed changes to CustomBoss

  • Made the constructor protected since its an abstract class
  • Added an override to onMobTick this handles the onBossPattern method, this was previously handled in MobTicker, this method also has the @OverridingMethodsMustInvokeSuper

Proposed changes to HeadlessHorseman

  • Replacing the manual distance checks with builtin methods
  • Re-arranged a lot within onMobTick to make it more readable, more performant, etc, etc
  • Replaced the assert helldog != null with a null check and warning to the log, an assertion error is not very clear to the server administrators

Proposed changes to PixieQueen

  • Basically all the same things changed in HeadlessHorseman just for pixie queen

@GallowsDove
Copy link
Owner

Seems like very sane changes, don't be afraid to involve GuineaPigs for testing. Please tag me when it's ready to be merged

@JustAHuman-xD
Copy link
Collaborator Author

@GallowsDove if you could look this over some and let me know if there's anything obvious I should change, just so that once I'm sure it's stable I've already got the code how you want it

Copy link
Owner

@GallowsDove GallowsDove left a comment

Choose a reason for hiding this comment

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

LGTM, sorry for the long wait!

@JustAHuman-xD JustAHuman-xD marked this pull request as ready for review June 27, 2024 01:57
@JustAHuman-xD
Copy link
Collaborator Author

Since no issues have been found I'm going ahead and marking this ready for review lol

@GallowsDove GallowsDove merged commit 184f8d3 into GallowsDove:master Aug 6, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants