PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
InteractPacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
18
20 public const NETWORK_ID = ProtocolInfo::INTERACT_PACKET;
21
22 public const ACTION_LEAVE_VEHICLE = 3;
23 public const ACTION_MOUSEOVER = 4;
24 public const ACTION_OPEN_NPC = 5;
25 public const ACTION_OPEN_INVENTORY = 6;
26
27 public int $action;
28 public int $targetActorRuntimeId;
29 public float $x;
30 public float $y;
31 public float $z;
32
33 protected function decodePayload(PacketSerializer $in) : void{
34 $this->action = $in->getByte();
35 $this->targetActorRuntimeId = $in->getActorRuntimeId();
36
37 if($this->action === self::ACTION_MOUSEOVER || $this->action === self::ACTION_LEAVE_VEHICLE){
38 //TODO: should this be a vector3?
39 $this->x = $in->getLFloat();
40 $this->y = $in->getLFloat();
41 $this->z = $in->getLFloat();
42 }
43 }
44
45 protected function encodePayload(PacketSerializer $out) : void{
46 $out->putByte($this->action);
47 $out->putActorRuntimeId($this->targetActorRuntimeId);
48
49 if($this->action === self::ACTION_MOUSEOVER || $this->action === self::ACTION_LEAVE_VEHICLE){
50 $out->putLFloat($this->x);
51 $out->putLFloat($this->y);
52 $out->putLFloat($this->z);
53 }
54 }
55
56 public function handle(PacketHandlerInterface $handler) : bool{
57 return $handler->handleInteract($this);
58 }
59}
handle(PacketHandlerInterface $handler)