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:
Dylan K. Taylor
2021-01-08 00:10:11 +00:00
parent 574b615b4c
commit e53b57732b
15 changed files with 103 additions and 60 deletions

View File

@ -26,6 +26,7 @@ namespace pocketmine\entity\projectile;
use pocketmine\block\Block;
use pocketmine\entity\animation\ArrowShakeAnimation;
use pocketmine\entity\Entity;
use pocketmine\entity\EntitySizeInfo;
use pocketmine\entity\Location;
use pocketmine\event\entity\ProjectileHitEvent;
use pocketmine\event\inventory\InventoryPickupArrowEvent;
@ -50,9 +51,6 @@ class Arrow extends Projectile{
private const TAG_PICKUP = "pickup"; //TAG_Byte
public $width = 0.25;
public $height = 0.25;
protected $gravity = 0.05;
protected $drag = 0.01;
@ -76,6 +74,8 @@ class Arrow extends Projectile{
$this->setCritical($critical);
}
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
protected function initEntity(CompoundTag $nbt) : void{
parent::initEntity($nbt);

View File

@ -24,16 +24,16 @@ declare(strict_types=1);
namespace pocketmine\entity\projectile;
use pocketmine\block\Block;
use pocketmine\entity\EntitySizeInfo;
use pocketmine\math\RayTraceResult;
abstract class Throwable extends Projectile{
public $width = 0.25;
public $height = 0.25;
protected $gravity = 0.03;
protected $drag = 0.01;
protected function getInitialSizeInfo() : EntitySizeInfo{ return new EntitySizeInfo(0.25, 0.25); }
protected function onHitBlock(Block $blockHit, RayTraceResult $hitResult) : void{
parent::onHitBlock($blockHit, $hitResult);
$this->flagForDespawn();