Hello, I spawn a fake player with Player AddPacket, the problem is that I can not do any action when the player clicks on the entity! I try EntityDamageEvent and PacketInteract, PacketInteract works but it is when we fly over the entity and not when clicking! Thanks for the help. »» CODE FOR SPAWN: PHP: public function spawn(Player $player, array $infos) { $pk = new AddPlayerPacket(); $pk->eid = (int)$infos['id']; $pk->uuid = UUID::fromRandom(); $pk->entityUniqueId = (int)$infos['id']; $pk->entityRuntimeId = (int)$infos['id']; $pk->username = $infos['name']; $pk->skin = clone $player->getSkin(); $pk->position = new Vector3($infos['x'], $infos['ya'], $infos['z']); $pk->x = $infos['x']; $pk->y = $infos['ya'] + 1; $pk->z = $infos['z']; $pk->item = Item::get($infos['item'], $infos['meta'], 1); $pk->speedX = 0; $pk->speedY = 0; $pk->speedZ = 0; $pk->yaw = $infos["yaw"]; $pk->pitch = $infos["pitch"]; $pk->metadata = [ Entity::DATA_FLAGS => [Entity::DATA_TYPE_BYTE, 0 << Entity::DATA_FLAG_INVISIBLE], Entity::DATA_NAMETAG => [Entity::DATA_TYPE_STRING, $infos['name']], Entity::DATA_FLAG_CAN_SHOW_NAMETAG => [Entity::DATA_TYPE_BYTE, 1], Entity::DATA_FLAG_NO_AI => [Entity::DATA_TYPE_BYTE, 1], Entity::DATA_LEAD_HOLDER_EID => [Entity::DATA_TYPE_LONG, -1], Entity::DATA_FLAG_LEASHED => [Entity::DATA_TYPE_BYTE, 0] ]; $player->dataPacket($pk); }
The problem is that you spawn the Entity on client side only and server doesn't keep it's "copy" of the entity on server side so no events/interactions can be made. This is basic game server logic. Take a look how Slapper does it (does Slapper still exist?). Hint: extend human class Edit: I found it this and also this
How ? PHP: public function onReceive(DataPacketReceiveEvent $event) { $pk = $event->getPacket(); if($pk instanceof InteractPacket) { if($pk->action instanceof InventoryTransactionPacket ) { } } }
Look how pocketmine does it https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Player.php#2269
The mojang people stuffed almost everything into InventoryTransactionPacket including Player->Entity interactions. Check if $pk is instanceof InventoryTransactionPacket and $pk->transactionType is InventoryTransactionPacket::USE_ITEM_ON_ENTITY_INTERACT. If so, then $pk->trData->entityRuntimeId will return the packet entity's entityRuntimeId. Anyway, what's wrong in using pocketmine's Entity class?
That's what I said. Human is instance of Entity after all. Might seem funny to us, but makes sense for them.