From 8c3cf7a6874953a871452d239e0b204ae950fbec Mon Sep 17 00:00:00 2001 From: IvanCraft623 <57236932+IvanCraft623@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:48:10 -0500 Subject: [PATCH] Use VISIBLE_MOB_EFFECTS actor metadata property to send effect bubbles (#6414) Close #6402 --- composer.json | 2 +- composer.lock | 12 ++++++------ src/entity/Living.php | 28 ++++++++++++++++++++++++++-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index 5c1282c45b6..21e3619a5e3 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,7 @@ "pocketmine/bedrock-block-upgrade-schema": "~4.2.0+bedrock-1.21.0", "pocketmine/bedrock-data": "~2.11.0+bedrock-1.21.0", "pocketmine/bedrock-item-upgrade-schema": "~1.10.0+bedrock-1.21.0", - "pocketmine/bedrock-protocol": "~32.1.0+bedrock-1.21.2", + "pocketmine/bedrock-protocol": "~32.2.0+bedrock-1.21.2", "pocketmine/binaryutils": "^0.2.1", "pocketmine/callback-validator": "^1.0.2", "pocketmine/color": "^0.3.0", diff --git a/composer.lock b/composer.lock index 128c28e6764..9d175040a50 100644 --- a/composer.lock +++ b/composer.lock @@ -205,16 +205,16 @@ }, { "name": "pocketmine/bedrock-protocol", - "version": "32.1.0+bedrock-1.21.2", + "version": "32.2.0+bedrock-1.21.2", "source": { "type": "git", "url": "https://github.com/pmmp/BedrockProtocol.git", - "reference": "bb23db51365bdc91d3135c3885986a691ae1cb44" + "reference": "229e5f3ae676a8601c576b7a57e56060b611d68d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/bb23db51365bdc91d3135c3885986a691ae1cb44", - "reference": "bb23db51365bdc91d3135c3885986a691ae1cb44", + "url": "https://api.github.com/repos/pmmp/BedrockProtocol/zipball/229e5f3ae676a8601c576b7a57e56060b611d68d", + "reference": "229e5f3ae676a8601c576b7a57e56060b611d68d", "shasum": "" }, "require": { @@ -245,9 +245,9 @@ "description": "An implementation of the Minecraft: Bedrock Edition protocol in PHP", "support": { "issues": "https://github.com/pmmp/BedrockProtocol/issues", - "source": "https://github.com/pmmp/BedrockProtocol/tree/32.1.0+bedrock-1.21.2" + "source": "https://github.com/pmmp/BedrockProtocol/tree/32.2.0+bedrock-1.21.2" }, - "time": "2024-07-10T01:38:43+00:00" + "time": "2024-08-10T19:23:18+00:00" }, { "name": "pocketmine/binaryutils", diff --git a/src/entity/Living.php b/src/entity/Living.php index b0d14957cbf..81f46424f17 100644 --- a/src/entity/Living.php +++ b/src/entity/Living.php @@ -68,6 +68,7 @@ use function ceil; use function count; use function floor; +use function ksort; use function lcg_value; use function max; use function min; @@ -76,6 +77,7 @@ use function round; use function sqrt; use const M_PI; +use const SORT_NUMERIC; abstract class Living extends Entity{ protected const DEFAULT_BREATH_TICKS = 300; @@ -883,8 +885,30 @@ protected function sendSpawnPacket(Player $player) : void{ protected function syncNetworkData(EntityMetadataCollection $properties) : void{ parent::syncNetworkData($properties); - $properties->setByte(EntityMetadataProperties::POTION_AMBIENT, $this->effectManager->hasOnlyAmbientEffects() ? 1 : 0); - $properties->setInt(EntityMetadataProperties::POTION_COLOR, Binary::signInt($this->effectManager->getBubbleColor()->toARGB())); + $visibleEffects = []; + foreach ($this->effectManager->all() as $effect) { + if (!$effect->isVisible() || !$effect->getType()->hasBubbles()) { + continue; + } + $visibleEffects[EffectIdMap::getInstance()->toId($effect->getType())] = $effect->isAmbient(); + } + + //TODO: HACK! the client may not be able to identify effects if they are not sorted. + ksort($visibleEffects, SORT_NUMERIC); + + $effectsData = 0; + $packedEffectsCount = 0; + foreach ($visibleEffects as $effectId => $isAmbient) { + $effectsData = ($effectsData << 7) | + (($effectId & 0x3f) << 1) | //Why not use 7 bits instead of only 6? mojang... + ($isAmbient ? 1 : 0); + + if (++$packedEffectsCount >= 8) { + break; + } + } + $properties->setLong(EntityMetadataProperties::VISIBLE_MOB_EFFECTS, $effectsData); + $properties->setShort(EntityMetadataProperties::AIR, $this->breathTicks); $properties->setShort(EntityMetadataProperties::MAX_AIR, $this->maxBreathTicks);