From a538543e4cde7df2446625695482b3cf575e9540 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 25 May 2013 19:27:29 +0200 Subject: [PATCH] Fixed #287 Items dropped will be deleted if picked up in creative mode [gh#287] --- src/Player.php | 26 ++++++++++++++++++++++++++ src/world/Entity.php | 24 +++++++++++++----------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/Player.php b/src/Player.php index 1f4a1119..2c63ef78 100644 --- a/src/Player.php +++ b/src/Player.php @@ -265,6 +265,32 @@ class Player{ $this->server->api->player->remove($this->CID); } } + + public function hasSpace($type, $damage, $count){ + $inv = $this->inventory; + while($count > 0){ + $add = 0; + foreach($inv as $s => $data){ + if($data[0] === AIR){ + $add = min(64, $count); + $inv[$s] = array($type, $damage, $add); + break; + }elseif($data[0] === $type and $data[1] === $damage){ + $add = min(64 - $data[2], $count); + if($add <= 0){ + continue; + } + $inv[$s] = array($type, $damage, $data[2] + $add); + break; + } + } + if($add === 0){ + return false; + } + $count -= $add; + } + return true; + } public function addItem($type, $damage, $count){ while($count > 0){ diff --git a/src/world/Entity.php b/src/world/Entity.php index 07e46a0b..d29faad8 100644 --- a/src/world/Entity.php +++ b/src/world/Entity.php @@ -183,17 +183,19 @@ class Entity extends Position{ }else{ return false; } - if(($player instanceof Player) and ($player->gamemode & 0x01) === 0x00 and $player->spawned === true){ - if($this->server->api->dhandle("player.pickup", array( - "eid" => $player->eid, - "player" => $player, - "entity" => $this, - "block" => $this->type, - "meta" => $this->meta, - "target" => $this->eid - )) !== false){ - $this->close(); - return false; + if(($player instanceof Player) and $player->spawned === true){ + if(($player->gamemode & 0x01) === 0x00){ + if($player->hasSpace($this->type, $this->meta, $this->stack) === true and $this->server->api->dhandle("player.pickup", array( + "eid" => $player->eid, + "player" => $player, + "entity" => $this, + "block" => $this->type, + "meta" => $this->meta, + "target" => $this->eid + )) !== false){ + $this->close(); + return false; + } } return true; }