diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 1489fd781..801083f14 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -122,7 +122,6 @@ use pocketmine\network\mcpe\protocol\types\CommandParameter; use pocketmine\network\mcpe\protocol\types\ContainerIds; use pocketmine\network\mcpe\protocol\types\PlayerPermissions; use pocketmine\network\mcpe\protocol\UpdateAttributesPacket; -use pocketmine\network\mcpe\protocol\UpdateBlockPacket; use pocketmine\network\mcpe\ProcessLoginTask; use pocketmine\permission\PermissibleBase; use pocketmine\permission\PermissionAttachment; @@ -2208,7 +2207,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $blocks = $target->getAllSides(); $blocks[] = $target; - $this->level->sendBlocks([$this], $blocks, UpdateBlockPacket::FLAG_ALL_PRIORITY); + $this->level->sendBlocks([$this], $blocks); foreach($blocks as $b){ $tile = $this->level->getTile($b); @@ -2255,7 +2254,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ /** @var Block[] $blocks */ $blocks = array_merge($target->getAllSides(), $block->getAllSides()); //getAllSides() on each of these will include $target and $block because they are next to each other - $this->level->sendBlocks([$this], $blocks, UpdateBlockPacket::FLAG_ALL_PRIORITY); + $this->level->sendBlocks([$this], $blocks); return false; } diff --git a/src/pocketmine/level/Level.php b/src/pocketmine/level/Level.php index 8d4699965..13cbbb65a 100644 --- a/src/pocketmine/level/Level.php +++ b/src/pocketmine/level/Level.php @@ -799,7 +799,7 @@ class Level implements ChunkManager, Metadatable{ $p->onChunkChanged($chunk); } }else{ - $this->sendBlocks($this->getChunkPlayers($chunkX, $chunkZ), $blocks, UpdateBlockPacket::FLAG_ALL); + $this->sendBlocks($this->getChunkPlayers($chunkX, $chunkZ), $blocks); } } }else{ @@ -870,62 +870,28 @@ class Level implements ChunkManager, Metadatable{ /** * @param Player[] $target * @param Vector3[] $blocks - * @param int $flags - * @param bool $optimizeRebuilds */ - public function sendBlocks(array $target, array $blocks, int $flags = UpdateBlockPacket::FLAG_NONE, bool $optimizeRebuilds = false){ + public function sendBlocks(array $target, array $blocks){ $packets = []; - if($optimizeRebuilds){ - $chunks = []; - foreach($blocks as $b){ - if(!($b instanceof Vector3)){ - throw new \TypeError("Expected Vector3 in blocks array, got " . (is_object($b) ? get_class($b) : gettype($b))); - } - $pk = new UpdateBlockPacket(); - $first = false; - if(!isset($chunks[$index = Level::chunkHash($b->x >> 4, $b->z >> 4)])){ - $chunks[$index] = true; - $first = true; - } - - $pk->x = $b->x; - $pk->y = $b->y; - $pk->z = $b->z; - - if($b instanceof Block){ - $pk->blockRuntimeId = $b->getRuntimeId(); - }else{ - $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z); - $pk->blockRuntimeId = BlockFactory::toStaticRuntimeId($fullBlock >> 4, $fullBlock & 0xf); - } - - $pk->flags = $first ? $flags : UpdateBlockPacket::FLAG_NONE; - - $packets[] = $pk; + foreach($blocks as $b){ + if(!($b instanceof Vector3)){ + throw new \TypeError("Expected Vector3 in blocks array, got " . (is_object($b) ? get_class($b) : gettype($b))); } - }else{ - foreach($blocks as $b){ - if(!($b instanceof Vector3)){ - throw new \TypeError("Expected Vector3 in blocks array, got " . (is_object($b) ? get_class($b) : gettype($b))); - } - $pk = new UpdateBlockPacket(); + $pk = new UpdateBlockPacket(); - $pk->x = $b->x; - $pk->y = $b->y; - $pk->z = $b->z; + $pk->x = $b->x; + $pk->y = $b->y; + $pk->z = $b->z; - if($b instanceof Block){ - $pk->blockRuntimeId = $b->getRuntimeId(); - }else{ - $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z); - $pk->blockRuntimeId = BlockFactory::toStaticRuntimeId($fullBlock >> 4, $fullBlock & 0xf); - } - - $pk->flags = $flags; - - $packets[] = $pk; + if($b instanceof Block){ + $pk->blockRuntimeId = $b->getRuntimeId(); + }else{ + $fullBlock = $this->getFullBlock($b->x, $b->y, $b->z); + $pk->blockRuntimeId = BlockFactory::toStaticRuntimeId($fullBlock >> 4, $fullBlock & 0xf); } + + $packets[] = $pk; } $this->server->broadcastPackets($target, $packets); @@ -1547,7 +1513,7 @@ class Level implements ChunkManager, Metadatable{ unset($this->blockCache[$chunkHash][$blockHash]); if($direct){ - $this->sendBlocks($this->getChunkPlayers($pos->x >> 4, $pos->z >> 4), [$block], UpdateBlockPacket::FLAG_ALL_PRIORITY); + $this->sendBlocks($this->getChunkPlayers($pos->x >> 4, $pos->z >> 4), [$block]); unset($this->chunkCache[$chunkHash], $this->changedBlocks[$chunkHash][$blockHash]); }else{ if(!isset($this->changedBlocks[$chunkHash])){ diff --git a/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php index db7066328..254f54bd0 100644 --- a/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php +++ b/src/pocketmine/network/mcpe/protocol/UpdateBlockPacket.php @@ -31,15 +31,6 @@ use pocketmine\network\mcpe\handler\SessionHandler; class UpdateBlockPacket extends DataPacket{ public const NETWORK_ID = ProtocolInfo::UPDATE_BLOCK_PACKET; - public const FLAG_NONE = 0b0000; - public const FLAG_NEIGHBORS = 0b0001; - public const FLAG_NETWORK = 0b0010; - public const FLAG_NOGRAPHIC = 0b0100; - public const FLAG_PRIORITY = 0b1000; - - public const FLAG_ALL = self::FLAG_NEIGHBORS | self::FLAG_NETWORK; - public const FLAG_ALL_PRIORITY = self::FLAG_ALL | self::FLAG_PRIORITY; - public const DATA_LAYER_NORMAL = 0; public const DATA_LAYER_LIQUID = 1; @@ -51,8 +42,12 @@ class UpdateBlockPacket extends DataPacket{ public $y; /** @var int */ public $blockRuntimeId; - /** @var int */ - public $flags; + /** + * @var int + * Flags are used by MCPE internally for block setting, but only flag 2 (network flag) is relevant for network. + * This field is pointless really. + */ + public $flags = 0x02; /** @var int */ public $dataLayerId = self::DATA_LAYER_NORMAL;