Fixed crashes, added flying check

This commit is contained in:
Shoghi Cervantes Pueyo 2013-04-09 18:44:13 +02:00
parent 2043534003
commit 2b741a2913
4 changed files with 43 additions and 10 deletions

View File

@ -79,7 +79,7 @@ class BanAPI{
if(!$this->isOp($data["player"]->iusername)){
$t = new Vector2($data["target"]->x, $data["target"]->z);
$s = new Vector2($this->server->spawn["x"], $this->server->spawn["z"]);
if($t->distance($s) <= $this->server->getProperty("spawn-protection") and $this->server->api->dhandle($event.".spawn", $data) !== true){
if($t->distance($s) <= $this->server->api->getProperty("spawn-protection") and $this->server->api->dhandle($event.".spawn", $data) !== true){
return false;
}
}

View File

@ -104,9 +104,10 @@ class ServerAPI{
"spawn-protection" => 16,
"view-distance" => 7,
"max-players" => 20,
"allow-flight" => false,
"server-type" => "normal",
"time-per-second" => 20,
"gamemode" => 1,
"gamemode" => CREATIVE,
"pvp" => true,
"difficulty" => 1,
"generator" => "",

View File

@ -110,7 +110,7 @@ class Player{
public function getNextChunk($repeat = false){
$c = key($this->chunksOrder);
$d = $this->chunksOrder[$c];
if($c === null or $d > $this->server->getProperty("view-distance")){
if($c === null or $d > $this->server->api->getProperty("view-distance")){
$this->server->schedule(50, array($this, "getNextChunk"));
return false;
}
@ -858,7 +858,7 @@ class Player{
$data["entity"] = $this->entity;
if(!($target instanceof Entity)){
break;
}elseif($target->class === ENTITY_PLAYER and ($this->server->getProperty("pvp") == false or $this->server->difficulty <= 0 or $target->player->gamemode === CREATIVE)){
}elseif($target->class === ENTITY_PLAYER and ($this->server->api->getProperty("pvp") == false or $this->server->difficulty <= 0 or $target->player->gamemode === CREATIVE)){
break;
}elseif($this->handle("player.interact", $data) !== false){
switch($this->equipment->getID()){

View File

@ -304,10 +304,27 @@ class Entity extends stdClass{
}
if($this->class === ENTITY_ITEM or $this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER){
$x = (int) round($this->x - 0.5);
$startX = ((int) round($this->x - 0.5)) - 1;
$y = (int) round($this->y - 1);
$z = (int) round($this->z - 0.5);
$blockDown = $this->server->api->block->getBlock(new Vector3($x, $y, $z));
$startZ = ((int) round($this->z - 0.5)) - 1;
$endX = $startX + 2;
$endZ = $startZ + 2;
$support = false;
for($z = $startZ; $z < $endZ; ++$z){
for($x = $startX; $x < $endX; ++$x){
$v = new Vector3($x, $y, $z);
if($this->isSupport($v)){
$b = $this->server->api->block->getBlock($v);
if($b->isFlowable !== true){
$support = true;
break;
}
}
}
if($support === true){
break;
}
}
if($this->class === ENTITY_ITEM or $this->class === ENTITY_MOB){
if($this->speedX != 0){
$this->x += $this->speedX * 5;
@ -318,7 +335,7 @@ class Entity extends stdClass{
if($this->speedZ != 0){
$this->z += $this->speedZ * 5;
}
if($blockDown->isFlowable === true){
if($support === false){
$this->speedY -= 0.04 * 5;
//$this->server->api->handle("entity.motion", $this);
}elseif($this->speedY < 0){
@ -329,13 +346,18 @@ class Entity extends stdClass{
//$this->server->api->handle("entity.motion", $this);
}
}else{
if($blockDown->isFlowable === true){
if($support === false){
if($this->fallY === false){
$this->fallY = $y;
$this->fallStart = microtime(true);
}elseif($this->class === ENTITY_PLAYER and ($this->fallStart + 5) < microtime(true)){
if($this->player->gamemode === CREATIVE and $this->server->api->getProperty("allow-flight") !== true){
$this->player->close("flying");
return;
}
}elseif($y > $this->fallY){
$this->fallY = $y;
}
}
}elseif($this->fallY !== false){ //Fall damage!
if($y < $this->fallY){
$d = $this->server->api->block->getBlock(new Vector3($x, $y + 1, $z));
@ -546,6 +568,16 @@ class Entity extends stdClass{
}
return false;
}
public function isSupport(Vector3 $pos, $radius = 0.75){
$me = new Vector3($this->x - 0.5, $this->y, $this->z - 0.5);
$diff = $pos->y - $this->y;
var_dump($diff);
if($me->distance($pos) < $radius and $diff >= -0.16 and $diff <= 0.6){
return true;
}
return false;
}
public function resetSpeed(){
$this->speedMeasure = array(0, 0, 0, 0, 0);