Prevent axolotls from targeting protected mobs #6140
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
Previously, axolotl would keep attacking the protected mobs by Towny within a town (so it looks like it's trying to keep attacking but no damage, forever). This PR additionally listens to the EntityTargetLivingEntityEvent, where it uses the original logic to check if the Axolotl is able to damage the defender. If it is not, then cancel the EntityTargetLivingEntityEvent and let the axolotl have its
has_hunting_cooldown
on (see here for this entity data).I think this PR improves the code efficiency a bit because if the
has_hunting_cooldown
is on then axolotls won't having any attacking behaviour for at least 2 min. So neither EntityTargetLivingEntityEvent nor EntityDamageEvent will be called.Previously, the axolotls would just keep attack the protected mobs and would never have
has_hunting_cooldown
on since protected mobs can't be killed..The commits might be a bit of messy but the final changes are just a few lines of code.
New Nodes/Commands/ConfigOptions:
None
Relevant Towny Issue ticket:
None, but I have asked a simple question on the discord related to this PR. Then I took a look at the code and found there was a TODO: Axolotl#setTarget(null) is not actually working. So I basically finished that TODO in this PR :)
By making this pull request, I represent that I have the right to waive copyright and related rights to my contribution, and agree that all copyright and related rights in my contributions are waived, and I acknowledge that the TownyAdvanced organization has the copyright to use and modify my contribution under the Towny License for perpetuity.