PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
AddItemActorPacket.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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
23
25 public const NETWORK_ID = ProtocolInfo::ADD_ITEM_ACTOR_PACKET;
26
27 public int $actorUniqueId;
28 public int $actorRuntimeId;
29 public ItemStackWrapper $item;
30 public Vector3 $position;
31 public ?Vector3 $motion = null;
36 public array $metadata = [];
37 public bool $isFromFishing = false;
38
44 public static function create(
45 int $actorUniqueId,
46 int $actorRuntimeId,
47 ItemStackWrapper $item,
48 Vector3 $position,
49 ?Vector3 $motion,
50 array $metadata,
51 bool $isFromFishing,
52 ) : self{
53 $result = new self;
54 $result->actorUniqueId = $actorUniqueId;
55 $result->actorRuntimeId = $actorRuntimeId;
56 $result->item = $item;
57 $result->position = $position;
58 $result->motion = $motion;
59 $result->metadata = $metadata;
60 $result->isFromFishing = $isFromFishing;
61 return $result;
62 }
63
64 protected function decodePayload(ByteBufferReader $in) : void{
65 $this->actorUniqueId = CommonTypes::getActorUniqueId($in);
66 $this->actorRuntimeId = CommonTypes::getActorRuntimeId($in);
67 $this->item = CommonTypes::getItemStackWrapper($in);
68 $this->position = CommonTypes::getVector3($in);
69 $this->motion = CommonTypes::getVector3($in);
70 $this->metadata = CommonTypes::getEntityMetadata($in);
71 $this->isFromFishing = CommonTypes::getBool($in);
72 }
73
74 protected function encodePayload(ByteBufferWriter $out) : void{
75 CommonTypes::putActorUniqueId($out, $this->actorUniqueId);
76 CommonTypes::putActorRuntimeId($out, $this->actorRuntimeId);
77 CommonTypes::putItemStackWrapper($out, $this->item);
78 CommonTypes::putVector3($out, $this->position);
79 CommonTypes::putVector3Nullable($out, $this->motion);
80 CommonTypes::putEntityMetadata($out, $this->metadata);
81 CommonTypes::putBool($out, $this->isFromFishing);
82 }
83
84 public function handle(PacketHandlerInterface $handler) : bool{
85 return $handler->handleAddItemActor($this);
86 }
87}
static create(int $actorUniqueId, int $actorRuntimeId, ItemStackWrapper $item, Vector3 $position, ?Vector3 $motion, array $metadata, bool $isFromFishing,)