Skip to content

Commit 8c3cf7a

Browse files
authored
Use VISIBLE_MOB_EFFECTS actor metadata property to send effect bubbles (#6414)
Close #6402
1 parent 3ed9615 commit 8c3cf7a

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"pocketmine/bedrock-block-upgrade-schema": "~4.2.0+bedrock-1.21.0",
3737
"pocketmine/bedrock-data": "~2.11.0+bedrock-1.21.0",
3838
"pocketmine/bedrock-item-upgrade-schema": "~1.10.0+bedrock-1.21.0",
39-
"pocketmine/bedrock-protocol": "~32.1.0+bedrock-1.21.2",
39+
"pocketmine/bedrock-protocol": "~32.2.0+bedrock-1.21.2",
4040
"pocketmine/binaryutils": "^0.2.1",
4141
"pocketmine/callback-validator": "^1.0.2",
4242
"pocketmine/color": "^0.3.0",

composer.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/entity/Living.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
use function ceil;
6969
use function count;
7070
use function floor;
71+
use function ksort;
7172
use function lcg_value;
7273
use function max;
7374
use function min;
@@ -76,6 +77,7 @@
7677
use function round;
7778
use function sqrt;
7879
use const M_PI;
80+
use const SORT_NUMERIC;
7981

8082
abstract class Living extends Entity{
8183
protected const DEFAULT_BREATH_TICKS = 300;
@@ -883,8 +885,30 @@ protected function sendSpawnPacket(Player $player) : void{
883885
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
884886
parent::syncNetworkData($properties);
885887

886-
$properties->setByte(EntityMetadataProperties::POTION_AMBIENT, $this->effectManager->hasOnlyAmbientEffects() ? 1 : 0);
887-
$properties->setInt(EntityMetadataProperties::POTION_COLOR, Binary::signInt($this->effectManager->getBubbleColor()->toARGB()));
888+
$visibleEffects = [];
889+
foreach ($this->effectManager->all() as $effect) {
890+
if (!$effect->isVisible() || !$effect->getType()->hasBubbles()) {
891+
continue;
892+
}
893+
$visibleEffects[EffectIdMap::getInstance()->toId($effect->getType())] = $effect->isAmbient();
894+
}
895+
896+
//TODO: HACK! the client may not be able to identify effects if they are not sorted.
897+
ksort($visibleEffects, SORT_NUMERIC);
898+
899+
$effectsData = 0;
900+
$packedEffectsCount = 0;
901+
foreach ($visibleEffects as $effectId => $isAmbient) {
902+
$effectsData = ($effectsData << 7) |
903+
(($effectId & 0x3f) << 1) | //Why not use 7 bits instead of only 6? mojang...
904+
($isAmbient ? 1 : 0);
905+
906+
if (++$packedEffectsCount >= 8) {
907+
break;
908+
}
909+
}
910+
$properties->setLong(EntityMetadataProperties::VISIBLE_MOB_EFFECTS, $effectsData);
911+
888912
$properties->setShort(EntityMetadataProperties::AIR, $this->breathTicks);
889913
$properties->setShort(EntityMetadataProperties::MAX_AIR, $this->maxBreathTicks);
890914

0 commit comments

Comments
 (0)