diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index f4aa31242..233491138 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -53,7 +53,7 @@ class LevelAPI{ $this->generateLevel($this->default, $this->server->seed); $this->loadLevel($this->default); } - $this->server->spawn = $this->getDefault()->getSpawn(); + $this->server->spawn = $this->getDefault()->getSafeSpawn(); } public function commandHandler($cmd, $params, $issuer, $alias){ diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 08e448234..f5eb3972c 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -269,7 +269,7 @@ class PlayerAPI{ $origin = $this->get($name); if($origin instanceof Player){ $name = $origin->username; - return $origin->teleport($lv->getSpawn()); + return $origin->teleport($lv->getSafeSpawn()); } }else{ return false; diff --git a/src/Player.php b/src/Player.php index 0434d0ca8..3912dbd15 100644 --- a/src/Player.php +++ b/src/Player.php @@ -1651,7 +1651,7 @@ class Player{ } $this->craftingItems = array(); $this->toCraft = array(); - if(isset($this->windows[$data["windowid"]]) and $this->windows[$data["windowid"]]->class === TILE_CHEST){ + /*if(isset($this->windows[$data["windowid"]]) and $this->windows[$data["windowid"]]->class === TILE_CHEST){ $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), MC_TILE_EVENT, array( "x" => $this->windows[$data["windowid"]]->x, "y" => $this->windows[$data["windowid"]]->y, @@ -1659,7 +1659,7 @@ class Player{ "case1" => 1, "case2" => 0, )); - } + }*/ unset($this->windows[$data["windowid"]]); $this->dataPacket(MC_CONTAINER_CLOSE, array( diff --git a/src/material/block/solid/Chest.php b/src/material/block/solid/Chest.php index f56033739..a4a760f60 100644 --- a/src/material/block/solid/Chest.php +++ b/src/material/block/solid/Chest.php @@ -116,13 +116,13 @@ class ChestBlock extends TransparentBlock{ "slots" => CHEST_SLOTS, "title" => "Chest", )); - $server->api->player->broadcastPacket($server->api->player->getAll($this->level), MC_TILE_EVENT, array( + /*$server->api->player->broadcastPacket($server->api->player->getAll($this->level), MC_TILE_EVENT, array( "x" => $this->x, "y" => $this->y, "z" => $this->z, "case1" => 1, "case2" => 2, - )); + ));*/ $slots = array(); for($s = 0; $s < CHEST_SLOTS; ++$s){ $slot = $chest->getSlot($s); diff --git a/src/world/Level.php b/src/world/Level.php index 2ffa6108a..8fa7d5e77 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -421,6 +421,26 @@ class Level{ return new Position($this->level->getData("spawnX"), $this->level->getData("spawnY"), $this->level->getData("spawnZ"), $this); } + public function getSafeSpawn(){ + if(($spawn = $this->getSpawn()) !== false){ + $x = (int) round($spawn->x); + $y = (int) round($spawn->y); + $z = (int) round($spawn->z); + for(; $y < 128; ++$y){ + $v = new Vector3($x, $y, $z); + if($this->getBlock($v->getSide(1)) instanceof AirBlock){ + if($this->getBlock($v) instanceof AirBlock){ + return new Position($x, $y, $z, $this); + } + }else{ + ++$y; + } + } + return new Position($x, $y, $z, $this); + } + return false; + } + public function setSpawn(Vector3 $pos){ if(!isset($this->level)){ return false;