Implemented Level::getSafeSpawn()

This commit is contained in:
Shoghi Cervantes 2013-08-27 00:22:06 +02:00
parent 4a05f04a00
commit 9e337e21d2
5 changed files with 26 additions and 6 deletions

View File

@ -53,7 +53,7 @@ class LevelAPI{
$this->generateLevel($this->default, $this->server->seed); $this->generateLevel($this->default, $this->server->seed);
$this->loadLevel($this->default); $this->loadLevel($this->default);
} }
$this->server->spawn = $this->getDefault()->getSpawn(); $this->server->spawn = $this->getDefault()->getSafeSpawn();
} }
public function commandHandler($cmd, $params, $issuer, $alias){ public function commandHandler($cmd, $params, $issuer, $alias){

View File

@ -269,7 +269,7 @@ class PlayerAPI{
$origin = $this->get($name); $origin = $this->get($name);
if($origin instanceof Player){ if($origin instanceof Player){
$name = $origin->username; $name = $origin->username;
return $origin->teleport($lv->getSpawn()); return $origin->teleport($lv->getSafeSpawn());
} }
}else{ }else{
return false; return false;

View File

@ -1651,7 +1651,7 @@ class Player{
} }
$this->craftingItems = array(); $this->craftingItems = array();
$this->toCraft = 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( $this->server->api->player->broadcastPacket($this->server->api->player->getAll($this->level), MC_TILE_EVENT, array(
"x" => $this->windows[$data["windowid"]]->x, "x" => $this->windows[$data["windowid"]]->x,
"y" => $this->windows[$data["windowid"]]->y, "y" => $this->windows[$data["windowid"]]->y,
@ -1659,7 +1659,7 @@ class Player{
"case1" => 1, "case1" => 1,
"case2" => 0, "case2" => 0,
)); ));
} }*/
unset($this->windows[$data["windowid"]]); unset($this->windows[$data["windowid"]]);
$this->dataPacket(MC_CONTAINER_CLOSE, array( $this->dataPacket(MC_CONTAINER_CLOSE, array(

View File

@ -116,13 +116,13 @@ class ChestBlock extends TransparentBlock{
"slots" => CHEST_SLOTS, "slots" => CHEST_SLOTS,
"title" => "Chest", "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, "x" => $this->x,
"y" => $this->y, "y" => $this->y,
"z" => $this->z, "z" => $this->z,
"case1" => 1, "case1" => 1,
"case2" => 2, "case2" => 2,
)); ));*/
$slots = array(); $slots = array();
for($s = 0; $s < CHEST_SLOTS; ++$s){ for($s = 0; $s < CHEST_SLOTS; ++$s){
$slot = $chest->getSlot($s); $slot = $chest->getSlot($s);

View File

@ -421,6 +421,26 @@ class Level{
return new Position($this->level->getData("spawnX"), $this->level->getData("spawnY"), $this->level->getData("spawnZ"), $this); 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){ public function setSpawn(Vector3 $pos){
if(!isset($this->level)){ if(!isset($this->level)){
return false; return false;