Hello, I'm new I would like to know that the packet InteractPacket had the action of clicking on an Entity Id this is not the car case when it was named from the id he received the order and I do not want not. I want to run it by clicking. If someone can help me. PHP: public function onPacketReceived(DataPacketReceiveEvent $event) { $pk = $event->getPacket(); if ($pk instanceof InteractPacket) { if (isset($this->entity[$pk->target])) { $entity = $this->entity[$pk->target]; if (!isset($this->command[$event->getPlayer()->getName()])) { $entity->executeCommand($event->getPlayer()); return true; } } } }
Also note that for whatever reason you're using DataPacketReceiveEvent, tapping an entity is no longer the Interact packet but an InventoryTransactionPacket.
Because you're not supposed to use packets directly where possible. Packets and the protocol are bound to change every update, and you can blame the developers at Mojang for that. When API methods are provided you're encouraged to use them. This is one of the reasons you should never use packets when there's API for it.
Solved Thanks @Sandertv for your help its work here the solution. PHP: /*** @param DataPacketReceiveEvent $event* @return bool*/public function onPacketReceived(DataPacketReceiveEvent $event) { $pk = $event->getPacket(); if ($pk instanceof InventoryTransactionPacket) { if ($pk->transactionType === InventoryTransactionPacket::TYPE_USE_ITEM_ON_ENTITY && $pk->trData->actionType === InventoryTransactionPacket::USE_ITEM_ON_ENTITY_ACTION_INTERACT) { if (isset($this->entity[$pk->trData->entityRuntimeId])) { $entity = $this->entity[$pk->trData->entityRuntimeId]; if (!isset($this->command[$event->getPlayer()->getName()])) { $entity->executeCommand($event->getPlayer()); return true; } } } } }
No, no, no! Stop your DataPacketReceiveEvent addiction! It's a stupid idea and causes way more load than is needed. Why don't you just use the events provided? You tap an entity, so it's an attack, which means you have the EntityDamageEvent. Then check if it's instanceof EntityDamageByEntityEvent and check if the damager is a Player. Forget about this DataPacketReceiveEvent if you can do it without. Which you can most of the time..
No False, Why do that so I did not use the nbt I used directly AddPlayerPacket () it can not be taken by an EntityDamageEvent.
If that's how you want to approach it, good luck with it. You should know DataPacketReceiveEvent is the most aggressive event in the whole core and it is strongly disadvised to use it if you can simply create an entity and use normal events instead.