mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
Added HeightMap get/set methods on chunks, Level
This commit is contained in:
parent
964bf98ca6
commit
e4557a2e8e
@ -1634,6 +1634,16 @@ class Level implements ChunkManager, Metadatable{
|
||||
return $this->getChunk($x >> 4, $z >> 4, true)->getBiomeColor($x & 0x0f, $z & 0x0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getHeightMap($x, $z){
|
||||
return $this->getChunk($x >> 4, $z >> 4, true)->getHeightMap($x & 0x0f, $z & 0x0f);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
@ -1654,6 +1664,15 @@ class Level implements ChunkManager, Metadatable{
|
||||
$this->getChunk($x >> 4, $z >> 4, true)->setBiomeColor($x & 0x0f, $z & 0x0f, $R, $G, $B);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $x
|
||||
* @param int $z
|
||||
* @param int $value
|
||||
*/
|
||||
public function setHeightMap($x, $z, $value){
|
||||
$this->getChunk($x >> 4, $z >> 4, true)->setHeightMap($x & 0x0f, $z & 0x0f, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the Chunk object
|
||||
*
|
||||
|
@ -148,6 +148,21 @@ interface FullChunk{
|
||||
*/
|
||||
public function getHighestBlockAt($x, $z);
|
||||
|
||||
/**
|
||||
* @param int $x 0-15
|
||||
* @param int $z 0-15
|
||||
*
|
||||
* @return int 0-255
|
||||
*/
|
||||
public function getHeightMap($x, $z);
|
||||
|
||||
/**
|
||||
* @param int $x 0-15
|
||||
* @param int $z 0-15
|
||||
* @param $value 0-255
|
||||
*/
|
||||
public function setHeightMap($x, $z, $value);
|
||||
|
||||
/**
|
||||
* @param int $x 0-15
|
||||
* @param int $z 0-15
|
||||
@ -267,6 +282,11 @@ interface FullChunk{
|
||||
*/
|
||||
public function getBiomeColorArray();
|
||||
|
||||
/**
|
||||
* @return int[]
|
||||
*/
|
||||
public function getHeightMapArray();
|
||||
|
||||
public function getBlockIdArray();
|
||||
|
||||
public function getBlockDataArray();
|
||||
|
@ -70,6 +70,10 @@ class Chunk extends BaseChunk{
|
||||
$this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a")));
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArray)){
|
||||
$this->nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 127));
|
||||
}
|
||||
|
||||
$sections = [];
|
||||
foreach($this->nbt->Sections as $section){
|
||||
if($section instanceof Compound){
|
||||
@ -85,7 +89,7 @@ class Chunk extends BaseChunk{
|
||||
}
|
||||
}
|
||||
|
||||
parent::__construct($level, (int) $this->nbt["xPos"], (int) $this->nbt["zPos"], $sections, $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
|
||||
parent::__construct($level, (int) $this->nbt["xPos"], (int) $this->nbt["zPos"], $sections, $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
|
||||
|
||||
unset($this->nbt->Sections);
|
||||
}
|
||||
@ -172,6 +176,8 @@ class Chunk extends BaseChunk{
|
||||
$nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray());
|
||||
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
|
||||
|
||||
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
|
||||
|
||||
$entities = [];
|
||||
|
||||
foreach($this->getEntities() as $entity){
|
||||
|
@ -35,24 +35,6 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{
|
||||
/** @var ChunkSection[] */
|
||||
protected $sections = [];
|
||||
|
||||
/** @var Entity[] */
|
||||
protected $entities = [];
|
||||
|
||||
/** @var Tile[] */
|
||||
protected $tiles = [];
|
||||
|
||||
/** @var string */
|
||||
protected $biomeIds;
|
||||
|
||||
/** @var int[256] */
|
||||
protected $biomeColors;
|
||||
|
||||
/** @var LevelProvider */
|
||||
protected $level;
|
||||
|
||||
protected $x;
|
||||
protected $z;
|
||||
|
||||
/**
|
||||
* @param LevelProvider $provider
|
||||
* @param int $x
|
||||
@ -60,12 +42,13 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{
|
||||
* @param ChunkSection[] $sections
|
||||
* @param string $biomeIds
|
||||
* @param int[] $biomeColors
|
||||
* @param int[] $heightMap
|
||||
* @param Compound[] $entities
|
||||
* @param Compound[] $tiles
|
||||
*
|
||||
* @throws ChunkException
|
||||
*/
|
||||
protected function __construct($provider, $x, $z, array $sections, $biomeIds = null, array $biomeColors = [], array $entities = [], array $tiles = []){
|
||||
protected function __construct($provider, $x, $z, array $sections, $biomeIds = null, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = []){
|
||||
$this->provider = $provider;
|
||||
$this->x = (int) $x;
|
||||
$this->z = (int) $z;
|
||||
@ -93,6 +76,12 @@ abstract class BaseChunk extends BaseFullChunk implements Chunk{
|
||||
$this->biomeColors = array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a"));
|
||||
}
|
||||
|
||||
if(count($heightMap) === 256){
|
||||
$this->heightMap = 256;
|
||||
}else{
|
||||
$this->heightMap = array_fill(0, 256, 127);
|
||||
}
|
||||
|
||||
$this->NBTtiles = $tiles;
|
||||
$this->NBTentities = $entities;
|
||||
}
|
||||
|
@ -54,6 +54,8 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
|
||||
protected $blockLight;
|
||||
|
||||
protected $heightMap;
|
||||
|
||||
protected $NBTtiles;
|
||||
|
||||
protected $NBTentities;
|
||||
@ -76,10 +78,11 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
* @param string $blockLight
|
||||
* @param string $biomeIds
|
||||
* @param int[] $biomeColors
|
||||
* @param int[] $heightMap
|
||||
* @param Compound[] $entities
|
||||
* @param Compound[] $tiles
|
||||
*/
|
||||
protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, $biomeIds = null, array $biomeColors = [], array $entities = [], array $tiles = []){
|
||||
protected function __construct($provider, $x, $z, $blocks, $data, $skyLight, $blockLight, $biomeIds = null, array $biomeColors = [], array $heightMap = [], array $entities = [], array $tiles = []){
|
||||
$this->provider = $provider;
|
||||
$this->x = (int) $x;
|
||||
$this->z = (int) $z;
|
||||
@ -101,6 +104,12 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
$this->biomeColors = array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a"));
|
||||
}
|
||||
|
||||
if(count($heightMap) === 256){
|
||||
$this->heightMap = 256;
|
||||
}else{
|
||||
$this->heightMap = array_fill(0, 256, 127);
|
||||
}
|
||||
|
||||
$this->NBTtiles = $tiles;
|
||||
$this->NBTentities = $entities;
|
||||
}
|
||||
@ -214,6 +223,14 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
$this->biomeColors[($z << 4) + $x] = 0 | (($R & 0xFF) << 16) | (($G & 0xFF) << 8) | ($B & 0xFF);
|
||||
}
|
||||
|
||||
public function getHeightMap($x, $z){
|
||||
return $this->heightMap[($z << 4) + $x];
|
||||
}
|
||||
|
||||
public function setHeightMap($x, $z, $value){
|
||||
$this->heightMap[($z << 4) + $x] = $value;
|
||||
}
|
||||
|
||||
public function getHighestBlockAt($x, $z){
|
||||
$column = $this->getBlockIdColumn($x, $z);
|
||||
for($y = 127; $y >= 0; --$y){
|
||||
@ -324,6 +341,10 @@ abstract class BaseFullChunk implements FullChunk{
|
||||
return $this->biomeColors;
|
||||
}
|
||||
|
||||
public function getHeightMapArray(){
|
||||
return $this->heightMap;
|
||||
}
|
||||
|
||||
public function hasChanged(){
|
||||
return $this->hasChanged;
|
||||
}
|
||||
|
@ -67,7 +67,11 @@ class Chunk extends BaseFullChunk{
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->BiomeColors) or !($this->nbt->BiomeColors instanceof IntArray)){
|
||||
$this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 156, Binary::readInt("\x00\x85\xb2\x4a")));
|
||||
$this->nbt->BiomeColors = new IntArray("BiomeColors", array_fill(0, 256, Binary::readInt("\x00\x85\xb2\x4a")));
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->HeightMap) or !($this->nbt->HeightMap instanceof IntArray)){
|
||||
$this->nbt->HeightMap = new IntArray("HeightMap", array_fill(0, 256, 127));
|
||||
}
|
||||
|
||||
if(!isset($this->nbt->Blocks)){
|
||||
@ -80,7 +84,7 @@ class Chunk extends BaseFullChunk{
|
||||
$this->nbt->BlockLight = new ByteArray("BlockLight", $half);
|
||||
}
|
||||
|
||||
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt["Blocks"], $this->nbt["Data"], $this->nbt["SkyLight"], $this->nbt["BlockLight"], $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
|
||||
parent::__construct($level, $this->nbt["xPos"], $this->nbt["zPos"], $this->nbt->Blocks->getValue(), $this->nbt->Data->getValue(), $this->nbt->SkyLight->getValue(), $this->nbt->BlockLight->getValue(), $this->nbt->Biomes->getValue(), $this->nbt->BiomeColors->getValue(), $this->nbt->HeightMap->getValue(), $this->nbt->Entities->getValue(), $this->nbt->TileEntities->getValue());
|
||||
unset($this->nbt->Blocks);
|
||||
unset($this->nbt->Data);
|
||||
unset($this->nbt->SkyLight);
|
||||
@ -284,6 +288,8 @@ class Chunk extends BaseFullChunk{
|
||||
|
||||
$nbt->Biomes = new ByteArray("Biomes", $this->getBiomeIdArray());
|
||||
$nbt->BiomeColors = new IntArray("BiomeColors", $this->getBiomeColorArray());
|
||||
|
||||
$nbt->HeightMap = new IntArray("HeightMap", $this->getHeightMapArray());
|
||||
}
|
||||
|
||||
$entities = [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user