From 72c4cc7a302c0e1c7b06ebc6b26a1699a3d45ff7 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Fri, 14 Dec 2012 15:48:18 +0100 Subject: [PATCH] X,Z offset fixed --- classes/API/LevelAPI.php | 7 +++++++ classes/API/PlayerAPI.php | 2 +- classes/ChunkParser.class.php | 3 +-- classes/CustomPacketHandler.class.php | 8 ++++---- classes/Session.class.php | 8 ++++++-- 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/classes/API/LevelAPI.php b/classes/API/LevelAPI.php index 212e4c77f..38214484c 100644 --- a/classes/API/LevelAPI.php +++ b/classes/API/LevelAPI.php @@ -50,6 +50,13 @@ class LevelAPI{ return false; } + public function getBlock($x, $y, $z){ + if($this->check()){ + return $this->map->getBlock($x, $y, $z); + } + return array(0,0); + } + public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){ $columnsPerPacket = max(1, (int) $columnsPerPacket); $c = $this->getChunk($X, $Z); diff --git a/classes/API/PlayerAPI.php b/classes/API/PlayerAPI.php index 4483f7cd5..90f711ed9 100644 --- a/classes/API/PlayerAPI.php +++ b/classes/API/PlayerAPI.php @@ -146,7 +146,7 @@ class PlayerAPI{ public function getOffline($name){ if(!file_exists(FILE_PATH."data/players/".$name.".dat")){ - console("[NOTICE] Player data not found for \"".$name."\", creating new"); + console("[NOTICE] Player data not found for \"".$name."\", creating new profile"); $data = array( "spawn" => array( "x" => $this->server->spawn["x"], diff --git a/classes/ChunkParser.class.php b/classes/ChunkParser.class.php index 51fa8d257..7090ff128 100644 --- a/classes/ChunkParser.class.php +++ b/classes/ChunkParser.class.php @@ -75,7 +75,7 @@ class ChunkParser{ private function getOffset($X, $Z, $sectors = 21){ //$info = $this->getOffsetPosition($X, $Z); //return 4096 + (($info[1] * $info[0]) << 12) + (($info[2] * $data[0]) << 16); - return 0x1000 + (($X * $sectors) << 12) + (($Z * $sectors) << 16); + return 0x1000 + (($Z * $sectors) << 12) + (($X * $sectors) << 16); } public function getChunk($X, $Z, $header = true){ @@ -163,7 +163,6 @@ class ChunkParser{ $aX = $x - ($X << 4); $aZ = $z - ($Z << 4); $index = $aX + ($aZ << 4); - console("[DEBUG] $x $y $z | $X $Z $index", true, true, 2); $block = ord($this->map[$X][$Z][0][$index]{$y}); //$meta = $this->getOffset($X, $Z) + 4 + (($x << 6) + $y + ($z << 10)); return array($block, 0); diff --git a/classes/CustomPacketHandler.class.php b/classes/CustomPacketHandler.class.php index 35fe9d4be..10ca279db 100644 --- a/classes/CustomPacketHandler.class.php +++ b/classes/CustomPacketHandler.class.php @@ -375,21 +375,21 @@ class CustomPacketHandler{ break; case MC_REQUEST_CHUNK: if($this->c === false){ - $this->data["z"] = Utils::readInt($this->get(4)); $this->data["x"] = Utils::readInt($this->get(4)); + $this->data["z"] = Utils::readInt($this->get(4)); }else{ - $this->raw .= Utils::writeInt($this->data["z"]); $this->raw .= Utils::writeInt($this->data["x"]); + $this->raw .= Utils::writeInt($this->data["z"]); } break; case MC_CHUNK_DATA: if($this->c === false){ - $this->data["z"] = Utils::readInt($this->get(4)); $this->data["x"] = Utils::readInt($this->get(4)); + $this->data["z"] = Utils::readInt($this->get(4)); $this->data["data"] = $this->get(true); }else{ - $this->raw .= Utils::writeInt($this->data["z"]); $this->raw .= Utils::writeInt($this->data["x"]); + $this->raw .= Utils::writeInt($this->data["z"]); $this->raw .= $this->data["data"]; } break; diff --git a/classes/Session.class.php b/classes/Session.class.php index c5abfb125..5c3337b53 100644 --- a/classes/Session.class.php +++ b/classes/Session.class.php @@ -367,13 +367,17 @@ class Session{ break; case MC_REMOVE_BLOCK: console("[DEBUG] EID ".$this->eid." broke block at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2); + $block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]); + if($block[0] === 0){ + break; + } $this->dataPacket(MC_ADD_ITEM_ENTITY, array( "eid" => $this->server->eidCnt++, "x" => $data["x"] + mt_rand(0, 100)/100, "y" => $data["y"], "z" => $data["z"] + mt_rand(0, 100)/100, - "block" => 1, - "meta" => 0, + "block" => $block[0], + "meta" => $block[1], "stack" => 1, )); /*$this->send(0x84, array(