ExperienceOrb: no possibility of interfering in search for target entity #4589
Labels
Category: API
Related to the plugin API
Resolution: Implemented
Type: Enhancement
Contributes features or other improvements to PocketMine-MP
Milestone
Description
Currently, you have the possibility by listening for
PlayerExperienceChangeEvent
, stop a player, or human entity to be more specific, from receiving experience.But by the way the experience orb entity searches for its target, there is no way for plugin developers to interfere and for example, block experience orbs to be attracted to certain players / human entities, apart from extending the whole ExperienceOrb class and overwriting the
ExperienceOrb::entityBaseTick()
method.https://github.com/pmmp/PocketMine-MP/blob/master/src/entity/object/ExperienceOrb.php#L179#L175
Justification
There is a variety of situations, where you wouldn't want experience orbs being attracted to specific entities, for example:
Possible solutions
Human::canPickupExperience()
method which could be overwritten by plugins in their entity classes. But this suggestion has two flaws in my opinion: First, the method could be misleading withExperienceManager::canPickupXp()
and second, this would work for those kinds of plugins listed in the first example. But for that method to be useful for plugins listed in the second example, they would need to overwrite the Player class, which is also rather impractical, even more than overwriting the ExperienceOrb class. (The second point can be ruled out if such a method would be implemented with a class attribute, a setter and getter likeEntity::hasGravity()
andEntity::setHasGravity()
.)ExperienceOrbAttractEvent
, which could be called before the following line https://github.com/pmmp/PocketMine-MP/blob/master/src/entity/object/ExperienceOrb.php#L178. This event would be very useful for both given plugin examples, as they could just cancel the event or maybe also provide a replacement entity with an inbuiltExperienceOrbAttractEvent::setEntity()
method, so that these plugins could not only remove experience orbs from being attracted to their entities but also give plugin developers a way to implement their own system of searching.Alternative methods
ExperienceOrb::entityBaseTick()
method so that you would be able to make a custom search, but that approach is rather impractical.Living
or onlyEntity
but notHuman
because experience orbs only search for human entities. But this is also rather impractical because you would end up just copying many methods like skin and inventory handling from the Human to your own class.The text was updated successfully, but these errors were encountered: