Skip to content

Commit

Permalink
fix text disappearing
Browse files Browse the repository at this point in the history
  • Loading branch information
fuyutsuki committed Mar 13, 2024
1 parent 160ce47 commit 0b3604e
Showing 1 changed file with 88 additions and 48 deletions.
136 changes: 88 additions & 48 deletions src/jp/mcbe/fuyutsuki/Texter/text/FloatingText.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace jp\mcbe\fuyutsuki\Texter\text;

use http\Exception\InvalidArgumentException;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\Entity;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\convert\TypeConverter;
use pocketmine\network\mcpe\protocol\AddActorPacket;
use pocketmine\network\mcpe\protocol\ClientboundPacket;
use pocketmine\network\mcpe\protocol\MoveActorAbsolutePacket;
use pocketmine\network\mcpe\protocol\RemoveActorPacket;
use pocketmine\network\mcpe\protocol\SetActorDataPacket;
use pocketmine\network\mcpe\protocol\types\entity\ByteMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
use pocketmine\network\mcpe\protocol\types\entity\FloatMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\IntMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\LongMetadataProperty;
use pocketmine\network\mcpe\protocol\types\entity\PropertySyncData;
use pocketmine\network\mcpe\protocol\types\entity\StringMetadataProperty;
Expand Down Expand Up @@ -71,56 +71,96 @@ public function setParent(FloatingTextCluster $parent) {
$this->parent = $parent;
}

public function asPacket(SendType $type): ClientboundPacket {
public function asPackets(SendType $type): array {
return match ($type) {
SendType::ADD => AddActorPacket::create(
$this->actorRuntimeId,
$this->actorRuntimeId,
EntityIds::ITEM,
$this->position,
motion: null,
pitch: 0.0,
yaw: 0.0,
headYaw: 0.0,
bodyYaw: 0.0,
attributes: [],
metadata: [
EntityMetadataProperties::ALWAYS_SHOW_NAMETAG => new ByteMetadataProperty(1),
EntityMetadataProperties::BOUNDING_BOX_HEIGHT => new FloatMetadataProperty(0.0),
EntityMetadataProperties::BOUNDING_BOX_WIDTH => new FloatMetadataProperty(0.0),
EntityMetadataProperties::FLAGS => LongMetadataProperty::buildFromFlags([
EntityMetadataFlags::IMMOBILE => true,
]),
EntityMetadataProperties::NAMETAG => new StringMetadataProperty($this->text),
EntityMetadataProperties::SCALE => new FloatMetadataProperty(0.0),
],
syncedProperties: new PropertySyncData([], []),
links: []
),
SendType::EDIT => SetActorDataPacket::create(
$this->actorRuntimeId,
metadata: [
EntityMetadataProperties::NAMETAG => new StringMetadataProperty($this->text),
],
syncedProperties: new PropertySyncData([], []),
tick: 0
),
SendType::MOVE => MoveActorAbsolutePacket::create(
$this->actorRuntimeId,
$this->position,
pitch: 0.0,
yaw: 0.0,
headYaw: 0.0,
flags: MoveActorAbsolutePacket::FLAG_TELEPORT
),
SendType::REMOVE => RemoveActorPacket::create(
$this->actorRuntimeId
),
SendType::ADD => [
AddActorPacket::create(
$this->actorRuntimeId,
$this->actorRuntimeId,
EntityIds::FALLING_BLOCK,
$this->position,
motion: null,
pitch: 0.0,
yaw: 0.0,
headYaw: 0.0,
bodyYaw: 0.0,
attributes: [],
metadata: [
EntityMetadataProperties::ALWAYS_SHOW_NAMETAG => new ByteMetadataProperty(1),
EntityMetadataProperties::BOUNDING_BOX_HEIGHT => new FloatMetadataProperty(0.0),
EntityMetadataProperties::BOUNDING_BOX_WIDTH => new FloatMetadataProperty(0.0),
EntityMetadataProperties::FLAGS => LongMetadataProperty::buildFromFlags([
EntityMetadataFlags::IMMOBILE => true,
]),
EntityMetadataProperties::NAMETAG => new StringMetadataProperty($this->text),
EntityMetadataProperties::SCALE => new FloatMetadataProperty(0.0),
EntityMetadataProperties::VARIANT => new IntMetadataProperty(TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId(VanillaBlocks::AIR()->getStateId()))
],
syncedProperties: new PropertySyncData([], []),
links: []
),
],
SendType::EDIT => [
SetActorDataPacket::create(
$this->actorRuntimeId,
metadata: [
EntityMetadataProperties::NAMETAG => new StringMetadataProperty($this->text),
],
syncedProperties: new PropertySyncData([], []),
tick: 0
),
],
SendType::MOVE => [
// MoveActorAbsolutePacket::create(
// $this->actorRuntimeId,
// $this->position,
// pitch: 0.0,
// yaw: 0.0,
// headYaw: 0.0,
// flags: MoveActorAbsolutePacket::FLAG_TELEPORT
// ),
RemoveActorPacket::create(
$this->actorRuntimeId
),
AddActorPacket::create(
$this->actorRuntimeId,
$this->actorRuntimeId,
EntityIds::FALLING_BLOCK,
$this->position,
motion: null,
pitch: 0.0,
yaw: 0.0,
headYaw: 0.0,
bodyYaw: 0.0,
attributes: [],
metadata: [
EntityMetadataProperties::ALWAYS_SHOW_NAMETAG => new ByteMetadataProperty(1),
EntityMetadataProperties::BOUNDING_BOX_HEIGHT => new FloatMetadataProperty(0.0),
EntityMetadataProperties::BOUNDING_BOX_WIDTH => new FloatMetadataProperty(0.0),
EntityMetadataProperties::FLAGS => LongMetadataProperty::buildFromFlags([
EntityMetadataFlags::IMMOBILE => true,
]),
EntityMetadataProperties::NAMETAG => new StringMetadataProperty($this->text),
EntityMetadataProperties::SCALE => new FloatMetadataProperty(0.0),
EntityMetadataProperties::VARIANT => new IntMetadataProperty(TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId(VanillaBlocks::AIR()->getStateId()))
],
syncedProperties: new PropertySyncData([], []),
links: []
),
],
SendType::REMOVE => [
RemoveActorPacket::create(
$this->actorRuntimeId
),
],
};
}

public function sendToPlayer(Player $player, SendType $type): void {
$player->getNetworkSession()->sendDataPacket($this->asPacket($type));
$packets = $this->asPackets($type);
foreach ($packets as $packet) {
$player->getNetworkSession()->sendDataPacket($packet);
}
}

public function sendToPlayers(array $players, SendType $type): void {
Expand Down

0 comments on commit 0b3604e

Please sign in to comment.