PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
FloatingTextParticle.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\world\particle;
25
41
43 //TODO: HACK!
44
45 protected ?int $entityId = null;
46 protected bool $invisible = false;
47
48 public function __construct(
49 protected string $text,
50 protected string $title = ""
51 ){}
52
53 public function getText() : string{
54 return $this->text;
55 }
56
57 public function setText(string $text) : void{
58 $this->text = $text;
59 }
60
61 public function getTitle() : string{
62 return $this->title;
63 }
64
65 public function setTitle(string $title) : void{
66 $this->title = $title;
67 }
68
69 public function isInvisible() : bool{
70 return $this->invisible;
71 }
72
73 public function setInvisible(bool $value = true) : void{
74 $this->invisible = $value;
75 }
76
77 public function encode(Vector3 $pos) : array{
78 $p = [];
79
80 if($this->entityId === null){
81 $this->entityId = Entity::nextRuntimeId();
82 }else{
83 $p[] = RemoveActorPacket::create($this->entityId);
84 }
85
86 if(!$this->invisible){
87 $name = $this->title . ($this->text !== "" ? "\n" . $this->text : "");
88
89 $actorFlags = (
90 1 << EntityMetadataFlags::NO_AI
91 );
92 $actorMetadata = [
93 EntityMetadataProperties::FLAGS => new LongMetadataProperty($actorFlags),
94 EntityMetadataProperties::SCALE => new FloatMetadataProperty(0.01), //zero causes problems on debug builds
95 EntityMetadataProperties::BOUNDING_BOX_WIDTH => new FloatMetadataProperty(0.0),
96 EntityMetadataProperties::BOUNDING_BOX_HEIGHT => new FloatMetadataProperty(0.0),
97 EntityMetadataProperties::NAMETAG => new StringMetadataProperty($name),
98 EntityMetadataProperties::VARIANT => new IntMetadataProperty(TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId(VanillaBlocks::AIR()->getStateId())),
99 EntityMetadataProperties::ALWAYS_SHOW_NAMETAG => new ByteMetadataProperty(1),
100 ];
101 $p[] = AddActorPacket::create(
102 $this->entityId, //TODO: actor unique ID
103 $this->entityId,
104 EntityIds::FALLING_BLOCK,
105 $pos, //TODO: check offset (0.49?)
106 null,
107 0,
108 0,
109 0,
110 0,
111 [],
112 $actorMetadata,
113 new PropertySyncData([], []),
114 []
115 );
116 }
117
118 return $p;
119 }
120}