mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 16:51:42 +00:00
PMF & Multiworld [part 3]
This commit is contained in:
parent
5938747083
commit
2254e87ce4
@ -359,7 +359,7 @@ class BlockAPI{
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,13 @@ class LevelAPI{
|
||||
public function __construct(){
|
||||
$this->server = ServerAPI::request();
|
||||
$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(){
|
||||
@ -54,6 +60,7 @@ class LevelAPI{
|
||||
$gen->save($path, $this->default);
|
||||
$this->loadLevel($this->default);
|
||||
}
|
||||
$this->server->spawn = $this->getDefault()->getSpawn();
|
||||
}
|
||||
|
||||
public function loadLevel($name){
|
||||
@ -85,11 +92,11 @@ class LevelAPI{
|
||||
));
|
||||
}elseif($entity["id"] === OBJECT_PAINTING){ //Painting
|
||||
$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"]);
|
||||
}else{
|
||||
$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"]);
|
||||
}
|
||||
}
|
||||
|
@ -302,6 +302,9 @@ class PlayerAPI{
|
||||
$player = $this->server->clients[$CID];
|
||||
$player->data = $this->getOffline($player->username);
|
||||
$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)."');");
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ class ServerAPI{
|
||||
"difficulty" => 1,
|
||||
"generator" => "",
|
||||
"generator-settings" => "",
|
||||
"level-name" => false,
|
||||
"level-name" => "world",
|
||||
"server-id" => false,
|
||||
"enable-query" => false,
|
||||
"enable-rcon" => false,
|
||||
@ -170,9 +170,6 @@ class ServerAPI{
|
||||
}
|
||||
$this->loadAPI("plugin", "PluginAPI"); //fix :(
|
||||
$this->plugin->init();
|
||||
|
||||
|
||||
$this->server->loadEntities();
|
||||
}
|
||||
|
||||
public function async(callable $callable, $params = array(), $remove = false){
|
||||
|
@ -93,8 +93,11 @@ class Player{
|
||||
console("[DEBUG] New Session started with ".$ip.":".$port.". MTU ".$this->MTU.", Client ID ".$this->clientID, true, true, 2);
|
||||
}
|
||||
|
||||
public function setSpawn(Position $pos){
|
||||
$this->spawnPosition = $pos;
|
||||
public function setSpawn(Vector3 $pos, $level){
|
||||
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(
|
||||
"x" => (int) $this->spawnPosition->x,
|
||||
"y" => (int) $this->spawnPosition->y,
|
||||
@ -546,7 +549,7 @@ class Player{
|
||||
$this->lastCorrect = $pos;
|
||||
$this->entity->fallY = 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->updateLast();
|
||||
$this->entity->calculateVelocity();
|
||||
@ -838,7 +841,7 @@ class Player{
|
||||
if(($this->gamemode & 0x01) === 0x01){
|
||||
$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->server->query("UPDATE players SET EID = ".$this->eid." WHERE clientID = ".$this->clientID.";");
|
||||
$this->entity->x = $this->data->get("position")["x"];
|
||||
@ -888,8 +891,8 @@ class Player{
|
||||
$this->sendSettings();
|
||||
$this->server->schedule(50, array($this, "orderChunks"), array(), true);
|
||||
$this->blocked = false;
|
||||
$this->teleport(new Vector3($this->data->get("position")["x"], $this->data->get("position")["y"], $this->data->get("position")["z"]));
|
||||
$this->setSpawn(new Vector3($this->data->get("spawn")["x"], $this->data->get("spawn")["y"], $this->data->get("spawn")["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->data->get("spawn")["level"]);
|
||||
break;
|
||||
case 2://Chunk loaded?
|
||||
break;
|
||||
@ -908,7 +911,7 @@ class Player{
|
||||
}
|
||||
console("[WARNING] ".$this->username." moved too quickly!");
|
||||
}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;
|
||||
|
@ -64,7 +64,7 @@ class PocketMinecraftServer{
|
||||
$this->description = "";
|
||||
$this->whitelist = false;
|
||||
$this->clients = array();
|
||||
$this->spawn = array("x" => 128.5,"y" => 100,"z" => 128.5);
|
||||
$this->spawn = false;
|
||||
$this->time = 0;
|
||||
$this->timePerSecond = 20;
|
||||
$this->tickMeasure = array_fill(0, 40, 0);
|
||||
|
@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
|
||||
class Packet{
|
||||
private $struct, $sock;
|
||||
private $struct;
|
||||
protected $pid, $packet;
|
||||
public $data, $raw;
|
||||
|
||||
@ -40,7 +40,6 @@ class Packet{
|
||||
$this->addRaw(chr($pid));
|
||||
}
|
||||
$this->struct = $struct;
|
||||
$this->sock = $sock;
|
||||
}
|
||||
|
||||
public function create($raw = false){
|
||||
|
@ -248,7 +248,7 @@ class Entity extends Position{
|
||||
switch($b->getID()){
|
||||
case WATER:
|
||||
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->updateMetadata();
|
||||
}
|
||||
@ -262,26 +262,26 @@ class Entity extends Position{
|
||||
break;
|
||||
case LAVA: //Lava damage
|
||||
case STILL_LAVA:
|
||||
if($this->inBlock($x, $y, $z)){
|
||||
if($this->inBlock(new Vector3($x, $y, $z))){
|
||||
$this->harm(5, "lava");
|
||||
$this->fire = 300;
|
||||
$this->updateMetadata();
|
||||
}
|
||||
break;
|
||||
case FIRE: //Fire block damage
|
||||
if($this->inBlock($x, $y, $z)){
|
||||
if($this->inBlock(new Vector3($x, $y, $z))){
|
||||
$this->harm(1, "fire");
|
||||
$this->fire = 300;
|
||||
$this->updateMetadata();
|
||||
}
|
||||
break;
|
||||
case CACTUS: //Cactus damage
|
||||
if($this->touchingBlock($x, $y, $z)){
|
||||
if($this->touchingBlock(new Vector3($x, $y, $z))){
|
||||
$this->harm(1, "cactus");
|
||||
}
|
||||
break;
|
||||
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
|
||||
}elseif($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)){
|
||||
$this->air = 300; //Breathing
|
||||
@ -362,8 +362,8 @@ class Entity extends Position{
|
||||
}
|
||||
}elseif($this->fallY !== false){ //Fall damage!
|
||||
if($y < $this->fallY){
|
||||
$d = $this->server->api->block->getBlock(new Vector3($x, $y + 1, $z));
|
||||
$d2 = $this->server->api->block->getBlock(new Vector3($x, $y + 2, $z));
|
||||
$d = $this->level->getBlock(new Vector3($x, $y + 1, $z));
|
||||
$d2 = $this->level->getBlock(new Vector3($x, $y + 2, $z));
|
||||
$dmg = ($this->fallY - $y) - 3;
|
||||
if($dmg > 0 and !($d instanceof LiquidBlock) and $d->getID() !== LADDER and !($d2 instanceof LiquidBlock) and $d2->getID() !== LADDER){
|
||||
$this->harm($dmg, "fall");
|
||||
@ -571,7 +571,7 @@ class Entity extends Position{
|
||||
|
||||
public function inBlock(Vector3 $block, $radius = 0.8){
|
||||
$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 false;
|
||||
@ -579,7 +579,7 @@ class Entity extends Position{
|
||||
|
||||
public function touchingBlock(Vector3 $block, $radius = 0.9){
|
||||
$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 false;
|
||||
|
@ -97,7 +97,7 @@ class Level{
|
||||
}
|
||||
|
||||
public function getOrderedMiniChunk($X, $Z, $Y, $MTU){
|
||||
$raw = $this->map->getMiniChunk($X, $Z, $Y);
|
||||
$raw = $this->level->getMiniChunk($X, $Z, $Y);
|
||||
$ordered = array();
|
||||
$i = 0;
|
||||
$ordered[$i] = "";
|
||||
|
@ -25,7 +25,7 @@ the Free Software Foundation, either version 3 of the License, or
|
||||
|
||||
*/
|
||||
|
||||
class Position{
|
||||
class Position extends Vector3{
|
||||
public $level;
|
||||
|
||||
public function __construct($x = 0, $y = 0, $z = 0, Level $level){
|
||||
|
Loading…
x
Reference in New Issue
Block a user