Added handling for attack-air action (#5912)

This commit is contained in:
ipad54 2023-07-25 16:50:28 +03:00 committed by GitHub
parent fb43f59458
commit 6086ef667c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 0 deletions

View File

@ -0,0 +1,39 @@
<?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\event\player;
use pocketmine\event\Cancellable;
use pocketmine\event\CancellableTrait;
use pocketmine\player\Player;
/**
* Called when a player attempts to perform the attack action (left-click) without a target entity.
*/
class PlayerMissedSwingEvent extends PlayerEvent implements Cancellable{
use CancellableTrait;
public function __construct(Player $player){
$this->player = $player;
}
}

View File

@ -236,6 +236,9 @@ class InGamePacketHandler extends PacketHandler{
if($packet->hasFlag(PlayerAuthInputFlags::START_JUMPING)){
$this->player->jump();
}
if($packet->hasFlag(PlayerAuthInputFlags::MISSED_SWING)){
$this->player->missSwing();
}
}
if(!$this->forceMoveSync && $hasMoved){

View File

@ -66,6 +66,7 @@ use pocketmine\event\player\PlayerItemUseEvent;
use pocketmine\event\player\PlayerJoinEvent;
use pocketmine\event\player\PlayerJumpEvent;
use pocketmine\event\player\PlayerKickEvent;
use pocketmine\event\player\PlayerMissedSwingEvent;
use pocketmine\event\player\PlayerMoveEvent;
use pocketmine\event\player\PlayerPostChunkSendEvent;
use pocketmine\event\player\PlayerQuitEvent;
@ -1894,6 +1895,18 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
return true;
}
/**
* Performs actions associated with the attack action (left-click) without a target entity.
* Under normal circumstances, this will play the no-damage attack sound and nothing else.
*/
public function missSwing() : void{
$ev = new PlayerMissedSwingEvent($this);
$ev->call();
if(!$ev->isCancelled()){
$this->broadcastSound(new EntityAttackNoDamageSound());
}
}
/**
* Interacts with the given entity using the currently-held item.
*/