Skip to content

Commit

Permalink
Use VISIBLE_MOB_EFFECTS actor metadata property to send effect bubbles (
Browse files Browse the repository at this point in the history
#6414)

Close #6402
  • Loading branch information
IvanCraft623 authored Aug 15, 2024
1 parent 3ed9615 commit 8c3cf7a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions src/entity/Living.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 8c3cf7a

Please sign in to comment.