当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityManager::createEntity方法代码示例

本文整理汇总了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);
     }
 }
开发者ID:MCPEGamerJPatGitHub,项目名称:MOBS,代码行数:35,代码来源:SpawnEntityTask.php


注:本文中的EntityManager::createEntity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。