Implemented bed bouncing

This commit is contained in:
Dylan K. Taylor
2021-09-05 20:11:49 +01:00
parent 92f3a7d206
commit ded778f422
4 changed files with 34 additions and 17 deletions

View File

@ -29,6 +29,7 @@ use pocketmine\block\utils\ColoredTrait;
use pocketmine\block\utils\DyeColor;
use pocketmine\block\utils\HorizontalFacingTrait;
use pocketmine\data\bedrock\DyeColorIdMap;
use pocketmine\entity\Entity;
use pocketmine\item\Item;
use pocketmine\lang\KnownTranslationFactory;
use pocketmine\math\AxisAlignedBB;
@ -170,6 +171,11 @@ class Bed extends Transparent{
}
}
public function onEntityLand(Entity $entity) : ?float{
$entity->fallDistance *= 0.5;
return $entity->getMotion()->y * -3 / 4; // 2/3 in Java, according to the wiki
}
public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
$down = $this->getSide(Facing::DOWN);
if(!$down->isTransparent()){

View File

@ -562,6 +562,14 @@ class Block{
return true;
}
/**
* Called when an entity lands on this block (usually due to falling).
* @return float|null The new vertical velocity of the entity, or null if unchanged.
*/
public function onEntityLand(Entity $entity) : ?float{
return null;
}
/**
* @return AxisAlignedBB[]
*/