mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-06 01:46:04 +00:00
Entity: replace separate height/width/eyeHeight fields with an EntitySizeInfo structure
this will make it easier to implement stuff like sleeping (properly), swimming and gliding without needing to duplicate all the fields.
This commit is contained in:
@ -118,13 +118,8 @@ abstract class Entity{
|
||||
/** @var bool */
|
||||
public $onGround = false;
|
||||
|
||||
/** @var float */
|
||||
public $eyeHeight = null;
|
||||
|
||||
/** @var float */
|
||||
public $height;
|
||||
/** @var float */
|
||||
public $width;
|
||||
/** @var EntitySizeInfo */
|
||||
public $size;
|
||||
|
||||
/** @var float */
|
||||
private $health = 20.0;
|
||||
@ -218,9 +213,7 @@ abstract class Entity{
|
||||
public function __construct(Location $location, ?CompoundTag $nbt = null){
|
||||
$this->timings = Timings::getEntityTimings($this);
|
||||
|
||||
if($this->eyeHeight === null){
|
||||
$this->eyeHeight = $this->height / 2 + 0.1;
|
||||
}
|
||||
$this->size = $this->getInitialSizeInfo();
|
||||
|
||||
$this->id = self::nextRuntimeId();
|
||||
$this->server = $location->getWorld()->getServer();
|
||||
@ -259,6 +252,8 @@ abstract class Entity{
|
||||
|
||||
}
|
||||
|
||||
abstract protected function getInitialSizeInfo() : EntitySizeInfo;
|
||||
|
||||
public function getNameTag() : string{
|
||||
return $this->nameTag;
|
||||
}
|
||||
@ -299,11 +294,7 @@ abstract class Entity{
|
||||
if($value <= 0){
|
||||
throw new \InvalidArgumentException("Scale must be greater than 0");
|
||||
}
|
||||
$multiplier = $value / $this->getScale();
|
||||
|
||||
$this->width *= $multiplier;
|
||||
$this->height *= $multiplier;
|
||||
$this->eyeHeight *= $multiplier;
|
||||
$this->size = $this->getInitialSizeInfo()->scale($value);
|
||||
|
||||
$this->scale = $value;
|
||||
|
||||
@ -315,14 +306,14 @@ abstract class Entity{
|
||||
}
|
||||
|
||||
protected function recalculateBoundingBox() : void{
|
||||
$halfWidth = $this->width / 2;
|
||||
$halfWidth = $this->size->getWidth() / 2;
|
||||
|
||||
$this->boundingBox = new AxisAlignedBB(
|
||||
$this->location->x - $halfWidth,
|
||||
$this->location->y + $this->ySize,
|
||||
$this->location->z - $halfWidth,
|
||||
$this->location->x + $halfWidth,
|
||||
$this->location->y + $this->height + $this->ySize,
|
||||
$this->location->y + $this->size->getHeight() + $this->ySize,
|
||||
$this->location->z + $halfWidth
|
||||
);
|
||||
}
|
||||
@ -1042,7 +1033,7 @@ abstract class Entity{
|
||||
}
|
||||
|
||||
public function getEyeHeight() : float{
|
||||
return $this->eyeHeight;
|
||||
return $this->size->getEyeHeight();
|
||||
}
|
||||
|
||||
public function getEyePos() : Vector3{
|
||||
@ -1585,8 +1576,8 @@ abstract class Entity{
|
||||
|
||||
protected function syncNetworkData(EntityMetadataCollection $properties) : void{
|
||||
$properties->setByte(EntityMetadataProperties::ALWAYS_SHOW_NAMETAG, $this->alwaysShowNameTag ? 1 : 0);
|
||||
$properties->setFloat(EntityMetadataProperties::BOUNDING_BOX_HEIGHT, $this->height);
|
||||
$properties->setFloat(EntityMetadataProperties::BOUNDING_BOX_WIDTH, $this->width);
|
||||
$properties->setFloat(EntityMetadataProperties::BOUNDING_BOX_HEIGHT, $this->size->getHeight());
|
||||
$properties->setFloat(EntityMetadataProperties::BOUNDING_BOX_WIDTH, $this->size->getWidth());
|
||||
$properties->setFloat(EntityMetadataProperties::SCALE, $this->scale);
|
||||
$properties->setLong(EntityMetadataProperties::LEAD_HOLDER_EID, -1);
|
||||
$properties->setLong(EntityMetadataProperties::OWNER_EID, $this->ownerId ?? -1);
|
||||
|
Reference in New Issue
Block a user