本文整理汇总了PHP中pocketmine\level\Level::chunkHash方法的典型用法代码示例。如果您正苦于以下问题:PHP Level::chunkHash方法的具体用法?PHP Level::chunkHash怎么用?PHP Level::chunkHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\level\Level
的用法示例。
在下文中一共展示了Level::chunkHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onUnloadChunk
public function onUnloadChunk(ChunkUnloadEvent $event)
{
if ($event->getLevel()->getName() !== "world_pvp") {
return;
}
$chunk = $event->getChunk();
$hash = Level::chunkHash($chunk->getX(), $chunk->getZ());
if (isset($this->modelLocs[$hash])) {
foreach ($this->modelLocs[$hash] as $id => $model) {
if (isset($this->models[$id])) {
$this->models[$id]->_kill();
unset($this->models[$id]);
}
}
}
if (isset($this->shopLocs[$hash])) {
foreach ($this->shopLocs[$hash] as $col => $loc) {
if (isset($this->shops[$col])) {
$this->shops[$col]->_kill();
unset($this->shops[$col]);
}
}
}
if ($hash === $this->bowHash) {
$this->bow->_kill();
$this->bow = null;
}
}
示例2: onUnload
public function onUnload(ChunkUnloadEvent $event)
{
if ($event->getLevel() === $this->level) {
foreach ($this->locs[Level::chunkHash($event->getChunk()->getX(), $event->getChunk()->getZ())] as $id => $spawn) {
if (isset($this->spawns[$spawn->getId()])) {
$this->level->removeEntity($this->spawns[$spawn->getId()]);
}
}
}
}
示例3: resetMine
public function resetMine()
{
$chunks = [];
for ($x = $this->getA()->getX(); $x - 16 <= $this->getB()->getX(); $x += 16) {
for ($z = $this->getA()->getZ(); $z - 16 <= $this->getB()->getZ(); $z += 16) {
//$this->getLevel()->getServer()->getLogger()->info(Level::chunkHash($x >> 4, $z >> 4));
$chunk = $this->level->getChunk($x >> 4, $z >> 4, true);
$chunkClass = get_class($chunk);
$chunks[Level::chunkHash($x >> 4, $z >> 4)] = $chunk->toBinary();
}
}
//var_dump($chunks);
$resetTask = new MineResetTask($chunks, $this->a, $this->b, $this->data, $this->getLevel()->getId(), $this->base->getRegionBlocker()->blockZone($this->a, $this->b, $this->level), $chunkClass);
$this->base->scheduleReset($resetTask);
}
示例4: spawnTo
public function spawnTo(Player $player)
{
if (!isset($this->hasSpawned[$player->getLoaderId()]) && isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])) {
$pk = new AddEntityPacket();
$pk->eid = $this->getID();
$pk->type = static::NETWORK_ID;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->speedX = 0;
$pk->speedY = 0;
$pk->speedZ = 0;
$pk->yaw = $this->yaw;
$pk->pitch = $this->pitch;
$pk->metadata = $this->dataProperties;
$player->dataPacket($pk);
$this->hasSpawned[$player->getLoaderId()] = $player;
}
}
示例5: onRun
/**
* Actions to execute when run
*
* @return void
*/
public function onRun()
{
$chunkClass = $this->chunkClass;
/** @var Chunk[] $chunks */
$chunks = unserialize($this->chunks);
foreach ($chunks as $hash => $binary) {
$chunks[$hash] = $chunkClass::fromBinary($binary);
}
$sum = [];
$id = array_keys(unserialize($this->ratioData));
for ($i = 0; $i < count($id); $i++) {
$blockId = explode(":", $id[$i]);
if (!isset($blockId[1])) {
$blockId[1] = 0;
}
$id[$i] = $blockId;
}
$m = array_values(unserialize($this->ratioData));
$sum[0] = $m[0];
for ($l = 1; $l < count($m); $l++) {
$sum[$l] = $sum[$l - 1] + $m[$l];
}
for ($x = $this->a->getX(); $x <= $this->b->getX(); $x++) {
for ($y = $this->a->getY(); $y <= $this->b->getY(); $y++) {
for ($z = $this->a->getZ(); $z <= $this->b->getZ(); $z++) {
$a = rand(0, end($sum));
for ($l = 0; $l < count($sum); $l++) {
if ($a <= $sum[$l]) {
$hash = Level::chunkHash($x >> 4, $z >> 4);
if (isset($chunks[$hash])) {
$chunks[$hash]->setBlock($x & 0xf, $y & 0x7f, $z & 0xf, $id[$l][0] & 0xff, $id[$l][1] & 0xff);
}
$l = count($sum);
}
}
}
}
}
$this->setResult($chunks);
}
示例6: generateLevel
/**
* Generates a new level if it does not exists
*
* @param string $name
* @param int $seed
* @param string $generator Class name that extends pocketmine\level\generator\Generator
* @param array $options
*
* @return bool
*/
public function generateLevel($name, $seed = null, $generator = null, $options = [])
{
if (trim($name) === "" or $this->isLevelGenerated($name)) {
return false;
}
$seed = $seed === null ? Binary::readInt(@Utils::getRandomBytes(4, false)) : (int) $seed;
if ($generator !== null and class_exists($generator) and is_subclass_of($generator, Generator::class)) {
$generator = new $generator($options);
} else {
$options["preset"] = $this->getConfigString("generator-settings", "");
$generator = Generator::getGenerator($this->getLevelType());
}
if (($provider = LevelProviderManager::getProviderByName($providerName = $this->getProperty("level-settings.default-format", "mcregion"))) === null) {
$provider = LevelProviderManager::getProviderByName($providerName = "mcregion");
}
try {
$path = $this->getDataPath() . "worlds/" . $name . "/";
/** @var \pocketmine\level\format\LevelProvider $provider */
$provider::generate($path, $name, $seed, $generator, $options);
$level = new Level($this, $name, $path, $provider);
$this->levels[$level->getId()] = $level;
$level->initLevel();
} catch (\Exception $e) {
$this->logger->error("Could not generate level \"" . $name . "\": " . $e->getMessage());
if ($this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
return false;
}
$this->getPluginManager()->callEvent(new LevelInitEvent($level));
$this->getPluginManager()->callEvent(new LevelLoadEvent($level));
$this->getLogger()->notice("Spawn terrain for level \"{$name}\" is being generated in the background");
$radiusSquared = ($this->getViewDistance() + 1) / M_PI;
$radius = ceil(sqrt($radiusSquared));
$centerX = $level->getSpawnLocation()->getX() >> 4;
$centerZ = $level->getSpawnLocation()->getZ() >> 4;
$order = [];
for ($X = -$radius; $X <= $radius; ++$X) {
for ($Z = -$radius; $Z <= $radius; ++$Z) {
$distance = $X ** 2 + $Z ** 2;
if ($distance > $radiusSquared) {
continue;
}
$chunkX = $X + $centerX;
$chunkZ = $Z + $centerZ;
$index = Level::chunkHash($chunkX, $chunkZ);
$order[$index] = $distance;
}
}
asort($order);
$chunkX = $chunkZ = null;
foreach ($order as $index => $distance) {
Level::getXZ($index, $chunkX, $chunkZ);
$level->generateChunk($chunkX, $chunkZ);
}
return true;
}
示例7: doChunkGarbageCollection
public function doChunkGarbageCollection()
{
$this->timings->doChunkGC->startTiming();
$X = null;
$Z = null;
foreach ($this->chunks as $index => $chunk) {
if (!isset($this->unloadQueue[$index]) and (!isset($this->usedChunks[$index]) or count($this->usedChunks[$index]) === 0)) {
Level::getXZ($index, $X, $Z);
if (!$this->isSpawnChunk($X, $Z)) {
$this->unloadChunkRequest($X, $Z, true);
}
}
}
foreach ($this->provider->getLoadedChunks() as $chunk) {
if (!isset($this->chunks[Level::chunkHash($chunk->getX(), $chunk->getZ())])) {
$this->provider->unloadChunk($chunk->getX(), $chunk->getZ(), false);
}
}
$this->provider->doGarbageCollection();
$this->timings->doChunkGC->stopTiming();
}
示例8: loadRegion
protected function loadRegion($x, $z)
{
if (!isset($this->regions[$index = Level::chunkHash($x, $z)])) {
$this->regions[$index] = new RegionLoader($this, $x, $z);
}
}
示例9: enqueueChunk
protected function enqueueChunk($levelID, $chunkX, $chunkZ)
{
if (!isset($this->requestQueue[$levelID])) {
$this->requestQueue[$levelID] = [];
}
if (!isset($this->requestQueue[$levelID][$index = Level::chunkHash($chunkX, $chunkZ)])) {
$this->requestQueue[$levelID][$index] = 1;
} else {
$this->requestQueue[$levelID][$index]++;
arsort($this->requestQueue[$levelID]);
}
}
示例10: generateLevel
/**
* Generates a new level if it does not exists
*
* @param string $name
* @param int $seed
* @param string $generator Class name that extends pocketmine\level\generator\Noise
* @param array $options
*
* @return bool
*/
public function generateLevel($name, $seed = null, $generator = null, $options = [])
{
if (trim($name) === "" or $this->isLevelGenerated($name)) {
return false;
}
$seed = $seed === null ? Binary::readInt(@Utils::getRandomBytes(4, false)) : (int) $seed;
if (!isset($options["preset"])) {
$options["preset"] = $this->getConfigString("generator-settings", "");
}
if (!($generator !== null and class_exists($generator, true) and is_subclass_of($generator, Generator::class))) {
$generator = Generator::getGenerator($this->getLevelType());
}
if (($provider = LevelProviderManager::getProviderByName($providerName = $this->getProperty("level-settings.default-format", "mcregion"))) === null) {
$provider = LevelProviderManager::getProviderByName($providerName = "mcregion");
}
try {
$path = $this->getDataPath() . "worlds/" . $name . "/";
/** @var \pocketmine\level\format\LevelProvider $provider */
$provider::generate($path, $name, $seed, $generator, $options);
$level = new Level($this, $name, $path, $provider);
$this->levels[$level->getId()] = $level;
$level->initLevel();
$level->setTickRate($this->baseTickRate);
} catch (\Exception $e) {
$this->logger->error($this->getLanguage()->translateString("pocketmine.level.generateError", [$name, $e->getMessage()]));
if ($this->logger instanceof MainLogger) {
$this->logger->logException($e);
}
return false;
}
$this->getPluginManager()->callEvent(new LevelInitEvent($level));
$this->getPluginManager()->callEvent(new LevelLoadEvent($level));
$this->getLogger()->notice($this->getLanguage()->translateString("pocketmine.level.backgroundGeneration", [$name]));
$centerX = $level->getSpawnLocation()->getX() >> 4;
$centerZ = $level->getSpawnLocation()->getZ() >> 4;
$order = [];
for ($X = -3; $X <= 3; ++$X) {
for ($Z = -3; $Z <= 3; ++$Z) {
$distance = $X ** 2 + $Z ** 2;
$chunkX = $X + $centerX;
$chunkZ = $Z + $centerZ;
$index = Level::chunkHash($chunkX, $chunkZ);
$order[$index] = $distance;
}
}
asort($order);
foreach ($order as $index => $distance) {
Level::getXZ($index, $chunkX, $chunkZ);
$level->populateChunk($chunkX, $chunkZ, true);
}
return true;
}
示例11: setChunk
public function setChunk($chunkX, $chunkZ, FullChunk $chunk)
{
if (!$chunk instanceof Chunk) {
throw new ChunkException("Invalid Chunk class");
}
$chunk->setProvider($this);
$chunk->setX($chunkX);
$chunk->setZ($chunkZ);
if (isset($this->chunks[$index = Level::chunkHash($chunkX, $chunkZ)]) and $this->chunks[$index] !== $chunk) {
$this->unloadChunk($chunkX, $chunkZ, false);
}
$this->chunks[$index] = $chunk;
}
示例12: setPlotBiome
/**
* Changes the biome of a plot
*
* @api
* @param Plot $plot
* @param Biome $biome
* @return bool
*/
public function setPlotBiome(Plot $plot, Biome $biome)
{
$plotLevel = $this->getLevelSettings($plot->levelName);
if ($plotLevel === null) {
return false;
}
$level = $this->getServer()->getLevelByName($plot->levelName);
$pos = $this->getPlotPosition($plot);
$plotSize = $plotLevel->plotSize;
$xMax = $pos->x + $plotSize;
$zMax = $pos->z + $plotSize;
$chunkIndexes = [];
for ($x = $pos->x; $x < $xMax; $x++) {
for ($z = $pos->z; $z < $zMax; $z++) {
$index = Level::chunkHash($x >> 4, $z >> 4);
if (!in_array($index, $chunkIndexes)) {
$chunkIndexes[] = $index;
}
$color = $biome->getColor();
$R = $color >> 16;
$G = $color >> 8 & 0xff;
$B = $color & 0xff;
$level->setBiomeColor($x, $z, $R, $G, $B);
}
}
foreach ($chunkIndexes as $index) {
Level::getXZ($index, $X, $Z);
$chunk = $level->getChunk($X, $Z);
foreach ($level->getChunkPlayers($X, $Z) as $player) {
$player->onChunkChanged($chunk);
}
}
$plot->biome = $biome->getName();
$this->dataProvider->savePlot($plot);
return true;
}
示例13: spawnTo
/**
* @param Player $player
*/
public function spawnTo(Player $player)
{
if (!isset($this->hasSpawned[$player->getLoaderId()]) and isset($player->usedChunks[Level::chunkHash($this->chunk->getX(), $this->chunk->getZ())])) {
$this->hasSpawned[$player->getLoaderId()] = $player;
}
}
示例14: generateChunk
protected function generateChunk($levelID, $chunkX, $chunkZ)
{
if (isset($this->levels[$levelID]) and !isset($this->generatedQueue[$levelID][$index = Level::chunkHash($chunkX, $chunkZ)])) {
$this->levels[$levelID]->populateChunk($chunkX, $chunkZ);
//Request population directly
if (isset($this->levels[$levelID])) {
$this->generatedQueue[$levelID][$index] = true;
foreach ($this->levels[$levelID]->getChangedChunks() as $index => $chunk) {
if ($chunk->isPopulated()) {
$this->sendChunk($levelID, $chunk);
$this->levels[$levelID]->cleanChangedChunk($index);
}
}
if (count($this->generatedQueue[$levelID]) > 4) {
$this->levels[$levelID]->doGarbageCollection();
$this->generatedQueue[$levelID] = [];
$this->levels[$levelID]->cleanChangedChunks();
}
}
}
}
示例15: setChunk
/**
* @param int $chunkX
* @param int $chunkZ
* @param FullChunk $chunk
*/
public function setChunk($chunkX, $chunkZ, FullChunk $chunk)
{
$this->chunks[$index = Level::chunkHash($chunkX, $chunkZ)] = $chunk;
$this->changes[$index] = $chunk;
if ($chunk->isPopulated()) {
//TODO: Queue to be sent
}
}