Hey guys! I'm working on a pet plugin, (which will be public soon) and am trying to implement riding the pets. Now, I sort of know how to link entities to eachother, but because the fields aren't yet added in PocketMine, I'm not entirely sure how. I've made two previous attempts, which both didn't seem to do anything. The following code is inside of an abstract entity class, which extends the Creature and implements the Rideable classes. The code gets executed on EntityDamageByEntityEvent, if the owner of the pet hits the pet with a saddle. The message of this get's shown, so the code does get executed correctly. Spoiler: Attempt 1 PHP: /** * @param Player $player */ public function setRider(Player $player) { $this->ridden = true; $this->rider = $player->getName(); $pk = new SetEntityLinkPacket(); $pk->from = $this->getId(); $pk->to = $player->getId(); $pk->type = 1; $this->server->broadcastPacket($this->level->getPlayers(), $pk); } public function throwRiderOff() { $pk = new SetEntityLinkPacket(); $pk->from = $this->getPetOwner()->getId(); $pk->to = $this->getId(); $pk->type = 0; $this->ridden = false; $this->rider = null; } /** * @return Player */ public function getRider(): Player { return $this->getLevel()->getServer()->getPlayer($this->rider); } /** * @return bool */ public function isRidden(): bool { return $this->ridden; } The second time I've switched around some things, because I'm not sure what has to go where. Spoiler: Attempt 2 PHP: /** * @param Player $player */ public function setRider(Player $player) { $this->ridden = true; $this->rider = $player->getName(); $pk = new SetEntityLinkPacket(); $pk->from = $player->getId(); $pk->to = $this->getId(); $pk->type = 1; $this->server->broadcastPacket($this->level->getPlayers(), $pk); } public function throwRiderOff() { $pk = new SetEntityLinkPacket(); $pk->from = $this->getPetOwner()->getId(); $pk->to = $this->getId(); $pk->type = 0; $this->ridden = false; $this->rider = null; } /** * @return Player */ public function getRider(): Player { return $this->getLevel()->getServer()->getPlayer($this->rider); } /** * @return bool */ public function isRidden(): bool { return $this->ridden; } I've also attempted to change the Packet type, but this didn't seem to have a different behaviour either. I assume type 1 is for riding. I know doing this is still kinda hacky, but I'm willing to do so to make riding it work. If anybody here has an idea what I'm doing wrong, or how it should be, please tell me. I'd greately appreciate it. Thanks in advance!
Some extra information: I've tried the code on any entity, with the thought in mind that it would only work on rideable animals such as horses and pigs, (I don't know, Mojang likes to hard code things sometimes) maybe even only if they have a saddle on. If anybody knows about that, feel free to tell me please.
AvengeTech was able to do this. But instead of the player riding the other player, the player is riding a squid, and the squid is teleported to the person that your riding.
Update: I got it to work! After some messing around, it worked, using this code: PHP: /*** @param Player $player*/public function setRider(Player $player) { $this->ridden = true; $this->rider = $player->getName(); $pk = new SetEntityLinkPacket(); $pk->to = $player->getId(); $pk->from = $this->getId(); $pk->type = self::STATE_SITTING; $this->server->broadcastPacket($this->level->getPlayers(), $pk); $pk = new SetEntityLinkPacket(); $pk->to = 0; $pk->from = $this->getId(); $pk->type = self::STATE_SITTING; $player->dataPacket($pk);}public function throwRiderOff() { $pk = new SetEntityLinkPacket(); $pk->from = $this->getId(); $pk->to = $this->getPetOwner()->getId(); $pk->type = self::STATE_STANDING; $this->ridden = false; $this->rider = null; $this->server->broadcastPacket($this->level->getPlayers(), $pk); $pk = new SetEntityLinkPacket(); $pk->from = $this->getPetOwner()->getId(); $pk->to = 0; $pk->type = self::STATE_STANDING; $this->getPetOwner()->dataPacket($pk);}/*** @return Player*/public function getRider() { return $this->getLevel()->getServer()->getPlayer($this->rider);}/*** @return bool*/public function isRidden(): bool { return $this->ridden;} The sending to the rider seems to be necessary for the rider to show up riding. I'm now facing a new issue however. This new issue is that plays are positioned UNDER the entity ridden, instead of on top of it. Is there any way to fix this, you know about? Workarounds are welcome too, as this seems to be an MCPE thing.
Tried a bit with 58, 57, 59, but no success with those. Is it the one that requires a Vector3F? Or...
I found it. PHP: const DATA_RIDE_POSITION = 57; //Try with 58 too$player->setDataProperty(Entity::DATA_TYPE_VECTOR3F, self::/*or Entity::*/DATA_RIDE_POSITION, [-0.02, 2.3, 0.19]);
And I'm not, plus, these are PocketMine forums, so solutions for forks/spoons of PocketMine will not fix the problem. Like I mentioned above, I already got it working. I just need to find the metadata ID for changing the seat position.