PocketMine-MP
PocketMine-MP copied to clipboard
Implement a proposed EntityRegistrar for PM4
Introduction
PM4 currently lacks a way to overwrite and/or "register" entities, this is due to the new improved design principles that avoids type-unsafe variadic argument passing to entity constructors and for the better separation of the network layer from the plugin API
Changes
Build
Implemented Closure
signature generation for build/generate-registry-annotations.php
API changes
Added a VanillaEntities
class that works similarly to other Vanilla<type>
classes
Backwards compatibility
Since there is no actual entity registration in PM4 and developers needed to construct the entities themselves, backwards-compatibility is not an issue.
Follow-up
This pull request is not done, this is just the first stage. However I am asking for comments for further development as the next stages require more changes in the internal PocketMine codebase to migrate from direct entity construction, to the usage of the VanillaEntities
class
EntityFactory
should be renamed appropriately to EntityDataParser
(or a similar name) as its actual purpose is to construct the entities from the NBT data read from disk.
Tests
// allowed:
VanillaEntities::register("human", function(Location $location, Skin $skin, ?CompoundTag $nbt = null):CustomHuman{
return new CustomHuman($location, $skin, $nbt);
});
// not allowed:
VanillaEntities::register("human", function(Location $location, Skin $skin, Player $linked, ?CompoundTag $nbt = null):EnderPearl{
return new EnderPearl($location, null, $nbt);
});
EntityFactory
should be renamed appropriately toEntityDataParser
(or a similar name) as its actual purpose is to construct the entities from the NBT data read from disk.
It should also be moved to the pocketmine/data
package.
Any updates on that, since it's quite a pain to overwrite existing entities.
I'm currently leaning towards an EntityCreationEvent
. I don't like this solution; it's too much of a hack and it's too inflexible. If we're going to do a hack for a poor API, we can at least do the hack well.
Closing due to lack of activity.