InGamePacketHandler: fixed block breaking borked by enabling PlayerAuthInputPacket

This commit is contained in:
Dylan K. Taylor 2021-12-15 04:01:40 +00:00
parent 6494375a53
commit d487e43766
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -37,6 +37,7 @@ use pocketmine\inventory\transaction\TransactionValidationException;
use pocketmine\item\VanillaItems; use pocketmine\item\VanillaItems;
use pocketmine\item\WritableBook; use pocketmine\item\WritableBook;
use pocketmine\item\WrittenBook; use pocketmine\item\WrittenBook;
use pocketmine\math\Facing;
use pocketmine\math\Vector3; use pocketmine\math\Vector3;
use pocketmine\nbt\tag\CompoundTag; use pocketmine\nbt\tag\CompoundTag;
use pocketmine\nbt\tag\StringTag; use pocketmine\nbt\tag\StringTag;
@ -83,6 +84,7 @@ use pocketmine\network\mcpe\protocol\SpawnExperienceOrbPacket;
use pocketmine\network\mcpe\protocol\SubClientLoginPacket; use pocketmine\network\mcpe\protocol\SubClientLoginPacket;
use pocketmine\network\mcpe\protocol\TextPacket; use pocketmine\network\mcpe\protocol\TextPacket;
use pocketmine\network\mcpe\protocol\types\ActorEvent; use pocketmine\network\mcpe\protocol\types\ActorEvent;
use pocketmine\network\mcpe\protocol\types\BlockPosition;
use pocketmine\network\mcpe\protocol\types\inventory\ContainerIds; use pocketmine\network\mcpe\protocol\types\inventory\ContainerIds;
use pocketmine\network\mcpe\protocol\types\inventory\MismatchTransactionData; use pocketmine\network\mcpe\protocol\types\inventory\MismatchTransactionData;
use pocketmine\network\mcpe\protocol\types\inventory\NetworkInventoryAction; use pocketmine\network\mcpe\protocol\types\inventory\NetworkInventoryAction;
@ -92,6 +94,8 @@ use pocketmine\network\mcpe\protocol\types\inventory\UIInventorySlotOffset;
use pocketmine\network\mcpe\protocol\types\inventory\UseItemOnEntityTransactionData; use pocketmine\network\mcpe\protocol\types\inventory\UseItemOnEntityTransactionData;
use pocketmine\network\mcpe\protocol\types\inventory\UseItemTransactionData; use pocketmine\network\mcpe\protocol\types\inventory\UseItemTransactionData;
use pocketmine\network\mcpe\protocol\types\PlayerAction; use pocketmine\network\mcpe\protocol\types\PlayerAction;
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionStopBreak;
use pocketmine\network\mcpe\protocol\types\PlayerBlockActionWithBlockInfo;
use pocketmine\network\PacketHandlingException; use pocketmine\network\PacketHandlingException;
use pocketmine\player\Player; use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError; use pocketmine\utils\AssumptionFailedError;
@ -182,7 +186,32 @@ class InGamePacketHandler extends PacketHandler{
//TODO: this packet has WAYYYYY more useful information that we're not using //TODO: this packet has WAYYYYY more useful information that we're not using
$this->player->handleMovement($newPos); $this->player->handleMovement($newPos);
return true; $packetHandled = true;
$useItemTransaction = $packet->getItemInteractionData();
if($useItemTransaction !== null && !$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
$packetHandled = false;
$this->session->getLogger()->debug("Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() . ")");
}
$blockActions = $packet->getBlockActions();
if($blockActions !== null){
foreach($blockActions as $k => $blockAction){
$actionHandled = false;
if($blockAction instanceof PlayerBlockActionStopBreak){
$actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), new BlockPosition(0, 0, 0), Facing::DOWN);
}elseif($blockAction instanceof PlayerBlockActionWithBlockInfo){
$actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), $blockAction->getBlockPosition(), $blockAction->getFace());
}
if(!$actionHandled){
$packetHandled = false;
$this->session->getLogger()->debug("Unhandled player block action at offset $k in PlayerAuthInputPacket");
}
}
}
return $packetHandled;
} }
public function handleLevelSoundEventPacketV1(LevelSoundEventPacketV1 $packet) : bool{ public function handleLevelSoundEventPacketV1(LevelSoundEventPacketV1 $packet) : bool{
@ -493,12 +522,16 @@ class InGamePacketHandler extends PacketHandler{
} }
public function handlePlayerAction(PlayerActionPacket $packet) : bool{ public function handlePlayerAction(PlayerActionPacket $packet) : bool{
$pos = new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ()); return $this->handlePlayerActionFromData($packet->action, $packet->blockPosition, $packet->face);
}
switch($packet->action){ private function handlePlayerActionFromData(int $action, BlockPosition $blockPosition, int $face) : bool{
$pos = new Vector3($blockPosition->getX(), $blockPosition->getY(), $blockPosition->getZ());
switch($action){
case PlayerAction::START_BREAK: case PlayerAction::START_BREAK:
if(!$this->player->attackBlock($pos, $packet->face)){ if(!$this->player->attackBlock($pos, $face)){
$this->onFailedBlockAction($pos, $packet->face); $this->onFailedBlockAction($pos, $face);
} }
break; break;
@ -540,7 +573,7 @@ class InGamePacketHandler extends PacketHandler{
case PlayerAction::STOP_GLIDE: case PlayerAction::STOP_GLIDE:
break; //TODO break; //TODO
case PlayerAction::CRACK_BREAK: case PlayerAction::CRACK_BREAK:
$this->player->continueBreakBlock($pos, $packet->face); $this->player->continueBreakBlock($pos, $face);
break; break;
case PlayerAction::START_SWIMMING: case PlayerAction::START_SWIMMING:
break; //TODO break; //TODO
@ -553,7 +586,7 @@ class InGamePacketHandler extends PacketHandler{
//TODO: do we need to handle this? //TODO: do we need to handle this?
break; break;
default: default:
$this->session->getLogger()->debug("Unhandled/unknown player action type " . $packet->action); $this->session->getLogger()->debug("Unhandled/unknown player action type " . $action);
return false; return false;
} }