Entity: Rename and document isImmobile() and friends

while I could implement server-side ability to disable entity movement, I don't think that's particularly useful. However, the intended function of this (disabling client sided AI) is useful, so it makes more sense to rename it to match its functionality, rather than changing its functionality to match the name.

closes #3130
This commit is contained in:
Dylan K. Taylor 2023-05-26 14:01:21 +01:00
parent cc77f18ff0
commit edafe9d21f
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 22 additions and 10 deletions

View File

@ -170,7 +170,7 @@ abstract class Entity{
protected bool $canClimb = false;
protected bool $canClimbWalls = false;
protected bool $immobile = false;
protected bool $noClientPredictions = false;
protected bool $invisible = false;
protected bool $silent = false;
@ -314,12 +314,24 @@ abstract class Entity{
$this->networkPropertiesDirty = true;
}
public function isImmobile() : bool{
return $this->immobile;
/**
* Returns whether clients may predict this entity's behaviour and movement. Used for things like water movement,
* burning, and movement smoothing (interpolation).
*/
public function hasNoClientPredictions() : bool{
return $this->noClientPredictions;
}
public function setImmobile(bool $value = true) : void{
$this->immobile = $value;
/**
* Things such as movement in water, burning, etc. may be predicted by the client. This is sometimes not desirable,
* since server-side logic may differ from client-side prediction. However, things like movement smoothing
* (interpolation) are also controlled by this, so it should be used with care.
*
* Setting this flag will also disable player movement inputs, but this should not be relied on, as cheat clients
* will be able to bypass it.
*/
public function setNoClientPredictions(bool $value = true) : void{
$this->noClientPredictions = $value;
$this->networkPropertiesDirty = true;
}
@ -730,7 +742,7 @@ abstract class Entity{
$wasStill = $this->lastMotion->lengthSquared() == 0.0;
if($wasStill !== $still){
//TODO: hack for client-side AI interference: prevent client sided movement when motion is 0
$this->setImmobile($still);
$this->setNoClientPredictions($still);
}
if($teleport || $diffPosition > 0.0001 || $diffRotation > 1.0 || (!$wasStill && $still)){
@ -1651,7 +1663,7 @@ abstract class Entity{
$properties->setGenericFlag(EntityMetadataFlags::CAN_CLIMB, $this->canClimb);
$properties->setGenericFlag(EntityMetadataFlags::CAN_SHOW_NAMETAG, $this->nameTagVisible);
$properties->setGenericFlag(EntityMetadataFlags::HAS_COLLISION, true);
$properties->setGenericFlag(EntityMetadataFlags::IMMOBILE, $this->immobile);
$properties->setGenericFlag(EntityMetadataFlags::NO_AI, $this->noClientPredictions);
$properties->setGenericFlag(EntityMetadataFlags::INVISIBLE, $this->invisible);
$properties->setGenericFlag(EntityMetadataFlags::SILENT, $this->silent);
$properties->setGenericFlag(EntityMetadataFlags::ONFIRE, $this->isOnFire());

View File

@ -809,7 +809,7 @@ class NetworkSession{
private function beginSpawnSequence() : void{
$this->setHandler(new PreSpawnPacketHandler($this->server, $this->player, $this, $this->invManager));
$this->player->setImmobile(); //TODO: HACK: fix client-side falling pre-spawn
$this->player->setNoClientPredictions(); //TODO: HACK: fix client-side falling pre-spawn
$this->logger->debug("Waiting for chunk radius request");
}
@ -824,7 +824,7 @@ class NetworkSession{
private function onClientSpawnResponse() : void{
$this->logger->debug("Received spawn response, entering in-game phase");
$this->player->setImmobile(false); //TODO: HACK: we set this during the spawn sequence to prevent the client sending junk movements
$this->player->setNoClientPredictions(false); //TODO: HACK: we set this during the spawn sequence to prevent the client sending junk movements
$this->player->doFirstSpawn();
$this->forceAsyncCompression = false;
$this->setHandler(new InGamePacketHandler($this->player, $this, $this->invManager));

View File

@ -87,7 +87,7 @@ class FloatingTextParticle implements Particle{
$name = $this->title . ($this->text !== "" ? "\n" . $this->text : "");
$actorFlags = (
1 << EntityMetadataFlags::IMMOBILE
1 << EntityMetadataFlags::NO_AI
);
$actorMetadata = [
EntityMetadataProperties::FLAGS => new LongMetadataProperty($actorFlags),