mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-14 17:59:41 +00:00
making BlockPunchSound server-controlled
This commit is contained in:
parent
1969766b70
commit
2964a4be35
@ -756,6 +756,7 @@ class InGamePacketHandler extends PacketHandler{
|
|||||||
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
|
public function handleLevelSoundEvent(LevelSoundEventPacket $packet) : bool{
|
||||||
//TODO: we want to block out this packet completely, but we don't yet know the full scope of sounds that the client sends us from here
|
//TODO: we want to block out this packet completely, but we don't yet know the full scope of sounds that the client sends us from here
|
||||||
switch($packet->sound){
|
switch($packet->sound){
|
||||||
|
case LevelSoundEventPacket::SOUND_HIT: //block punch, maybe entity attack too?
|
||||||
case LevelSoundEventPacket::SOUND_LAND:
|
case LevelSoundEventPacket::SOUND_LAND:
|
||||||
case LevelSoundEventPacket::SOUND_FALL:
|
case LevelSoundEventPacket::SOUND_FALL:
|
||||||
case LevelSoundEventPacket::SOUND_FALL_SMALL:
|
case LevelSoundEventPacket::SOUND_FALL_SMALL:
|
||||||
|
@ -100,6 +100,7 @@ use pocketmine\world\ChunkLoader;
|
|||||||
use pocketmine\world\format\Chunk;
|
use pocketmine\world\format\Chunk;
|
||||||
use pocketmine\world\particle\PunchBlockParticle;
|
use pocketmine\world\particle\PunchBlockParticle;
|
||||||
use pocketmine\world\Position;
|
use pocketmine\world\Position;
|
||||||
|
use pocketmine\world\sound\BlockPunchSound;
|
||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
use function abs;
|
use function abs;
|
||||||
use function assert;
|
use function assert;
|
||||||
@ -1583,6 +1584,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
public function continueBreakBlock(Vector3 $pos, int $face) : void{
|
public function continueBreakBlock(Vector3 $pos, int $face) : void{
|
||||||
$block = $this->getWorld()->getBlock($pos);
|
$block = $this->getWorld()->getBlock($pos);
|
||||||
$this->getWorld()->addParticle($pos, new PunchBlockParticle($block, $face));
|
$this->getWorld()->addParticle($pos, new PunchBlockParticle($block, $face));
|
||||||
|
$this->getWorld()->addSound($pos, new BlockPunchSound($block));
|
||||||
$this->broadcastEntityEvent(ActorEventPacket::ARM_SWING, null, $this->getViewers());
|
$this->broadcastEntityEvent(ActorEventPacket::ARM_SWING, null, $this->getViewers());
|
||||||
|
|
||||||
//TODO: destroy-progress level event
|
//TODO: destroy-progress level event
|
||||||
|
49
src/world/sound/BlockPunchSound.php
Normal file
49
src/world/sound/BlockPunchSound.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* ____ _ _ __ __ _ __ __ ____
|
||||||
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||||
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||||
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||||
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* @author PocketMine Team
|
||||||
|
* @link http://www.pocketmine.net/
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace pocketmine\world\sound;
|
||||||
|
|
||||||
|
use pocketmine\block\Block;
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Played when a player attacks a block in survival, attempting to break it.
|
||||||
|
*/
|
||||||
|
class BlockPunchSound implements Sound{
|
||||||
|
|
||||||
|
/** @var Block */
|
||||||
|
private $block;
|
||||||
|
|
||||||
|
public function __construct(Block $block){
|
||||||
|
$this->block = $block;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function encode(?Vector3 $pos){
|
||||||
|
return LevelSoundEventPacket::create(
|
||||||
|
LevelSoundEventPacket::SOUND_HIT,
|
||||||
|
$pos,
|
||||||
|
$this->block->getRuntimeId()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user