Added invisibility potion, metadata sending for invisibility/nametags

This commit is contained in:
Shoghi Cervantes 2015-03-16 19:01:25 +01:00
parent 29ca349b3d
commit bc31df37d0
5 changed files with 33 additions and 1 deletions

View File

@ -2704,11 +2704,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
public function getData(){ //TODO public function getData(){ //TODO
$flags = 0; $flags = 0;
$flags |= $this->fireTicks > 0 ? 1 : 0; $flags |= $this->fireTicks > 0 ? 1 : 0;
$flags |= $this->hasEffect(Effect::INVISIBILITY) ? 1 << 5 : 0;
//$flags |= ($this->crouched === true ? 0b10:0) << 1; //$flags |= ($this->crouched === true ? 0b10:0) << 1;
$flags |= ($this->inAction === true ? 0b10000 : 0); $flags |= ($this->inAction === true ? 0b10000 : 0);
$d = [ $d = [
0 => ["type" => 0, "value" => $flags], 0 => ["type" => 0, "value" => $flags],
1 => ["type" => 1, "value" => $this->airTicks], 1 => ["type" => 1, "value" => $this->airTicks],
3 => ["type" => 0, "value" => $this->hasEffect(Effect::INVISIBILITY) ? 0 : 1],
16 => ["type" => 0, "value" => 0], 16 => ["type" => 0, "value" => 0],
17 => ["type" => 6, "value" => [0, 0, 0]], 17 => ["type" => 6, "value" => [0, 0, 0]],
]; ];

View File

@ -38,7 +38,7 @@ class Effect{
//TODO: const DAMAGE_RESISTANCE = 11; //TODO: const DAMAGE_RESISTANCE = 11;
const FIRE_RESISTANCE = 12; const FIRE_RESISTANCE = 12;
//TODO: const WATER_BREATHING = 13; //TODO: const WATER_BREATHING = 13;
//const INVISIBILITY = 14; const INVISIBILITY = 14;
//const BLINDNESS = 15; //const BLINDNESS = 15;
//const NIGHT_VISION = 16; //const NIGHT_VISION = 16;
//const HUNGER = 17; //const HUNGER = 17;
@ -67,6 +67,7 @@ class Effect{
//self::$effects[Effect::DAMAGE_RESISTANCE] = new Effect(Effect::DAMAGE_RESISTANCE, "Damage Resistance"); //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::FIRE_RESISTANCE] = new Effect(Effect::FIRE_RESISTANCE, "Fire Resistance");
//self::$effects[Effect::WATER_BREATHING] = new Effect(Effect::WATER_BREATHING, "Water Breathing"); //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::WEAKNESS] = new Effect(Effect::WEAKNESS, "Weakness", true);
self::$effects[Effect::POISON] = new Effect(Effect::POISON, "Poison", true); self::$effects[Effect::POISON] = new Effect(Effect::POISON, "Poison", true);
self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "Wither", true); self::$effects[Effect::WITHER] = new Effect(Effect::WITHER, "Wither", true);

View File

@ -251,6 +251,11 @@ abstract class Entity extends Location implements Metadatable{
} }
unset($this->effects[$effectId]); 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->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){ public function spawnTo(Player $player){
if(!isset($this->hasSpawned[$player->getId()]) and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){ if(!isset($this->hasSpawned[$player->getId()]) and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])){
$this->hasSpawned[$player->getId()] = $player; $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); $effect->setDuration($effect->getDuration() - $tickDiff);
if($effect->getDuration() <= 0){ if($effect->getDuration() <= 0){
$this->removeEffect($effect->getId()); $this->removeEffect($effect->getId());
$this->sendMetadata($this->hasSpawned);
if($this instanceof Player){
$this->sendMetadata($this);
}
} }
} }
} }

View File

@ -189,11 +189,13 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public function getData(){ //TODO public function getData(){ //TODO
$flags = 0; $flags = 0;
$flags |= $this->fireTicks > 0 ? 1 : 0; $flags |= $this->fireTicks > 0 ? 1 : 0;
$flags |= $this->hasEffect(Effect::INVISIBILITY) ? 1 << 5 : 0;
//$flags |= ($this->crouched === true ? 0b10:0) << 1; //$flags |= ($this->crouched === true ? 0b10:0) << 1;
//$flags |= ($this->inAction === true ? 0b10000:0); //$flags |= ($this->inAction === true ? 0b10000:0);
$d = [ $d = [
0 => ["type" => 0, "value" => $flags], 0 => ["type" => 0, "value" => $flags],
1 => ["type" => 1, "value" => $this->airTicks], 1 => ["type" => 1, "value" => $this->airTicks],
3 => ["type" => 0, "value" => $this->hasEffect(Effect::INVISIBILITY) ? 0 : 1],
16 => ["type" => 0, "value" => 0], 16 => ["type" => 0, "value" => 0],
17 => ["type" => 6, "value" => [0, 0, 0]], 17 => ["type" => 6, "value" => [0, 0, 0]],
]; ];

View File

@ -43,6 +43,8 @@ abstract class Living extends Entity implements Damageable{
protected $attackTime = 0; protected $attackTime = 0;
protected $invisible = false;
protected function initEntity(){ protected function initEntity(){
if(isset($this->namedtag->HealF)){ if(isset($this->namedtag->HealF)){
$this->namedtag->Health = new Short("Health", (int) $this->namedtag["HealF"]); $this->namedtag->Health = new Short("Health", (int) $this->namedtag["HealF"]);