mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
2159
This commit is contained in:
parent
0f72601891
commit
2573e4f90d
14 changed files with 65 additions and 57 deletions
|
|
@ -274,10 +274,17 @@ class ConsoleAPI{
|
|||
}
|
||||
|
||||
public static function debug($msg){
|
||||
console($msg, true, true, 2);
|
||||
console("[DEBUG] ".$msg, true, true, 2);
|
||||
}
|
||||
public static function info($msg){
|
||||
console("[INFO] ".$msg);
|
||||
}
|
||||
public static function warn($msg){
|
||||
console("[WARNING] ".$msg);
|
||||
}
|
||||
public static function error($msg){
|
||||
console("[ERROR] ".$msg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class ConsoleLoop extends Thread{
|
||||
|
|
|
|||
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
interface ITileNavigator
|
||||
{
|
||||
public function navigate(PathTile $from, PathTile $to);
|
||||
public function navigate(PathTile $from, PathTile $to, $maxDist);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@ class PathTileXYZ extends PathTile
|
|||
return new Vector3($this->x, $this->y, $this->z);
|
||||
}
|
||||
|
||||
public function asArray(){
|
||||
return ["x" => $this->x, "y" => $this->y, "z" => $this->z];
|
||||
}
|
||||
|
||||
public function addOffset($offset){
|
||||
$this->x += $offset[0];
|
||||
$this->y += $offset[1];
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ class TileNavigator implements ITileNavigator
|
|||
return array_reverse($totalPath);
|
||||
}
|
||||
|
||||
public function navigate(PathTile $from, PathTile $to)
|
||||
public function navigate(PathTile $from, PathTile $to, $maxDist) //TODO optimizations, no arraylist
|
||||
{
|
||||
$closed = new ArrayList();
|
||||
$open = new ArrayList();
|
||||
|
|
@ -54,14 +54,20 @@ class TileNavigator implements ITileNavigator
|
|||
$closed->add($current);
|
||||
foreach($this->neighborProvider->getNeighbors($current) as $neighbor)
|
||||
{
|
||||
|
||||
if(in_array($neighbor, $visited)){
|
||||
continue;
|
||||
}
|
||||
|
||||
$visited[] = $neighbor;
|
||||
if ($closed->has($neighbor) || $this->blockedProvider->isBlocked($neighbor))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if(in_array($neighbor, $visited)){
|
||||
if(!Utils::in_range(Utils::distance($neighbor->asArray(), $from->asArray()), -$maxDist, $maxDist)){
|
||||
continue;
|
||||
}
|
||||
$visited[] = $neighbor;
|
||||
|
||||
$tentativeG = $gScore[(string) $current] + $this->distanceAlgorithm->calculate($current, $neighbor);
|
||||
|
||||
if (!$open->has($neighbor))
|
||||
|
|
|
|||
|
|
@ -780,6 +780,15 @@ class Entity extends Position
|
|||
if($this->class !== ENTITY_PLAYER && $update){
|
||||
$this->updateMovement();
|
||||
}
|
||||
|
||||
if($this->headYaw != $this->lastHeadYaw) {
|
||||
$this->lastHeadYaw = $this->headYaw;
|
||||
$pk = new RotateHeadPacket();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->yaw = $this->headYaw;
|
||||
$this->server->api->player->broadcastPacket($this->level->players, $pk);
|
||||
}
|
||||
|
||||
$this->needsUpdate = $hasUpdate;
|
||||
$this->lastUpdate = $now;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,13 @@ abstract class Living extends Entity implements Damageable, Pathfindable{
|
|||
$this->ai->updateTasks();
|
||||
}
|
||||
|
||||
$this->pathFollower->followPath();
|
||||
if($this->onGround){
|
||||
/*if($this->path === null && $this->pathFinder instanceof ITileNavigator){ // mt_rand(0, 120) === 0){
|
||||
$this->path = $this->pathFinder->navigate(new PathTileXYZ($this->x, $this->y, $this->z, $this->level), new PathTileXYZ($this->x + mt_rand(-10, 10), $this->y, $this->z + mt_rand(-10, 10), $this->level), 10);
|
||||
}*/
|
||||
$this->pathFollower->followPath();
|
||||
}
|
||||
|
||||
|
||||
parent::update();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,10 +21,6 @@ class MobController
|
|||
$oz = ($z > 0 ? 1 : ($z < 0 ? -1 : 0));
|
||||
$this->entity->moveEntityWithOffset($ox, $oy, $oz);
|
||||
$this->faceEntity($this->entity->add($ox, $oy, $oz));
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $this->entity->eid;
|
||||
$pk->yaw = $this->entity->yaw;
|
||||
$this->entity->server->api->player->broadcastPacket($this->entity->level->players, $pk);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -46,7 +42,7 @@ class MobController
|
|||
$tan = $z == 0 ? ($x < 0 ? 180 : 0) : (90 - rad2deg(atan($x / $z))); /*arctan(infinity) = pi/2 = (90deg) - 90 = 0*/
|
||||
$thetaOffset = $z <= 0 ? 90 : 270;
|
||||
$calcYaw = $tan + $thetaOffset;
|
||||
$this->entity->yaw = $calcYaw;
|
||||
$this->entity->headYaw = $calcYaw;
|
||||
if($pitch){
|
||||
$diff = sqrt($x * $x + $z * $z);
|
||||
$calcPitch = rad2deg(atan($y / $diff));
|
||||
|
|
|
|||
|
|
@ -25,11 +25,7 @@ class TaskLookAround extends TaskBase
|
|||
$this->selfCounter = 0;
|
||||
}
|
||||
$v = min(Utils::getSign($this->rotation) * 10, $this->rotation);
|
||||
$ai->entity->yaw += $v;
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $ai->entity->eid;
|
||||
$pk->yaw = $ai->entity->yaw;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
|
||||
$ai->entity->headYaw += $v;
|
||||
$this->rotation -= $v;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,10 +47,6 @@ class TaskLookAtPlayer extends TaskBase{
|
|||
return;
|
||||
}
|
||||
$ai->mobController->lookOn($this->target);
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $ai->entity->eid;
|
||||
$pk->yaw = $ai->entity->yaw;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
|
||||
$this->selfCounter--;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,10 +23,6 @@ class TaskTempt extends TaskBase
|
|||
}
|
||||
//TODO following
|
||||
$ai->mobController->lookOn($this->target);
|
||||
$pk = new RotateHeadPacket(); //TODO headYaw auto update
|
||||
$pk->eid = $ai->entity->eid;
|
||||
$pk->yaw = $ai->entity->yaw;
|
||||
$ai->entity->server->api->player->broadcastPacket($ai->entity->level->players, $pk);
|
||||
}
|
||||
|
||||
public function canBeExecuted(EntityAI $ai)
|
||||
|
|
|
|||
|
|
@ -50,6 +50,6 @@ class UDPSocket{
|
|||
return false;
|
||||
}
|
||||
|
||||
return socket_sendto($this->sock, $data, strlen($data), MSG_DONTROUTE, $dest, $port);
|
||||
return @socket_sendto($this->sock, $data, strlen($data), MSG_DONTROUTE, $dest, $port);
|
||||
}
|
||||
}
|
||||
|
|
@ -87,11 +87,11 @@ class RakNetCodec{
|
|||
++$pointer;
|
||||
if($type === false){
|
||||
$payload .= "\x00";
|
||||
$payload .= strrev(Utils::writeTriad($start));
|
||||
$payload .= strrev(Utils::writeTriad($end));
|
||||
$payload .= Utils::writeLTriad($start);
|
||||
$payload .= Utils::writeLTriad($end);
|
||||
}else{
|
||||
$payload .= Utils::writeBool(true);
|
||||
$payload .= strrev(Utils::writeTriad($start));
|
||||
$payload .= Utils::writeLTriad($start);
|
||||
}
|
||||
++$records;
|
||||
}
|
||||
|
|
@ -126,7 +126,7 @@ class RakNetCodec{
|
|||
}
|
||||
|
||||
protected function putLTriad($v){
|
||||
$this->buffer .= strrev(Utils::writeTriad($v));
|
||||
$this->buffer .= Utils::writeLTriad($v);
|
||||
}
|
||||
|
||||
private function encodeDataPacket(RakNetDataPacket $pk){
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ abstract class RakNetDataPacket extends stdClass{
|
|||
}
|
||||
|
||||
protected function putLTriad($v){
|
||||
$this->buffer .= strrev(Utils::writeTriad($v));
|
||||
$this->buffer .= Utils::writeLTriad($v);
|
||||
}
|
||||
|
||||
protected function getDataArray($len = 10){
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function in_range($num, $min, $max){
|
||||
return $num >= $min && $num <= $max;
|
||||
return $num >= $min && $num <= $max;
|
||||
}
|
||||
|
||||
public function xrange($start, $limit, $step = 1) {
|
||||
|
|
@ -274,9 +274,6 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function writeLShort($value){
|
||||
if($value < 0){
|
||||
$value += 0x10000;
|
||||
}
|
||||
return pack("v", $value);
|
||||
}
|
||||
|
||||
|
|
@ -296,9 +293,6 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function writeShort($value){
|
||||
if($value < 0){
|
||||
$value += 0x10000;
|
||||
}
|
||||
return pack("n", $value);
|
||||
}
|
||||
|
||||
|
|
@ -402,11 +396,11 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function readLInt($str){
|
||||
list(, $unpacked) = @unpack("V", $str);
|
||||
if($unpacked >= 2147483648){
|
||||
$unpacked -= 4294967296;
|
||||
if(PHP_INT_SIZE === 8){
|
||||
return @unpack("V", $str)[1] << 32 >> 32;
|
||||
}else{
|
||||
return @unpack("V", $str)[1];
|
||||
}
|
||||
return (int) $unpacked;
|
||||
}
|
||||
|
||||
public static function readLFloat($str){
|
||||
|
|
@ -427,8 +421,7 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function readTriad($str){
|
||||
list(, $unpacked) = @unpack("N", "\x00" . $str);
|
||||
return $unpacked;
|
||||
return @unpack("N", "\x00" . $str)[1];
|
||||
}
|
||||
|
||||
public static function writeDataArray($data){
|
||||
|
|
@ -439,7 +432,11 @@ class Utils{
|
|||
}
|
||||
return $raw;
|
||||
}
|
||||
|
||||
|
||||
public static function writeLTriad($value){
|
||||
return substr(pack("V", $value), 0, -1);
|
||||
}
|
||||
|
||||
public static function writeTriad($value){
|
||||
return substr(pack("N", $value), 1);
|
||||
}
|
||||
|
|
@ -563,7 +560,7 @@ class Utils{
|
|||
* Euclidian distance, but without square roots
|
||||
*/
|
||||
public static function distance_noroot(Vector3 $pos1, Vector3 $pos2){
|
||||
return pow($pos2->x - $pos1->x, 2) + pow($pos2->z - $pos1->z, 2) + pow($pos2->z - $pos1->z, 2);
|
||||
return ($pos2->x - $pos1->x)*($pos2->x - $pos1->x) + ($pos2->z - $pos1->z)*($pos2->z - $pos1->z) + ($pos2->z - $pos1->z)*($pos2->z - $pos1->z);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -579,7 +576,7 @@ class Utils{
|
|||
if($pos2 instanceof Vector3){
|
||||
$pos2 = $pos2->toArray();
|
||||
}
|
||||
return sqrt(pow($pos1["x"] - $pos2["x"], 2) + pow($pos1["y"] - $pos2["y"], 2) + pow($pos1["z"] - $pos2["z"], 2));
|
||||
return sqrt(($pos1["x"] - $pos2["x"])*($pos1["x"] - $pos2["x"]) + ($pos1["y"] - $pos2["y"])*($pos1["y"] - $pos2["y"]) + ($pos1["z"] - $pos2["z"])*($pos1["z"] - $pos2["z"]));
|
||||
}
|
||||
|
||||
public static function angle3D($pos1, $pos2){
|
||||
|
|
@ -637,16 +634,11 @@ class Utils{
|
|||
}
|
||||
|
||||
public static function readInt($str){
|
||||
if(strlen($str) === 0){
|
||||
return;
|
||||
if(PHP_INT_SIZE === 8){
|
||||
return @unpack("N", $str)[1] << 32 >> 32;
|
||||
}else{
|
||||
return @unpack("N", $str)[1];
|
||||
}
|
||||
|
||||
list(, $unpacked) = unpack("N", $str);
|
||||
if($unpacked >= 2147483648){
|
||||
$unpacked -= 4294967296;
|
||||
}
|
||||
|
||||
return (int) $unpacked;
|
||||
}
|
||||
|
||||
public static function writeInt($value){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue