Working creative inventory, with a few more hacks than I'd like

This commit is contained in:
Dylan K. Taylor
2023-01-05 18:09:57 +00:00
parent 30d3869eea
commit 3d6baa8a55
2 changed files with 67 additions and 24 deletions

View File

@ -60,7 +60,6 @@ use pocketmine\network\PacketHandlingException;
use pocketmine\player\Player;
use pocketmine\utils\AssumptionFailedError;
use pocketmine\utils\ObjectSet;
use function array_map;
use function array_search;
use function get_class;
use function is_int;
@ -512,10 +511,14 @@ class InventoryManager{
public function syncCreative() : void{
$typeConverter = TypeConverter::getInstance();
$nextEntryId = 1;
$this->session->sendDataPacket(CreativeContentPacket::create(array_map(function(Item $item) use($typeConverter, &$nextEntryId) : CreativeContentEntry{
return new CreativeContentEntry($nextEntryId++, $typeConverter->coreItemStackToNet($item));
}, $this->player->isSpectator() ? [] : CreativeInventory::getInstance()->getAll())));
$entries = [];
if(!$this->player->isSpectator()){
//creative inventory may have holes if items were unregistered - ensure network IDs used are always consistent
foreach(CreativeInventory::getInstance()->getAll() as $k => $item){
$entries[] = new CreativeContentEntry($k, $typeConverter->coreItemStackToNet($item));
}
}
$this->session->sendDataPacket(CreativeContentPacket::create($entries));
}
private function newItemStackId() : int{