Windowy
Windowy copied to clipboard
A Fake Inventory Generator For PocketMine-MP (PMMP)
About
-
Windowy is a temporary inventory generator and manager, focused on item transactions, for PocketMine-MP.
-
Functional as a Plugin and Library, for multiple different tasks.
WindowyLibrary
- WindowyLibrary was created for direct tasks in plugins, follow the example of how to use below:
# Do the following function in your PluginBase to activate it (WindowyLibrary).
if(Windowy::hasHolder() === false){
Windowy::setHolder($this);
}
Getting a Window
- Windowy comes with 4 registered inventories
use DayKoala\inventory\WindowIds;
$id = WindowIds::CHEST;
$id = WindowIds::DOUBLE_CHEST;
$id = WindowIds::FURNACE;
$id = WindowIds::HOPPER;
- You can get the desired inventory using:
use DayKoala\inventory\WindowFactory;
/**
*
* @param String $id
* @param String|null $name
* @return SimpleWindow|null
*
*/
$window = WindowFactory::getInstance()->get($id, $name);
- If you want to simplify:
use DayKoala\Windowy;
$window = Windowy::getWindow($id, $name);
- It is
not mandatoryfor you to fill in thenameof the inventory, if you do not fill it or leave it innull, the result will be the name of the inventory selected by theid.
Registering your Window
- You need the inventory you are going to register to be a
SimpleWindow extension, otherwise it won't work. Registeryour inventorylike this:
use DayKoala\block\BlockEntityMetadata;
use pocketmine\network\mcpe\protocol\types\inventory\WindowTypes;
use pocketmine\block\tile\Tile;
use pocketmine\block\BlockLegacyIds;
/**
*
* @param Int $network
* @param Int $size
* @param BlockEntityMetadata $metadata
*
*/
$window = new MyWindow(WindowTypes::CONTAINER, 27, new BlockEntityMetadata(Tile::class, BlockLegacyIds::Block));
/**
*
* @param String $id
* @param SimpleWindow $inventory
* @param boolean $override
*
*/
WindowFactory::register('MyWindow', $window, $override);
Adding Actions to Your Window
- Actions can be
added before or afterregistration, as well as items and derivatives. You can adda specific actionto your inventory using:
use DayKoala\inventory\action\WindowTransaction;
$callback = function(WindowTransaction $action){
$player = $action->getPlayer();
$player->sendMessage("I won't let you take this item haha!");
$action->cancel();
};
/**
*
* @param Closure $callback
* @return self
*
*/
$window->setTransaction($callback);
- If you want
a certain itemto have someactionin the inventory, you can use:
$window->setItem($slot, $item, $callback);
or
/**
*
* @param Item $item
* @param Closure $callback
* @return self
*
*/
$window->setItemCallback($item, $callback);
- If the
transaction is not canceledand the item moved from its defined slot, theitem's action will be removed.
Closing your Window Differently
- Usually we need to do things in a different way and
closing a windowwith a different action can help you, so you canadd an actionwhen closing it using:
use DayKoala\inventory\action\WindowAction;
$callback = function(WindowAction $action){
$player = $action->getPlayer();
$player->sendMessage("Closing...");
};
/**
*
* @param Closure $callback
* @return self
*
*/
$window->setCloseCallback($callback);
