added PunchBlockParticle, encapsulate more network logic

This commit is contained in:
Dylan K. Taylor 2019-05-09 15:40:58 +01:00
parent 51a8c2be9d
commit 5eb3c52a37
2 changed files with 50 additions and 5 deletions

View File

@ -113,6 +113,7 @@ use pocketmine\utils\UUID;
use pocketmine\world\ChunkListener;
use pocketmine\world\ChunkLoader;
use pocketmine\world\format\Chunk;
use pocketmine\world\particle\PunchBlockParticle;
use pocketmine\world\Position;
use pocketmine\world\World;
use function abs;
@ -1932,11 +1933,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
public function continueBreakBlock(Vector3 $pos, int $face) : void{
$block = $this->world->getBlock($pos);
$this->world->broadcastLevelEvent(
$pos,
LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK,
$block->getRuntimeId() | ($face << 24)
);
$this->world->addParticle($pos, new PunchBlockParticle($block, $face));
//TODO: destroy-progress level event
}

View File

@ -0,0 +1,48 @@
<?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\particle;
use pocketmine\block\Block;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\LevelEventPacket;
/**
* This particle appears when a player is attacking a block face in survival mode attempting to break it.
*/
class PunchBlockParticle implements Particle{
/** @var Block */
private $block;
/** @var int */
private $face;
public function __construct(Block $block, int $face){
$this->block = $block;
$this->face = $face;
}
public function encode(Vector3 $pos){
return LevelEventPacket::create(LevelEventPacket::EVENT_PARTICLE_PUNCH_BLOCK, $this->block->getRuntimeId() | ($this->face << 24), $pos);
}
}