diff --git a/src/pocketmine/block/Block.php b/src/pocketmine/block/Block.php index 6056ec5ff..9e9db8203 100644 --- a/src/pocketmine/block/Block.php +++ b/src/pocketmine/block/Block.php @@ -107,6 +107,14 @@ class Block extends Position implements BlockIds, Metadatable{ return $this->idInfo->getBlockId(); } + /** + * @internal + * @return int + */ + public function getFullId() : int{ + return ($this->getId() << 4) | $this->getMeta(); + } + public function asItem() : Item{ return ItemFactory::get($this->idInfo->getItemId(), $this->idInfo->getVariant()); } @@ -155,7 +163,7 @@ class Block extends Position implements BlockIds, Metadatable{ } public function writeStateToWorld() : void{ - $this->level->getChunkAtPosition($this)->setBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getId(), $this->getMeta()); + $this->level->getChunkAtPosition($this)->setFullBlock($this->x & 0xf, $this->y, $this->z & 0xf, $this->getFullId()); $tileType = $this->idInfo->getTileClass(); $oldTile = $this->level->getTile($this); diff --git a/src/pocketmine/level/SimpleChunkManager.php b/src/pocketmine/level/SimpleChunkManager.php index 7c3c038d1..6d019cc20 100644 --- a/src/pocketmine/level/SimpleChunkManager.php +++ b/src/pocketmine/level/SimpleChunkManager.php @@ -54,7 +54,8 @@ class SimpleChunkManager implements ChunkManager{ public function setBlockAt(int $x, int $y, int $z, Block $block) : bool{ if(($chunk = $this->getChunk($x >> 4, $z >> 4)) !== null){ - return $chunk->setBlock($x & 0xf, $y, $z & 0xf, $block->getId(), $block->getMeta()); + $chunk->setFullBlock($x & 0xf, $y, $z & 0xf, $block->getFullId()); + return true; } return false; } diff --git a/src/pocketmine/level/format/Chunk.php b/src/pocketmine/level/format/Chunk.php index efa0819ac..68a3103c2 100644 --- a/src/pocketmine/level/format/Chunk.php +++ b/src/pocketmine/level/format/Chunk.php @@ -176,7 +176,7 @@ class Chunk{ } /** - * Returns a bitmap of block ID and meta at the specified chunk block coordinates + * Returns the internal ID of the blockstate at the given coordinates. * * @param int $x 0-15 * @param int $y @@ -189,22 +189,16 @@ class Chunk{ } /** - * Sets block ID and meta in one call at the specified chunk block coordinates + * Sets the blockstate at the given coordinate by internal ID. * - * @param int $x 0-15 + * @param int $x * @param int $y - * @param int $z 0-15 - * @param int $blockId 0-255 - * @param int $meta 0-15 - * - * @return bool + * @param int $z + * @param int $block */ - public function setBlock(int $x, int $y, int $z, int $blockId, int $meta) : bool{ - if($this->getSubChunk($y >> 4, true)->setBlock($x, $y & 0x0f, $z, $blockId, $meta & 0x0f)){ - $this->hasChanged = true; - return true; - } - return false; + public function setFullBlock(int $x, int $y, int $z, int $block) : void{ + $this->getSubChunk($y >> 4)->setFullBlock($x, $y & 0xf, $z, $block); + $this->hasChanged = true; } /** diff --git a/src/pocketmine/level/format/EmptySubChunk.php b/src/pocketmine/level/format/EmptySubChunk.php index f45a8b071..54bb0d69c 100644 --- a/src/pocketmine/level/format/EmptySubChunk.php +++ b/src/pocketmine/level/format/EmptySubChunk.php @@ -45,8 +45,8 @@ class EmptySubChunk implements SubChunkInterface{ return 0; } - public function setBlock(int $x, int $y, int $z, int $id, int $data) : bool{ - return false; + public function setFullBlock(int $x, int $y, int $z, int $block) : void{ + } public function getBlockLayers() : array{ diff --git a/src/pocketmine/level/format/SubChunk.php b/src/pocketmine/level/format/SubChunk.php index 4a4aa4f43..0bb3a0b3f 100644 --- a/src/pocketmine/level/format/SubChunk.php +++ b/src/pocketmine/level/format/SubChunk.php @@ -94,12 +94,11 @@ class SubChunk implements SubChunkInterface{ return $this->blockLayers[0]->get($x, $y, $z); } - public function setBlock(int $x, int $y, int $z, int $id, int $data) : bool{ + public function setFullBlock(int $x, int $y, int $z, int $block) : void{ if(empty($this->blockLayers)){ $this->blockLayers[] = new PalettedBlockArray(BlockIds::AIR << 4); } - $this->blockLayers[0]->set($x, $y, $z, ($id << 4) | $data); - return true; + $this->blockLayers[0]->set($x, $y, $z, $block); } /** diff --git a/src/pocketmine/level/format/SubChunkInterface.php b/src/pocketmine/level/format/SubChunkInterface.php index 6b57b6bec..245c49298 100644 --- a/src/pocketmine/level/format/SubChunkInterface.php +++ b/src/pocketmine/level/format/SubChunkInterface.php @@ -45,12 +45,9 @@ interface SubChunkInterface{ * @param int $x * @param int $y * @param int $z - * @param int $id - * @param int $data - * - * @return bool + * @param int $block */ - public function setBlock(int $x, int $y, int $z, int $id, int $data) : bool; + public function setFullBlock(int $x, int $y, int $z, int $block) : void; /** * @return PalettedBlockArray[] diff --git a/src/pocketmine/level/generator/Flat.php b/src/pocketmine/level/generator/Flat.php index 220ec3a0e..a0aebdca5 100644 --- a/src/pocketmine/level/generator/Flat.php +++ b/src/pocketmine/level/generator/Flat.php @@ -43,7 +43,7 @@ class Flat extends Generator{ private $chunk; /** @var Populator[] */ private $populators = []; - /** @var int[][] */ + /** @var int[] */ private $structure; /** @var int */ private $floorLevel; @@ -96,7 +96,7 @@ class Flat extends Generator{ /** * @param string $layers * - * @return int[][] + * @return int[] * @throws InvalidGeneratorOptionsException */ public static function parseLayers(string $layers) : array{ @@ -116,7 +116,7 @@ class Flat extends Generator{ throw new InvalidGeneratorOptionsException("Invalid preset layer \"$line\": " . $e->getMessage(), 0, $e); } for($cY = $y, $y += $cnt; $cY < $y; ++$cY){ - $result[$cY] = [$b->getId(), $b->getMeta()]; + $result[$cY] = $b->getFullId(); } } @@ -164,11 +164,11 @@ class Flat extends Generator{ for($sy = 0; $sy < $count; $sy += 16){ $subchunk = $this->chunk->getSubChunk($sy >> 4, true); for($y = 0; $y < 16 and isset($this->structure[$y | $sy]); ++$y){ - list($id, $meta) = $this->structure[$y | $sy]; + $id = $this->structure[$y | $sy]; for($Z = 0; $Z < 16; ++$Z){ for($X = 0; $X < 16; ++$X){ - $subchunk->setBlock($X, $y, $Z, $id, $meta); + $subchunk->setFullBlock($X, $y, $Z, $id); } } } diff --git a/src/pocketmine/level/generator/hell/Nether.php b/src/pocketmine/level/generator/hell/Nether.php index 5f1c096d3..9a6115ea7 100644 --- a/src/pocketmine/level/generator/hell/Nether.php +++ b/src/pocketmine/level/generator/hell/Nether.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\level\generator\hell; use pocketmine\block\Block; +use pocketmine\block\BlockFactory; use pocketmine\level\biome\Biome; use pocketmine\level\ChunkManager; use pocketmine\level\generator\Generator; @@ -89,6 +90,10 @@ class Nether extends Generator{ $chunk = $this->level->getChunk($chunkX, $chunkZ); + $bedrock = BlockFactory::get(Block::BEDROCK)->getFullId(); + $netherrack = BlockFactory::get(Block::NETHERRACK)->getFullId(); + $stillLava = BlockFactory::get(Block::STILL_LAVA)->getFullId(); + for($x = 0; $x < 16; ++$x){ for($z = 0; $z < 16; ++$z){ @@ -97,16 +102,16 @@ class Nether extends Generator{ for($y = 0; $y < 128; ++$y){ if($y === 0 or $y === 127){ - $chunk->setBlock($x, $y, $z, Block::BEDROCK, 0); + $chunk->setFullBlock($x, $y, $z, $bedrock); continue; } $noiseValue = (abs($this->emptyHeight - $y) / $this->emptyHeight) * $this->emptyAmplitude - $noise[$x][$z][$y]; $noiseValue -= 1 - $this->density; if($noiseValue > 0){ - $chunk->setBlock($x, $y, $z, Block::NETHERRACK, 0); + $chunk->setFullBlock($x, $y, $z, $netherrack); }elseif($y <= $this->waterHeight){ - $chunk->setBlock($x, $y, $z, Block::STILL_LAVA, 0); + $chunk->setFullBlock($x, $y, $z, $stillLava); } } } diff --git a/src/pocketmine/level/generator/normal/Normal.php b/src/pocketmine/level/generator/normal/Normal.php index 091fb995b..660a6e3ba 100644 --- a/src/pocketmine/level/generator/normal/Normal.php +++ b/src/pocketmine/level/generator/normal/Normal.php @@ -178,6 +178,10 @@ class Normal extends Generator{ $biomeCache = []; + $bedrock = BlockFactory::get(Block::BEDROCK)->getFullId(); + $stillWater = BlockFactory::get(Block::STILL_WATER)->getFullId(); + $stone = BlockFactory::get(Block::STONE)->getFullId(); + for($x = 0; $x < 16; ++$x){ for($z = 0; $z < 16; ++$z){ $minSum = 0; @@ -217,15 +221,15 @@ class Normal extends Generator{ for($y = 0; $y < 128; ++$y){ if($y === 0){ - $chunk->setBlock($x, $y, $z, Block::BEDROCK, 0); + $chunk->setFullBlock($x, $y, $z, $bedrock); continue; } $noiseValue = $noise[$x][$z][$y] - 1 / $smoothHeight * ($y - $smoothHeight - $minSum); if($noiseValue > 0){ - $chunk->setBlock($x, $y, $z, Block::STONE, 0); + $chunk->setFullBlock($x, $y, $z, $stone); }elseif($y <= $this->waterHeight){ - $chunk->setBlock($x, $y, $z, Block::STILL_WATER, 0); + $chunk->setFullBlock($x, $y, $z, $stillWater); } } } diff --git a/src/pocketmine/level/generator/populator/GroundCover.php b/src/pocketmine/level/generator/populator/GroundCover.php index 84e0405c8..e493a103b 100644 --- a/src/pocketmine/level/generator/populator/GroundCover.php +++ b/src/pocketmine/level/generator/populator/GroundCover.php @@ -63,7 +63,7 @@ class GroundCover extends Populator{ continue; } - $chunk->setBlock($x, $y, $z, $b->getId(), $b->getMeta()); + $chunk->setFullBlock($x, $y, $z, $b->getFullId()); } } }