Adds beds

This commit is contained in:
Shoghi Cervantes 2013-09-03 22:50:47 +02:00
parent f7508adb29
commit 1677ce4b1d
4 changed files with 59 additions and 13 deletions

View File

@ -20,7 +20,7 @@
*/ */
class TimeAPI{ class TimeAPI{
var $phases = array( public static $phases = array(
"day" => 0, "day" => 0,
"sunset" => 9500, "sunset" => 9500,
"night" => 10900, "night" => 10900,
@ -105,7 +105,7 @@ class TimeAPI{
$time = !is_integer($time) ? $this->get(false, $time):$time; $time = !is_integer($time) ? $this->get(false, $time):$time;
if($time < TimeAPI::$phases["sunset"]){ if($time < TimeAPI::$phases["sunset"]){
$time = "day"; $time = "day";
}elseif($time < TimeAPI::$phase["night"]){ }elseif($time < TimeAPI::$phases["night"]){
$time = "sunset"; $time = "sunset";
}elseif($time < TimeAPI::$phases["sunrise"]){ }elseif($time < TimeAPI::$phases["sunrise"]){
$time = "night"; $time = "night";

View File

@ -41,6 +41,7 @@ class Player{
private $iusername; private $iusername;
private $eid = false; private $eid = false;
private $startAction = false; private $startAction = false;
private $isSleeping = false;
public $data; public $data;
public $entity = false; public $entity = false;
public $auth = false; public $auth = false;
@ -290,6 +291,39 @@ class Player{
} }
} }
public function sleepOn(Vector3 $pos){
$this->isSleeping = $pos;
$this->teleport(new Position($pos->x, $pos->y, $pos->z, $this->level));
if($this->entity instanceof Entity){
$this->entity->updateMetadata();
}
$this->setSpawn($pos);
$this->server->schedule(30, array($this, "checkSleep"));
}
public function stopSleep(){
$this->isSleeping = false;
if($this->entity instanceof Entity){
$this->entity->updateMetadata();
}
}
public function checkSleep(){
if($this->isSleeping !== false){
if($this->server->api->time->getPhase($this->level) === "night"){
foreach($this->server->api->player->getAll($this->level) as $p){
if($p->isSleeping === false){
return false;
}
}
$this->server->api->time->set("day", $this->level);
foreach($this->server->api->player->getAll($this->level) as $p){
$p->stopSleep();
}
}
}
}
public function hasSpace($type, $damage, $count){ public function hasSpace($type, $damage, $count){
$inv = $this->inventory; $inv = $this->inventory;
while($count > 0){ while($count > 0){
@ -1196,6 +1230,9 @@ class Player{
$this->entity->x = $this->data->get("position")["x"]; $this->entity->x = $this->data->get("position")["x"];
$this->entity->y = $this->data->get("position")["y"]; $this->entity->y = $this->data->get("position")["y"];
$this->entity->z = $this->data->get("position")["z"]; $this->entity->z = $this->data->get("position")["z"];
if(($level = $this->server->api->level->get($this->data->get("spawn")["level"])) !== false){
$this->spawnPosition = new Position($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"], $level);
}
$this->entity->check = false; $this->entity->check = false;
$this->entity->setName($this->username); $this->entity->setName($this->username);
$this->entity->data["CID"] = $this->CID; $this->entity->data["CID"] = $this->CID;
@ -1374,9 +1411,10 @@ class Player{
} }
$this->craftingItems = array(); $this->craftingItems = array();
$this->toCraft = array(); $this->toCraft = array();
if($this->entity->inAction === true){
switch($data["action"]){ switch($data["action"]){
case 5: //Shot arrow case 5: //Shot arrow
if($this->entity->inAction === true){
if($this->getSlot($this->slot)->getID() === BOW){ if($this->getSlot($this->slot)->getID() === BOW){
if($this->startAction !== false){ if($this->startAction !== false){
$time = microtime(true) - $this->startAction; $time = microtime(true) - $this->startAction;
@ -1389,13 +1427,15 @@ class Player{
$this->server->api->entity->spawnToAll($e); $this->server->api->entity->spawnToAll($e);
} }
} }
break;
}
} }
$this->startAction = false; $this->startAction = false;
$this->entity->inAction = false; $this->entity->inAction = false;
$this->entity->updateMetadata(); $this->entity->updateMetadata();
break; break;
case 6: //get out of the bed
$this->stopSleep();
}
break;
case MC_REMOVE_BLOCK: case MC_REMOVE_BLOCK:
if($this->spawned === false or $this->blocked === true or $this->entity->distance(new Vector3($data["x"], $data["y"], $data["z"])) > 8){ if($this->spawned === false or $this->blocked === true or $this->entity->distance(new Vector3($data["x"], $data["y"], $data["z"])) > 8){
$target = $this->level->getBlock(new Vector3($data["x"], $data["y"], $data["z"])); $target = $this->level->getBlock(new Vector3($data["x"], $data["y"], $data["z"]));

View File

@ -27,9 +27,10 @@ class BedBlock extends TransparentBlock{
} }
public function onActivate(Item $item, Player $player){ public function onActivate(Item $item, Player $player){
$player->dataPacket(MC_CLIENT_MESSAGE, array( $player->sleepOn($this);
/*$player->dataPacket(MC_CLIENT_MESSAGE, array(
"message" => "This bed has been corrupted by your hands!" "message" => "This bed has been corrupted by your hands!"
)); ));*/
return true; return true;
} }

View File

@ -575,6 +575,11 @@ class Entity extends Position{
$this->data["Color"] = mt_rand(0,15); $this->data["Color"] = mt_rand(0,15);
} }
$d[16]["value"] = (($this->data["Sheared"] == 1 ? 1:0) << 4) | ($this->data["Color"] & 0x0F); $d[16]["value"] = (($this->data["Sheared"] == 1 ? 1:0) << 4) | ($this->data["Color"] & 0x0F);
}elseif($this->class === ENTITY_PLAYER){
if($this->player->isSleeping !== false){
$d[16]["value"] = 2;
$d[17]["value"] = array($this->player->isSleeping->x, $this->player->isSleeping->y, $this->player->isSleeping->z);
}
} }
return $d; return $d;
} }