From ce695ba0523e5796136c1f22a1bef0b6d63dd7ee Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 22 Jul 2024 12:21:50 +0300 Subject: [PATCH] fixed cheking for space on item take --- src/API/BanAPI.php | 2 +- src/Player.php | 23 +++++++++++++++++++++-- src/entity/Entity.php | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/API/BanAPI.php b/src/API/BanAPI.php index 74a95d67..efc80b49 100644 --- a/src/API/BanAPI.php +++ b/src/API/BanAPI.php @@ -201,7 +201,7 @@ class BanAPI{ $reason = $reason == "" ? "No reason" : $reason; $this->server->schedule(60, [$player, "close"], "You have been kicked: " . $reason); //Forces a kick - $player->lastCorrect = new Vector3($player->entity->x, $player->entity->y, $player->entity->z); //TODO better fix + $player->lastCorrect = new Vector3($player->entity->x, $player->entity->y, $player->entity->z); $player->blocked = true; if($issuer instanceof Player){ $this->server->api->chat->broadcast($player->username . " has been kicked by " . $issuer->username . ": $reason"); diff --git a/src/Player.php b/src/Player.php index 89939251..8c5ec992 100755 --- a/src/Player.php +++ b/src/Player.php @@ -696,12 +696,14 @@ class Player{ while($count > 0){ $add = 0; foreach($inv as $s => $item){ + console("{$item->getID()} {$item->getMetadata()} $type, $damage"); if($item->getID() === AIR){ $add = min($item->getMaxStackSize(), $count); $inv[$s] = BlockAPI::getItem($type, $damage, $add); break; }elseif($item->getID() === $type and $item->getMetadata() === $damage){ $add = min($item->getMaxStackSize() - $item->count, $count); + if($add <= 0){ continue; } @@ -1476,7 +1478,7 @@ class Player{ if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){ return; } - + switch($packet->pid()){ case 0x01: break; @@ -2200,7 +2202,24 @@ class Player{ break; } $packet->eid = $this->eid; + $prevItem = $packet->item; $packet->item = $this->getSlot($this->slot); + $sendOnDrop = false; + + /*if($prevItem != $packet->item){ + if(count($this->inventory) >= 36){ + foreach($this->inventory as $slot => $item){ + if($item->getID() == 0) goto inv_desync_on_drop; + } + //crafting sends drop packet if inv is full, TODO: add it into craffting array + goto inv_desync_on_drop; + }else{ + inv_desync_on_drop: + ConsoleAPI::debug("Inventory desync on drop({$this->iusername})"); + $sendOnDrop = true; + } + }*/ + $this->craftingItems = []; $this->toCraft = []; $data["eid"] = $packet->eid; @@ -2219,7 +2238,7 @@ class Player{ $sY += ($this->entity->random->nextFloat() - $this->entity->random->nextFloat()) * 0.1; $sZ += sin($f3) * $f1; $this->server->api->entity->dropRawPos($this->level, $this->entity->x, $this->entity->y - 0.3 + $this->entity->height - 0.12, $this->entity->z, $packet->item, $sX, $sY, $sZ); - $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), false); + $this->setSlot($this->slot, BlockAPI::getItem(AIR, 0, 0), $sendOnDrop); } if($this->entity->inAction === true){ $this->entity->inAction = false; diff --git a/src/entity/Entity.php b/src/entity/Entity.php index f24a6081..66ef4c08 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -416,11 +416,11 @@ class Entity extends Position foreach($this->server->api->entity->getRadius($this, 2, false) as $item){ if($item->class === ENTITY_ITEM && !$item->closed && $item->spawntime > 0 && $item->delayBeforePickup <= 0){ if($item->boundingBox->intersectsWith($myBB)){ - if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->type, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array( + if((($this->player->gamemode & 0x01) === 1 || $this->player->hasSpace($item->itemID, $item->meta, $item->stack) === true) && $this->server->api->dhandle("player.pickup", array( "eid" => $this->player->eid, "player" => $this->player, "entity" => $item, - "block" => $item->type, + "block" => $item->itemID, "meta" => $item->meta, "target" => $item->eid )) !== false){