mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
mob fixes related to time and headYaw
This commit is contained in:
parent
0a36a67f78
commit
21d0530d39
9 changed files with 35 additions and 27 deletions
|
|
@ -134,7 +134,8 @@ class ServerAPI{
|
|||
if(ADVANCED_CACHE == true){
|
||||
console("[INFO] Advanced cache enabled");
|
||||
}
|
||||
|
||||
MobSpawner::$spawnAnimals = $this->getProperty("spawn-animals");
|
||||
MobSpawner::$spawnMobs = $this->getProperty("spawn-mobs");
|
||||
if($this->getProperty("upnp-forwarding") == true){
|
||||
console("[INFO] [UPnP] Trying to port forward...");
|
||||
UPnP_PortForward($this->getProperty("server-port"));
|
||||
|
|
|
|||
|
|
@ -197,10 +197,13 @@ class Entity extends Position
|
|||
$this->speedY += $vY;
|
||||
$this->speedZ += $vZ;
|
||||
}
|
||||
|
||||
public function isMovingHorizontally()
|
||||
{
|
||||
return ($this->speedX > 0.01 || $this->speedX < - 0.01) || ($this->speedZ > 0.01 || $this->speedZ < - 0.01);
|
||||
}
|
||||
public function isMoving()
|
||||
{
|
||||
return ($this->speedX > 0.01 || $this->speedX < - 0.01) || ($this->speedY > 0.007 || $this->speedY < - 0.007) || ($this->speedZ > 0.01 || $this->speedZ < - 0.01);
|
||||
return $this->isMovingHorizontally() || ($this->speedY > 0.007 || $this->speedY < - 0.007);
|
||||
}
|
||||
|
||||
public function setVelocity($vX, $vY = 0, $vZ = 0)
|
||||
|
|
@ -756,14 +759,6 @@ class Entity extends Position
|
|||
$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;
|
||||
}
|
||||
|
|
@ -774,13 +769,13 @@ class Entity extends Position
|
|||
return false;
|
||||
}
|
||||
$now = microtime(true);
|
||||
if($this->isStatic === false and ($this->last[0] != $this->x or $this->last[1] != $this->y or $this->last[2] != $this->z or $this->last[3] != $this->yaw or $this->last[4] != $this->pitch)){
|
||||
if($this->isStatic === false and ($this->lastX != $this->x or $this->lastY != $this->y or $this->lastZ != $this->z or $this->lastYaw != $this->yaw or $this->lastPitch != $this->pitch or $this->lastHeadYaw != $this->headYaw)){
|
||||
if($this->class === ENTITY_PLAYER or ($this->last[5] + 8) < $now){
|
||||
if($this->server->api->handle("entity.move", $this) === false){
|
||||
if($this->class === ENTITY_PLAYER){
|
||||
$this->player->teleport(new Vector3($this->last[0], $this->last[1], $this->last[2]), $this->last[3], $this->last[4]);
|
||||
} else{
|
||||
$this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]);
|
||||
//TODO fix $this->setPosition($this->last[0], $this->last[1], $this->last[2], $this->last[3], $this->last[4]);
|
||||
}
|
||||
} else{
|
||||
$this->updateLast();
|
||||
|
|
@ -797,6 +792,7 @@ class Entity extends Position
|
|||
$pk->bodyYaw = $this->yaw;
|
||||
$this->server->api->player->broadcastPacket($players, $pk);
|
||||
} else{
|
||||
|
||||
$pk = new MoveEntityPacket_PosRot();
|
||||
$pk->eid = $this->eid;
|
||||
$pk->x = $this->x;
|
||||
|
|
@ -814,6 +810,8 @@ class Entity extends Position
|
|||
}
|
||||
$this->updateLast();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$this->lastUpdate = $now;
|
||||
|
|
|
|||
|
|
@ -35,14 +35,17 @@ class MobController
|
|||
|
||||
$tan = $dz == 0 ? ($dx < 0 ? 180 : 0) : (90 - rad2deg(atan($dx / $dz)));
|
||||
$thetaOffset = $dz < 0 ? 90 : 270;
|
||||
$this->entity->yaw = $this->entity->headYaw = ($thetaOffset + $tan);
|
||||
$calcYaw = ($thetaOffset + $tan);
|
||||
$this->entity->yaw = $this->entity->headYaw = $calcYaw;
|
||||
}
|
||||
|
||||
public function lookOffset($x, $y, $z, $pitch = true){
|
||||
$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->headYaw = $calcYaw;
|
||||
|
||||
$this->entity->yaw = $this->entity->headYaw = $calcYaw;
|
||||
|
||||
if($pitch){
|
||||
$diff = sqrt($x * $x + $z * $z);
|
||||
$calcPitch = rad2deg(atan($y / $diff));
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ class TaskLookAtPlayer extends TaskBase{
|
|||
public $target = false;
|
||||
private $state, $yaw, $pitch;
|
||||
public function canBeExecuted(EntityAI $ai){
|
||||
return Utils::randomFloat() < 0.02 && !$ai->entity->isMoving() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath();
|
||||
return Utils::randomFloat() < 0.02 && !$ai->entity->isMovingHorizontally() && !$ai->isStarted("TaskLookAround") && !$ai->isStarted("TaskTempt") && !$ai->entity->hasPath();
|
||||
}
|
||||
|
||||
protected function findTarget($e, $r){
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Skeleton extends Monster{
|
|||
}
|
||||
|
||||
public function updateBurning(){
|
||||
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
|
||||
if($this->fire > 0 or !$this->level->isDay()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Zombie extends Monster{
|
|||
}
|
||||
|
||||
public function updateBurning(){
|
||||
if($this->fire > 0 or $this->server->api->time->getPhase($this->level->getTime()) != "day"){
|
||||
if($this->fire > 0 or !$this->level->isDay()){
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class Utils{
|
|||
public static function wrapAngleTo180_float($par0)
|
||||
{
|
||||
$par0 %= 360.0;
|
||||
return $par0 >= 180 ? $par0 - 360 : ($par0 + 360);
|
||||
return $par0 >= 180 ? $par0 - 360 : (($par0 < -180) ? ($par0 + 360) : $par0);
|
||||
}
|
||||
|
||||
public static function getSign($v){
|
||||
|
|
|
|||
|
|
@ -81,6 +81,13 @@ class Level{
|
|||
unset($this->mobSpawner->level);
|
||||
}
|
||||
|
||||
public function isDay(){
|
||||
return $this->getTime() % 19200 < TimeAPI::$phases["sunset"];
|
||||
}
|
||||
public function isNight(){
|
||||
$t = $this->getTime() % 19200;
|
||||
return $t < TimeAPI::$phases["sunrise"] && $t > TimeAPI::$phases["sunset"];
|
||||
}
|
||||
public function save($force = false, $extra = true){
|
||||
if(!isset($this->level)){
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
class MobSpawner{
|
||||
public static $spawnAnimals = false, $spawnMobs = false;
|
||||
private $server;
|
||||
public $level;
|
||||
const MOB_LIMIT = 50; //constant for now
|
||||
|
|
@ -11,10 +12,8 @@ class MobSpawner{
|
|||
|
||||
public function countEntities(){
|
||||
$ents = 0;
|
||||
foreach($this->level->entityList as $e){ //TODO no for loop
|
||||
if(!$e->isPlayer() && $e->class === ENTITY_MOB){
|
||||
++$ents;
|
||||
}
|
||||
foreach($this->level->entityList as $e){
|
||||
if(!$e->isPlayer() && $e->class === ENTITY_MOB) ++$ents;
|
||||
}
|
||||
return $ents;
|
||||
}
|
||||
|
|
@ -28,12 +27,10 @@ class MobSpawner{
|
|||
|
||||
public function spawnMobs(){
|
||||
|
||||
$t = $this->level->getTime();
|
||||
if($this->server->api->getProperty("spawn-animals") && $t <= 9500){ //Animal
|
||||
if(self::$spawnAnimals && $this->level->isDay()){ //Animal
|
||||
$type = mt_rand(10, 13);
|
||||
$baby = false; //TODO baby
|
||||
}else
|
||||
if($this->server->api->getProperty("spawn-mobs") && $t >= 10000){ //Monster
|
||||
}elseif(self::$spawnMobs && $this->level->isNight()){ //Monster
|
||||
$type = mt_rand(32, 35);
|
||||
$baby = 2;
|
||||
}else{
|
||||
|
|
@ -47,7 +44,9 @@ class MobSpawner{
|
|||
}
|
||||
$data = $this->genPosData($x, $y + 1, $z);
|
||||
if($baby != 2) $data["IsBaby"] = $baby;
|
||||
|
||||
$e = $this->server->api->entity->add($this->level, 2, $type, $data);
|
||||
|
||||
if($e instanceof Entity){
|
||||
$this->server->api->entity->spawnToAll($e);
|
||||
//console("[DEBUG] $type spawned at $x, $y, $z");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue