moving entity attack sounds to server-side

This commit is contained in:
Dylan K. Taylor 2020-05-04 11:50:42 +01:00
parent d40152e3bb
commit d3dcb8a4e3
4 changed files with 94 additions and 0 deletions

View File

@ -757,6 +757,9 @@ class InGamePacketHandler extends PacketHandler{
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
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_LAND:
case LevelSoundEventPacket::SOUND_FALL:

View File

@ -104,6 +104,8 @@ use pocketmine\world\format\Chunk;
use pocketmine\world\particle\BlockPunchParticle;
use pocketmine\world\Position;
use pocketmine\world\sound\BlockPunchSound;
use pocketmine\world\sound\EntityAttackNoDamageSound;
use pocketmine\world\sound\EntityAttackSound;
use pocketmine\world\World;
use function abs;
use function assert;
@ -1686,10 +1688,13 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
$entity->attack($ev);
$soundPos = $entity->getPosition()->add(0, $entity->width / 2, 0);
if($ev->isCancelled()){
$this->getWorld()->addSound($soundPos, new EntityAttackNoDamageSound());
return false;
}
$this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers());
$this->getWorld()->addSound($soundPos, new EntityAttackSound());
if($ev->getModifier(EntityDamageEvent::MODIFIER_CRITICAL) > 0 and $entity instanceof Living){
$entity->broadcastAnimation(new CriticalHitAnimation($entity));

View 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"
);
}
}

View 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"
);
}
}