mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
Implemented bed bouncing
This commit is contained in:
parent
92f3a7d206
commit
ded778f422
@ -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()){
|
||||
|
@ -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[]
|
||||
*/
|
||||
|
@ -1022,11 +1022,12 @@ abstract class Entity{
|
||||
$this->fallDistance = 0.0;
|
||||
}
|
||||
|
||||
protected function updateFallState(float $distanceThisTick, bool $onGround) : void{
|
||||
protected function updateFallState(float $distanceThisTick, bool $onGround) : ?float{
|
||||
if($onGround){
|
||||
if($this->fallDistance > 0){
|
||||
$this->onHitGround();
|
||||
$newVerticalVelocity = $this->onHitGround();
|
||||
$this->resetFallDistance();
|
||||
return $newVerticalVelocity;
|
||||
}
|
||||
}elseif($distanceThisTick < $this->fallDistance){
|
||||
//we've fallen some distance (distanceThisTick is negative)
|
||||
@ -1037,13 +1038,14 @@ abstract class Entity{
|
||||
//reset it so it will be measured starting from the new, higher position
|
||||
$this->fallDistance = 0;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a falling entity hits the ground.
|
||||
*/
|
||||
protected function onHitGround() : void{
|
||||
|
||||
protected function onHitGround() : ?float{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getEyeHeight() : float{
|
||||
@ -1183,11 +1185,11 @@ abstract class Entity{
|
||||
$this->getWorld()->onEntityMoved($this);
|
||||
$this->checkBlockIntersections();
|
||||
$this->checkGroundState($wantedX, $wantedY, $wantedZ, $dx, $dy, $dz);
|
||||
$this->updateFallState($dy, $this->onGround);
|
||||
$postFallVerticalVelocity = $this->updateFallState($dy, $this->onGround);
|
||||
|
||||
$this->motion = $this->motion->withComponents(
|
||||
$wantedX != $dx ? 0 : null,
|
||||
$wantedY != $dy ? 0 : null,
|
||||
$postFallVerticalVelocity ?? ($wantedY != $dy ? 0 : null),
|
||||
$wantedZ != $dz ? 0 : null
|
||||
);
|
||||
|
||||
|
@ -309,7 +309,15 @@ abstract class Living extends Entity{
|
||||
return ceil($fallDistance - 3 - (($jumpBoost = $this->effectManager->get(VanillaEffects::JUMP_BOOST())) !== null ? $jumpBoost->getEffectLevel() : 0));
|
||||
}
|
||||
|
||||
protected function onHitGround() : void{
|
||||
protected function onHitGround() : ?float{
|
||||
$fallBlockPos = $this->location->floor();
|
||||
$fallBlock = $this->getWorld()->getBlock($fallBlockPos);
|
||||
if(count($fallBlock->getCollisionBoxes()) === 0){
|
||||
$fallBlockPos = $fallBlockPos->down();
|
||||
$fallBlock = $this->getWorld()->getBlock($fallBlockPos);
|
||||
}
|
||||
$newVerticalVelocity = $fallBlock->onEntityLand($this);
|
||||
|
||||
$damage = $this->calculateFallDamage($this->fallDistance);
|
||||
if($damage > 0){
|
||||
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
|
||||
@ -319,17 +327,10 @@ abstract class Living extends Entity{
|
||||
new EntityLongFallSound($this) :
|
||||
new EntityShortFallSound($this)
|
||||
);
|
||||
}else{
|
||||
$fallBlockPos = $this->location->floor();
|
||||
$fallBlock = $this->getWorld()->getBlock($fallBlockPos);
|
||||
if(count($fallBlock->getCollisionBoxes()) === 0){
|
||||
$fallBlockPos = $fallBlockPos->down();
|
||||
$fallBlock = $this->getWorld()->getBlock($fallBlockPos);
|
||||
}
|
||||
if($fallBlock->getId() !== BlockLegacyIds::AIR){
|
||||
$this->broadcastSound(new EntityLandSound($this, $fallBlock));
|
||||
}
|
||||
}elseif($fallBlock->getId() !== BlockLegacyIds::AIR){
|
||||
$this->broadcastSound(new EntityLandSound($this, $fallBlock));
|
||||
}
|
||||
return $newVerticalVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user