diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 337dcd07f..e649e0048 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -1363,23 +1363,42 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{ if(($this->gamemode & 0x01) === 1){ //Creative mode match $item = Item::get($packet->item, $packet->meta, 1); - $packet->slot = $this->getCreativeBlock($item); + $slot = $this->getCreativeBlock($item); }else{ $item = $this->inventory->getItem($packet->slot); + $slot = $packet->slot; } - - if(!isset($item) or $packet->slot === -1 or $item->getID() !== $packet->item or $item->getDamage() !== $packet->meta){ + + if($packet->slot === -1){ //Air + if(($this->gamemode & 0x01) === Player::CREATIVE){ + $found = false; + for($i = 0; $i < $this->inventory->getHotbarSize(); ++$i){ + if($this->inventory->getHotbarSlotIndex($i) === -1){ + $this->inventory->setHeldItemIndex($i); + $found = true; + break; + } + } + + if(!$found){ //couldn't find a empty slot (error) + $this->inventory->sendContents($this); + break; + } + }else{ + $this->inventory->setHeldItemSlot($packet->slot); //set Air + } + }elseif(!isset($item) or $slot === -1 or $item->getID() !== $packet->item or $item->getDamage() !== $packet->meta){ // packet error or not implemented $this->inventory->sendContents($this); break; }elseif(($this->gamemode & 0x01) === Player::CREATIVE){ $item = Item::get( - Block::$creative[$packet->slot][0], - Block::$creative[$packet->slot][1], + Block::$creative[$slot][0], + Block::$creative[$slot][1], 1 ); - $this->inventory->setItemInHand($item); + $this->inventory->setHeldItemIndex($index); }else{ - $this->inventory->setHeldItemSlot($packet->slot); + $this->inventory->setHeldItemSlot($slot); } $this->inventory->sendHeldItem($this->hasSpawned);