|
68 | 68 | use function ceil;
|
69 | 69 | use function count;
|
70 | 70 | use function floor;
|
| 71 | +use function ksort; |
71 | 72 | use function lcg_value;
|
72 | 73 | use function max;
|
73 | 74 | use function min;
|
|
76 | 77 | use function round;
|
77 | 78 | use function sqrt;
|
78 | 79 | use const M_PI;
|
| 80 | +use const SORT_NUMERIC; |
79 | 81 |
|
80 | 82 | abstract class Living extends Entity{
|
81 | 83 | protected const DEFAULT_BREATH_TICKS = 300;
|
@@ -883,8 +885,30 @@ protected function sendSpawnPacket(Player $player) : void{
|
883 | 885 | protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
884 | 886 | parent::syncNetworkData($properties);
|
885 | 887 |
|
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 | + |
888 | 912 | $properties->setShort(EntityMetadataProperties::AIR, $this->breathTicks);
|
889 | 913 | $properties->setShort(EntityMetadataProperties::MAX_AIR, $this->maxBreathTicks);
|
890 | 914 |
|
|
0 commit comments