コード例 #1
0
 public function __construct(Level $level, FullChunk $chunk)
 {
     $this->state = true;
     $this->levelId = $level->getId();
     $this->chunk = $chunk->toFastBinary();
     $this->chunkClass = get_class($chunk);
 }
コード例 #2
0
ファイル: Flat.php プロジェクト: gitter-badger/BukkitPE
 protected function parsePreset($preset, $chunkX, $chunkZ)
 {
     $this->preset = $preset;
     $preset = explode(";", $preset);
     $version = (int) $preset[0];
     $blocks = isset($preset[1]) ? $preset[1] : "";
     $biome = isset($preset[2]) ? $preset[2] : 1;
     $options = isset($preset[3]) ? $preset[3] : "";
     preg_match_all('#^(([0-9]*x|)([0-9]{1,3})(|:[0-9]{0,2}))$#m', str_replace(",", "\n", $blocks), $matches);
     $y = 0;
     $this->structure = [];
     $this->chunks = [];
     foreach ($matches[3] as $i => $b) {
         $b = Item::fromString($b . $matches[4][$i]);
         $cnt = $matches[2][$i] === "" ? 1 : intval($matches[2][$i]);
         for ($cY = $y, $y += $cnt; $cY < $y; ++$cY) {
             $this->structure[$cY] = [$b->getId(), $b->getDamage()];
         }
     }
     $this->floorLevel = $y;
     for (; $y < 0xff; ++$y) {
         $this->structure[$y] = [0, 0];
     }
     $this->chunk = clone $this->level->getChunk($chunkX, $chunkZ);
     $this->chunk->setGenerated();
     $c = Biome::getBiome($biome)->getColor();
     $R = $c >> 16;
     $G = $c >> 8 & 0xff;
     $B = $c & 0xff;
     for ($Z = 0; $Z < 16; ++$Z) {
         for ($X = 0; $X < 16; ++$X) {
             $this->chunk->setBiomeId($X, $Z, $biome);
             $this->chunk->setBiomeColor($X, $Z, $R, $G, $B);
             for ($y = 0; $y < 128; ++$y) {
                 $this->chunk->setBlock($X, $y, $Z, ...$this->structure[$y]);
             }
         }
     }
     preg_match_all('#(([0-9a-z_]{1,})\\(?([0-9a-z_ =:]{0,})\\)?),?#', $options, $matches);
     foreach ($matches[2] as $i => $option) {
         $params = true;
         if ($matches[3][$i] !== "") {
             $params = [];
             $p = explode(" ", $matches[3][$i]);
             foreach ($p as $k) {
                 $k = explode("=", $k);
                 if (isset($k[1])) {
                     $params[$k[0]] = $k[1];
                 }
             }
         }
         $this->options[$option] = $params;
     }
 }
コード例 #3
0
 public function __construct(Level $level, FullChunk $chunk)
 {
     $this->state = true;
     $this->levelId = $level->getId();
     $this->chunk = $chunk->toFastBinary();
     $this->chunkClass = get_class($chunk);
     for ($i = 0; $i < 9; ++$i) {
         if ($i === 4) {
             continue;
         }
         $xx = -1 + $i % 3;
         $zz = -1 + (int) ($i / 3);
         $ck = $level->getChunk($chunk->getX() + $xx, $chunk->getZ() + $zz, false);
         $this->{"chunk{$i}"} = $ck !== null ? $ck->toFastBinary() : null;
     }
 }
コード例 #4
0
ファイル: Tile.php プロジェクト: gitter-badger/BukkitPE
 public function __construct(FullChunk $chunk, Compound $nbt)
 {
     if ($chunk === null or $chunk->getProvider() === null) {
         throw new ChunkException("Invalid garbage Chunk given to Tile");
     }
     $this->timings = Timings::getTileEntityTimings($this);
     $this->server = $chunk->getProvider()->getLevel()->getServer();
     $this->chunk = $chunk;
     $this->setLevel($chunk->getProvider()->getLevel());
     $this->namedtag = $nbt;
     $this->name = "";
     $this->lastUpdate = microtime(true);
     $this->id = Tile::$tileCount++;
     $this->x = (int) $this->namedtag["x"];
     $this->y = (int) $this->namedtag["y"];
     $this->z = (int) $this->namedtag["z"];
     $this->chunk->addTile($this);
     $this->getLevel()->addTile($this);
     $this->tickTimer = Timings::getTileEntityTimings($this);
 }
コード例 #5
0
ファイル: Level.php プロジェクト: MunkySkunk/BukkitPE
 public function generateChunkCallback($x, $z, FullChunk $chunk)
 {
     Timings::$generationCallbackTimer->startTiming();
     if (isset($this->chunkPopulationQueue[$index = Level::chunkHash($x, $z)])) {
         $oldChunk = $this->getChunk($x, $z, false);
         for ($xx = -1; $xx <= 1; ++$xx) {
             for ($zz = -1; $zz <= 1; ++$zz) {
                 unset($this->chunkPopulationLock[Level::chunkHash($x + $xx, $z + $zz)]);
             }
         }
         unset($this->chunkPopulationQueue[$index]);
         $chunk->setProvider($this->provider);
         $this->setChunk($x, $z, $chunk, false);
         $chunk = $this->getChunk($x, $z, false);
         if ($chunk !== null and ($oldChunk === null or $oldChunk->isPopulated() === false) and $chunk->isPopulated() and $chunk->getProvider() !== null) {
             $this->server->getPluginManager()->callEvent(new ChunkPopulateEvent($chunk));
             foreach ($this->getChunkLoaders($x, $z) as $loader) {
                 $loader->onChunkPopulated($chunk);
             }
         }
     } elseif (isset($this->chunkGenerationQueue[$index]) or isset($this->chunkPopulationLock[$index])) {
         unset($this->chunkGenerationQueue[$index]);
         unset($this->chunkPopulationLock[$index]);
         $chunk->setProvider($this->provider);
         $this->setChunk($x, $z, $chunk, false);
     } else {
         $chunk->setProvider($this->provider);
         $this->setChunk($x, $z, $chunk, false);
     }
     Timings::$generationCallbackTimer->stopTiming();
 }
コード例 #6
0
ファイル: Player.php プロジェクト: MunkySkunk/BukkitPE
 public function onChunkChanged(FullChunk $chunk)
 {
     $this->loadQueue[Level::chunkHash($chunk->getX(), $chunk->getZ())] = abs(($this->x >> 4) - $chunk->getX()) + abs(($this->z >> 4) - $chunk->getZ());
 }
コード例 #7
0
ファイル: McRegion.php プロジェクト: MunkySkunk/BukkitPE
 public function setChunk($chunkX, $chunkZ, FullChunk $chunk)
 {
     if (!$chunk instanceof Chunk) {
         throw new ChunkException("Invalid Chunk class");
     }
     $chunk->setProvider($this);
     self::getRegionIndex($chunkX, $chunkZ, $regionX, $regionZ);
     $this->loadRegion($regionX, $regionZ);
     $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;
 }
コード例 #8
0
ファイル: RegionLoader.php プロジェクト: MunkySkunk/BukkitPE
 public function writeChunk(FullChunk $chunk)
 {
     $this->lastUsed = time();
     $chunkData = $chunk->toBinary();
     if ($chunkData !== false) {
         $this->saveChunk($chunk->getX() - $this->getX() * 32, $chunk->getZ() - $this->getZ() * 32, $chunkData);
     }
 }
コード例 #9
0
ファイル: ChunkEvent.php プロジェクト: MunkySkunk/BukkitPE
 /**
  * @param FullChunk $chunk
  */
 public function __construct(FullChunk $chunk)
 {
     parent::__construct($chunk->getProvider()->getLevel());
     $this->chunk = $chunk;
 }
コード例 #10
0
ファイル: Entity.php プロジェクト: MunkySkunk/BukkitPE
 public function __construct(FullChunk $chunk, Compound $nbt)
 {
     if ($chunk === null or $chunk->getProvider() === null) {
         throw new ChunkException("Invalid garbage Chunk given to Entity");
     }
     $this->timings = Timings::getEntityTimings($this);
     $this->isPlayer = $this instanceof Player;
     $this->temporalVector = new Vector3();
     if ($this->eyeHeight === null) {
         $this->eyeHeight = $this->height / 2 + 0.1;
     }
     $this->id = Entity::$entityCount++;
     $this->justCreated = true;
     $this->namedtag = $nbt;
     $this->chunk = $chunk;
     $this->setLevel($chunk->getProvider()->getLevel());
     $this->server = $chunk->getProvider()->getLevel()->getServer();
     $this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
     $this->setPositionAndRotation($this->temporalVector->setComponents($this->namedtag["Pos"][0], $this->namedtag["Pos"][1], $this->namedtag["Pos"][2]), $this->namedtag->Rotation[0], $this->namedtag->Rotation[1]);
     $this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
     if (!isset($this->namedtag->FallDistance)) {
         $this->namedtag->FallDistance = new Float("FallDistance", 0);
     }
     $this->fallDistance = $this->namedtag["FallDistance"];
     if (!isset($this->namedtag->Fire)) {
         $this->namedtag->Fire = new Short("Fire", 0);
     }
     $this->fireTicks = $this->namedtag["Fire"];
     if (!isset($this->namedtag->Air)) {
         $this->namedtag->Air = new Short("Air", 300);
     }
     $this->setDataProperty(self::DATA_AIR, self::DATA_TYPE_SHORT, $this->namedtag["Air"]);
     if (!isset($this->namedtag->OnGround)) {
         $this->namedtag->OnGround = new Byte("OnGround", 0);
     }
     $this->onGround = $this->namedtag["OnGround"] > 0 ? true : false;
     if (!isset($this->namedtag->Invulnerable)) {
         $this->namedtag->Invulnerable = new Byte("Invulnerable", 0);
     }
     $this->invulnerable = $this->namedtag["Invulnerable"] > 0 ? true : false;
     $this->chunk->addEntity($this);
     $this->level->addEntity($this);
     $this->initEntity();
     $this->lastUpdate = $this->server->getTick();
     $this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this));
     $this->scheduleUpdate();
 }