mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-05 17:36:12 +00:00
Implement swimming/gliding including AABB recalculation (#4446)
- The following events have been added: - PlayerToggleGlideEvent - PlayerToggleSwimEvent - The following API methods have been added: - Entity->getSize() - Living->isSwimming() - Living->setSwimming() - Living->isGliding() - Living->setSwimming() - Player->toggleSwim() - Player->toggleGlide()
This commit is contained in:
@ -116,6 +116,10 @@ abstract class Living extends Entity{
|
||||
protected $sprinting = false;
|
||||
/** @var bool */
|
||||
protected $sneaking = false;
|
||||
/** @var bool */
|
||||
protected $gliding = false;
|
||||
/** @var bool */
|
||||
protected $swimming = false;
|
||||
|
||||
abstract public function getName() : string;
|
||||
|
||||
@ -227,6 +231,37 @@ abstract class Living extends Entity{
|
||||
}
|
||||
}
|
||||
|
||||
public function isGliding() : bool{
|
||||
return $this->gliding;
|
||||
}
|
||||
|
||||
public function setGliding(bool $value = true) : void{
|
||||
$this->gliding = $value;
|
||||
$this->networkPropertiesDirty = true;
|
||||
$this->recalculateSize();
|
||||
}
|
||||
|
||||
public function isSwimming() : bool{
|
||||
return $this->swimming;
|
||||
}
|
||||
|
||||
public function setSwimming(bool $value = true) : void{
|
||||
$this->swimming = $value;
|
||||
$this->networkPropertiesDirty = true;
|
||||
$this->recalculateSize();
|
||||
}
|
||||
|
||||
private function recalculateSize() : void{
|
||||
$size = $this->getInitialSizeInfo();
|
||||
if($this->isSwimming() || $this->isGliding()){
|
||||
$width = $size->getWidth();
|
||||
//we don't actually know an appropriate eye height for a swimming mob, but 2/3 should be good enough.
|
||||
$this->setSize((new EntitySizeInfo($width, $width, $width * 2 / 3))->scale($this->getScale()));
|
||||
}else{
|
||||
$this->setSize($size->scale($this->getScale()));
|
||||
}
|
||||
}
|
||||
|
||||
public function getMovementSpeed() : float{
|
||||
return $this->moveSpeedAttr->getValue();
|
||||
}
|
||||
@ -800,6 +835,8 @@ abstract class Living extends Entity{
|
||||
$properties->setGenericFlag(EntityMetadataFlags::BREATHING, $this->breathing);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::SNEAKING, $this->sneaking);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::SPRINTING, $this->sprinting);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::GLIDING, $this->gliding);
|
||||
$properties->setGenericFlag(EntityMetadataFlags::SWIMMING, $this->swimming);
|
||||
}
|
||||
|
||||
protected function onDispose() : void{
|
||||
|
Reference in New Issue
Block a user