mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
Added Entity->fastMove() for players and direct-controlled entities, improved speed checking
This commit is contained in:
parent
eb0525e892
commit
bb71a3c4a6
@ -1073,11 +1073,13 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
|
|
||||||
protected function processMovement($currentTick){
|
protected function processMovement($currentTick){
|
||||||
if($this->dead or !$this->spawned or !($this->newPosition instanceof Vector3)){
|
if($this->dead or !$this->spawned or !($this->newPosition instanceof Vector3)){
|
||||||
if(++$this->speedTicks >= 10){
|
$diff = ($currentTick - $this->lastSpeedTick);
|
||||||
|
if($diff >= 10){
|
||||||
$this->speed = new Vector3(0, 0, 0);
|
$this->speed = new Vector3(0, 0, 0);
|
||||||
$this->speedTicks = -PHP_INT_MAX;
|
}elseif($diff > 5 and $this->speedTicks < 20){
|
||||||
$this->lastSpeedTick = $currentTick;
|
++$this->speedTicks;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1107,8 +1109,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$dy = $this->newPosition->y - $this->y;
|
$dy = $this->newPosition->y - $this->y;
|
||||||
$dz = $this->newPosition->z - $this->z;
|
$dz = $this->newPosition->z - $this->z;
|
||||||
|
|
||||||
//$this->inBlock = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z);
|
$this->fastMove($dx, $dy, $dz);
|
||||||
$this->move($dx, $dy, $dz);
|
|
||||||
|
|
||||||
$diffX = $this->x - $this->newPosition->x;
|
$diffX = $this->x - $this->newPosition->x;
|
||||||
$diffZ = $this->z - $this->newPosition->z;
|
$diffZ = $this->z - $this->newPosition->z;
|
||||||
@ -1124,12 +1125,6 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
if($diff > 0.0625){
|
if($diff > 0.0625){
|
||||||
$revert = true;
|
$revert = true;
|
||||||
$this->server->getLogger()->warning($this->getName()." moved wrongly!");
|
$this->server->getLogger()->warning($this->getName()." moved wrongly!");
|
||||||
}elseif($diff > 0){
|
|
||||||
$this->x = $this->newPosition->x;
|
|
||||||
$this->y = $this->newPosition->y;
|
|
||||||
$this->z = $this->newPosition->z;
|
|
||||||
$radius = $this->width / 2;
|
|
||||||
$this->boundingBox->setBounds($this->x - $radius, $this->y + $this->ySize, $this->z - $radius, $this->x + $radius, $this->y + $this->height + $this->ySize, $this->z + $radius);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}elseif($diff > 0){
|
}elseif($diff > 0){
|
||||||
@ -1181,15 +1176,21 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->speed = $to->subtract($from)->divide($currentTick - $this->lastSpeedTick);
|
$ticks = min(20, $currentTick - $this->lastSpeedTick + 0.5);
|
||||||
$this->speedTicks = 0;
|
if($this->speedTicks > 0){
|
||||||
|
$ticks += $this->speedTicks;
|
||||||
|
}
|
||||||
|
$this->speed = $from->subtract($to)->divide($ticks);
|
||||||
$this->lastSpeedTick = $currentTick;
|
$this->lastSpeedTick = $currentTick;
|
||||||
}elseif($distanceSquared == 0){
|
}elseif($distanceSquared == 0){
|
||||||
$this->speed = new Vector3(0, 0, 0);
|
$this->speed = new Vector3(0, 0, 0);
|
||||||
$this->speedTicks = 0;
|
|
||||||
$this->lastSpeedTick = $currentTick;
|
$this->lastSpeedTick = $currentTick;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($this->speedTicks > 0){
|
||||||
|
--$this->speedTicks;
|
||||||
|
}
|
||||||
|
|
||||||
if($revert){
|
if($revert){
|
||||||
|
|
||||||
$this->lastX = $from->x;
|
$this->lastX = $from->x;
|
||||||
@ -1248,19 +1249,21 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
|
|
||||||
if($this->speed and $this->isSurvival()){
|
if($this->speed and $this->isSurvival()){
|
||||||
$speed = sqrt($this->speed->x ** 2 + $this->speed->z ** 2);
|
$speed = sqrt($this->speed->x ** 2 + $this->speed->z ** 2);
|
||||||
if($speed > 0.30){
|
if($speed > 0.45){
|
||||||
$this->highSpeedTicks += $speed > 1 ? 3 : 1;
|
$this->highSpeedTicks += $speed > 3 ? 2 : 1;
|
||||||
if($this->highSpeedTicks > 40 and !$this->server->getAllowFlight()){
|
if($this->highSpeedTicks > 40 and !$this->server->getAllowFlight()){
|
||||||
$this->kick("Flying is not enabled on this server");
|
$this->kick("Flying is not enabled on this server");
|
||||||
return false;
|
return false;
|
||||||
}elseif($this->highSpeedTicks > 5){
|
}elseif($this->highSpeedTicks >= 10 and $this->highSpeedTicks % 4 === 0){
|
||||||
$factor = min(1, ($speed - 0.22) / $speed);
|
$this->forceMovement = $this->getPosition();
|
||||||
$mot = new Vector3($this->speed->x * $factor, 0, $this->speed->z * $factor);
|
$this->speed = null;
|
||||||
$this->setMotion($mot);
|
|
||||||
$this->speed = $mot;
|
|
||||||
}
|
}
|
||||||
}elseif($this->highSpeedTicks > 0){
|
}elseif($this->highSpeedTicks > 0){
|
||||||
$this->highSpeedTicks--;
|
if($speed < 22){
|
||||||
|
$this->highSpeedTicks = 0;
|
||||||
|
}else{
|
||||||
|
$this->highSpeedTicks--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1599,7 +1602,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
|||||||
$this->forceMovement = new Vector3($this->x, $this->y, $this->z);
|
$this->forceMovement = new Vector3($this->x, $this->y, $this->z);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->forceMovement instanceof Vector3 and ($revert or $newPos->distanceSquared($this->forceMovement) > 0.04)){
|
if($this->forceMovement instanceof Vector3 and (($dist = $newPos->distanceSquared($this->forceMovement)) > 0.04 or $revert)){
|
||||||
$pk = new MovePlayerPacket();
|
$pk = new MovePlayerPacket();
|
||||||
$pk->eid = 0;
|
$pk->eid = 0;
|
||||||
$pk->x = $this->forceMovement->x;
|
$pk->x = $this->forceMovement->x;
|
||||||
|
@ -819,6 +819,53 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function fastMove($dx, $dy, $dz){
|
||||||
|
if($dx == 0 and $dz == 0 and $dy == 0){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Timings::$entityMoveTimer->startTiming();
|
||||||
|
|
||||||
|
$axisalignedbb = clone $this->boundingBox;
|
||||||
|
|
||||||
|
$newBB = $this->boundingBox->getOffsetBoundingBox($dx, $dy, $dz);
|
||||||
|
|
||||||
|
$list = $this->level->getCollisionCubes($this, $newBB->expand(-0.01, -0.01, -0.01));
|
||||||
|
|
||||||
|
if(count($list) === 0){
|
||||||
|
$this->boundingBox = $newBB;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pos = new Vector3(
|
||||||
|
($this->boundingBox->minX + $this->boundingBox->maxX) / 2,
|
||||||
|
$this->boundingBox->minY + $this->ySize,
|
||||||
|
($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = true;
|
||||||
|
|
||||||
|
if(!$this->setPosition($pos)){
|
||||||
|
$this->boundingBox->setBB($axisalignedbb);
|
||||||
|
$result = false;
|
||||||
|
}else{
|
||||||
|
if(!$this->onGround or $dy != 0){
|
||||||
|
$bb = clone $this->boundingBox;
|
||||||
|
$bb->minY -= 0.75;
|
||||||
|
$this->onGround = false;
|
||||||
|
|
||||||
|
if(count($this->level->getCollisionBlocks($bb)) > 0){
|
||||||
|
$this->onGround = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->isCollided = $this->onGround;
|
||||||
|
$this->updateFallState($dy, $this->onGround);
|
||||||
|
}
|
||||||
|
|
||||||
|
Timings::$entityMoveTimer->stopTiming();
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
public function move($dx, $dy, $dz){
|
public function move($dx, $dy, $dz){
|
||||||
|
|
||||||
if($dx == 0 and $dz == 0 and $dy == 0){
|
if($dx == 0 and $dz == 0 and $dy == 0){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user