PlaceBlockPacket impelement

This commit is contained in:
yefengeeeeeeeeeee 2025-04-22 19:41:57 +08:00
parent eccf3e7131
commit edefb7fe05
2 changed files with 92 additions and 36 deletions

View file

@ -356,9 +356,12 @@ class Player{
return; return;
} }
$packet->PROTOCOL = $this->PROTOCOL; $packet->PROTOCOL = $this->PROTOCOL;
$packet->encode(); $packet->encode();
if($packet->pid() == 163 or $packet->pid() == 164 && $this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){
return;
}
$len = strlen($packet->buffer) + 1; $len = strlen($packet->buffer) + 1;
$MTU = $this->MTU - 24; $MTU = $this->MTU - 24;
if($len > $MTU){ if($len > $MTU){
@ -2228,6 +2231,73 @@ class Player{
} }
} }
break; break;
case ProtocolInfo::PLACE_BLOCK_PACKET:
if (!($this->entity instanceof Entity)) {
break;
}
$blockVector = new Vector3($packet->x, $packet->y, $packet->z);
if (($this->spawned === false or $this->blocked === true) and $packet->face >= 0 and $packet->face <= 5) {
$target = $this->level->getBlock($blockVector);
$block = $target->getSide($packet->face);
$pk = new UpdateBlockPacket;
$pk->x = $target->x;
$pk->y = $target->y;
$pk->z = $target->z;
$pk->block = $target->getID();
$pk->meta = $target->getMetadata();
$this->dataPacket($pk);
$pk = new UpdateBlockPacket;
$pk->x = $block->x;
$pk->y = $block->y;
$pk->z = $block->z;
$pk->block = $block->getID();
$pk->meta = $block->getMetadata();
$this->dataPacket($pk);
break;
}
$this->craftingItems = [];
$this->toCraft = [];
$packet->eid = $this->eid;
$data = [];
if ($packet->face >= 0 and $packet->face <= 5) { //Use Block, place
if ($this->entity->inAction === true) {
$this->entity->inAction = false;
$this->entity->inActionCounter = 0;
$this->entity->updateMetadata();
}
if ($this->blocked === true or ($this->entity->position instanceof Vector3 and $blockVector->distance($this->entity->position) > 10)) {
} else {
$this->server->api->block->playerBlockAction($this, $blockVector, $packet->face, $packet->fx, $packet->fy, $packet->fz);
break;
}
$target = $this->level->getBlock($blockVector);
$block = $target->getSide($packet->face);
$pk = new UpdateBlockPacket;
$pk->x = $target->x;
$pk->y = $target->y;
$pk->z = $target->z;
$pk->block = $target->getID();
$pk->meta = $target->getMetadata();
$this->dataPacket($pk);
$pk = new UpdateBlockPacket;
$pk->x = $block->x;
$pk->y = $block->y;
$pk->z = $block->z;
$pk->block = $block->getID();
$pk->meta = $block->getMetadata();
$this->dataPacket($pk);
break;
}
break;
case ProtocolInfo::PLAYER_ACTION_PACKET: case ProtocolInfo::PLAYER_ACTION_PACKET:
if ($this->spawned === false or $this->blocked === true) { if ($this->spawned === false or $this->blocked === true) {
break; break;

View file

@ -1,13 +1,13 @@
<?php <?php
class PlaceBlockPacket extends RakNetDataPacket{ class PlaceBlockPacket extends RakNetDataPacket{
public $unknown1 = 0; public $eid;
public $unknown2 = 0; public $x;
public $unknown3 = 0; public $z;
public $unknown4 = 0; public $y;
public $unknown5 = 0; public $block;
public $unknown6 = 0; public $meta;
public $unknown7 = 0; public $face;
public function pid(){ public function pid(){
if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL) { if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL) {
@ -17,38 +17,24 @@ class PlaceBlockPacket extends RakNetDataPacket{
} }
public function decode(){ public function decode(){
$this->unknown1 = $this->getInt(); $this->eid = $this->getInt();
$this->unknown2 = $this->getInt(); $this->x = $this->getInt();
$this->unknown3 = $this->getInt(); $this->z = $this->getInt();
$this->unknown4 = $this->getByte(); $this->y = $this->getByte();
$this->unknown5 = $this->getByte(); $this->block = $this->getByte();
$this->unknown6 = $this->getByte(); $this->meta = $this->getByte();
$this->unknown7 = $this->getByte(); $this->face = $this->getByte();
ConsoleAPI::info("Int1:".$this->unknown1);
ConsoleAPI::info("Int2:".$this->unknown2);
ConsoleAPI::info("Int3:".$this->unknown3);
ConsoleAPI::info("Byte4:".$this->unknown4);
ConsoleAPI::info("Byte5:".$this->unknown5);
ConsoleAPI::info("Byte6:".$this->unknown6);
ConsoleAPI::info("Byte7:".$this->unknown7);
} }
public function encode(){ public function encode(){
$this->reset(); $this->reset();
$this->putInt($this->unknown1); $this->putInt($this->eid);
$this->putInt($this->unknown2); $this->putInt($this->x);
$this->putInt($this->unknown3); $this->putInt($this->z);
$this->putByte($this->unknown4); $this->putByte($this->y);
$this->putByte($this->unknown5); $this->putByte($this->block);
$this->putByte($this->unknown6); $this->putByte($this->meta);
$this->putByte($this->unknown7); $this->putByte($this->face);
ConsoleAPI::info("Int1:".$this->unknown1);
ConsoleAPI::info("Int2:".$this->unknown2);
ConsoleAPI::info("Int3:".$this->unknown3);
ConsoleAPI::info("Byte4:".$this->unknown4);
ConsoleAPI::info("Byte5:".$this->unknown5);
ConsoleAPI::info("Byte6:".$this->unknown6);
ConsoleAPI::info("Byte7:".$this->unknown7);
} }
} }