Skip to content

Commit

Permalink
Added block breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
shoghicp committed Jun 30, 2014
1 parent 4c761a3 commit fe2e7ec
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/shoghicp/BigBrother/network/Packet.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace shoghicp\BigBrother\network;

use pocketmine\item\Item;
use shoghicp\BigBrother\utils\Binary;

abstract class Packet extends \stdClass{
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions src/shoghicp/BigBrother/network/ProtocolInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
52 changes: 52 additions & 0 deletions src/shoghicp/BigBrother/network/translation/Translator_16.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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){
Expand Down
1 change: 0 additions & 1 deletion src/shoghicp/BigBrother/tasks/OnlineProfile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit fe2e7ec

Please sign in to comment.