本文整理汇总了PHP中EntityManager::createEntity方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::createEntity方法的具体用法?PHP EntityManager::createEntity怎么用?PHP EntityManager::createEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::createEntity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onRun
public function onRun($currentTicks)
{
/** @var EntityManager $owner */
$owner = $this->owner;
if (count(MOBS::getEntities()) >= $owner->getData("entity.maximum")) {
return;
}
$rand = explode("/", $owner->getData("spawn.rand"));
foreach (EntityManager::$spawn as $key => $data) {
if (mt_rand(...$rand) > $rand[0]) {
continue;
}
if (count($data["mob-list"]) === 0) {
unset(EntityManager::$spawn[$key]);
continue;
}
$radius = (int) $data["radius"];
$pos = Position::fromObject(new Vector3(...$vec = explode(":", $key)), ($k = Server::getInstance()->getLevelByName((string) array_pop($vec))) == null ? Server::getInstance()->getDefaultLevel() : $k);
$pos->y = $pos->getLevel()->getHighestBlockAt($pos->x += mt_rand(-$radius, $radius), $pos->z += mt_rand(-$radius, $radius));
EntityManager::createEntity($data["mob-list"][mt_rand(0, count($data["mob-list"]) - 1)], $pos);
}
if (!$owner->getData("autospawn.turn-on")) {
return;
}
foreach ($this->owner->getServer()->getOnlinePlayers() as $player) {
if (mt_rand(...$rand) > $rand[0]) {
continue;
}
$radius = (int) $owner->getData("autospawn.radius");
$pos = $player->getPosition();
$pos->y = $player->level->getHighestBlockAt($pos->x += mt_rand(-$radius, $radius), $pos->z += mt_rand(-$radius, $radius));
$ent = [["Cow", "Pig", "Sheep", "Chicken", "Wolf", null], ["Zombie", "Creeper", "Skeleton", "Spider", "PigZombie", "Enderman"]];
EntityManager::createEntity($ent[mt_rand(0, 1)][mt_rand(0, 5)], $pos);
}
}