mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-13 09:19:42 +00:00
Improved updates after first tick
This commit is contained in:
parent
03f178379e
commit
75cab3dfc3
@ -184,7 +184,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
public $isCollidedVertically = false;
|
public $isCollidedVertically = false;
|
||||||
|
|
||||||
public $noDamageTicks;
|
public $noDamageTicks;
|
||||||
private $justCreated;
|
protected $justCreated;
|
||||||
protected $fireProof;
|
protected $fireProof;
|
||||||
private $invulnerable;
|
private $invulnerable;
|
||||||
|
|
||||||
@ -223,16 +223,15 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
|
|
||||||
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
|
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
|
||||||
$this->setPositionAndRotation(
|
$this->setPositionAndRotation(
|
||||||
new Vector3(
|
$this->temporalVector->setComponents(
|
||||||
$this->namedtag["Pos"][0],
|
$this->namedtag["Pos"][0],
|
||||||
$this->namedtag["Pos"][1],
|
$this->namedtag["Pos"][1],
|
||||||
$this->namedtag["Pos"][2]
|
$this->namedtag["Pos"][2]
|
||||||
),
|
),
|
||||||
$this->namedtag->Rotation[0],
|
$this->namedtag->Rotation[0],
|
||||||
$this->namedtag->Rotation[1],
|
$this->namedtag->Rotation[1]
|
||||||
true
|
|
||||||
);
|
);
|
||||||
$this->setMotion(new Vector3($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
|
$this->setMotion($this->temporalVector->setComponents($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
|
||||||
|
|
||||||
if(!isset($this->namedtag->FallDistance)){
|
if(!isset($this->namedtag->FallDistance)){
|
||||||
$this->namedtag->FallDistance = new Float("FallDistance", 0);
|
$this->namedtag->FallDistance = new Float("FallDistance", 0);
|
||||||
@ -971,10 +970,8 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
if($onGround === true){
|
if($onGround === true){
|
||||||
if($this->fallDistance > 0){
|
if($this->fallDistance > 0){
|
||||||
if($this instanceof Living){
|
if($this instanceof Living){
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->fall($this->fallDistance);
|
$this->fall($this->fallDistance);
|
||||||
|
}
|
||||||
$this->resetFallDistance();
|
$this->resetFallDistance();
|
||||||
}
|
}
|
||||||
}elseif($distanceThisTick < 0){
|
}elseif($distanceThisTick < 0){
|
||||||
@ -1246,18 +1243,9 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$pos = new Vector3(
|
$this->x = ($this->boundingBox->minX + $this->boundingBox->maxX) / 2;
|
||||||
($this->boundingBox->minX + $this->boundingBox->maxX) / 2,
|
$this->y = $this->boundingBox->minY - $this->ySize;
|
||||||
$this->boundingBox->minY + $this->ySize,
|
$this->z = ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2;
|
||||||
($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = true;
|
|
||||||
|
|
||||||
if(!$this->setPosition($pos)){
|
|
||||||
$this->boundingBox->setBB($axisalignedbb);
|
|
||||||
$result = false;
|
|
||||||
}else{
|
|
||||||
|
|
||||||
if($this instanceof Player){
|
if($this instanceof Player){
|
||||||
if(!$this->onGround or $movY != 0){
|
if(!$this->onGround or $movY != 0){
|
||||||
@ -1289,13 +1277,13 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
if($movZ != $dz){
|
if($movZ != $dz){
|
||||||
$this->motionZ = 0;
|
$this->motionZ = 0;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: vehicle collision events (first we need to spawn them!)
|
//TODO: vehicle collision events (first we need to spawn them!)
|
||||||
|
|
||||||
Timings::$entityMoveTimer->stopTiming();
|
Timings::$entityMoveTimer->stopTiming();
|
||||||
|
|
||||||
return $result;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1349,25 +1337,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
$this->scheduleUpdate();
|
$this->scheduleUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setPosition(Vector3 $pos){
|
protected function checkChunks(){
|
||||||
if($this->closed){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){
|
|
||||||
if($this->switchLevel($pos->getLevel()) === false){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->x = $pos->x;
|
|
||||||
$this->y = $pos->y;
|
|
||||||
$this->z = $pos->z;
|
|
||||||
|
|
||||||
$radius = $this->width / 2;
|
|
||||||
$this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius);
|
|
||||||
|
|
||||||
|
|
||||||
if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) or $this->chunk->getZ() !== ($this->z >> 4))){
|
if($this->chunk === null or ($this->chunk->getX() !== ($this->x >> 4) or $this->chunk->getZ() !== ($this->z >> 4))){
|
||||||
if($this->chunk !== null){
|
if($this->chunk !== null){
|
||||||
$this->chunk->removeEntity($this);
|
$this->chunk->removeEntity($this);
|
||||||
@ -1390,11 +1360,32 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($this->chunk === null){
|
if($this->chunk === null){
|
||||||
return true;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->chunk->addEntity($this);
|
$this->chunk->addEntity($this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPosition(Vector3 $pos){
|
||||||
|
if($this->closed){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($pos instanceof Position and $pos->level !== null and $pos->level !== $this->level){
|
||||||
|
if($this->switchLevel($pos->getLevel()) === false){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->x = $pos->x;
|
||||||
|
$this->y = $pos->y;
|
||||||
|
$this->z = $pos->z;
|
||||||
|
|
||||||
|
$radius = $this->width / 2;
|
||||||
|
$this->boundingBox->setBounds($pos->x - $radius, $pos->y, $pos->z - $radius, $pos->x + $radius, $pos->y + $this->height, $pos->z + $radius);
|
||||||
|
|
||||||
|
$this->checkChunks();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,10 @@ class FallingSand extends Entity{
|
|||||||
|
|
||||||
$this->timings->startTiming();
|
$this->timings->startTiming();
|
||||||
|
|
||||||
$tickDiff = max(1, $currentTick - $this->lastUpdate);
|
$tickDiff = $currentTick - $this->lastUpdate;
|
||||||
|
if($tickDiff <= 0 and !$this->justCreated){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
$this->lastUpdate = $currentTick;
|
$this->lastUpdate = $currentTick;
|
||||||
|
|
||||||
$hasUpdate = $this->entityBaseTick($tickDiff);
|
$hasUpdate = $this->entityBaseTick($tickDiff);
|
||||||
|
@ -81,8 +81,8 @@ class Item extends Entity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
$tickDiff = $currentTick - $this->lastUpdate;
|
$tickDiff = $currentTick - $this->lastUpdate;
|
||||||
if($tickDiff <= 0){
|
if($tickDiff <= 0 and !$this->justCreated){
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->lastUpdate = $currentTick;
|
$this->lastUpdate = $currentTick;
|
||||||
@ -102,7 +102,9 @@ class Item extends Entity{
|
|||||||
|
|
||||||
$this->motionY -= $this->gravity;
|
$this->motionY -= $this->gravity;
|
||||||
|
|
||||||
$this->checkObstruction($this->x, $this->y, $this->z);
|
if($this->checkObstruction($this->x, $this->y, $this->z)){
|
||||||
|
$hasUpdate = true;
|
||||||
|
}
|
||||||
|
|
||||||
$this->move($this->motionX, $this->motionY, $this->motionZ);
|
$this->move($this->motionX, $this->motionY, $this->motionZ);
|
||||||
|
|
||||||
|
@ -78,7 +78,10 @@ class PrimedTNT extends Entity implements Explosive{
|
|||||||
|
|
||||||
$this->timings->startTiming();
|
$this->timings->startTiming();
|
||||||
|
|
||||||
$tickDiff = max(1, $currentTick - $this->lastUpdate);
|
$tickDiff = $currentTick - $this->lastUpdate;
|
||||||
|
if($tickDiff <= 0 and !$this->justCreated){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
$this->lastUpdate = $currentTick;
|
$this->lastUpdate = $currentTick;
|
||||||
|
|
||||||
$hasUpdate = $this->entityBaseTick($tickDiff);
|
$hasUpdate = $this->entityBaseTick($tickDiff);
|
||||||
|
@ -83,7 +83,10 @@ abstract class Projectile extends Entity{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$tickDiff = max(1, $currentTick - $this->lastUpdate);
|
$tickDiff = $currentTick - $this->lastUpdate;
|
||||||
|
if($tickDiff <= 0 and !$this->justCreated){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
$this->lastUpdate = $currentTick;
|
$this->lastUpdate = $currentTick;
|
||||||
|
|
||||||
$hasUpdate = $this->entityBaseTick($tickDiff);
|
$hasUpdate = $this->entityBaseTick($tickDiff);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user