mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 00:29:54 +00:00
Implement FallingBlock missing sounds (#5348)
This commit is contained in:
parent
3d75094874
commit
1785cbb6b5
@ -37,6 +37,8 @@ use pocketmine\math\Facing;
|
|||||||
use pocketmine\math\Vector3;
|
use pocketmine\math\Vector3;
|
||||||
use pocketmine\player\Player;
|
use pocketmine\player\Player;
|
||||||
use pocketmine\world\BlockTransaction;
|
use pocketmine\world\BlockTransaction;
|
||||||
|
use pocketmine\world\sound\AnvilFallSound;
|
||||||
|
use pocketmine\world\sound\Sound;
|
||||||
use function lcg_value;
|
use function lcg_value;
|
||||||
use function round;
|
use function round;
|
||||||
|
|
||||||
@ -109,4 +111,8 @@ class Anvil extends Transparent implements Fallable{
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLandSound() : ?Sound{
|
||||||
|
return new AnvilFallSound();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ namespace pocketmine\block\utils;
|
|||||||
|
|
||||||
use pocketmine\block\Block;
|
use pocketmine\block\Block;
|
||||||
use pocketmine\entity\object\FallingBlock;
|
use pocketmine\entity\object\FallingBlock;
|
||||||
|
use pocketmine\world\sound\Sound;
|
||||||
|
|
||||||
interface Fallable{
|
interface Fallable{
|
||||||
|
|
||||||
@ -40,4 +41,9 @@ interface Fallable{
|
|||||||
* Returns whether the block should be placed.
|
* Returns whether the block should be placed.
|
||||||
*/
|
*/
|
||||||
public function onHitGround(FallingBlock $blockEntity) : bool;
|
public function onHitGround(FallingBlock $blockEntity) : bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the sound that will be played when FallingBlock hits the ground.
|
||||||
|
*/
|
||||||
|
public function getLandSound() : ?Sound;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ use pocketmine\entity\object\FallingBlock;
|
|||||||
use pocketmine\math\Facing;
|
use pocketmine\math\Facing;
|
||||||
use pocketmine\utils\AssumptionFailedError;
|
use pocketmine\utils\AssumptionFailedError;
|
||||||
use pocketmine\world\Position;
|
use pocketmine\world\Position;
|
||||||
|
use pocketmine\world\sound\Sound;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This trait handles falling behaviour for blocks that need them.
|
* This trait handles falling behaviour for blocks that need them.
|
||||||
@ -62,4 +63,8 @@ trait FallableTrait{
|
|||||||
public function onHitGround(FallingBlock $blockEntity) : bool{
|
public function onHitGround(FallingBlock $blockEntity) : bool{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLandSound() : ?Sound{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ use pocketmine\network\mcpe\protocol\types\entity\EntityIds;
|
|||||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
|
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataCollection;
|
||||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||||
use pocketmine\world\format\io\GlobalBlockStateHandlers;
|
use pocketmine\world\format\io\GlobalBlockStateHandlers;
|
||||||
|
use pocketmine\world\sound\BlockBreakSound;
|
||||||
use function abs;
|
use function abs;
|
||||||
|
|
||||||
class FallingBlock extends Entity{
|
class FallingBlock extends Entity{
|
||||||
@ -128,14 +129,20 @@ class FallingBlock extends Entity{
|
|||||||
if($this->onGround || $blockTarget !== null){
|
if($this->onGround || $blockTarget !== null){
|
||||||
$this->flagForDespawn();
|
$this->flagForDespawn();
|
||||||
|
|
||||||
|
$blockResult = $blockTarget ?? $this->block;
|
||||||
$block = $world->getBlock($pos);
|
$block = $world->getBlock($pos);
|
||||||
if(!$block->canBeReplaced() || !$world->isInWorld($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()) || ($this->onGround && abs($this->location->y - $this->location->getFloorY()) > 0.001)){
|
if(!$block->canBeReplaced() || !$world->isInWorld($pos->getFloorX(), $pos->getFloorY(), $pos->getFloorZ()) || ($this->onGround && abs($this->location->y - $this->location->getFloorY()) > 0.001)){
|
||||||
$world->dropItem($this->location, $this->block->asItem());
|
$world->dropItem($this->location, $this->block->asItem());
|
||||||
|
$world->addSound($pos->add(0.5, 0.5, 0.5), new BlockBreakSound($blockResult));
|
||||||
}else{
|
}else{
|
||||||
$ev = new EntityBlockChangeEvent($this, $block, $blockTarget ?? $this->block);
|
$ev = new EntityBlockChangeEvent($this, $block, $blockResult);
|
||||||
$ev->call();
|
$ev->call();
|
||||||
if(!$ev->isCancelled()){
|
if(!$ev->isCancelled()){
|
||||||
$world->setBlock($pos, $ev->getTo());
|
$b = $ev->getTo();
|
||||||
|
$world->setBlock($pos, $b);
|
||||||
|
if($this->onGround && $b instanceof Fallable && ($sound = $b->getLandSound()) !== null){
|
||||||
|
$world->addSound($pos->add(0.5, 0.5, 0.5), $sound);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$hasUpdate = true;
|
$hasUpdate = true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user