mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
moving entity attack sounds to server-side
This commit is contained in:
parent
d40152e3bb
commit
d3dcb8a4e3
@ -757,6 +757,9 @@ 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_ATTACK:
|
||||||
|
case LevelSoundEventPacket::SOUND_ATTACK_NODAMAGE:
|
||||||
|
case LevelSoundEventPacket::SOUND_ATTACK_STRONG: //TODO: reassess this, seems like the regular attack is never used ??
|
||||||
case LevelSoundEventPacket::SOUND_HIT: //block punch, maybe entity attack too?
|
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:
|
||||||
|
@ -104,6 +104,8 @@ use pocketmine\world\format\Chunk;
|
|||||||
use pocketmine\world\particle\BlockPunchParticle;
|
use pocketmine\world\particle\BlockPunchParticle;
|
||||||
use pocketmine\world\Position;
|
use pocketmine\world\Position;
|
||||||
use pocketmine\world\sound\BlockPunchSound;
|
use pocketmine\world\sound\BlockPunchSound;
|
||||||
|
use pocketmine\world\sound\EntityAttackNoDamageSound;
|
||||||
|
use pocketmine\world\sound\EntityAttackSound;
|
||||||
use pocketmine\world\World;
|
use pocketmine\world\World;
|
||||||
use function abs;
|
use function abs;
|
||||||
use function assert;
|
use function assert;
|
||||||
@ -1686,10 +1688,13 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
|
|||||||
|
|
||||||
$entity->attack($ev);
|
$entity->attack($ev);
|
||||||
|
|
||||||
|
$soundPos = $entity->getPosition()->add(0, $entity->width / 2, 0);
|
||||||
if($ev->isCancelled()){
|
if($ev->isCancelled()){
|
||||||
|
$this->getWorld()->addSound($soundPos, new EntityAttackNoDamageSound());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers());
|
$this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers());
|
||||||
|
$this->getWorld()->addSound($soundPos, new EntityAttackSound());
|
||||||
|
|
||||||
if($ev->getModifier(EntityDamageEvent::MODIFIER_CRITICAL) > 0 and $entity instanceof Living){
|
if($ev->getModifier(EntityDamageEvent::MODIFIER_CRITICAL) > 0 and $entity instanceof Living){
|
||||||
$entity->broadcastAnimation(new CriticalHitAnimation($entity));
|
$entity->broadcastAnimation(new CriticalHitAnimation($entity));
|
||||||
|
43
src/world/sound/EntityAttackNoDamageSound.php
Normal file
43
src/world/sound/EntityAttackNoDamageSound.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?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\math\Vector3;
|
||||||
|
use pocketmine\network\mcpe\protocol\ClientboundPacket;
|
||||||
|
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Played when a player attacks a mob, but fails to deal damage (e.g. cancelled or attack cooldown).
|
||||||
|
*/
|
||||||
|
class EntityAttackNoDamageSound implements Sound{
|
||||||
|
|
||||||
|
public function encode(?Vector3 $pos){
|
||||||
|
return LevelSoundEventPacket::create(
|
||||||
|
LevelSoundEventPacket::SOUND_ATTACK_NODAMAGE,
|
||||||
|
$pos,
|
||||||
|
-1,
|
||||||
|
"minecraft:player"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
43
src/world/sound/EntityAttackSound.php
Normal file
43
src/world/sound/EntityAttackSound.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?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\math\Vector3;
|
||||||
|
use pocketmine\network\mcpe\protocol\ClientboundPacket;
|
||||||
|
use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Played when a player attacks a mob, dealing damage.
|
||||||
|
*/
|
||||||
|
class EntityAttackSound implements Sound{
|
||||||
|
|
||||||
|
public function encode(?Vector3 $pos){
|
||||||
|
return LevelSoundEventPacket::create(
|
||||||
|
LevelSoundEventPacket::SOUND_ATTACK_STRONG, //TODO: seems like ATTACK is dysfunctional
|
||||||
|
$pos,
|
||||||
|
-1,
|
||||||
|
"minecraft:player"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user