ClientboundMapItemDataPacket

This commit is contained in:
Dylan K. Taylor
2017-03-03 19:54:50 +00:00
parent 005c2419e9
commit 9e92a350e3
5 changed files with 318 additions and 4 deletions

View File

@ -38,6 +38,7 @@ use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
use pocketmine\network\mcpe\protocol\BlockEventPacket;
use pocketmine\network\mcpe\protocol\ChangeDimensionPacket;
use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket;
use pocketmine\network\mcpe\protocol\ClientboundMapItemDataPacket;
use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket;
use pocketmine\network\mcpe\protocol\CommandStepPacket;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
@ -328,6 +329,7 @@ class Network{
$this->registerPacket(ProtocolInfo::BLOCK_EVENT_PACKET, BlockEventPacket::class);
$this->registerPacket(ProtocolInfo::CHANGE_DIMENSION_PACKET, ChangeDimensionPacket::class);
$this->registerPacket(ProtocolInfo::CHUNK_RADIUS_UPDATED_PACKET, ChunkRadiusUpdatedPacket::class);
$this->registerPacket(ProtocolInfo::CLIENTBOUND_MAP_ITEM_DATA_PACKET, ClientboundMapItemDataPacket::class);
$this->registerPacket(ProtocolInfo::CLIENT_TO_SERVER_HANDSHAKE_PACKET, ClientToServerHandshakePacket::class);
$this->registerPacket(ProtocolInfo::COMMAND_STEP_PACKET, CommandStepPacket::class);
$this->registerPacket(ProtocolInfo::CONTAINER_CLOSE_PACKET, ContainerClosePacket::class);

View File

@ -37,6 +37,7 @@ use pocketmine\network\mcpe\protocol\BlockEntityDataPacket;
use pocketmine\network\mcpe\protocol\BlockEventPacket;
use pocketmine\network\mcpe\protocol\ChangeDimensionPacket;
use pocketmine\network\mcpe\protocol\ChunkRadiusUpdatedPacket;
use pocketmine\network\mcpe\protocol\ClientboundMapItemDataPacket;
use pocketmine\network\mcpe\protocol\ClientToServerHandshakePacket;
use pocketmine\network\mcpe\protocol\CommandStepPacket;
use pocketmine\network\mcpe\protocol\ContainerClosePacket;
@ -234,7 +235,7 @@ interface NetworkSession{
public function handleSpawnExperienceOrb(SpawnExperienceOrbPacket $packet) : bool;
//public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool; //TODO
public function handleClientboundMapItemData(ClientboundMapItemDataPacket $packet) : bool;
public function handleMapInfoRequest(MapInfoRequestPacket $packet) : bool; //TODO

View File

@ -0,0 +1,149 @@
<?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/
*
*
*/
namespace pocketmine\network\mcpe\protocol;
#include <rules/DataPacket.h>
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\utils\Color;
class ClientboundMapItemDataPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::CLIENTBOUND_MAP_ITEM_DATA_PACKET;
const BITFLAG_TEXTURE_UPDATE = 0x02;
const BITFLAG_DECORATION_UPDATE = 0x04;
public $mapId;
public $type;
public $eids = [];
public $scale;
public $decorations = [];
public $width;
public $height;
public $xOffset = 0;
public $yOffset = 0;
/** @var Color[][] */
public $colors = [];
public function decode(){
$this->mapId = $this->getVarInt();
$this->type = $this->getUnsignedVarInt();
if(($this->type & 0x08) !== 0){
$count = $this->getUnsignedVarInt();
for($i = 0; $i < $count; ++$i){
$this->eids[] = $this->getVarInt(); //entity unique ID, signed var-int
}
}
if(($this->type & (self::BITFLAG_DECORATION_UPDATE | self::BITFLAG_TEXTURE_UPDATE)) !== 0){ //Decoration bitflag or colour bitflag
$this->scale = $this->getByte();
}
if(($this->type & self::BITFLAG_DECORATION_UPDATE) !== 0){
$count = $this->getUnsignedVarInt();
for($i = 0; $i < $count; ++$i){
$weird = $this->getVarInt();
$this->decorations[$i]["rot"] = $weird & 0x0f;
$this->decorations[$i]["img"] = $weird >> 4;
$this->decorations[$i]["xOffset"] = $this->getByte();
$this->decorations[$i]["yOffset"] = $this->getByte();
$this->decorations[$i]["label"] = $this->getString();
$this->decorations[$i]["color"] = Color::fromARGB($this->getLInt()); //already BE, don't need to reverse it again
}
}
if(($this->type & self::BITFLAG_TEXTURE_UPDATE) !== 0){
$this->width = $this->getVarInt();
$this->height = $this->getVarInt();
$this->xOffset = $this->getVarInt();
$this->yOffset = $this->getVarInt();
for($y = 0; $y < $this->height; ++$y){
for($x = 0; $x < $this->width; ++$x){
$this->colors[$y][$x] = Color::fromABGR($this->getUnsignedVarInt());
}
}
}
}
public function encode(){
$this->reset();
$this->putVarInt($this->mapId); //entity unique ID, signed var-int
$type = 0;
if(($eidsCount = count($this->eids)) > 0){
$type |= 0x08;
}
if(($decorationCount = count($this->decorations)) > 0){
$type |= self::BITFLAG_DECORATION_UPDATE;
}
if(count($this->colors) > 0){
$type |= self::BITFLAG_TEXTURE_UPDATE;
}
$this->putUnsignedVarInt($type);
if(($type & 0x08) !== 0){ //TODO: find out what these are for
$this->putUnsignedVarInt($eidsCount);
foreach($this->eids as $eid){
$this->putVarInt($eid);
}
}
if(($type & (self::BITFLAG_TEXTURE_UPDATE | self::BITFLAG_DECORATION_UPDATE)) !== 0){
$this->putByte($this->scale);
}
if(($type & self::BITFLAG_DECORATION_UPDATE) !== 0){
$this->putUnsignedVarInt($decorationCount);
foreach($this->decorations as $decoration){
$this->putVarInt(($decoration["rot"] & 0x0f) | ($decoration["img"] << 4));
$this->putByte($decoration["xOffset"]);
$this->putByte($decoration["yOffset"]);
$this->putString($decoration["label"]);
$this->putLInt($decoration["color"]->toARGB());
}
}
if(($type & self::BITFLAG_TEXTURE_UPDATE) !== 0){
$this->putVarInt($this->width);
$this->putVarInt($this->height);
$this->putVarInt($this->xOffset);
$this->putVarInt($this->yOffset);
for($y = 0; $y < $this->height; ++$y){
for($x = 0; $x < $this->width; ++$x){
$this->putUnsignedVarInt($this->colors[$y][$x]->toABGR());
}
}
}
}
public function handle(NetworkSession $session) : bool{
$session->handleClientboundMapItemData($this);
}
}