public static function dropExpOrb__api200(Position $source, $exp = 1, Vector3 $motion = \null, $delay = 40) { $motion = $motion === \null ? new Vector3(\lcg_value() * 0.2 - 0.1, 0.4, \lcg_value() * 0.2 - 0.1) : $motion; $entity = Entity::createEntity("ExperienceOrb", $source->getLevel()->getChunk($source->getX() >> 4, $source->getZ() >> 4, \true), new \pocketmine\nbt\tag\CompoundTag("", ["Pos" => new \pocketmine\nbt\tag\ListTag("Pos", [new \pocketmine\nbt\tag\DoubleTag("", $source->getX()), new \pocketmine\nbt\tag\DoubleTag("", $source->getY()), new \pocketmine\nbt\tag\DoubleTag("", $source->getZ())]), "Motion" => new \pocketmine\nbt\tag\ListTag("Motion", [new \pocketmine\nbt\tag\DoubleTag("", $motion->x), new \pocketmine\nbt\tag\DoubleTag("", $motion->y), new \pocketmine\nbt\tag\DoubleTag("", $motion->z)]), "Rotation" => new \pocketmine\nbt\tag\ListTag("Rotation", [new \pocketmine\nbt\tag\FloatTag("", \lcg_value() * 360), new \pocketmine\nbt\tag\FloatTag("", 0)]), "Health" => new \pocketmine\nbt\tag\ShortTag("Health", 20), "PickupDelay" => new \pocketmine\nbt\tag\ShortTag("PickupDelay", $delay)])); if ($entity instanceof ExperienceOrb) { $entity->setExp($exp); } $entity->spawnToAll(); }
public function setHome(IPlayer $player, Position $pos) { $n = strtolower($player->getName()); $l = "l-" . strtolower($pos->getLevel()->getName()); $this->homes[$l][$n] = [$pos->getX(), $pos->getY(), $pos->getZ()]; $this->saveHomes(); }
public function checkMove(Position $p) { if (!$this->cfg["mines"]) { return false; } $bl = []; for ($i = 1; $i < 4; $i++) { $bl[$i] = $p->getLevel()->getBlockIdAt($p->getX(), $p->getY() - $i, $p->getZ()); } for ($i = 1; $i < 3; $i++) { if ($bl[$i] == $this->mine["block1"]) { if (isset($this->mine["block2"]) && $this->mine["block2"] != $bl[$i + 1]) { continue; } // explode! $p->getLevel()->setBlockIdAt($p->getX(), $p->getY() - $i, $p->getZ(), 0); $this->scorchit(new Position($p->getX() + 0.5, $p->getY() - $i + 0.5, $p->getZ() + 0.5, $p->getLevel()), new Vector3(0, 0, 0), 1); return false; } } return false; }
/** * Teleport a player near a location * @param Player $player - player to be teleported * @param Position $target - location to teleport nearby * @param int $rand - how far to randomize positions * @param int|null $dist - if not null it will make sure that new location is upto $dist * @return bool - true on success, false on failure */ public static function tpNearBy(Player $player, Position $target, $rand = 3, $dist = null) { $mv = new Vector3($target->getX() + mt_rand(-$rand, $rand), $target->getY(), $target->getZ() + mt_rand(-$rand, $rand)); $pos = $target->getLevel()->getSafeSpawn($mv); if ($dist !== null) { $newdist = $pos->distance($target); if ($newdist > $dist) { return false; } // Will not get close enough! } $player->teleport($pos); return true; }
public function __construct(Position $a, Vector3 $b) { $this->raw0 = $a; if (!$b instanceof Position) { $b = new Position($b->getX(), $b->getY(), $b->getZ(), $a->getLevel()); } $this->raw1 = $b; if ($a->getLevel()->getName() !== $b->getLevel()->getName()) { trigger_error("Positions of different levels (\"" . $a->getLevel()->getName() . "\" and \"" . $b->getLevel()->getName() . "\" passed to constructor of " . get_class($this), E_USER_WARNING); } $this->bake(); parent::__construct(); // call this at the last because it has to bake before acquiring }
public function explode(Position $pos) { $aabb = new AxisAlignedBB($pos->getX() - self::RANGE, $pos->getY() - self::RANGE, $pos->getZ() - self::RANGE, $pos->getX() + self::RANGE, $pos->getY() + self::RANGE, $pos->getZ() + self::RANGE); $nearbyEntities = $this->getPlayer()->getLevel()->getNearbyEntities($aabb, null); $pk = new ExplodePacket(); $pk->x = $pos->x; $pk->y = $pos->y; $pk->z = $pos->z; $pk->radius = 10; $pk->records = [new Vector3($pos->x, $pos->y, $pos->z)]; Server::broadcastPacket($this->getPlayer()->getLevel()->getChunkPlayers($pos->x >> 4, $pos->z >> 4), $pk->setChannel(Network::CHANNEL_BLOCKS)); foreach ($nearbyEntities as $entity) { if (!$entity instanceof Player) { continue; } if ($this->getPlugin()->isEnemy($this->getPlayer()->getName(), $entity->getName())) { $event = new EntityDamageByEntityEvent($this->getPlayer(), $entity, 16, 15); $entity->attack($event->getFinalDamage(), $event); } } for ($i = 0; $i < 100; $i++) { $this->getPlayer()->getLevel()->addParticle(new CriticalParticle(new Vector3($pos->x + mt_rand(-self::RANGE, self::RANGE), $pos->y + mt_rand(-self::RANGE, self::RANGE), $pos->z + mt_rand(-self::RANGE, self::RANGE)))); } }
public function isInside(Vector3 $v) { $out = true; switch ($this->axis) { case self::X: $out = ($out and $this->base->getX() <= $v->getX() and $v->getX() <= $this->base->getX() + $this->height); $out = ($out and $v->distance(new Vector3($v->getX(), $this->base->getY(), $this->base->getZ())) <= $this->radius); break; case self::Y: $out = ($out and $this->base->getY() <= $v->getY() and $v->getY() <= $this->base->getY() + $this->height); $out = ($out and $v->distance(new Vector3($this->base->getX(), $v->getY(), $this->base->getZ())) <= $this->radius); break; case self::Z: $out = ($out and $this->base->getZ() <= $v->getZ() and $v->getZ() <= $this->base->getZ() + $this->height); $out = ($out and $v->distance(new Vector3($this->base->getX(), $this->base->getY(), $v->getZ())) <= $this->radius); break; } if ($v instanceof Position) { $out = ($out and $v->getLevel()->getName() === $this->base->getLevel()->getName()); } return $out; }
public function getLocationByPosition(Position $pos) { return $pos->getLevel()->getFolderName() . ";" . $pos->getX() . ";" . $pos->getY() . ";" . $pos->getZ(); }
public function setSpawnPoint(Position $pos) { $this->plugin->warDB["spawn"]["red-team"]["pos"] = (int) $pos->getX() . "." . (int) $pos->getY() . "." . (int) $pos->getZ(); $this->plugin->warDB["spawn"]["red-team"]["level"] = $pos->getLevel()->getName(); }
public function setLobby(Position $pos) { $this->plugin->warDB["spawn"]["lobby"]["pos"] = (int) $pos->getX() . "." . (int) $pos->getY() . "." . (int) $pos->getZ(); $this->plugin->warDB["spawn"]["lobby"]["level"] = $pos->getLevel()->getName(); }
public function onBreak(BlockBreakEvent $event) { if ($this->active == false and isset($this->players[$event->getPlayer()->getName()])) { $event->setCancelled(); } if (isset($this->players[$event->getPlayer()->getName()])) { if ($event->getBlock()->getID() != $this->plugin->getConfig()->get("surface")) { $event->setCancelled(); } else { if ($this->active == true) { $block = $event->getBlock(); $event->setInstaBreak(true); $block = new Position($block->getX(), $block->getY(), $block->getZ(), $block->getLevel()); $this->broken[] = $block; } } } }
public function areaPosCast(Position $pos1, Position $pos2) { $startX = (int) $pos1->getX(); $startZ = (int) $pos1->getZ(); $endX = (int) $pos2->getX(); $endZ = (int) $pos2->getZ(); if ($startX > $endX) { $backup = $startX; $startX = $endX; $endX = $backup; } if ($startZ > $endZ) { $backup = $startZ; $startZ = $endZ; $endZ = $backup; } return [$startX, $endX, $startZ, $endZ]; }
protected function writePosition(Position $pos) { $this->buffer .= Bin::writeInt($pos->getX() >> 4); $this->buffer .= Bin::writeInt($pos->getZ() >> 4); $this->buffer .= Bin::writeByte(($pos->getX() & 0xf) << 4 & ($pos->getZ() & 0xf)); $this->buffer .= Bin::writeByte(strlen($pos->getLevel()->getName())); $this->buffer .= $pos->getLevel()->getName(); }
/** * @param Position $pos * @return static */ public static function fromObject(Position $pos) { return new self($pos->getX() >> 4, $pos->getZ() >> 4, $pos->getLevel()); // don't refer to the object directly, else clone it }
public function snowShoot(Position $pos) { $player = Entity::Human; $nbt = new Compound("", [new Enum("Pos", [new Double("", $pos->getX()), new Double("", $pos->getY()), new Double("", $pos->getZ())]), new Enum("Motion", [new Double("", 0.0), new Double("", 1.0), new Double("", 0.0)])]); $snow = Entity::createEntity('Snowball', $pos->getLevel()->getChunk($pos->getX() >> 4, $pos->getY() >> 4, $pos->getZ() >> 4, $nbt)); $snow->spawnToAll(); $snow->canCollideWith($player); return $snow->getId(); }
public function insideLevelEntracePortal($pos) { $p1 = new Position($this->portalEnterPos1->x, $this->portalEnterPos1->y, $this->portalEnterPos1->z); $p2 = new Position($this->portalEnterPos2->x, $this->portalEnterPos2->y + 1, $this->portalEnterPos2->z); if (min($p1->getX(), $p2->getX()) <= $pos->getX() && max($p1->getX(), $p2->getX()) >= $pos->getX() && min($p1->getY(), $p2->getY()) <= $pos->getY() && max($p1->getY(), $p2->getY()) >= $pos->getY() && min($p1->getZ(), $p2->getZ()) <= $pos->getZ() && max($p1->getZ(), $p2->getZ()) >= $pos->getZ()) { return true; } else { return false; } }
/** * Creates a new spawnpoint at a position * @param Position $position * @param $id */ public function addSpawnpoint(Position $position, Player $sender, $id) { //create an array for the spawnpoint $spawnpoint = array('x' => $position->getX(), 'y' => $position->getY(), 'z' => $position->getZ(), 'level' => $position->getLevel()->getName()); for ($i = 0; $i < count($this->config->arenas); $i++) { $arenas = $this->config->arenas; $arena = $arenas[$i]; if ($arena['id'] == $id) { $arena['spawnpoints'][] = $spawnpoint; PluginUtils::consoleLog(json_encode($arena['spawnpoints'])); //debug $arenas[$i] = $arena; $this->config->set('arenas', $arenas); $this->config->save(); $sender->sendMessage(TextFormat::DARK_BLUE . "[HungerGames]" . TextFormat::WHITE . " Spawn added!"); $arenaSet = true; } } if (!isset($arenaSet)) { $sender->sendMessage(TextFormat::DARK_BLUE . "[HungerGames]" . TextFormat::WHITE . " This arena id does not exist"); } }
private function getPos(Position $pos) { $pos->x = (int) $pos->getX(); $pos->y = (int) $pos->getY(); $pos->z = (int) $pos->getZ(); return $pos; }
public function placeJail(Position $pos, $type = "default", $key = null) { $blocks = $this->getJailBlocks($type); if ($blocks !== false) { $x = (int) $pos->getX(); $y = (int) $pos->getY(); $z = (int) $pos->getZ(); $level = $pos->getLevel(); $log = array($level); foreach ($blocks as $data) { //data[0] x座標, data[1] y座標, data[2] z座標, data[3] blockid, data[4] meta値 $pos = new Vector3($x + $data[0], $y + $data[1], $z + $data[2]); $block = Block::get($data[3], $data[4]); if ($key !== null) { $log[] = array($pos, $level->getBlock($pos)); } $level->setBlock($pos, $block); } if ($key !== null) { $this->logs[$key][] = $log; } return true; } return false; }
public function setWarp($name, Position $pos) { $n = strtolower($name); if ($n == "version") { return false; } $this->warps[$n] = [$pos->getX(), $pos->getY(), $pos->getZ(), $pos->getLevel()->getName()]; return $this->saveWarps(); }
/** * @param Position $p * @param $cmd * @return Block */ public function addBlock(Position $p, $cmd) { $block = new Block(new Position($p->getX(), $p->getY(), $p->getZ(), $p->getLevel()), [$cmd], $this, count($this->config->get("blocks"))); $this->saveBlock($block); $this->config->save(); return $block; }
/** * Create a warp or override its position * * @param string $warp * @param Position $pos * @param int $yaw * @param int $pitch * @return bool */ public function setWarp($warp, Position $pos, $yaw = 0, $pitch = 0) { if (!$this->validateName($warp, false)) { return false; } if ($pos instanceof Location) { $yaw = $pos->getYaw(); $pitch = $pos->getPitch(); } $this->warps[$warp] = new BaseLocation($warp, $pos->getX(), $pos->getY(), $pos->getZ(), $pos->getLevel(), $yaw, $pitch); return true; }
public function calculateVector(Vector3 $vector, Position $position, $maxStep, $size, $yOffset) { $motionX = $vector->getX(); $motionY = $vector->getY(); $motionZ = $vector->getZ(); $x = $position->getX(); $y = $position->getY() + $yOffset; $z = $position->getZ(); $return = ["stack" => array(), "final" => null]; $return["stack"] = array(); for ($i = 0; $i < $maxStep; $i++) { $x += $motionX; $y += $motionY; $z += $motionZ; $aabb = new AxisAlignedBB($x - $size, $y - $size, $z - $size, $x + $size, $y + $size, $z + $size); $currentPos = new Position($x, $y, $z, $position->getLevel()); array_push($return["stack"], $currentPos); $collidingEntities = $position->getLevel()->getCollidingEntities($aabb); foreach ($collidingEntities as $entity) { if ($entity instanceof Player && $this->getPlugin()->isEnemy($this->player->getName(), $entity->getName())) { $return["final"] = $currentPos; $this->processBazookaShoot($return); return; } } $block = $position->getLevel()->getBlock($currentPos); if ($block->getId() !== 0 || $y < 0) { $return["final"] = $currentPos; $this->processBazookaShoot($return); return; } } $this->processBazookaShoot(null); }