public function getZombie(Position $pos, $maxHealth = 20, $health = 20) { $chunk = $pos->level->getChunk($pos->x >> 4, $pos->z >> 4, false); $nbt = $this->getNBT(); $zo = new Zombie($chunk, $nbt); $zo->setPosition($pos); $zo->setMaxHealth($maxHealth); $zo->setHealth($health); return $zo; }
/** * @param Position $pos 出生位置坐标(世界) * @param int $maxHealth 最高血量 * @param int $health 血量 * 出生一只僵尸在某坐标 */ public function spawnZombie(Position $pos, $maxHealth = 20, $health = 20) { $chunk = $pos->level->getChunk($pos->x >> 4, $pos->z >> 4, false); $nbt = $this->getNBT(); $zo = new Zombie($chunk, $nbt); $zo->setPosition($pos); $zo->setMaxHealth($maxHealth); $zo->setHealth($health); $zo->spawnToAll(); //$this->getLogger()->info("生成了一只僵尸"); }
public function SpecialMobGenerate() { foreach ($this->getServer()->getOnlinePlayers() as $p) { $level = $p->getLevel(); //if ($level->getTime() >= 13500) {//是夜晚\ if ($level->getTime() >= 14000) { //是夜晚 if ($this->smobbirth_A >= $this->smob_A) { $this->smob_A = $this->smob_A + 1; $v3 = new Vector3($p->getX() + mt_rand(-$this->birth_r, $this->birth_r), $p->getY(), $p->getZ() + mt_rand(-$this->birth_r, $this->birth_r)); for ($y0 = $p->getY() - 10; $y0 <= $p->getY() + 10; $y0++) { $v3->y = $y0; if ($this->whatBlock($level, $v3) == "block") { $v3_1 = $v3; $v3_1->y = $y0 + 1; $v3_2 = $v3; $v3_2->y = $y0 + 2; if ($level->getBlock($v3_1)->getID() == 0 and $level->getBlock($v3_2)->getID() == 0) { //$this->getLogger()->info("地面OK"); //找到地面 //$this->getLogger()->info("亮度".$this->getLight($level,$v3)); if ($this->getLight($level, $v3) < 20) { //$this->getLogger()->info("亮度OK".$this->getLight($level,$v3)); $chunk = $level->getChunk($v3->x >> 4, $v3->z >> 4, false); $nbt = $this->getNBT($v3); $zo = new Zombie($chunk, $nbt); $zo->setPosition($v3); $zo->spawnToAll(); $zo->sethealth(20); $type = $this->specialMobtype[array_rand($this->specialMobtype)]; $pk2 = new RemoveEntityPacket(); $pk2->eid = $zo->getId(); $pk3 = new AddEntityPacket(); $pk3->eid = $zo->getId(); $pk3->type = $type; $pk3->x = $zo->getX(); $pk3->y = $zo->getY(); $pk3->z = $zo->getZ(); $pk3->pitch = $zo->pitch; $pk3->yaw = $zo->yaw; $pk3->metadata = []; foreach ($this->getServer()->getOnlinePlayers() as $p) { $p->dataPacket($pk2); $p->dataPacket($pk3); } //var_dump($type); //$this->getLogger()->info("生成了一只"); //var_dump($zo->getId()); if (!isset($this->animals[$zo->getId()])) { $this->addanimal($zo->getId(), $type, $zo->yaw, $zo->getLevel()->getName(), $zo->getX(), $zo->getY(), $zo->getZ()); //$this->getLogger()->info("加入成功"); } } break; } } } } } } }
public function ZombieGenerate() { //僵尸生成 foreach ($this->getServer()->getOnlinePlayers() as $p) { //$this->getLogger()->info("开始生成僵尸"); $level = $p->getLevel(); if ($level->getTime() >= 14000) { //是夜晚 $v3 = new Vector3($p->getX() + mt_rand(-$this->birth_r, $this->birth_r), $p->getY(), $p->getZ() + mt_rand(-$this->birth_r, $this->birth_r)); for ($y0 = $p->getY() - 10; $y0 <= $p->getY() + 10; $y0++) { $v3->y = $y0; if ($level->getBlock($v3)->getID() != 0) { $v3_1 = $v3; $v3_1->y = $y0 + 1; $v3_2 = $v3; $v3_2->y = $y0 + 2; if ($level->getBlock($v3_1)->getID() == 0 and $level->getBlock($v3_2)->getID() == 0) { //找到地面 if ($this->getLight($level, $v3) == 0) { $chunk = $level->getChunk($v3->x >> 4, $v3->z >> 4, false); $nbt = $this->getNBT($v3); $zo = new Zombie($chunk, $nbt); $zo->setPosition($v3); $zo->spawnToAll(); //$zo = Entity::createEntity("Zombie", $level->getChunk($v3->x >> 4, $v3->z >> 4, false), $nbt, $level); //$zo->spawnToAll(); //$this->getLogger()->info("生成了一只僵尸"); break; } } } } } } }