本文整理汇总了PHP中pocketmine\level\Position::fromObject方法的典型用法代码示例。如果您正苦于以下问题:PHP Position::fromObject方法的具体用法?PHP Position::fromObject怎么用?PHP Position::fromObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\level\Position
的用法示例。
在下文中一共展示了Position::fromObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startDuel
/**
* Really starts the duel after countdown
*/
public function startDuel()
{
Server::getInstance()->getScheduler()->cancelTask($this->countdownTaskHandler->getTaskId());
$player1 = $this->players[0];
$player2 = $this->players[1];
$pos_player1 = Position::fromObject($this->position, $this->position->getLevel());
$pos_player1->x += self::PLAYER_1_OFFSET_X;
$pos_player2 = Position::fromObject($this->position, $this->position->getLevel());
$pos_player2->x += self::PLAYER_2_OFFSET_X;
$player1->teleport($pos_player1, 90, 0);
$player2->teleport($pos_player2, -90, 0);
$this->sparyParticle($player1);
$this->sparyParticle($player2);
$player1->setGamemode(0);
$player2->setGamemode(0);
// Give kit
foreach ($this->players as $player) {
$this->giveKit($player);
}
// Fix start time
$this->startTime = new DateTime('now');
$player1->sendTip(OneVsOne::getMessage("duel_tip"));
$player1->sendMessage(OneVsOne::getMessage("duel_start"));
$player2->sendTip(OneVsOne::getMessage("duel_tip"));
$player2->sendMessage(OneVsOne::getMessage("duel_start"));
// Launch the end round task
$task = new RoundCheckTask(OneVsOne::getInstance());
$task->arena = $this;
$this->taskHandler = Server::getInstance()->getScheduler()->scheduleDelayedTask($task, self::ROUND_DURATION * 20);
}
示例2: startDuel
/**
* Really starts the duel after countdown
*/
public function startDuel()
{
Server::getInstance()->getScheduler()->cancelTask($this->countdownTaskHandler->getTaskId());
$player1 = $this->players[0];
$player2 = $this->players[1];
$pos_player1 = Position::fromObject($this->position, $this->position->getLevel());
$pos_player1->x += self::PLAYER_1_OFFSET_X;
$pos_player2 = Position::fromObject($this->position, $this->position->getLevel());
$pos_player2->x += self::PLAYER_2_OFFSET_X;
$player1->teleport($pos_player1, 90, 0);
$player2->teleport($pos_player2, -90, 0);
// Fix start time
$this->startTime = new DateTime('now');
$player1->sendTip(TextFormat::RED . "You are strarting a duel !");
$player1->sendMessage(" ");
$player1->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
$player1->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You're starting a duel against : " . $player2->getName() . " !");
$player1->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You have 3min !");
$player1->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " Good luck :) !");
$player1->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
$player1->sendMessage(" ");
$player1->sendTip(TextFormat::RED . "You are strarting a duel !");
$player2->sendMessage(" ");
$player2->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
$player2->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You're starting a duel against : " . $player1->getName() . " !");
$player2->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " You have 3min !");
$player2->sendMessage(TextFormat::AQUA . ">" . TextFormat::RESET . " Good luck :) !");
$player2->sendMessage(TextFormat::RED . TextFormat::BOLD . "++++++++=++++++++");
$player2->sendMessage(" ");
// Launch the end round task
$task = new RoundCheckTask(OneVsOne::getInstance());
$task->arena = $this;
$this->taskHandler = Server::getInstance()->getScheduler()->scheduleDelayedTask($task, self::ROUND_DURATION * 20);
}
示例3: onRun
public function onRun($currentTicks)
{
/** @var EntityManager $owner */
$owner = $this->owner;
$rand = explode("/", $owner->getData("spawn.rand", "1/4"));
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::create($data["mob-list"][mt_rand(0, count($data["mob-list"]) - 1)], $pos);
}
if (!$owner->getData("autospawn.turn-on", true)) {
return;
}
foreach ($this->owner->getServer()->getOnlinePlayers() as $player) {
if (mt_rand(...$rand) > $rand[0]) {
continue;
}
$radius = (int) $owner->getData("autospawn.radius", 25);
$pos = $player->getPosition();
$pos->y = $player->level->getHighestBlockAt($pos->x += mt_rand(-$radius, $radius), $pos->z += mt_rand(-$radius, $radius)) + 2;
$ent = [["Cow", "Pig", "Sheep", "Chicken", "Slime", "Wolf", "Ocelot", "Rabbit"], ["Zombie", "Creeper", "Skeleton", "Spider", "PigZombie", "Enderman", "", ""]];
$entity = EntityManager::create($ent[mt_rand(0, 1)][mt_rand(0, 7)], $pos);
if ($entity != null) {
$entity->spawnToAll();
}
}
}
示例4: onRun
public function onRun(array $args, Player $player)
{
if (!isset($args[0])) {
return self::WRONG_USE;
}
$center = $player->floor();
$level = $player->getLevel();
$radius = floatval(array_shift($args));
$height = (int) array_shift($args);
$axis = WorldEditArt::directionNumber2Array($player->getDirection());
while (count($args) > 0) {
$arg = array_shift($args);
switch ($arg) {
case "a":
case "anchor":
$anchor = $this->getMain()->getAnchor($player);
if (!$anchor instanceof Position) {
return self::NO_ANCHOR;
}
$center = $anchor->floor();
break;
case "d":
$d = array_shift($args);
switch (strtolower($d)) {
case "m":
case "me":
break;
case "u":
case "up":
$axis = [CylinderSpace::Y, CylinderSpace::PLUS];
break;
case "d":
case "down":
$axis = [CylinderSpace::Y, CylinderSpace::MINUS];
break;
case "l":
case "left":
$axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 3));
break;
case "r":
case "right":
$axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 1));
break;
case "b":
case "back":
$axis = WorldEditArt::directionNumber2Array(WorldEditArt::rotateDirectionNumberClockwise($player->getDirection(), 2));
break;
}
break;
}
}
$center = Position::fromObject($center, $level);
$space = new CylinderSpace($axis[0], $radius, $center, $height * $axis[1]);
$this->getMain()->setSelection($player, $space);
return "Your selection is now {$space}.";
}
示例5: execute
public function execute(CommandSender $sender, $commandLabel, array $args)
{
$dist = 0;
if (count($args) === 0) {
$sender->sendMessage("Usage: /dtp [from] <to>[-<distance behind <to>>]");
return;
} elseif (count($args) === 1) {
if (!($from = $sender) instanceof Player) {
$sender->sendMessage("Please run this command in-game.");
return;
}
$toName = $args[0];
$pos = strpos($toName, "-");
if ($pos !== false) {
$dist = (int) substr($toName, $pos + 1);
$toName = substr($toName, 0, $pos);
}
$to = $sender->getServer()->getPlayer($toName);
if (!$to instanceof Player) {
$sender->sendMessage("{$toName} isn't online!");
return;
}
} else {
$from = $sender->getServer()->getPlayer($args[0]);
if (!$from instanceof Player) {
$sender->sendMessage("{$args['0']} isn't online!");
return;
}
$toName = $args[1];
$pos = strpos($toName, "-");
if ($pos !== false) {
$dist = (int) substr($toName, $pos + 1);
$toName = substr($toName, 0, $pos);
}
$to = $sender->getServer()->getPlayer($toName);
if (!$to instanceof Player) {
$sender->sendMessage("{$toName} isn't online!");
return;
}
}
$l = $to->getLevel();
$v3 = $to->subtract($to->getDirectionVector()->multiply($dist))->floor();
for ($i = $v3->y; $i < 128; $v3->y = ++$i) {
$b = $l->getBlock($v3);
$id = $b->getId();
if ($id === 0 or 8 <= $id and $id <= 11) {
break;
}
}
$from->teleport(Position::fromObject($v3, $l));
$from->sendMessage("Teleported to {$to->getName()}");
}
示例6: addEntry
/**
* @param Block $sourceBlock a Block with the absolute X, Y and Z from the original level
*/
public function addEntry(Block $sourceBlock)
{
if (!$this->isWritable) {
throw new \InvalidStateException("This clip is not writable");
}
if (!$sourceBlock->isValid()) {
throw new \InvalidArgumentException("Source block must contain a level and absolute coords");
}
if ($sourceBlock->getLevel()->getName() !== $this->levelName) {
throw new \InvalidStateException("Block is not from the level clip is being written in");
}
$delta = $sourceBlock->subtract($this->anchor);
$insert = Block::get($sourceBlock->getId(), $sourceBlock->getDamage(), Position::fromObject($delta->subtract($this->anchor)));
$this->entries[] = $insert;
}
示例7: __construct
public function __construct($axis, $radius, Position $base, $height)
{
$this->base = Position::fromObject($base->floor(), $base->getLevel());
$this->height = $height;
$this->radius = $radius;
$this->axis = $axis % 3;
if ($this->axis === self::Y) {
$y = [$this->base->getY(), $this->base->getY() + $height];
$maxY = max($y);
$minY = min($y);
} else {
$y = [$this->base->getY() + $radius, $this->base->getY() - $radius];
$maxY = max($y);
$minY = min($y);
}
$maxHeight = 127;
if (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT")) {
$maxHeight = constant($path);
}
if ($maxY > $maxHeight or $minY < 0) {
throw new SelectionExceedWorldException("CylinderSpace");
}
parent::__construct();
}
示例8: teleport
/**
* @param Vector3|Position|Location $pos
* @param float $yaw
* @param float $pitch
*
* @return bool
*/
public function teleport(Vector3 $pos, $yaw = \null, $pitch = \null)
{
if ($pos instanceof Location) {
$yaw = $yaw === \null ? $pos->yaw : $yaw;
$pitch = $pitch === \null ? $pos->pitch : $pitch;
}
$from = Position::fromObject($this, $this->level);
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
$this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to));
if ($ev->isCancelled()) {
return \false;
}
$this->ySize = 0;
$pos = $ev->getTo();
$this->setMotion(new Vector3(0, 0, 0));
if ($this->setPositionAndRotation($pos, $yaw === \null ? $this->yaw : $yaw, $pitch === \null ? $this->pitch : $pitch, \true) !== \false) {
$this->resetFallDistance();
$this->onGround = \true;
$this->lastX = $this->x;
$this->lastY = $this->y;
$this->lastZ = $this->z;
$this->lastYaw = $this->yaw;
$this->lastPitch = $this->pitch;
foreach ($this->hasSpawned as $player) {
$player->addEntityMovement($this->getId(), $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch, $this->yaw);
}
return \true;
}
return \false;
}
示例9: getSide
/**
* Returns a side Vector
*
* @param int $side
* @param int $step
*
* @return Position
*
* @throws LevelException
*/
public function getSide($side, $step = 1)
{
assert($this->isValid());
return Position::fromObject(parent::getSide($side, $step), $this->level);
}
示例10: onUpdate
public function onUpdate($type)
{
return false;
$newId = $this->id;
$level = $this->meta & 0x7;
if ($type !== Level::BLOCK_UPDATE_NORMAL) {
return false;
}
$this->checkLava();
$falling = $this->meta >> 3;
$down = $this->getSide(0);
$from = $this->getFrom();
//Has Source or Its Source
if ($from !== null || $level == 0x0) {
if ($level !== 0x7) {
if ($down instanceof Air || $down instanceof Water) {
$this->getLevel()->setBlock($down, new Water(0x1), false, false, true);
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($down, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
} else {
for ($side = 2; $side <= 5; ++$side) {
$b = $this->getSide($side);
if ($b instanceof Water) {
if ($this->getSourceCount() >= 2 && $level != 0x0) {
$this->getLevel()->setBlock($this, new Water(0), false, false, true);
}
} elseif ($b->isFlowable === true) {
$this->getLevel()->setBlock($b, new Water($level + 1), false, false, true);
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
}
}
}
} else {
//Extend Remove for Left Waters
for ($side = 2; $side <= 5; ++$side) {
$sb = $this->getSide($side);
if ($sb instanceof Water) {
$tlevel = $sb->meta & 0x7;
if ($tlevel != 0x0) {
for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s);
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
$this->getLevel()->setBlock($sb, new Air(), false, false, true);
}
}
$b = $this->getSide(0)->getSide($side);
if ($b instanceof Water) {
$tlevel = $b->meta & 0x7;
if ($tlevel != 0x0) {
for ($s = 0; $s <= 5; $s++) {
$ssb = $sb->getSide($s);
Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($ssb, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
$this->getLevel()->setBlock($b, new Air(), false, false, true);
}
}
//Server::getInstance()->api->block->scheduleBlockUpdate(Position::fromObject($b, $this->level), 10, Level::BLOCK_UPDATE_NORMAL);
}
$this->getLevel()->setBlock($this, new Air(), false, false, true);
}
return false;
}
示例11: getSpawnLocation
/**
* Returns a Position pointing to the spawn
*
* @return Position
*/
public function getSpawnLocation()
{
return Position::fromObject($this->provider->getSpawn(), $this);
}
示例12: onRun
public function onRun(array $args, Player $player)
{
$flag = 0;
// 0 for me, 1 for anchor, 2 for crosshair
if (isset($args[0])) {
$arg = array_shift($args);
switch ($arg) {
case "a":
case "anchor":
$flag = 1;
break;
case "c":
case "crosshair":
$flag = 2;
break;
}
}
$selected = $player->getPosition();
if ($flag === 1) {
$selected = $this->getMain()->getAnchor($player);
if (!$selected instanceof Position) {
return self::NO_ANCHOR;
}
}
if ($flag === 2) {
$selected = WorldEditArt::getCrosshairTarget($player);
if (!$selected instanceof Position) {
return "The block is too far/in the void/in the sky.";
}
}
if ($selected->y < 0 or $selected->y > (defined($path = "pemapmodder\\worldeditart\\MAX_WORLD_HEIGHT") ? constant($path) : 127)) {
return "The selected point is too high/too low.";
}
$selected->getLevel()->loadChunk($selected->x >> 4, $selected->z >> 4);
$selected = Position::fromObject($selected->floor(), $selected->getLevel());
$space = $this->getMain()->getSelection($player);
if ($space instanceof CuboidSpace and $space->getLevel() === $selected->getLevel()) {
if ($this->is2) {
$space->set1($selected);
} else {
$space->set0($selected);
}
goto end;
}
$temp = $this->getMain()->getTempPos($player);
if (is_array($temp) and $temp["#"] !== $this->is2) {
/** @var Position $pos */
$pos = $temp["position"];
if ($pos->getLevel() === $selected->getLevel()) {
if ($this->is2) {
$this->getMain()->setSelection($player, new CuboidSpace($pos, $selected));
} else {
$this->getMain()->setSelection($player, new CuboidSpace($selected, $pos));
}
goto end;
}
}
$this->getMain()->unsetSelection($player);
$this->getMain()->setTempPos($player, $selected, $this->is2);
end:
$space = $this->getMain()->getSelection($player);
if ($space instanceof Space) {
$cnt = count($space);
}
return ($this->is2 ? "Second" : "First") . " position set to " . "({$selected->x}, {$selected->y}, {$selected->z})." . (isset($cnt) ? "\n (Cuboid selected with {$cnt} blocks)" : "");
}
示例13: spawnPlayerToArena
/**
* Adds a player to an arena
* @param Player $player
*/
public function spawnPlayerToArena(Player $player)
{
if ($this->getPlayerArena($player) == null) {
foreach ($this->arenas as $arena) {
if (!$arena->inUse) {
if (count($arena->players) != $arena->capacity && count($arena->spawnpoints) >= count($arena->players)) {
foreach ($arena->spawnpoints as $spawn) {
//What the heck is this
if (!in_array($spawn, $arena->usedSpawnpoints)) {
$spawnString = json_encode($spawn);
$spawnArray = json_decode($spawnString, true);
$vector = new Vector3($spawnArray['x'], $spawnArray['y'], $spawnArray['z']);
$pos = Position::fromObject($vector, Server::getInstance()->getLevelByName($spawnArray['level']));
$player->teleport($pos);
$player->setGamemode(0);
array_push($arena->players, $player);
$arena->playerSpawns[$player->getName()] = $pos;
$arena->usedSpawnpoints[] = $spawn;
break 2;
}
}
}
}
}
}
}
示例14: teleport
public function teleport(Vector3 $pos, $yaw = null, $pitch = null)
{
$from = Position::fromObject($this, $this->getLevel());
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->getLevel());
$this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to));
if ($ev->isCancelled()) {
return false;
}
$this->ySize = 0;
$pos = $ev->getTo();
$this->setMotion(new Vector3(0, 0, 0));
if ($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false) {
$this->fallDistance = 0;
$this->onGround = true;
return true;
}
return false;
}
示例15: setHome
/**
* @param string $name
* @param Position $pos
*/
public function setHome($name = "default", Position $pos)
{
$this->homes[$name] = Position::fromObject($pos, $pos->getLevel());
$db = $this->getMain()->getFList()->getDb();
$op = $db->prepare("INSERT OR REPLACE INTO factions_homes (x, y, z, name, fid) VALUES (:x, :y, :z, :name, :id);");
$op->bindValue(":x", $pos->getX());
$op->bindValue(":y", $pos->getY());
$op->bindValue(":z", $pos->getZ());
$op->bindValue(":name", $name);
$op->bindValue(":id", $this->id);
$op->execute();
}