Merge remote-tracking branch 'origin/release/3.3'

This commit is contained in:
Dylan K. Taylor 2018-09-12 10:39:49 +01:00
commit ebc1524f9a
3 changed files with 41 additions and 54 deletions

View File

@ -237,14 +237,10 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
/** @var Vector3|null */ /** @var Vector3|null */
protected $newPosition; protected $newPosition;
/** @var Vector3|null */
public $speed = null;
/** @var bool */ /** @var bool */
protected $isTeleporting = false; protected $isTeleporting = false;
/** @var int */ /** @var int */
protected $inAirTicks = 0; protected $inAirTicks = 0;
/** @var int */
protected $startAirTicks = 5;
/** @var float */ /** @var float */
protected $stepHeight = 0.6; protected $stepHeight = 0.6;
/** @var bool */ /** @var bool */
@ -499,9 +495,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
public function resetFallDistance() : void{ public function resetFallDistance() : void{
parent::resetFallDistance(); parent::resetFallDistance();
if($this->inAirTicks !== 0){
$this->startAirTicks = 5;
}
$this->inAirTicks = 0; $this->inAirTicks = 0;
} }
@ -1551,10 +1544,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
} }
} }
} }
$this->speed = $to->subtract($from)->divide($tickDiff);
}elseif($distanceSquared == 0){
$this->speed = new Vector3(0, 0, 0);
} }
if($revert){ if($revert){
@ -1580,10 +1569,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if(parent::setMotion($motion)){ if(parent::setMotion($motion)){
$this->broadcastMotion(); $this->broadcastMotion();
if($this->motion->y > 0){
$this->startAirTicks = (-log($this->gravity / ($this->gravity + $this->drag * $this->motion->y)) / $this->drag) * 2 + 5;
}
return true; return true;
} }
return false; return false;
@ -1637,6 +1622,11 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
if($this->spawned){ if($this->spawned){
$this->processMovement($tickDiff); $this->processMovement($tickDiff);
$this->motion->x = $this->motion->y = $this->motion->z = 0; //TODO: HACK! (Fixes player knockback being messed up) $this->motion->x = $this->motion->y = $this->motion->z = 0; //TODO: HACK! (Fixes player knockback being messed up)
if($this->onGround){
$this->inAirTicks = 0;
}else{
$this->inAirTicks += $tickDiff;
}
Timings::$timerEntityBaseTick->startTiming(); Timings::$timerEntityBaseTick->startTiming();
$this->entityBaseTick($tickDiff); $this->entityBaseTick($tickDiff);
@ -1646,32 +1636,6 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
Timings::$playerCheckNearEntitiesTimer->startTiming(); Timings::$playerCheckNearEntitiesTimer->startTiming();
$this->checkNearEntities(); $this->checkNearEntities();
Timings::$playerCheckNearEntitiesTimer->stopTiming(); Timings::$playerCheckNearEntitiesTimer->stopTiming();
if($this->speed !== null){
if($this->onGround){
if($this->inAirTicks !== 0){
$this->startAirTicks = 5;
}
$this->inAirTicks = 0;
}else{
if(!$this->allowFlight and $this->inAirTicks > 10 and !$this->isSleeping() and !$this->isImmobile()){
$expectedVelocity = (-$this->gravity) / $this->drag - ((-$this->gravity) / $this->drag) * exp(-$this->drag * ($this->inAirTicks - $this->startAirTicks));
$diff = ($this->speed->y - $expectedVelocity) ** 2;
if(!$this->hasEffect(Effect::JUMP) and !$this->hasEffect(Effect::LEVITATION) and $diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()){
if($this->inAirTicks < 100){
$this->setMotion(new Vector3(0, $expectedVelocity, 0));
}elseif($this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"]))){
$this->timings->stopTiming();
return false;
}
}
}
$this->inAirTicks += $tickDiff;
}
}
} }
} }
@ -2436,7 +2400,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
$handled = false; $handled = false;
$isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING); $isFlying = $packet->getFlag(AdventureSettingsPacket::FLYING);
if($isFlying and !$this->allowFlight and !$this->server->getAllowFlight()){ if($isFlying and !$this->allowFlight){
$this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"])); $this->kick($this->server->getLanguage()->translateString("kick.reason.cheat", ["%ability.flight"]));
return true; return true;
}elseif($isFlying !== $this->isFlying()){ }elseif($isFlying !== $this->isFlying()){

View File

@ -559,10 +559,11 @@ class Server{
} }
/** /**
* @deprecated
* @return bool * @return bool
*/ */
public function getAllowFlight() : bool{ public function getAllowFlight() : bool{
return $this->getConfigBool("allow-flight", false); return true;
} }
/** /**
@ -1493,7 +1494,6 @@ class Server{
"announce-player-achievements" => true, "announce-player-achievements" => true,
"spawn-protection" => 16, "spawn-protection" => 16,
"max-players" => 20, "max-players" => 20,
"allow-flight" => false,
"spawn-animals" => true, "spawn-animals" => true,
"spawn-mobs" => true, "spawn-mobs" => true,
"gamemode" => 0, "gamemode" => 0,

View File

@ -247,6 +247,11 @@ class Level implements ChunkManager, Metadatable{
/** @var bool */ /** @var bool */
private $closed = false; private $closed = false;
/** @var BlockLightUpdate|null */
private $blockLightUpdate = null;
/** @var SkyLightUpdate|null */
private $skyLightUpdate = null;
public static function chunkHash(int $x, int $z) : int{ public static function chunkHash(int $x, int $z) : int{
return (($x & 0xFFFFFFFF) << 32) | ($z & 0xFFFFFFFF); return (($x & 0xFFFFFFFF) << 32) | ($z & 0xFFFFFFFF);
} }
@ -758,6 +763,8 @@ class Level implements ChunkManager, Metadatable{
$this->tickChunks(); $this->tickChunks();
$this->timings->doTickTiles->stopTiming(); $this->timings->doTickTiles->stopTiming();
$this->executeQueuedLightUpdates();
if(count($this->changedBlocks) > 0){ if(count($this->changedBlocks) > 0){
if(count($this->players) > 0){ if(count($this->players) > 0){
foreach($this->changedBlocks as $index => $blocks){ foreach($this->changedBlocks as $index => $blocks){
@ -1414,22 +1421,21 @@ class Level implements ChunkManager, Metadatable{
$newHeightMap = $oldHeightMap; $newHeightMap = $oldHeightMap;
} }
$update = new SkyLightUpdate($this); if($this->skyLightUpdate === null){
$this->skyLightUpdate = new SkyLightUpdate($this);
}
if($newHeightMap > $oldHeightMap){ //Heightmap increase, block placed, remove sky light if($newHeightMap > $oldHeightMap){ //Heightmap increase, block placed, remove sky light
for($i = $y; $i >= $oldHeightMap; --$i){ for($i = $y; $i >= $oldHeightMap; --$i){
$update->setAndUpdateLight($x, $i, $z, 0); //Remove all light beneath, adjacent recalculation will handle the rest. $this->skyLightUpdate->setAndUpdateLight($x, $i, $z, 0); //Remove all light beneath, adjacent recalculation will handle the rest.
} }
}elseif($newHeightMap < $oldHeightMap){ //Heightmap decrease, block changed or removed, add sky light }elseif($newHeightMap < $oldHeightMap){ //Heightmap decrease, block changed or removed, add sky light
for($i = $y; $i >= $newHeightMap; --$i){ for($i = $y; $i >= $newHeightMap; --$i){
$update->setAndUpdateLight($x, $i, $z, 15); $this->skyLightUpdate->setAndUpdateLight($x, $i, $z, 15);
} }
}else{ //No heightmap change, block changed "underground" }else{ //No heightmap change, block changed "underground"
$update->setAndUpdateLight($x, $y, $z, max(0, $this->getHighestAdjacentBlockSkyLight($x, $y, $z) - BlockFactory::$lightFilter[$sourceId])); $this->skyLightUpdate->setAndUpdateLight($x, $y, $z, max(0, $this->getHighestAdjacentBlockSkyLight($x, $y, $z) - BlockFactory::$lightFilter[$sourceId]));
} }
$update->execute();
$this->timings->doBlockSkyLightUpdates->stopTiming(); $this->timings->doBlockSkyLightUpdates->stopTiming();
} }
@ -1459,13 +1465,30 @@ class Level implements ChunkManager, Metadatable{
$id = $this->getBlockIdAt($x, $y, $z); $id = $this->getBlockIdAt($x, $y, $z);
$newLevel = max(BlockFactory::$light[$id], $this->getHighestAdjacentBlockLight($x, $y, $z) - BlockFactory::$lightFilter[$id]); $newLevel = max(BlockFactory::$light[$id], $this->getHighestAdjacentBlockLight($x, $y, $z) - BlockFactory::$lightFilter[$id]);
$update = new BlockLightUpdate($this); if($this->blockLightUpdate === null){
$update->setAndUpdateLight($x, $y, $z, $newLevel); $this->blockLightUpdate = new BlockLightUpdate($this);
$update->execute(); }
$this->blockLightUpdate->setAndUpdateLight($x, $y, $z, $newLevel);
$this->timings->doBlockLightUpdates->stopTiming(); $this->timings->doBlockLightUpdates->stopTiming();
} }
public function executeQueuedLightUpdates() : void{
if($this->blockLightUpdate !== null){
$this->timings->doBlockLightUpdates->startTiming();
$this->blockLightUpdate->execute();
$this->blockLightUpdate = null;
$this->timings->doBlockLightUpdates->stopTiming();
}
if($this->skyLightUpdate !== null){
$this->timings->doBlockSkyLightUpdates->startTiming();
$this->skyLightUpdate->execute();
$this->skyLightUpdate = null;
$this->timings->doBlockSkyLightUpdates->stopTiming();
}
}
/** /**
* Sets on Vector3 the data from a Block object, * Sets on Vector3 the data from a Block object,
* does block updates and puts the changes to the send queue. * does block updates and puts the changes to the send queue.