public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz) { $entity = null; $chunk = $level->getChunkAt($block->getX() >> 4, $block->getZ() >> 4); if (!$chunk instanceof FullChunk) { return false; } $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX()), new Double("", $block->getY()), new Double("", $block->getZ())]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]); switch ($this->meta) { case Villager::NETWORK_ID: $nbt->Health = new Short("Health", 20); $entity = new Villager($chunk, $nbt); break; case Zombie::NETWORK_ID: $nbt->Health = new Short("Health", 20); $entity = new Zombie($chunk, $nbt); break; /* //TODO: use entity constants case 10: case 11: case 12: case 13: $data = array( "x" => $block->x + 0.5, "y" => $block->y, "z" => $block->z + 0.5, ); //$e = Server::getInstance()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data); //Server::getInstance()->api->entity->spawnToAll($e); if(($player->gamemode & 0x01) === 0){ --$this->count; } return true;*/ } if ($entity instanceof Entity) { if (($player->gamemode & 0x1) === 0) { --$this->count; } $entity->spawnToAll(); return true; } return false; }
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; } } } } } } }
/** * @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 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; } } } } } } }