PMF & Multiworld [part 3]

This commit is contained in:
Shoghi Cervantes Pueyo 2013-05-14 20:58:53 +02:00
parent 5938747083
commit 2254e87ce4
10 changed files with 38 additions and 29 deletions

View File

@ -359,7 +359,7 @@ class BlockAPI{
return $this->cancelAction($block, $player); return $this->cancelAction($block, $player);
} }
if($hand->isTransparent === false and $player->entity->inBlock($block->x, $block->y, $block->z)){ if($hand->isTransparent === false and $player->entity->inBlock($block)){
return $this->cancelAction($block, $player); //Entity in block return $this->cancelAction($block, $player); //Entity in block
} }

View File

@ -30,7 +30,13 @@ class LevelAPI{
public function __construct(){ public function __construct(){
$this->server = ServerAPI::request(); $this->server = ServerAPI::request();
$this->levels = array(); $this->levels = array();
$this->map = $this->server->level; }
public function get($name){
if(isset($this->levels[$name])){
return $this->levels[$name];
}
return false;
} }
public function getDefault(){ public function getDefault(){
@ -54,6 +60,7 @@ class LevelAPI{
$gen->save($path, $this->default); $gen->save($path, $this->default);
$this->loadLevel($this->default); $this->loadLevel($this->default);
} }
$this->server->spawn = $this->getDefault()->getSpawn();
} }
public function loadLevel($name){ public function loadLevel($name){
@ -85,11 +92,11 @@ class LevelAPI{
)); ));
}elseif($entity["id"] === OBJECT_PAINTING){ //Painting }elseif($entity["id"] === OBJECT_PAINTING){ //Painting
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity); $e = $this->server->api->entity->add($this->levels[$name], ENTITY_OBJECT, $entity["id"], $entity);
$e->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]); $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth($entity["Health"]); $e->setHealth($entity["Health"]);
}else{ }else{
$e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity); $e = $this->server->api->entity->add($this->levels[$name], ENTITY_MOB, $entity["id"], $entity);
$e->setPosition($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2], $entity["Rotation"][0], $entity["Rotation"][1]); $e->setPosition(new Vector3($entity["Pos"][0], $entity["Pos"][1], $entity["Pos"][2]), $entity["Rotation"][0], $entity["Rotation"][1]);
$e->setHealth($entity["Health"]); $e->setHealth($entity["Health"]);
} }
} }

View File

@ -302,6 +302,9 @@ class PlayerAPI{
$player = $this->server->clients[$CID]; $player = $this->server->clients[$CID];
$player->data = $this->getOffline($player->username); $player->data = $this->getOffline($player->username);
$player->gamemode = $player->data->get("gamemode"); $player->gamemode = $player->data->get("gamemode");
if(($player->level = $this->server->api->level->get($player->data->get("position")["level"])) === false){
$player->level = $this->server->api->level->getDefault();
}
$this->server->query("INSERT OR REPLACE INTO players (clientID, ip, port, name) VALUES (".$player->clientID.", '".$player->ip."', ".$player->port.", '".strtolower($player->username)."');"); $this->server->query("INSERT OR REPLACE INTO players (clientID, ip, port, name) VALUES (".$player->clientID.", '".$player->ip."', ".$player->port.", '".strtolower($player->username)."');");
} }
} }

View File

@ -78,7 +78,7 @@ class ServerAPI{
"difficulty" => 1, "difficulty" => 1,
"generator" => "", "generator" => "",
"generator-settings" => "", "generator-settings" => "",
"level-name" => false, "level-name" => "world",
"server-id" => false, "server-id" => false,
"enable-query" => false, "enable-query" => false,
"enable-rcon" => false, "enable-rcon" => false,
@ -170,9 +170,6 @@ class ServerAPI{
} }
$this->loadAPI("plugin", "PluginAPI"); //fix :( $this->loadAPI("plugin", "PluginAPI"); //fix :(
$this->plugin->init(); $this->plugin->init();
$this->server->loadEntities();
} }
public function async(callable $callable, $params = array(), $remove = false){ public function async(callable $callable, $params = array(), $remove = false){

View File

@ -93,8 +93,11 @@ class Player{
console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2); console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2);
} }
public function setSpawn(Position $pos){ public function setSpawn(Vector3 $pos, $level){
$this->spawnPosition = $pos; if(($level = $this->server->api->level->get($level)) === false){
$level = $this->server->api->level->getDefault();
}
$this->spawnPosition = new Position($pos->x, $pos->y, $pos->z, $level);
$this->dataPacket(MC_SET_SPAWN_POSITION, array( $this->dataPacket(MC_SET_SPAWN_POSITION, array(
"x" => (int) $this->spawnPosition->x, "x" => (int) $this->spawnPosition->x,
"y" => (int) $this->spawnPosition->y, "y" => (int) $this->spawnPosition->y,
@ -546,7 +549,7 @@ class Player{
$this->lastCorrect = $pos; $this->lastCorrect = $pos;
$this->entity->fallY = false; $this->entity->fallY = false;
$this->entity->fallStart = false; $this->entity->fallStart = false;
$this->entity->setPosition($pos->x, $pos->y, $pos->z, $yaw, $pitch); $this->entity->setPosition($pos, $yaw, $pitch);
$this->entity->resetSpeed(); $this->entity->resetSpeed();
$this->entity->updateLast(); $this->entity->updateLast();
$this->entity->calculateVelocity(); $this->entity->calculateVelocity();
@ -838,7 +841,7 @@ class Player{
if(($this->gamemode & 0x01) === 0x01){ if(($this->gamemode & 0x01) === 0x01){
$this->equipment = BlockAPI::getItem($this->inventory[7][0], $this->inventory[7][1], $this->inventory[7][2]); $this->equipment = BlockAPI::getItem($this->inventory[7][0], $this->inventory[7][1], $this->inventory[7][2]);
} }
$this->entity = $this->server->api->entity->add(ENTITY_PLAYER, 0, array("player" => $this)); $this->entity = $this->server->api->entity->add($this->level, ENTITY_PLAYER, 0, array("player" => $this));
$this->eid = $this->entity->eid; $this->eid = $this->entity->eid;
$this->server->query("UPDATE players SET EID = ".$this->eid." WHERE clientID = ".$this->clientID.";"); $this->server->query("UPDATE players SET EID = ".$this->eid." WHERE clientID = ".$this->clientID.";");
$this->entity->x = $this->data->get("position")["x"]; $this->entity->x = $this->data->get("position")["x"];
@ -888,8 +891,8 @@ class Player{
$this->sendSettings(); $this->sendSettings();
$this->server->schedule(50, array($this, "orderChunks"), array(), true); $this->server->schedule(50, array($this, "orderChunks"), array(), true);
$this->blocked = false; $this->blocked = false;
$this->teleport(new Vector3($this->data->get("position")["x"], $this->data->get("position")["y"], $this->data->get("position")["z"])); $this->teleport(new Position($this->data->get("position")["x"], $this->data->get("position")["y"], $this->data->get("position")["z"], $this->level));
$this->setSpawn(new Vector3($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"])); $this->setSpawn(new Vector3($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["z"]), $this->data->get("spawn")["level"]);
break; break;
case 2://Chunk loaded? case 2://Chunk loaded?
break; break;
@ -908,7 +911,7 @@ class Player{
} }
console("[WARNING] ".$this->username." moved too quickly!"); console("[WARNING] ".$this->username." moved too quickly!");
}else{ }else{
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["yaw"], $data["pitch"]); $this->entity->setPosition(new Vector3($data["x"], $data["y"], $data["z"]), $data["yaw"], $data["pitch"]);
} }
} }
break; break;

View File

@ -64,7 +64,7 @@ class PocketMinecraftServer{
$this->description = ""; $this->description = "";
$this->whitelist = false; $this->whitelist = false;
$this->clients = array(); $this->clients = array();
$this->spawn = array("x" => 128.5,"y" => 100,"z" => 128.5); $this->spawn = false;
$this->time = 0; $this->time = 0;
$this->timePerSecond = 20; $this->timePerSecond = 20;
$this->tickMeasure = array_fill(0, 40, 0); $this->tickMeasure = array_fill(0, 40, 0);

View File

@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
class Packet{ class Packet{
private $struct, $sock; private $struct;
protected $pid, $packet; protected $pid, $packet;
public $data, $raw; public $data, $raw;
@ -40,7 +40,6 @@ class Packet{
$this->addRaw(chr($pid)); $this->addRaw(chr($pid));
} }
$this->struct = $struct; $this->struct = $struct;
$this->sock = $sock;
} }
public function create($raw = false){ public function create($raw = false){

View File

@ -248,7 +248,7 @@ class Entity extends Position{
switch($b->getID()){ switch($b->getID()){
case WATER: case WATER:
case STILL_WATER: //Drowing case STILL_WATER: //Drowing
if($this->fire > 0 and $this->inBlock($x, $y, $z)){ if($this->fire > 0 and $this->inBlock(new Vector3($x, $y, $z))){
$this->fire = 0; $this->fire = 0;
$this->updateMetadata(); $this->updateMetadata();
} }
@ -262,26 +262,26 @@ class Entity extends Position{
break; break;
case LAVA: //Lava damage case LAVA: //Lava damage
case STILL_LAVA: case STILL_LAVA:
if($this->inBlock($x, $y, $z)){ if($this->inBlock(new Vector3($x, $y, $z))){
$this->harm(5, "lava"); $this->harm(5, "lava");
$this->fire = 300; $this->fire = 300;
$this->updateMetadata(); $this->updateMetadata();
} }
break; break;
case FIRE: //Fire block damage case FIRE: //Fire block damage
if($this->inBlock($x, $y, $z)){ if($this->inBlock(new Vector3($x, $y, $z))){
$this->harm(1, "fire"); $this->harm(1, "fire");
$this->fire = 300; $this->fire = 300;
$this->updateMetadata(); $this->updateMetadata();
} }
break; break;
case CACTUS: //Cactus damage case CACTUS: //Cactus damage
if($this->touchingBlock($x, $y, $z)){ if($this->touchingBlock(new Vector3($x, $y, $z))){
$this->harm(1, "cactus"); $this->harm(1, "cactus");
} }
break; break;
default: default:
if($this->inBlock($x, $y, $z, 0.7) and $y == $endY and $b->isTransparent === false and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)){ if($this->inBlock(new Vector3($x, $y, $z), 0.7) and $y == $endY and $b->isTransparent === false and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)){
$this->harm(1, "suffocation"); //Suffocation $this->harm(1, "suffocation"); //Suffocation
}elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)){ }elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)){
$this->air = 300; //Breathing $this->air = 300; //Breathing
@ -362,8 +362,8 @@ class Entity extends Position{
} }
}elseif($this->fallY !== false){ //Fall damage! }elseif($this->fallY !== false){ //Fall damage!
if($y < $this->fallY){ if($y < $this->fallY){
$d = $this->server->api->block->getBlock(new Vector3($x, $y + 1, $z)); $d = $this->level->getBlock(new Vector3($x, $y + 1, $z));
$d2 = $this->server->api->block->getBlock(new Vector3($x, $y + 2, $z)); $d2 = $this->level->getBlock(new Vector3($x, $y + 2, $z));
$dmg = ($this->fallY - $y) - 3; $dmg = ($this->fallY - $y) - 3;
if($dmg > 0 and !($d instanceof LiquidBlock) and $d->getID() !== LADDER and !($d2 instanceof LiquidBlock) and $d2->getID() !== LADDER){ if($dmg > 0 and !($d instanceof LiquidBlock) and $d->getID() !== LADDER and !($d2 instanceof LiquidBlock) and $d2->getID() !== LADDER){
$this->harm($dmg, "fall"); $this->harm($dmg, "fall");
@ -571,7 +571,7 @@ class Entity extends Position{
public function inBlock(Vector3 $block, $radius = 0.8){ public function inBlock(Vector3 $block, $radius = 0.8){
$me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5); $me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5);
if(($y == ((int) $this->y) or $y == (((int) $this->y) + 1)) and $block->maxPlainDistance($me) < $radius){ if(($block->y == ((int) $this->y) or $block->y == (((int) $this->y) + 1)) and $block->maxPlainDistance($me) < $radius){
return true; return true;
} }
return false; return false;
@ -579,7 +579,7 @@ class Entity extends Position{
public function touchingBlock(Vector3 $block, $radius = 0.9){ public function touchingBlock(Vector3 $block, $radius = 0.9){
$me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5); $me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5);
if(($y == (((int) $this->y) - 1) or $y == ((int) $this->y) or $y == (((int) $this->y) + 1)) and $block->maxPlainDistance($me) < $radius){ if(($block->y == (((int) $this->y) - 1) or $block->y == ((int) $this->y) or $block->y == (((int) $this->y) + 1)) and $block->maxPlainDistance($me) < $radius){
return true; return true;
} }
return false; return false;

View File

@ -97,7 +97,7 @@ class Level{
} }
public function getOrderedMiniChunk($X, $Z, $Y, $MTU){ public function getOrderedMiniChunk($X, $Z, $Y, $MTU){
$raw = $this->map->getMiniChunk($X, $Z, $Y); $raw = $this->level->getMiniChunk($X, $Z, $Y);
$ordered = array(); $ordered = array();
$i = 0; $i = 0;
$ordered[$i] = ""; $ordered[$i] = "";

View File

@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
*/ */
class Position{ class Position extends Vector3{
public $level; public $level;
public function __construct($x = 0, $y = 0, $z = 0, Level $level){ public function __construct($x = 0, $y = 0, $z = 0, Level $level){