diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 027773493..4fbe939c0 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -2704,11 +2704,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ public function getData(){ //TODO $flags = 0; $flags |= $this->fireTicks > 0 ? 1 : 0; + $flags |= $this->hasEffect(Effect::INVISIBILITY) ? 1 << 5 : 0; //$flags |= ($this->crouched === true ? 0b10:0) << 1; $flags |= ($this->inAction === true ? 0b10000 : 0); $d = [ 0 => ["type" => 0, "value" => $flags], 1 => ["type" => 1, "value" => $this->airTicks], + 3 => ["type" => 0, "value" => $this->hasEffect(Effect::INVISIBILITY) ? 0 : 1], 16 => ["type" => 0, "value" => 0], 17 => ["type" => 6, "value" => [0, 0, 0]], ]; diff --git a/src/pocketmine/entity/Effect.php b/src/pocketmine/entity/Effect.php index adabdee78..1c78b553a 100644 --- a/src/pocketmine/entity/Effect.php +++ b/src/pocketmine/entity/Effect.php @@ -38,7 +38,7 @@ class Effect{ //TODO: const DAMAGE_RESISTANCE = 11; const FIRE_RESISTANCE = 12; //TODO: const WATER_BREATHING = 13; - //const INVISIBILITY = 14; + const INVISIBILITY = 14; //const BLINDNESS = 15; //const NIGHT_VISION = 16; //const HUNGER = 17; @@ -67,6 +67,7 @@ class Effect{ //self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "Damage Resistance"); self::$effects[Effect::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "Fire Resistance"); //self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "Water Breathing"); + self::$effects[Effect::INVISIBILITY] = new Effect(Effect::INVISIBILITY, "Invisibility"); //self::$effects[Effect::WEAKNESS] = new Effect(Effect::WEAKNESS, "Weakness", true); self::$effects[Effect::POISON] = new Effect(Effect::POISON, "Poison", true); self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "Wither", true); diff --git a/src/pocketmine/entity/Entity.php b/src/pocketmine/entity/Entity.php index 1ce1bfa34..f72339885 100644 --- a/src/pocketmine/entity/Entity.php +++ b/src/pocketmine/entity/Entity.php @@ -251,6 +251,11 @@ abstract class Entity extends Location implements Metadatable{ } unset($this->effects[$effectId]); + + $this->sendMetadata($this->hasSpawned); + if($this instanceof Player){ + $this->sendMetadata($this); + } } } @@ -277,6 +282,11 @@ abstract class Entity extends Location implements Metadatable{ } $this->effects[$effect->getId()] = $effect; + + $this->sendMetadata($this->hasSpawned); + if($this instanceof Player){ + $this->sendMetadata($this); + } } /** @@ -366,6 +376,17 @@ abstract class Entity extends Location implements Metadatable{ public function spawnTo(Player $player){ if(!isset($this->hasSpawned[$player->getId()]) and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){ $this->hasSpawned[$player->getId()] = $player; + foreach($this->effects as $effect){ + $pk = new MobEffectPacket(); + $pk->eid = $this->getId(); + $pk->effectId = $effect->getId(); + $pk->amplifier = $effect->getAmplifier(); + $pk->particles = $effect->isVisible(); + $pk->duration = $effect->getDuration(); + $pk->eventId = MobEffectPacket::EVENT_ADD; + + $player->dataPacket($pk); + } } } @@ -585,6 +606,10 @@ abstract class Entity extends Location implements Metadatable{ $effect->setDuration($effect->getDuration() - $tickDiff); if($effect->getDuration() <= 0){ $this->removeEffect($effect->getId()); + $this->sendMetadata($this->hasSpawned); + if($this instanceof Player){ + $this->sendMetadata($this); + } } } } diff --git a/src/pocketmine/entity/Human.php b/src/pocketmine/entity/Human.php index 64cfe7f51..c2e3bd6a0 100644 --- a/src/pocketmine/entity/Human.php +++ b/src/pocketmine/entity/Human.php @@ -189,11 +189,13 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{ public function getData(){ //TODO $flags = 0; $flags |= $this->fireTicks > 0 ? 1 : 0; + $flags |= $this->hasEffect(Effect::INVISIBILITY) ? 1 << 5 : 0; //$flags |= ($this->crouched === true ? 0b10:0) << 1; //$flags |= ($this->inAction === true ? 0b10000:0); $d = [ 0 => ["type" => 0, "value" => $flags], 1 => ["type" => 1, "value" => $this->airTicks], + 3 => ["type" => 0, "value" => $this->hasEffect(Effect::INVISIBILITY) ? 0 : 1], 16 => ["type" => 0, "value" => 0], 17 => ["type" => 6, "value" => [0, 0, 0]], ]; diff --git a/src/pocketmine/entity/Living.php b/src/pocketmine/entity/Living.php index c13aa9391..0370b0c0a 100644 --- a/src/pocketmine/entity/Living.php +++ b/src/pocketmine/entity/Living.php @@ -42,6 +42,8 @@ abstract class Living extends Entity implements Damageable{ protected $drag = 0.02; protected $attackTime = 0; + + protected $invisible = false; protected function initEntity(){ if(isset($this->namedtag->HealF)){