Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
add save slot inventory
Browse files Browse the repository at this point in the history
  • Loading branch information
MakStashkevich committed Dec 22, 2019
1 parent 17b4eb4 commit 75effdc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
22 changes: 19 additions & 3 deletions client/PocketEditionClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use client\entity\inventory\utils\ContainerIds;
use client\utils\PlayerLocation;
use Exception;
use pocketmine\item\Item;
use pocketmine\network\mcpe\protocol\AddPlayerPacket;
use pocketmine\network\mcpe\protocol\AdventureSettingsPacket;
use pocketmine\network\mcpe\protocol\AnimatePacket;
Expand Down Expand Up @@ -747,15 +748,30 @@ protected function handleDataPacket(DataPacket $packet): void
$player->getArmor()->setAll($slots);
break;
default:
mess('CONTAINER_ID', $packet->windowid);
mess('CONTENT_CONTAINER_ID', $packet->windowid);
break;
}
}
return;
} elseif ($packet instanceof ContainerSetSlotPacket) {
//todo
$player = $this->getPlayer();
$slot = $packet->slot;
$item = $packet->item;
if (!$item instanceof Item) return;
switch ($packet->windowid) {
case ContainerIds::INVENTORY:
$player->getInventory()->saveSlot($slot, $item);
break;
case ContainerIds::ARMOR:
$player->getArmor()->saveSlot($slot, $item);
break;
default:
mess('SLOT_CONTAINER_ID', $packet->windowid);
break;
}
return;
} elseif ($packet instanceof ContainerSetDataPacket) {
//todo
//furnace change icons
} elseif ($packet instanceof RespawnPacket) {
//todo
} elseif ($packet instanceof DisconnectPacket) {
Expand Down
15 changes: 15 additions & 0 deletions client/entity/inventory/ClientInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ function getSlot(int $slot): Item
return $this->slots[$slot];
}

/**
* @param int $slot
* @param Item $item
* @return bool
*/
function saveSlot(int $slot, Item $item): bool
{
if (!isset($this->slots[$slot])) {
error('U can\'t save slot = ' . $slot . ' on saveSlot()');
return false;
}
$this->slots[$slot] = $item;
return true;
}

/**
* @return InventoryType
*/
Expand Down

0 comments on commit 75effdc

Please sign in to comment.