Inheritance: extends Creature, implements ProjectileSource, implements pocketmine\inventory\InventoryHolder
 /**
  * @param Vector3 $v
  * @param mixed $data
  * @param int $id
  * @param FullChunk $chunk
  */
 public function __construct($v, $data, $id = -2, $chunk = null)
 {
     $this->data = $data;
     if (!$v instanceof Vector3) {
         if ($v instanceof FullChunk) {
             $v->removeEntity($this);
         }
         throw new \RuntimeException("BadConstructCustomHuman");
     }
     $nbt = new Compound();
     $nbt->Pos = new Enum("Motion", [new Double(0, $v->x), new Double(1, $v->y), new Double(2, $v->z)]);
     $nbt->Motion = new Enum("Motion", [new Double(0, 0), new Double(1, 0), new Double(2, 0)]);
     $nbt->Rotation = new Enum("Rotation", [new Float(0, $this->getDefaultYaw()), new Float(1, $this->getDefaultPitch())]);
     $nbt->FallDistance = new Float("FallDistance", 0);
     $nbt->Fire = new Short("Fire", 0);
     $nbt->Air = new Short("Air", 0);
     $nbt->OnGround = new Byte("OnGround", 1);
     $nbt->Invulnerable = new Byte("Invulnerable", 1);
     $nbt->Health = new Short("Health", 20);
     $nbt->NameTag = $this->getDefaultName();
     $nbt->Inventory = new Enum("Inventory", []);
     $nbt->Inventory->setTagType(NBT::TAG_Compound);
     $this->inventory = new PlayerInventory($this);
     $this->setSkin($this->getDefaultSkin());
     parent::__construct($chunk, $nbt);
 }
Example #2
0
 /**
  * This method may not be reliable. Clients don't like to be moved into unloaded chunks.
  * Use teleport() for a delayed teleport after chunks have been sent.
  *
  * @param Vector3 $pos
  * @param float   $yaw
  * @param float   $pitch
  */
 public function teleportImmediate(Vector3 $pos, $yaw = null, $pitch = null)
 {
     if (parent::teleport($pos, $yaw, $pitch)) {
         foreach ($this->windowIndex as $window) {
             if ($window === $this->inventory) {
                 continue;
             }
             $this->removeWindow($window);
         }
         $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
         $this->sendPosition($this, $this->yaw, $this->pitch, 1);
         $this->resetFallDistance();
         $this->orderChunks();
         $this->nextChunkOrderRun = 0;
         $this->newPosition = null;
     }
 }
Example #3
0
 public function teleport(Vector3 $pos, $yaw = null, $pitch = null)
 {
     if (parent::teleport($pos, $yaw, $pitch)) {
         foreach ($this->windowIndex as $window) {
             if ($window === $this->inventory) {
                 continue;
             }
             $this->removeWindow($window);
         }
         $this->airTicks = 300;
         $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, 300);
         $pk = new MovePlayerPacket();
         $pk->eid = $this->getId();
         $pk->x = $this->x;
         $pk->y = $this->y + $this->getEyeHeight();
         $pk->z = $this->z;
         $pk->bodyYaw = 0;
         $pk->pitch = $this->pitch;
         $pk->yaw = $this->yaw;
         $pk->mode = 1;
         $pk->teleport = 1;
         $this->directDataPacket($pk);
         $this->resetFallDistance();
         $this->orderChunks();
         $this->nextChunkOrderRun = 0;
         $this->forceMovement = new Vector3($this->x, $this->y, $this->z);
         $this->newPosition = null;
     }
 }
Example #4
0
 public function kill()
 {
     parent::kill();
     $this->poofAway();
 }
Example #5
0
 public function knockBack(Entity $attacker, $damage, $x, $z, $base = 0.4)
 {
     $this->knockback = time() + 1;
     // Stunned for 1 second...
     parent::knockBack($attacker, $damage, 0.1, 0.1, 0.1);
 }
 public function setExp($exp)
 {
     $this->progress = $exp / Human::getLevelXpRequirement($this->level);
 }
Example #7
0
 public function teleport(Vector3 $pos, $yaw = null, $pitch = null)
 {
     if (!$this->isOnline()) {
         return;
     }
     $oldPos = $this->getPosition();
     if (parent::teleport($pos, $yaw, $pitch)) {
         foreach ($this->windowIndex as $window) {
             if ($window === $this->inventory) {
                 continue;
             }
             $this->removeWindow($window);
         }
         $this->teleportPosition = new Vector3($this->x, $this->y, $this->z);
         if (!$this->checkTeleportPosition()) {
             $this->forceMovement = $oldPos;
         } else {
             $this->spawnToAll();
         }
         $this->resetFallDistance();
         $this->nextChunkOrderRun = 0;
         $this->newPosition = null;
     }
 }
Example #8
0
 /**
  * Load skin
  * @param Human $human
  * @param bool $slim
  * @param str $fn
  * @return bool
  */
 public static function loadSkin(Human $human, $slim, $fn)
 {
     if (self::isPngExt($fn)) {
         if (!extension_loaded("gd")) {
             return false;
         }
         if (!self::isSkinFile($fn)) {
             return false;
         }
         $img = imagecreatefrompng($fn);
         if ($img === false) {
             return false;
         }
         $bytes = "";
         $x = $y = 0;
         while ($y < 32) {
             $rgb = imagecolorat($img, $x, $y);
             $r = $rgb >> 16 & 0xff;
             $g = $rgb >> 8 & 0xff;
             $b = $rgb & 0xff;
             $bytes .= chr($r) . chr($g) . chr($b) . chr(255);
             $x++;
             if ($x === 64) {
                 $x = 0;
                 $y++;
             }
         }
         imagedestroy($img);
         echo "BYTES=" . strlen($bytes) . "\n";
         //##DEBUG
         $human->setSkin($bytes, $slim);
         return true;
     }
     $bin = file_get_contents($fn);
     if ($bin === false) {
         return false;
     }
     $human->setSkin(zlib_decode($bin), $slim);
     return true;
 }
Example #9
0
 public function spawnTo(Player $player)
 {
     parent::spawnTo($player);
 }
 /**
  * Creates a new file containing skin data
  * @param Human $human
  */
 public static function toFile(Human $human)
 {
     @mkdir(SkinTools::getInstance()->getDataFolder() . "data/");
     file_put_contents(SkinTools::getInstance()->getDataFolder() . "data/" . strtolower($human->getName()) . ".dat", self::compress($human->getSkinData()));
 }
Example #11
0
 public function teleport(Vector3 $pos, $yaw = null, $pitch = null)
 {
     if (parent::teleport($pos, $yaw, $pitch)) {
         $this->airTicks = 300;
         $this->fallDistance = 0;
         $this->orderChunks();
         $this->chunkLoadTask->setNextRun(0);
         $this->forceMovement = $pos;
         $pk = new MovePlayerPacket();
         $pk->eid = 0;
         $pk->x = $this->x;
         $pk->y = $this->y + $this->getEyeHeight();
         $pk->z = $this->z;
         $pk->bodyYaw = $this->yaw;
         $pk->pitch = $this->pitch;
         $pk->yaw = $this->yaw;
         $pk->teleport = true;
         $this->directDataPacket($pk);
     }
 }
Example #12
0
 /**
  * @param Effect
  */
 public function addEffect(Effect $effect)
 {
     //Overwrite
     if ($effect->isBad() && $this->isCreative()) {
         return;
     }
     parent::addEffect($effect);
 }