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;
}
$packet->PROTOCOL = $this->PROTOCOL;
$packet->PROTOCOL = $this->PROTOCOL;
$packet->encode();
if($packet->pid() == 163 or $packet->pid() == 164 && $this->PROTOCOL < ProtocolInfo7::CURRENT_PROTOCOL_7){
return;
}
$len = strlen($packet->buffer) + 1;
$MTU = $this->MTU - 24;
if($len > $MTU){
@ -2228,6 +2231,73 @@ class Player{
}
}
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:
if ($this->spawned === false or $this->blocked === true) {
break;

View file

@ -1,13 +1,13 @@
<?php
class PlaceBlockPacket extends RakNetDataPacket{
public $unknown1 = 0;
public $unknown2 = 0;
public $unknown3 = 0;
public $unknown4 = 0;
public $unknown5 = 0;
public $unknown6 = 0;
public $unknown7 = 0;
public $eid;
public $x;
public $z;
public $y;
public $block;
public $meta;
public $face;
public function pid(){
if($this->PROTOCOL < ProtocolInfo::CURRENT_PROTOCOL) {
@ -17,38 +17,24 @@ class PlaceBlockPacket extends RakNetDataPacket{
}
public function decode(){
$this->unknown1 = $this->getInt();
$this->unknown2 = $this->getInt();
$this->unknown3 = $this->getInt();
$this->unknown4 = $this->getByte();
$this->unknown5 = $this->getByte();
$this->unknown6 = $this->getByte();
$this->unknown7 = $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);
$this->eid = $this->getInt();
$this->x = $this->getInt();
$this->z = $this->getInt();
$this->y = $this->getByte();
$this->block = $this->getByte();
$this->meta = $this->getByte();
$this->face = $this->getByte();
}
public function encode(){
$this->reset();
$this->putInt($this->unknown1);
$this->putInt($this->unknown2);
$this->putInt($this->unknown3);
$this->putByte($this->unknown4);
$this->putByte($this->unknown5);
$this->putByte($this->unknown6);
$this->putByte($this->unknown7);
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);
$this->putInt($this->eid);
$this->putInt($this->x);
$this->putInt($this->z);
$this->putByte($this->y);
$this->putByte($this->block);
$this->putByte($this->meta);
$this->putByte($this->face);
}
}