Support 256-block build height and fixed world saving

This commit is contained in:
Dylan K. Taylor
2016-12-01 23:44:25 +00:00
parent ce289cbe25
commit 577dbbce1f
5 changed files with 71 additions and 53 deletions

View File

@ -38,16 +38,16 @@ class EmptySubChunk extends SubChunk{
return 0;
}
public function setBlockId(int $x, int $y, int $z, int $id){
public function setBlockId(int $x, int $y, int $z, int $id) : bool{
return false;
}
public function getBlockData(int $x, int $y, int $z) : int{
return 0;
}
public function setBlockData(int $x, int $y, int $z, int $data){
public function setBlockData(int $x, int $y, int $z, int $data) : bool{
return false;
}
public function getFullBlock(int $x, int $y, int $z) : int{
@ -55,23 +55,23 @@ class EmptySubChunk extends SubChunk{
}
public function setBlock(int $x, int $y, int $z, $id = null, $data = null) : bool{
return false;
}
public function getBlockSkyLight(int $x, int $y, int $z) : int{
return 15;
}
public function setBlockSkyLight(int $x, int $y, int $z, int $level){
public function setBlockSkyLight(int $x, int $y, int $z, int $level) : bool{
return false;
}
public function getBlockLight(int $x, int $y, int $z) : int{
return 0;
}
public function setBlockLight(int $x, int $y, int $z, int $level){
public function setBlockLight(int $x, int $y, int $z, int $level) : bool{
return false;
}
public function getBlockIdColumn(int $x, int $z) : string{

View File

@ -164,7 +164,11 @@ class GenericChunk implements Chunk{
}
public function setBlock(int $x, int $y, int $z, $blockId = null, $meta = null) : bool{
return $this->getSubChunk($y >> 4, true)->setBlock($x, $y & 0x0f, $z, $blockId !== null ? ($blockId & 0xff) : null, $meta !== null ? ($meta & 0x0f) : null);
if($this->getSubChunk($y >> 4, true)->setBlock($x, $y & 0x0f, $z, $blockId !== null ? ($blockId & 0xff) : null, $meta !== null ? ($meta & 0x0f) : null)){
$this->hasChanged = true;
return true;
}
return false;
}
public function getBlockId(int $x, int $y, int $z) : int{
@ -172,7 +176,9 @@ class GenericChunk implements Chunk{
}
public function setBlockId(int $x, int $y, int $z, int $id){
$this->getSubChunk($y >> 4, true)->setBlockId($x, $y & 0x0f, $z, $id);
if($this->getSubChunk($y >> 4, true)->setBlockId($x, $y & 0x0f, $z, $id)){
$this->hasChanged = true;
}
}
public function getBlockData(int $x, int $y, int $z) : int{
@ -180,7 +186,9 @@ class GenericChunk implements Chunk{
}
public function setBlockData(int $x, int $y, int $z, int $data){
$this->getSubChunk($y >> 4)->setBlockData($x, $y & 0x0f, $z, $data);
if($this->getSubChunk($y >> 4)->setBlockData($x, $y & 0x0f, $z, $data)){
$this->hasChanged = true;
}
}
public function getBlockExtraData(int $x, int $y, int $z) : int{
@ -202,7 +210,9 @@ class GenericChunk implements Chunk{
}
public function setBlockSkyLight(int $x, int $y, int $z, int $level){
$this->getSubChunk($y >> 4)->setBlockSkyLight($x, $y & 0x0f, $z, $level);
if($this->getSubChunk($y >> 4)->setBlockSkyLight($x, $y & 0x0f, $z, $level)){
$this->hasChanged = true;
}
}
public function getBlockLight(int $x, int $y, int $z) : int{
@ -210,7 +220,9 @@ class GenericChunk implements Chunk{
}
public function setBlockLight(int $x, int $y, int $z, int $level){
$this->getSubChunk($y >> 4)->setBlockLight($x, $y & 0x0f, $z, $level);
if($this->getSubChunk($y >> 4)->setBlockLight($x, $y & 0x0f, $z, $level)){
$this->hasChanged = true;
}
}
public function getHighestBlockAt(int $x, int $z, bool $useHeightMap = true) : int{

View File

@ -59,8 +59,9 @@ class SubChunk{
return ord($this->ids{($x << 8) | ($z << 4) | $y});
}
public function setBlockId(int $x, int $y, int $z, int $id){
public function setBlockId(int $x, int $y, int $z, int $id) : bool{
$this->ids{($x << 8) | ($z << 4) | $y} = chr($id);
return true;
}
public function getBlockData(int $x, int $y, int $z) : int{
@ -72,15 +73,14 @@ class SubChunk{
}
}
public function setBlockData(int $x, int $y, int $z, int $data){
public function setBlockData(int $x, int $y, int $z, int $data) : bool{
$i = ($x << 7) | ($z << 3) | ($y >> 1);
$current = ord($this->data{$i});
if(($y & 1) === 0){
$this->data{$i} = chr(($current & 0xf0) | ($data & 0x0f));
$this->data{$i} = chr((ord($this->data{$i}) & 0xf0) | ($data & 0x0f));
}else{
$this->data{$i} = chr((($data & 0x0f) << 4) | ($current & 0x0f));
$this->data{$i} = chr((($data & 0x0f) << 4) | (ord($this->data{$i}) & 0x0f));
}
$this->hasChanged = true;
return true;
}
public function getFullBlock(int $x, int $y, int $z) : int{
@ -128,7 +128,7 @@ class SubChunk{
}
}
public function setBlockSkyLight(int $x, int $y, int $z, int $level){
public function setBlockSkyLight(int $x, int $y, int $z, int $level) : bool{
$i = ($x << 7) + ($z << 3) + ($y >> 1);
$byte = ord($this->skyLight{$i});
if(($y & 1) === 0){
@ -136,6 +136,7 @@ class SubChunk{
}else{
$this->skyLight{$i} = chr((($level & 0x0f) << 4) | ($byte & 0x0f));
}
return true;
}
public function getBlockLight(int $x, int $y, int $z) : int{
@ -147,7 +148,7 @@ class SubChunk{
}
}
public function setBlockLight(int $x, int $y, int $z, int $level){
public function setBlockLight(int $x, int $y, int $z, int $level) : bool{
$i = ($x << 7) + ($z << 3) + ($y >> 1);
$byte = ord($this->blockLight{$i});
if(($y & 1) === 0){
@ -155,6 +156,7 @@ class SubChunk{
}else{
$this->blockLight{$i} = chr((($level & 0x0f) << 4) | ($byte & 0x0f));
}
return true;
}
public function getHighestBlockAt(int $x, int $z) : int{