Fixed rotated map chunks

This commit is contained in:
Shoghi Cervantes Pueyo 2012-12-20 22:43:38 +01:00
parent 6339fb31bc
commit 5c9880fc13
3 changed files with 23 additions and 12 deletions

View File

@ -109,19 +109,25 @@ class LevelAPI{
return array(str_repeat("\x00", 256)); return array(str_repeat("\x00", 256));
} }
$ordered = array(); $ordered = array();
for($i = 0;$i < 0xff; ){ $i = 0;
$ordered[$i] = str_repeat("\x00", $i); $cnt = 0;
for($j = 0; $j < $columnsPerPacket; ++$j){ $ordered[$i] = "";
if(($i + $j) > 0xff){ for($z = 0; $z < 16; ++$z){
break; for($x = 0; $x < 16; ++$x){
if($cnt >= $columnsPerPacket){
++$i;
$ordered[$i] = str_repeat("\x00", $i * $columnsPerPacket);
$cnt = 0;
} }
$ordered[$i] .= "\xff"; $ordered[$i] .= "\xff";
$block = $this->map->getChunkColumn($X, $Z, $x, $z, 0);
$meta = $this->map->getChunkColumn($X, $Z, $x, $z, 1);
for($k = 0; $k < 8; ++$k){ for($k = 0; $k < 8; ++$k){
$ordered[$i] .= substr($c[0][$i+$j], $k << 4, 16); //Block data $ordered[$i] .= substr($block, $k << 4, 16);
$ordered[$i] .= substr($c[1][$i+$j], $k << 3, 8); //Meta data $ordered[$i] .= substr($meta, $k << 3, 8);
} }
++$cnt;
} }
$i += $columnsPerPacket;
} }
return $ordered; return $ordered;
} }

View File

@ -74,7 +74,7 @@ class ChunkParser{
} }
private function getOffset($X, $Z, $sectors = 21){ private function getOffset($X, $Z, $sectors = 21){
return 0x1000 + (($Z * $sectors) << 12) + (($X * $sectors) << 16); return 0x1000 + (($X * $sectors) << 12) + (($Z * $sectors) << 16);
} }
private function getOffsetLocation($X, $Z){ private function getOffsetLocation($X, $Z){
@ -162,7 +162,7 @@ class ChunkParser{
$Z = $z >> 4; $Z = $z >> 4;
$aX = $x - ($X << 4); $aX = $x - ($X << 4);
$aZ = $z - ($Z << 4); $aZ = $z - ($Z << 4);
$index = $aX + ($aZ << 4); $index = $aZ + ($aX << 4);
$block = ord($this->map[$X][$Z][0][$index]{$y}); $block = ord($this->map[$X][$Z][0][$index]{$y});
$meta = ord($this->map[$X][$Z][1][$index]{$y >> 1}); $meta = ord($this->map[$X][$Z][1][$index]{$y >> 1});
if(($y & 1) === 0){ if(($y & 1) === 0){
@ -173,6 +173,11 @@ class ChunkParser{
return array($block, $meta); return array($block, $meta);
} }
public function getChunkColumn($X, $Z, $x, $z, $type = 0){
$index = $z + ($x << 4);
return $this->map[$X][$Z][$type][$index];
}
public function setBlock($x, $y, $z, $block, $meta = 0){ public function setBlock($x, $y, $z, $block, $meta = 0){
$x = (int) $x; $x = (int) $x;
$y = (int) $y; $y = (int) $y;
@ -181,7 +186,7 @@ class ChunkParser{
$Z = $z >> 4; $Z = $z >> 4;
$aX = $x - ($X << 4); $aX = $x - ($X << 4);
$aZ = $z - ($Z << 4); $aZ = $z - ($Z << 4);
$index = $aX + ($aZ << 4); $index = $aZ + ($aX << 4);
$this->map[$X][$Z][0][$index]{$y} = chr($block); $this->map[$X][$Z][0][$index]{$y} = chr($block);
$old_meta = ord($this->map[$X][$Z][1][$index]{$y >> 1}); $old_meta = ord($this->map[$X][$Z][1][$index]{$y >> 1});
if(($y & 1) === 0){ if(($y & 1) === 0){

View File

@ -304,7 +304,7 @@ class Session{
"x" => '.$data["x"].', "x" => '.$data["x"].',
"z" => '.$data["z"].', "z" => '.$data["z"].',
"data" => $d, "data" => $d,
)); ), true);
} }
'); ');
console("[INTERNAL] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 3); console("[INTERNAL] Chunk X ".$data["x"]." Z ".$data["z"]." requested", true, true, 3);