mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-20 15:41:33 +00:00
Implemented scheduled and partial entity updates
This commit is contained in:
@@ -67,14 +67,17 @@ class Arrow extends Projectile{
|
||||
|
||||
}
|
||||
|
||||
public function onUpdate(){
|
||||
public function onUpdate($currentTick){
|
||||
if($this->closed){
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->timings->startTiming();
|
||||
|
||||
$this->entityBaseTick();
|
||||
$tickDiff = max(1, $currentTick - $this->lastUpdate);
|
||||
$this->lastUpdate = $currentTick;
|
||||
|
||||
$hasUpdate = $this->entityBaseTick($tickDiff);
|
||||
|
||||
if(!$this->dead){
|
||||
|
||||
@@ -143,6 +146,7 @@ class Arrow extends Projectile{
|
||||
}
|
||||
|
||||
$this->kill();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,14 +160,16 @@ class Arrow extends Projectile{
|
||||
$this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this));
|
||||
}
|
||||
|
||||
if($this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){
|
||||
if(!$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){
|
||||
$f = sqrt(($this->motionX ** 2) + ($this->motionZ ** 2));
|
||||
$this->yaw = (atan2($this->motionX, $this->motionZ) * 180 / M_PI);
|
||||
$this->pitch = (atan2($this->motionY, $f) * 180 / M_PI);
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
if($this->age > 1200){
|
||||
$this->kill();
|
||||
$hasUpdate = true;
|
||||
}
|
||||
$this->updateMovement();
|
||||
|
||||
@@ -171,7 +177,7 @@ class Arrow extends Projectile{
|
||||
|
||||
$this->timings->stopTiming();
|
||||
|
||||
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
|
||||
return $hasUpdate;
|
||||
}
|
||||
|
||||
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
||||
|
||||
@@ -73,19 +73,22 @@ class DroppedItem extends Entity{
|
||||
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
|
||||
}
|
||||
|
||||
public function onUpdate(){
|
||||
public function onUpdate($currentTick){
|
||||
if($this->closed !== false){
|
||||
return false;
|
||||
}
|
||||
|
||||
$tickDiff = max(1, $currentTick - $this->lastUpdate);
|
||||
$this->lastUpdate = $currentTick;
|
||||
|
||||
$this->timings->startTiming();
|
||||
|
||||
$this->entityBaseTick();
|
||||
$hasUpdate = $this->entityBaseTick($tickDiff);
|
||||
|
||||
if(!$this->dead){
|
||||
|
||||
if($this->pickupDelay > 0 and $this->pickupDelay < 32767){ //Infinite delay
|
||||
--$this->pickupDelay;
|
||||
$this->pickupDelay -= $tickDiff;
|
||||
}
|
||||
|
||||
$this->motionY -= $this->gravity;
|
||||
@@ -115,6 +118,7 @@ class DroppedItem extends Entity{
|
||||
$this->age = 0;
|
||||
}else{
|
||||
$this->kill();
|
||||
$hasUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +126,7 @@ class DroppedItem extends Entity{
|
||||
|
||||
$this->timings->stopTiming();
|
||||
|
||||
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
|
||||
return $hasUpdate or !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
|
||||
}
|
||||
|
||||
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
||||
|
||||
@@ -142,8 +142,6 @@ abstract class Entity extends Location implements Metadatable{
|
||||
protected $fireProof;
|
||||
private $invulnerable;
|
||||
|
||||
protected $spawnTime;
|
||||
|
||||
protected $gravity;
|
||||
protected $drag;
|
||||
|
||||
@@ -215,7 +213,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->chunk->addEntity($this);
|
||||
$this->getLevel()->addEntity($this);
|
||||
$this->initEntity();
|
||||
$this->lastUpdate = $this->spawnTime = microtime(true);
|
||||
$this->lastUpdate = $this->server->getTick();
|
||||
$this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this));
|
||||
|
||||
$this->scheduleUpdate();
|
||||
@@ -462,7 +460,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
}
|
||||
}
|
||||
|
||||
public function entityBaseTick(){
|
||||
public function entityBaseTick($tickDiff = 1){
|
||||
|
||||
Timings::$tickEntityTimer->startTiming();
|
||||
//TODO: check vehicles
|
||||
@@ -476,7 +474,7 @@ abstract class Entity extends Location implements Metadatable{
|
||||
$this->close();
|
||||
}
|
||||
Timings::$tickEntityTimer->stopTiming();
|
||||
return false;
|
||||
return $isPlayer;
|
||||
}
|
||||
|
||||
$hasUpdate = false;
|
||||
@@ -488,36 +486,39 @@ abstract class Entity extends Location implements Metadatable{
|
||||
if(!$ev->isCancelled()){
|
||||
$this->attack($ev->getFinalDamage(), $ev);
|
||||
}
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
if($this->fireTicks > 0){
|
||||
if($this->fireProof){
|
||||
$this->fireTicks -= 4;
|
||||
$this->fireTicks -= 4 * $tickDiff;
|
||||
if($this->fireTicks < 0){
|
||||
$this->fireTicks = 0;
|
||||
}
|
||||
}else{
|
||||
if(($this->fireTicks % 20) === 0){
|
||||
if(($this->fireTicks % 20) === 0 or $tickDiff > 20){
|
||||
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
if(!$ev->isCancelled()){
|
||||
$this->attack($ev->getFinalDamage(), $ev);
|
||||
}
|
||||
}
|
||||
--$this->fireTicks;
|
||||
$this->fireTicks -= $tickDiff;
|
||||
}
|
||||
|
||||
if($this->fireTicks <= 0){
|
||||
$this->extinguish();
|
||||
}else{
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
++$this->age;
|
||||
++$this->ticksLived;
|
||||
$this->age += $tickDiff;
|
||||
$this->ticksLived += $tickDiff;
|
||||
|
||||
Timings::$tickEntityTimer->stopTiming();
|
||||
|
||||
return $hasUpdate;
|
||||
}
|
||||
|
||||
public function updateMovement(){
|
||||
@@ -587,20 +588,24 @@ abstract class Entity extends Location implements Metadatable{
|
||||
return new Vector3($x, $y, $z);
|
||||
}
|
||||
|
||||
public function onUpdate(){
|
||||
public function onUpdate($currentTick){
|
||||
if($this->closed){
|
||||
return false;
|
||||
}
|
||||
|
||||
$tickDiff = max(1, $currentTick - $this->lastUpdate);
|
||||
$this->lastUpdate = $currentTick;
|
||||
|
||||
$this->timings->startTiming();
|
||||
|
||||
$hasUpdate = $this->entityBaseTick();
|
||||
$hasUpdate = $this->entityBaseTick($tickDiff);
|
||||
|
||||
$this->updateMovement();
|
||||
|
||||
$this->timings->stopTiming();
|
||||
|
||||
//if($this->isStatic())
|
||||
return true;
|
||||
return $hasUpdate;
|
||||
//return !($this instanceof Player);
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class FallingBlock extends Entity{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function onUpdate(){
|
||||
public function onUpdate($currentTick){
|
||||
|
||||
if($this->closed){
|
||||
return false;
|
||||
@@ -74,7 +74,10 @@ class FallingBlock extends Entity{
|
||||
|
||||
$this->timings->startTiming();
|
||||
|
||||
$this->entityBaseTick();
|
||||
$tickDiff = max(1, $currentTick - $this->lastUpdate);
|
||||
$this->lastUpdate = $currentTick;
|
||||
|
||||
$hasUpdate = $this->entityBaseTick($tickDiff);
|
||||
|
||||
if(!$this->dead){
|
||||
if($this->ticksLived === 1){
|
||||
@@ -110,13 +113,13 @@ class FallingBlock extends Entity{
|
||||
$this->getLevel()->setBlock($pos, $ev->getTo(), true);
|
||||
}
|
||||
}
|
||||
$hasUpdate = true;
|
||||
}
|
||||
|
||||
$this->updateMovement();
|
||||
}
|
||||
|
||||
|
||||
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
|
||||
return $hasUpdate or !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
|
||||
}
|
||||
|
||||
public function getBlock(){
|
||||
|
||||
@@ -130,7 +130,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
}
|
||||
}
|
||||
|
||||
public function entityBaseTick(){
|
||||
public function entityBaseTick($tickDiff = 1){
|
||||
Timings::$timerEntityBaseTick->startTiming();
|
||||
parent::entityBaseTick();
|
||||
|
||||
@@ -142,7 +142,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
}
|
||||
|
||||
if($this->dead !== true and $this->isInsideOfWater()){
|
||||
--$this->airTicks;
|
||||
$this->airTicks -= $tickDiff;
|
||||
if($this->airTicks <= -20){
|
||||
$this->airTicks = 0;
|
||||
|
||||
@@ -156,7 +156,7 @@ abstract class Living extends Entity implements Damageable{
|
||||
}
|
||||
|
||||
if($this->attackTime > 0){
|
||||
--$this->attackTime;
|
||||
$this->attackTime -= $tickDiff;
|
||||
}
|
||||
|
||||
Timings::$timerEntityBaseTick->stopTiming();
|
||||
|
||||
@@ -71,7 +71,7 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
$this->namedtag->Fuse = new Byte("Fuse", $this->fuse);
|
||||
}
|
||||
|
||||
public function onUpdate(){
|
||||
public function onUpdate($currentTick){
|
||||
|
||||
if($this->closed){
|
||||
return false;
|
||||
@@ -79,7 +79,10 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
|
||||
$this->timings->startTiming();
|
||||
|
||||
$this->entityBaseTick();
|
||||
$tickDiff = max(1, $currentTick - $this->lastUpdate);
|
||||
$this->lastUpdate = $currentTick;
|
||||
|
||||
$hasUpdate = $this->entityBaseTick($tickDiff);
|
||||
|
||||
if(!$this->dead){
|
||||
|
||||
@@ -101,7 +104,9 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
$this->motionZ *= 0.7;
|
||||
}
|
||||
|
||||
if($this->fuse-- <= 0){
|
||||
$this->fuse -= $tickDiff;
|
||||
|
||||
if($this->fuse <= 0){
|
||||
$this->kill();
|
||||
$this->explode();
|
||||
}else{
|
||||
@@ -111,7 +116,7 @@ class PrimedTNT extends Entity implements Explosive{
|
||||
}
|
||||
|
||||
|
||||
return !$this->onGround or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
|
||||
return $hasUpdate or $this->fuse > 0 or ($this->motionX == 0 and $this->motionY == 0 and $this->motionZ == 0);
|
||||
}
|
||||
|
||||
public function attack($damage, $source = EntityDamageEvent::CAUSE_MAGIC){
|
||||
|
||||
Reference in New Issue
Block a user