getChunk() 공개 메소드

Gets the Chunk object
public getChunk ( integer $x, integer $z, boolean $create = false ) : pocketmine\level\format\FullChunk | pocketmine\level\format\Chunk
$x integer
$z integer
$create boolean Whether to generate the chunk if it does not exist
리턴 pocketmine\level\format\FullChunk | pocketmine\level\format\Chunk
예제 #1
1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
     $entity = Entity::createEntity($this->meta, $chunk, $nbt);
     if ($entity instanceof Entity) {
         if ($player->isSurvival()) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
예제 #2
0
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->getId() == Block::MONSTER_SPAWNER) {
         return true;
     } else {
         $entity = null;
         $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
         if (!$chunk instanceof FullChunk) {
             return false;
         }
         $nbt = new CompoundTag("", ["Pos" => new EnumTag("Pos", [new DoubleTag("", $block->getX() + 0.5), new DoubleTag("", $block->getY()), new DoubleTag("", $block->getZ() + 0.5)]), "Motion" => new EnumTag("Motion", [new DoubleTag("", 0), new DoubleTag("", 0), new DoubleTag("", 0)]), "Rotation" => new EnumTag("Rotation", [new FloatTag("", lcg_value() * 360), new FloatTag("", 0)])]);
         if ($this->hasCustomName()) {
             $nbt->CustomName = new StringTag("CustomName", $this->getCustomName());
         }
         $entity = Entity::createEntity($this->meta, $chunk, $nbt);
         if ($entity instanceof Entity) {
             if ($player->isSurvival()) {
                 --$this->count;
             }
             $entity->spawnToAll();
             return true;
         }
     }
     return false;
 }
예제 #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);
     $this->chunk00 = $level->getChunk($chunk->getX() - 1, $chunk->getZ() - 1, true)->toFastBinary();
     $this->chunk01 = $level->getChunk($chunk->getX() - 1, $chunk->getZ(), true)->toFastBinary();
     $this->chunk02 = $level->getChunk($chunk->getX() - 1, $chunk->getZ() + 1, true)->toFastBinary();
     $this->chunk10 = $level->getChunk($chunk->getX(), $chunk->getZ() - 1, true)->toFastBinary();
     $this->chunk12 = $level->getChunk($chunk->getX(), $chunk->getZ() + 1, true)->toFastBinary();
     $this->chunk20 = $level->getChunk($chunk->getX() + 1, $chunk->getZ() - 1, true)->toFastBinary();
     $this->chunk21 = $level->getChunk($chunk->getX() + 1, $chunk->getZ(), true)->toFastBinary();
     $this->chunk22 = $level->getChunk($chunk->getX() + 1, $chunk->getZ() + 1, true)->toFastBinary();
 }
예제 #4
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;
     }
 }
예제 #5
0
 public function generateChunk($chunkX, $chunkZ)
 {
     $shape = $this->getShape($chunkX << 4, $chunkZ << 4);
     $chunk = $this->level->getChunk($chunkX, $chunkZ);
     $chunk->setGenerated();
     $c = Biome::getBiome(1)->getColor();
     $R = $c >> 16;
     $G = $c >> 8 & 0xff;
     $B = $c & 0xff;
     $bottomBlockId = $this->bottomBlock->getId();
     $bottomBlockMeta = $this->bottomBlock->getDamage();
     $plotFillBlockId = $this->plotFillBlock->getId();
     $plotFillBlockMeta = $this->plotFillBlock->getDamage();
     $plotFloorBlockId = $this->plotFloorBlock->getId();
     $plotFloorBlockMeta = $this->plotFloorBlock->getDamage();
     $roadBlockId = $this->roadBlock->getId();
     $roadBlockMeta = $this->roadBlock->getDamage();
     $wallBlockId = $this->wallBlock->getId();
     $wallBlockMeta = $this->wallBlock->getDamage();
     $groundHeight = $this->groundHeight;
     for ($Z = 0; $Z < 16; ++$Z) {
         for ($X = 0; $X < 16; ++$X) {
             $chunk->setBiomeId($X, $Z, 1);
             $chunk->setBiomeColor($X, $Z, $R, $G, $B);
             $chunk->setBlock($X, 0, $Z, $bottomBlockId, $bottomBlockMeta);
             for ($y = 1; $y < $groundHeight; ++$y) {
                 $chunk->setBlock($X, $y, $Z, $plotFillBlockId, $plotFillBlockMeta);
             }
             $type = $shape[$Z << 4 | $X];
             if ($type === self::PLOT) {
                 $chunk->setBlock($X, $groundHeight, $Z, $plotFloorBlockId, $plotFloorBlockMeta);
             } elseif ($type === self::ROAD) {
                 $chunk->setBlock($X, $groundHeight, $Z, $roadBlockId, $roadBlockMeta);
             } else {
                 $chunk->setBlock($X, $groundHeight, $Z, $roadBlockId, $roadBlockMeta);
                 $chunk->setBlock($X, $groundHeight + 1, $Z, $wallBlockId, $wallBlockMeta);
             }
         }
     }
     $chunk->setX($chunkX);
     $chunk->setZ($chunkZ);
     $this->level->setChunk($chunkX, $chunkZ, $chunk);
 }
예제 #6
0
 public function getLight(Level $level, $pos)
 {
     $chunk = $level->getChunk($pos->x >> 4, $pos->z >> 4, false);
     $l = 0;
     if ($chunk instanceof FullChunk) {
         $l = $chunk->getBlockSkyLight($pos->x & 0xf, $pos->y & 0x7f, $pos->z & 0xf);
         if ($l < 15) {
             //$l = \max($chunk->getBlockLight($pos->x & 0x0f, $pos->y & 0x7f, $pos->z & 0x0f));
             $l = $chunk->getBlockLight($pos->x & 0xf, $pos->y & 0x7f, $pos->z & 0xf);
         }
     }
     return $l;
 }
예제 #7
0
 public function createVillager($x, $y, $z, Level $level)
 {
     $x += 0.5;
     $z += 0.5;
     $nbt = new CompoundTag();
     $nbt->Pos = new ListTag("Pos", [new DoubleTag("", $x), new DoubleTag("", $y), new DoubleTag("", $z)]);
     $nbt->Rotation = new ListTag("Rotation", [new FloatTag("", 0), new FloatTag("", 0)]);
     $nbt->Health = new ShortTag("Health", 20);
     $nbt->CustomName = new StringTag("CustomName", TextFormat::GOLD . "SHOP");
     $nbt->CustomNameVisible = new ByteTag("CustomNameVisible", 1);
     $level->loadChunk($x >> 4, $z >> 4);
     $villager = Entity::createEntity("Villager", $level->getChunk($x >> 4, $y >> 4), $nbt);
     $villager->spawnToAll();
 }
예제 #8
-1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     $entity = null;
     $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
     if (!$chunk instanceof FullChunk) {
         return false;
     }
     $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $block->getX() + 0.5), new Double("", $block->getY()), new Double("", $block->getZ() + 0.5)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", lcg_value() * 360), new Float("", 0)])]);
     if ($this->hasCustomName()) {
         $nbt->CustomName = new String("CustomName", $this->getCustomName());
     }
     $entity = Entity::createEntity($this->meta, $chunk, $nbt);
     if ($entity instanceof Entity) {
         $entity->setDataProperty(15, Entity::DATA_TYPE_BYTE, 1);
         $entity->getLevel()->getServer()->broadcastPopup(TextFormat::RED . "Mob AI isn't implemented yet!");
         if ($player->isSurvival()) {
             --$this->count;
         }
         $entity->spawnToAll();
         return true;
     }
     return false;
 }
예제 #9
-1
 public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz)
 {
     if ($target->isTransparent() === false and $face > 1 and $block->isSolid() === false) {
         $chunk = $level->getChunk($block->getX() >> 4, $block->getZ() >> 4);
         $faces = [2 => 1, 3 => 3, 4 => 0, 5 => 2];
         $motives = [["Kebab", 1, 1], ["Aztec", 1, 1], ["Alban", 1, 1], ["Aztec2", 1, 1], ["Bomb", 1, 1], ["Plant", 1, 1], ["Wasteland", 1, 1], ["Wanderer", 1, 2], ["Graham", 1, 2], ["Pool", 2, 1], ["Courbet", 2, 1], ["Sunset", 2, 1], ["Sea", 2, 1], ["Creebet", 2, 1], ["Match", 2, 2], ["Bust", 2, 2], ["Stage", 2, 2], ["Void", 2, 2], ["SkullAndRoses", 2, 2], ["Fighters", 4, 2], ["Skeleton", 4, 3], ["DonkeyKong", 4, 3], ["Pointer", 4, 4], ["Pigscene", 4, 4], ["Flaming Skull", 4, 4]];
         if ($this->hasCustomName()) {
             $nbt->CustomName = new String("CustomName", $this->getCustomName());
         }
         $motive = $motives[mt_rand(0, count($motives) - 1)];
         $data = ["x" => $target->x, "y" => $target->y, "z" => $target->z, "yaw" => $faces[$face] * 90, "Motive" => $motive[0]];
         $nbt = new Compound("", ["Pos" => new Enum("Pos", [new Double("", $target->x), new Double("", $target->y), new Double("", $target->z)]), "Motion" => new Enum("Motion", [new Double("", 0), new Double("", 0), new Double("", 0)]), "Rotation" => new Enum("Rotation", [new Float("", $faces[$face] * 90), new Float("", 0)])]);
         $entity = Entity::createEntity($this->meta, $chunk, $nbt, $data);
         if ($entity instanceof Entity) {
             if ($player->isSurvival()) {
                 --$this->count;
             }
             $entity->spawnToAll();
             return true;
         }
         return true;
     }
     return false;
 }