mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Further out-phasing of legacy ID/meta
this paves the way for making internal IDs fully dynamic.
This commit is contained in:
parent
6f54b53f7a
commit
5830ca958b
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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{
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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[]
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user