mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +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:
@ -304,12 +304,8 @@ abstract class Entity{
|
||||
if($value <= 0){
|
||||
throw new \InvalidArgumentException("Scale must be greater than 0");
|
||||
}
|
||||
$this->size = $this->getInitialSizeInfo()->scale($value);
|
||||
|
||||
$this->scale = $value;
|
||||
|
||||
$this->recalculateBoundingBox();
|
||||
$this->networkPropertiesDirty = true;
|
||||
$this->setSize($this->getInitialSizeInfo()->scale($value));
|
||||
}
|
||||
|
||||
public function getBoundingBox() : AxisAlignedBB{
|
||||
@ -329,6 +325,16 @@ abstract class Entity{
|
||||
);
|
||||
}
|
||||
|
||||
public function getSize() : EntitySizeInfo{
|
||||
return $this->size;
|
||||
}
|
||||
|
||||
protected function setSize(EntitySizeInfo $size) : void{
|
||||
$this->size = $size;
|
||||
$this->recalculateBoundingBox();
|
||||
$this->networkPropertiesDirty = true;
|
||||
}
|
||||
|
||||
public function isImmobile() : bool{
|
||||
return $this->immobile;
|
||||
}
|
||||
|
@ -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