Recently tried my hand at Mobs (a Wither): PHP: <?phpnamespace endermysteryteam\megawalls\entities;use pocketmine\entity\Monster;use pocketmine\network\mcpe\protocol\AddEntityPacket;use pocketmine\Player;use pocketmine\entity\ProjectileSource;abstract class WitherEntity extends Monster implements ProjectileSource{ const NETWORK_ID = 52; public $width = 0.9; public $height = 3.5; public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->entityRuntimeId = $this->getId(); $pk->type = WitherEntity::NETWORK_ID; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->speedX = $this->motionX; $pk->speedY = $this->motionY; $pk->speedZ = $this->motionZ; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->metadata = $this->dataProperties; $player->dataPacket($pk); parent::spawnTo($player); } public static function addWitherEntity(Location $pos, string $name){ $nbt = new CompoundTag; $nbt->Pos = new ListTag("Pos", [ new DoubleTag("", $pos->x), new DoubleTag("", $pos->y), new DoubleTag("", $pos->z) ]); $nbt->Rotation = new ListTag("Rotation", [ new FloatTag("", $pos->yaw), new FloatTag("", $pos->pitch) ]); $nbt->Health = new ShortTag("Health", 600); $nbt->displayname = $name; $chunk = $player->chunk; if (!$chunk instanceof Chunk) { return; } $entity = Entity::createEntity("Wither", $chunk, $nbt); $entity->spawnToAll(); $entity->saveNBT(); $entity->setNamedTagVisible(true); $entity->setNamedTagAlwaysVisible(true); $entity->setNamedTag($nbt->displayname); } }?> How would I spawn/register the Wither now?
Why abstract class? You can register entity using PHP: Entity::registerEntity(); https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Entity.php#L750
Didnt want the Wither to implement the drop loot and get name method lel Edit: crud just read the registerEntity method and it dosent accept abstract class Also what does the $force boolean do?
You cannot construct abstract classes. Overwrites a previously registered entity if it has the same class name.
https://github.com/pmmp/PocketMine-...0f/src/pocketmine/entity/Entity.php#L753-L757 Actually, it just allows registering entities that have no network ID.
How do i spawn it and define custom behaviour though? This seems so much different than on Bukkit where NMS was so fun to mess with... Interestingly though, in the Entity class constructor, the EntitySpawnEvent is called, which must mean that spawning the mob you added via Plugin must have something to do with the constructor, just cant figure out what to do yet...
Oops PHP: $entity = pocketmine\entity\Entity::create("WitherEntity", pocketmine/Server::getInstance()->getDefaultLevel(), new pocketmine\nbt\tag\CompoundTag("", [ new pocketmine\nbt\tag\ListTag("Pos", [ new pocketmine\nbt\tag\DoubleTag("", 127), new pocketmine\nbt\tag\DoubleTag("", 80), new pocketmine\nbt\tag\DoubleTag("", 127), ], new pocketmine\nbt\tag\ListTag("Motion", [ new pocketmine\nbt\tag\DoubleTag("", 0), new pocketmine\nbt\tag\DoubleTag("", 0), new pocketmine\nbt\tag\DoubleTag("", 0), ], new pocketmine\nbt\tag\ListTag("Rotation", [ new pocketmine\nbt\tag\FloatTag("", 0.0), new pocketmine\nbt\tag\FloatTag("", 0.0), ],]);$entity->spawnToAll();
Actually would this work? PHP: <?phpnamespace endermysteryteam\megawalls\entities;use pocketmine\entity\Monster;use pocketmine\network\mcpe\protocol\AddEntityPacket;use pocketmine\Player;use pocketmine\entity\ProjectileSource;class WitherEntity extends Monster implements ProjectileSource{ const NETWORK_ID = 52; public $width = 0.9; public $height = 3.5; public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->entityRuntimeId = $this->getId(); $pk->type = WitherEntity::NETWORK_ID; $pk->x = $this->x; $pk->y = $this->y; $pk->z = $this->z; $pk->speedX = $this->motionX; $pk->speedY = $this->motionY; $pk->speedZ = $this->motionZ; $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->metadata = $this->dataProperties; $player->dataPacket($pk); parent::spawnTo($player); } public static function addWitherEntity(Location $pos, string $name){ $nbt = new CompoundTag; $nbt->Pos = new ListTag("Pos", [ new DoubleTag("", $pos->x), new DoubleTag("", $pos->y), new DoubleTag("", $pos->z) ]); $nbt->Rotation = new ListTag("Rotation", [ new FloatTag("", $pos->yaw), new FloatTag("", $pos->pitch) ]); $nbt->Health = new ShortTag("Health", 600); $nbt->displayname = $name; $chunk = $player->chunk; if (!$chunk instanceof Chunk) { return; } $entity = Entity::createEntity("WitherEntity", $chunk, $nbt); $entity->spawnToAll(); $entity->saveNBT(); $entity->setNamedTagVisible(true); $entity->setNamedTagAlwaysVisible(true); $entity->setNamedTag($nbt->displayname); } }?>
Just a note, if you have the NETWORK_ID set to anything other than -1, spawn eggs with that same damage value will spawn your entity.
Try executing it. Entity::setNamedTagVisible(), Entity::setNamedTagAlwaysVisible() and Entity::setNamedTag() do not exist. You probably meant Entity::setNameTag*(). Aside from that... The chunk checking is unneeded. The game doesn't listen to "displayname" tag, you can remove that unless you are using it (the game isn't using it). If you are implementing it, create a StringTag instance. I don't think that NBT key is gonna get saved.
If you are using alpha8 or 9 you need to update your code: newer API versions use Vector3 for Entity speed and motion, not x, y, z.
Everywhere you set position or speed for an entity. If you set up your IDE correctly it should tell you that $pk->x doesn't exist, for example.
Dammit i guess Eclipse is a potato then (But no PHP IDE i seen so far ever corrects errors in code soo...) Edit: GitHub sure is handy PHP: public function spawnTo(Player $player){ $pk = new AddEntityPacket(); $pk->entityRuntimeId = $this->getId(); $pk->type = Zombie::NETWORK_ID; $pk->position = $this->asVector3(); $pk->motion = $this->getMotion(); $pk->yaw = $this->yaw; $pk->pitch = $this->pitch; $pk->metadata = $this->dataProperties; $player->dataPacket($pk); parent::spawnTo($player); }
As long as you add pocketmine source code to your projects you'll be able to 'inspect', and you should see warnings on the page itself for errors like this in any decent IDE, such as PHPStorm, Eclipse and Netbeans.
NetBeans didnt do shit when i added the pocketmine source it didnt even auto import from pocketmine lmao Eclipse is working better but even then its still a potato most of the time. Sure as heck dosent match the Java version of itself