diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 05f5c377..57c04b3b 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -70,7 +70,7 @@ class EntityAPI{ } elseif(is_numeric($args[1])){//summon [amount] $amount = (int) $args[1]; - if($amount > 100){ + if($amount > 1000){ return "Cannot spawn > 100 mobs"; } $isBaby = false; @@ -167,10 +167,7 @@ class EntityAPI{ } public function get($eid){ - if(isset($this->entities[$eid])){ - return $this->entities[$eid]; - } - return false; + return nullsafe($this->entities[$eid], false); } public function remove($eid){ diff --git a/src/Player.php b/src/Player.php index e35710d9..90cef4fa 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1167,6 +1167,7 @@ class Player{ $this->resendQueue = []; $this->ackQueue = []; $this->server->api->player->remove($this->CID); + console($msg.":".$this->username.":".$this->spawned); if($msg === true and $this->username != "" and $this->spawned !== false){ $this->server->api->chat->broadcast($this->username . " left the game: " . $reason); } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 5a90181b..2b893905 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -409,12 +409,12 @@ class Entity extends Position } } - $startX = (int) (round($this->x - 0.5) - 1); - $startY = (int) (round($this->y) - 1); - $startZ = (int) (round($this->z - 0.5) - 1); - $endX = $startX + 2; - $endY = $startY + 2; - $endZ = $startZ + 2; + $startX = $this->boundingBox->minX; + $startY = $this->boundingBox->minY; + $startZ = $this->boundingBox->minZ; + $endX = $this->boundingBox->maxX; + $endY = $this->boundingBox->maxY; + $endZ = $this->boundingBox->maxZ; $waterDone = false; for ($y = $startY; $y <= $endY; ++$y){ for ($x = $startX; $x <= $endX; ++$x){ @@ -432,7 +432,7 @@ class Entity extends Position $this->harm(2, "water"); $hasUpdate = true; $waterDone = true; - } elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1 - (($b->getMetadata() % 8) / 9)) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and ! $waterDone) { + } elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1 - (($b->getMetadata() % 8) / 9)) and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER) and !$waterDone) { $this->air -= 1; $waterDone = true; $this->updateMetadata(); @@ -463,7 +463,7 @@ class Entity extends Position } break; default: - if ($this->inBlock($pos, 0.7) and $y == $endY and $b->isTransparent === false and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)) { + if ($this->inBlock($pos, 0.7) and $y == $endY and !$b->isTransparent and ($this->class === ENTITY_MOB or $this->class === ENTITY_PLAYER)) { $this->harm(1, "suffocation"); // Suffocation $hasUpdate = true; } elseif ($x == ($endX - 1) and $y == $endY and $z == ($endZ - 1)) { @@ -576,7 +576,6 @@ class Entity extends Position $x1 = $x1 > 256 ? 256 : $x1; $y1 = $y1 > 128 ? 128 : $y1; $z1 = $z1 > 256 ? 256 : $z1; - $waterDone = false; for($x = $x0; $x < $x1; ++$x){ for($y = $y0; $y < $y1; ++$y){ for($z = $z0; $z < $z1; ++$z){ diff --git a/src/entity/ai/tasks/TaskTempt.php b/src/entity/ai/tasks/TaskTempt.php index 78172ad9..5c03b5a1 100644 --- a/src/entity/ai/tasks/TaskTempt.php +++ b/src/entity/ai/tasks/TaskTempt.php @@ -45,23 +45,26 @@ class TaskTempt extends TaskBase protected function findTarget($e, $r){ $svd = null; $svdDist = -1; - foreach($e->server->api->entity->getRadius($e, $r * 3, ENTITY_PLAYER) as $p){ + foreach($e->level->players as $p){ + $p = $p->entity; + if(Utils::distance_noroot($e, $p) > $r*$r){ + continue; + } if($svdDist === -1){ - $svdDist = Utils::manh_distance($e, $p); + $svdDist = Utils::distance_noroot($e, $p); $svd = $p; continue; } if($svd != null && $svdDist === 0){ $svd = $p; } - - if(($cd = Utils::manh_distance($e, $p)) < $svdDist){ + if(($cd = Utils::distance_noroot($e, $p)) < $svdDist){ $svdDist = $cd; $svd = $p; } } - if($svd == null || Utils::distance_noroot($e, $svd) > ($r * $r)){ + if($svd == null){ return null; } diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 24cb04cb..538324b6 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -558,7 +558,7 @@ class Utils{ return round($number, 0, PHP_ROUND_HALF_DOWN); } /** - * manhattan distance, less accurate, but still useful sometimes + * manhattan distance */ public static function manh_distance($pos1, $pos2){ if($pos1 instanceof Vector3){ diff --git a/src/world/Level.php b/src/world/Level.php index b2ab8d70..04868cda 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -502,7 +502,7 @@ class Level{ } $now = microtime(true); if($this->stopTime == true){ - + $time = $this->startTime; }else{ $time = $this->startTime + ($now - $this->startCheck) * 20; }