<commit_before><?php

namespace BlockHorizons\BlockPets\pets\inventory;

use BlockHorizons\BlockPets\pets\BasePet;
use pocketmine\inventory\ChestInventory;
use pocketmine\inventory\InventoryType;
use pocketmine\Player;
use pocketmine\tile\Chest;
use pocketmine\tile\Tile;

class PetInventory extends ChestInventory {

	private $pet;
	private $chestPos = null;
	/** @var null|Tile */
	private $tile = null;

	public function __construct(Chest $tile, BasePet $pet) {
		parent::__construct($tile, InventoryType::get(InventoryType::CHEST));
		$this->pet = $pet;
		$this->tile = $tile;
	}

	/**
	 * @return BasePet
	 */
	public function getPet(): BasePet {
		return $this->pet;
	}

	public function onClose(Player $player) {
		$this->save();
		$player->level->sendBlocks([$player], [$this->chestPos]);
		$this->tile->close();
	}

	public function save(): bool {
		if(!empty($this->getContents())) {
			$this->pet->getInventory()->setInventoryContents($this->getContents());
			$this->pet->getLoader()->getDatabase()->updateInventory($this->pet->getPetName(), $this->pet->getPetOwnerName(), $this->pet->getInventory()->compressContents());
		}
		return true;
	}
}<commit_msg>Seems that getContents is filled with air objects.<commit_after><?php

namespace BlockHorizons\BlockPets\pets\inventory;

use BlockHorizons\BlockPets\pets\BasePet;
use pocketmine\inventory\ChestInventory;
use pocketmine\inventory\InventoryType;
use pocketmine\item\Item;
use pocketmine\Player;
use pocketmine\tile\Chest;
use pocketmine\tile\Tile;

class PetInventory extends ChestInventory {

	private $pet;
	private $chestPos = null;
	/** @var null|Tile */
	private $tile = null;

	public function __construct(Chest $tile, BasePet $pet) {
		parent::__construct($tile, InventoryType::get(InventoryType::CHEST));
		$this->pet = $pet;
		$this->tile = $tile;
	}

	/**
	 * @return BasePet
	 */
	public function getPet(): BasePet {
		return $this->pet;
	}

	public function onClose(Player $player) {
		$this->save();
		$player->level->sendBlocks([$player], [$this->chestPos]);
		$this->tile->close();
	}

	public function save(): bool {
		foreach($this->getContents() as $item) {
			if($item->getId() === Item::AIR) {
				continue;
			}
			$this->pet->getInventory()->setInventoryContents($this->getContents());
			$this->pet->getLoader()->getDatabase()->updateInventory($this->pet->getPetName(), $this->pet->getPetOwnerName(), $this->pet->getInventory()->compressContents());
			break;
		}
		return true;
	}
}
{'fraction_non_alphanumeric': 0.17380759902991108, 'fraction_numerical': 0.0, 'mean_word_length': 5.156716417910448, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3748170', 'n_tokens_mistral': 878, 'n_tokens_neox': 820, 'n_words': 151}