1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace muqsit \invmenu \type \graphic ;
6+
7+ use muqsit \invmenu \type \graphic \network \InvMenuGraphicNetworkTranslator ;
8+ use pocketmine \inventory \Inventory ;
9+ use pocketmine \network \mcpe \protocol \AddActorPacket ;
10+ use pocketmine \network \mcpe \protocol \RemoveActorPacket ;
11+ use pocketmine \network \mcpe \protocol \types \entity \EntityMetadataProperties ;
12+ use pocketmine \network \mcpe \protocol \types \entity \MetadataProperty ;
13+ use pocketmine \network \mcpe \protocol \types \entity \PropertySyncData ;
14+ use pocketmine \network \mcpe \protocol \types \entity \StringMetadataProperty ;
15+ use pocketmine \player \Player ;
16+
17+ final class ActorInvMenuGraphic implements InvMenuGraphic{
18+
19+ /**
20+ * @param string $actor_identifier
21+ * @param int $actor_runtime_identifier
22+ * @param array<int, MetadataProperty> $actor_metadata
23+ * @param InvMenuGraphicNetworkTranslator|null $network_translator
24+ * @param int $animation_duration
25+ */
26+ public function __construct (
27+ private string $ actor_identifier ,
28+ private int $ actor_runtime_identifier ,
29+ private array $ actor_metadata ,
30+ private ?InvMenuGraphicNetworkTranslator $ network_translator = null ,
31+ private int $ animation_duration = 0
32+ ){}
33+
34+ public function send (Player $ player , ?string $ name ) : void {
35+ $ metadata = $ this ->actor_metadata ;
36+ if ($ name !== null ){
37+ $ metadata [EntityMetadataProperties::NAMETAG ] = new StringMetadataProperty ($ name );
38+ }
39+ $ player ->getNetworkSession ()->sendDataPacket (AddActorPacket::create (
40+ $ this ->actor_runtime_identifier ,
41+ $ this ->actor_runtime_identifier ,
42+ $ this ->actor_identifier ,
43+ $ player ->getPosition ()->asVector3 (),
44+ null ,
45+ 0.0 ,
46+ 0.0 ,
47+ 0.0 ,
48+ 0.0 ,
49+ [],
50+ $ metadata ,
51+ new PropertySyncData ([], []),
52+ []
53+ ));
54+ }
55+
56+ public function sendInventory (Player $ player , Inventory $ inventory ) : bool {
57+ return $ player ->setCurrentWindow ($ inventory );
58+ }
59+
60+ public function remove (Player $ player ) : void {
61+ $ player ->getNetworkSession ()->sendDataPacket (RemoveActorPacket::create ($ this ->actor_runtime_identifier ));
62+ }
63+
64+ public function getNetworkTranslator () : ?InvMenuGraphicNetworkTranslator {
65+ return $ this ->network_translator ;
66+ }
67+
68+ public function getAnimationDuration () : int {
69+ return $ this ->animation_duration ;
70+ }
71+ }
0 commit comments