prevent useitem if heldItem on client doesnt match server

This commit is contained in:
GameHerobrine 2025-05-09 14:36:33 +03:00
parent 16324d32f2
commit 38ee5daed2
2 changed files with 18 additions and 3 deletions

View file

@ -686,6 +686,7 @@ class Player{
$pk->hotbar = $hotbar;
$this->dataPacket($pk);
}
/**
* @param $type
* @param $damage
@ -1948,6 +1949,20 @@ class Player{
$data["posY"] = $packet->posY;
$data["posZ"] = $packet->posZ;
//nc: check item desync
$heldItem = $this->getHeldItem();
if($heldItem->getID() != $packet->item || $heldItem->getMetadata() != $packet->meta){
ConsoleAPI::warn("{$this->username}'s heldItem doesnt match on clientside and serverside when using item. Resending inventory.");
$this->sendInventory();
if($packet->face >= 0 && $packet->face <= 5){
$target = $this->level->getBlock($blockVector);
$block = $target->getSide($packet->face);
$this->addBlockUpdateIntoQueue($target->x, $target->y, $target->z, $target->getID(), $target->getMetadata());
$this->addBlockUpdateIntoQueue($block->x, $block->y, $block->z, $block->getID(), $block->getMetadata());
}
break;
}
if($packet->face >= 0 and $packet->face <= 5){ //Use Block, place
if($this->entity->inAction === true){
$this->entity->inAction = false;

View file

@ -25,18 +25,18 @@ class UseItemPacket extends RakNetDataPacket{
$this->z = $this->getInt();
$this->face = $this->getInt();
$this->item = $this->getShort();
$this->meta = $this->getByte(); //Mojang: fix this
$this->meta = $this->getByte();
$this->eid = $this->getInt();
$this->fx = $this->getFloat();
$this->fy = $this->getFloat();
$this->fz = $this->getFloat();
$this->posX = $this->getFloat();
$this->posY = $this->getFloat();
$this->posZ = $this->getFloat();
$this->posZ = $this->getFloat();
}
public function encode(){
}
}
}