From fe2e7ec56b54d7689e890a05f88190a8f73ea84e Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 30 Jun 2014 02:03:14 +0200 Subject: [PATCH] Added block breaking --- src/shoghicp/BigBrother/network/Packet.php | 30 +++++++++++ .../BigBrother/network/ProtocolInterface.php | 8 +++ .../network/translation/Translator_16.php | 52 +++++++++++++++++++ .../BigBrother/tasks/OnlineProfile.php | 1 - 4 files changed, 90 insertions(+), 1 deletion(-) diff --git a/src/shoghicp/BigBrother/network/Packet.php b/src/shoghicp/BigBrother/network/Packet.php index 7b57b11c..14233143 100644 --- a/src/shoghicp/BigBrother/network/Packet.php +++ b/src/shoghicp/BigBrother/network/Packet.php @@ -17,6 +17,7 @@ namespace shoghicp\BigBrother\network; +use pocketmine\item\Item; use shoghicp\BigBrother\utils\Binary; abstract class Packet extends \stdClass{ @@ -57,6 +58,35 @@ protected function getDouble(){ return Binary::readDouble($this->get(8)); } + /** + * @return Item + */ + protected function getSlot(){ + $itemId = $this->getShort(); + if($itemId === -1){ //Empty + return Item::get(Item::AIR, 0, 0); + }else{ + $count = $this->getByte(); + $damage = $this->getShort(true); + $len = $this->getShort(true); + if($len > 0){ + $nbt = $this->get($len); + } + return Item::get($itemId, $damage, $count); + } + } + + protected function putSlot(Item $item){ + if($item->getID() === 0){ + $this->putShort(-1); + }else{ + $this->putShort($item->getID()); + $this->putByte($item->getCount()); + $this->putShort($item->getDamage()); + $this->putShort(0); + } + } + protected function getShort($unsigned = false){ return Binary::readShort($this->get(2), $unsigned); } diff --git a/src/shoghicp/BigBrother/network/ProtocolInterface.php b/src/shoghicp/BigBrother/network/ProtocolInterface.php index d19a22e6..d37abdea 100644 --- a/src/shoghicp/BigBrother/network/ProtocolInterface.php +++ b/src/shoghicp/BigBrother/network/ProtocolInterface.php @@ -26,6 +26,8 @@ use shoghicp\BigBrother\network\protocol\CTSChatPacket; use shoghicp\BigBrother\network\protocol\EncryptionResponsePacket; use shoghicp\BigBrother\network\protocol\LoginStartPacket; +use shoghicp\BigBrother\network\protocol\PlayerBlockPlacementPacket; +use shoghicp\BigBrother\network\protocol\PlayerDiggingPacket; use shoghicp\BigBrother\network\protocol\PlayerLookPacket; use shoghicp\BigBrother\network\protocol\PlayerPositionAndLookPacket; use shoghicp\BigBrother\network\protocol\PlayerPositionPacket; @@ -173,6 +175,12 @@ protected function handlePacket(DesktopPlayer $player, $payload){ case 0x06: $pk = new PlayerPositionAndLookPacket(); break; + case 0x07: + $pk = new PlayerDiggingPacket(); + break; + case 0x08: + $pk = new PlayerBlockPlacementPacket(); + break; default: return; } diff --git a/src/shoghicp/BigBrother/network/translation/Translator_16.php b/src/shoghicp/BigBrother/network/translation/Translator_16.php index c7cdf555..dae246f1 100644 --- a/src/shoghicp/BigBrother/network/translation/Translator_16.php +++ b/src/shoghicp/BigBrother/network/translation/Translator_16.php @@ -17,10 +17,14 @@ namespace shoghicp\BigBrother\network\translation; +use pocketmine\math\Vector3; use pocketmine\network\protocol\DataPacket; use pocketmine\network\protocol\Info; use pocketmine\network\protocol\MessagePacket; use pocketmine\network\protocol\MovePlayerPacket; +use pocketmine\network\protocol\RemoveBlockPacket; +use pocketmine\network\protocol\UpdateBlockPacket; +use pocketmine\network\protocol\UseItemPacket; use pocketmine\utils\TextFormat; use shoghicp\BigBrother\DesktopPlayer; use shoghicp\BigBrother\network\Packet; @@ -80,9 +84,57 @@ public function interfaceToServer(DesktopPlayer $player, Packet $packet){ $pk->pitch = $packet->pitch; return $pk; + case 0x07: //PlayerDiggingPacket + if($packet->status === 2 or ($player->getGamemode() === 1 and $packet->status === 0)){ //Finished digging + $pk = new RemoveBlockPacket(); + $pk->eid = 0; + $pk->x = $packet->x; + $pk->y = $packet->y; + $pk->z = $packet->z; + return $pk; + } + return null; + + case 0x08; //PlayerBlockPlacementPacket + + $target = $player->getLevel()->getBlock(new Vector3($packet->x, $packet->y, $packet->z)); + $block = $target->getSide($packet->direction); + + $pk = new UpdateBlockPacket; + $pk->x = $target->x; + $pk->y = $target->y; + $pk->z = $target->z; + $pk->block = $target->getID(); + $pk->meta = $target->getDamage(); + $player->dataPacket($pk); + + $pk = new UpdateBlockPacket; + $pk->x = $block->x; + $pk->y = $block->y; + $pk->z = $block->z; + $pk->block = $block->getID(); + $pk->meta = $block->getDamage(); + $player->dataPacket($pk); + break; + //TODO + $pk = new UseItemPacket(); + $pk->x = $packet->x; + $pk->y = $packet->y; + $pk->z = $packet->z; + $pk->face = $packet->direction; + $pk->item = $packet->heldItem->getID(); + $pk->meta = $packet->heldItem->getDamage(); + $pk->eid = 0; + $pk->fx = $packet->cursorX / 16; + $pk->fy = $packet->cursorY / 16; + $pk->fz = $packet->cursorZ / 16; + return $pk; + default: return null; } + + return null; } public function serverToInterface(DesktopPlayer $player, DataPacket $packet){ diff --git a/src/shoghicp/BigBrother/tasks/OnlineProfile.php b/src/shoghicp/BigBrother/tasks/OnlineProfile.php index 900fe758..a538a179 100644 --- a/src/shoghicp/BigBrother/tasks/OnlineProfile.php +++ b/src/shoghicp/BigBrother/tasks/OnlineProfile.php @@ -67,7 +67,6 @@ public function onCompletion(Server $server){ foreach($server->getOnlinePlayers() as $clientID => $player){ if($player instanceof DesktopPlayer and $clientID === $this->clientID){ $result = $this->getResult(); - var_dump($result); if(is_array($result) and isset($result["id"])){ $player->bigBrother_authenticate($this->username, $result["id"], $result["properties"]); }else{