FakeInventories
Features
- Fast opening without any delay
- Opening a FakeInventory behind the player so the player cannot see it
- Simple un-clicking item
- Example patterns
- Simple API
- Tested on several servers
Installation
- Download plugin by clicking here
- Put the plugin into your plugins folder
Usage
Construct FakeInventory
public function __construct() {
// "Test1" it's a title
// FakeInventorySize::LARGE_CHEST is a size of FakeInventory (for small chest just type FakeInventorySize::SMALL_CHEST)
// The "true" at the end is whether the FakeInventory should appear behind the player
parent::__construct("Test1", FakeInventorySize::LARGE_CHEST, true);
}
Setting items (you need to add this function)
public function setItems() : void {
//$this->setItem(slot, item);
$this->setItem(0, VanillaItems::DIAMOND());
}
At the end actions which are to be performed after clicking on an item
// $player - Player which cliekd on item
// $sourceItem - It's the item that was clicked
// $targetItem - It's the item that was clicked (almost useless)
// $slot - It's a slot which was clicked by player
public function onTransaction(Player $player, Item $sourceItem, Item $targetItem, int $slot) : bool {
// returned value means whether transaction is cancelled or not
// example if return value is true then transaction is cancelled otherwise not
return true;
}
Changing inventory
$this->changeInventory($player, (new YourFakeInventory($player)));
Closing inventory
$this->closeFor($player);
Opening inventory
//if you want to open an inventory from a command level or another class, use
(new YourFakeInventory($player))->openFor([$player]);
//otherwise use this
$this->openFor([$player]);
Un-clicking item
$this->unClickItem($player);
✨
That's all, your code should looks like this
✨
<?php
declare(strict_types=1);
namespace your\namespace;
use fakeinventory\inventories\FakeInventory;
use pocketmine\item\Item;
use pocketmine\item\ItemIds;
use pocketmine\item\VanillaItems;
use pocketmine\player\Player;
class ExampleInventory extends FakeInventory {
public function __construct() {
parent::__construct("Second inventory");
}
public function setItems() : void {
$this->setItem(0, VanillaItems::GOLD_INGOT());
}
public function onTransaction(Player $player, Item $sourceItem, Item $targetItem, int $slot) : bool {
if($sourceItem->getId() === ItemIds::GOLD_INGOT) {
$this->changeInventory($player, new YourInventory());
}
return true;
}
}