Skip to content

Commit

Permalink
Fix #460
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Jul 17, 2024
1 parent e3c317f commit e3d885a
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 45 deletions.
9 changes: 0 additions & 9 deletions src/entity/Living.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,6 @@ private function recalculateSize() : void{
}
}

public function getDefaultSpeed() : float{
return $this->moveSpeedAttr->getDefaultValue();
}

public function setDefaultSpeed(float $speed, bool $fit = false) : void{
$this->moveSpeedAttr->setDefaultValue($speed);
$this->setMovementSpeed($this->isSprinting() ? ($speed * 1.3) : $speed, $fit);
}

public function getMovementSpeed() : float{
return $this->moveSpeedAttr->getValue();
}
Expand Down
4 changes: 2 additions & 2 deletions src/entity/effect/SlownessEffect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
class SlownessEffect extends Effect{

public function add(Living $entity, EffectInstance $instance) : void{
$entity->setDefaultSpeed($entity->getDefaultSpeed() * (1 - 0.15 * $instance->getEffectLevel()), true);
$entity->setMovementSpeed($entity->getMovementSpeed() * (1 - 0.15 * $instance->getEffectLevel()), true);
}

public function remove(Living $entity, EffectInstance $instance) : void{
$entity->setDefaultSpeed($entity->getDefaultSpeed() / (1 - 0.15 * $instance->getEffectLevel()));
$entity->setMovementSpeed($entity->getMovementSpeed() / (1 - 0.15 * $instance->getEffectLevel()));
}
}
4 changes: 2 additions & 2 deletions src/entity/effect/SpeedEffect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
class SpeedEffect extends Effect{

public function add(Living $entity, EffectInstance $instance) : void{
$entity->setDefaultSpeed($entity->getDefaultSpeed() * (1 + 0.2 * $instance->getEffectLevel()));
$entity->setMovementSpeed($entity->getMovementSpeed() * (1 + 0.2 * $instance->getEffectLevel()));
}

public function remove(Living $entity, EffectInstance $instance) : void{
$entity->setDefaultSpeed($entity->getDefaultSpeed() / (1 + 0.2 * $instance->getEffectLevel()));
$entity->setMovementSpeed($entity->getMovementSpeed() / (1 + 0.2 * $instance->getEffectLevel()));
}
}
32 changes: 0 additions & 32 deletions src/player/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -2486,38 +2486,6 @@ protected function syncNetworkData(EntityMetadataCollection $properties) : void{
$properties->setBlockPos(EntityMetadataProperties::PLAYER_BED_POSITION, $this->sleeping !== null ? BlockPosition::fromVector3($this->sleeping) : new BlockPosition(0, 0, 0));
}

/**
* @internal Used to sync player actions with the server.
*/
public function syncPlayerActions(?bool $sneaking, ?bool $sprinting, ?bool $swimming, ?bool $gliding) : bool{
$networkPropertiesDirty = $this->networkPropertiesDirty;
$isDesynchronized = $this->moveSpeedAttr->isDesynchronized();

$mismatch =
($sneaking !== null && !$this->toggleSneak($sneaking)) |
($sprinting !== null && !$this->toggleSprint($sprinting)) |
($swimming !== null && !$this->toggleSwim($swimming)) |
($gliding !== null && !$this->toggleGlide($gliding));

if((bool) $mismatch){
return false;
}

// We do not want to do anything with gliding and swimming,
// because it is syncing the player own bounding boxes.
if($sprinting !== null){
// In case the previous network properties was dirty.
$this->networkPropertiesDirty = $networkPropertiesDirty;

if(!$isDesynchronized){
// Mark as synchronized, we accept them as-is
$this->moveSpeedAttr->markSynchronized();
}
}

return true;
}

public function sendData(?array $targets, ?array $data = null) : void{
if($targets === null){
$targets = $this->getViewers();
Expand Down

0 comments on commit e3d885a

Please sign in to comment.