j1b1x / functionalitem
该包最新版本(dev-master)没有可用的许可信息。
dev-master
2023-12-11 01:27 UTC
Requires (Dev)
- pocketmine/pocketmine-mp: ^5.0
This package is auto-updated.
Last update: 2024-09-11 03:08:53 UTC
README
FunctionalItem 是一个 PocketMine-MP 库,通过实际类而不是事件来赋予物品功能。
分类
库注册
只需在您的插件 onEnable 函数中这样做
\Jibix\FuctionalItem\FunctionalItemManager::register($this);
物品注册
为了使功能物品真正工作,您首先需要注册它,就像这样
\Jibix\FuctionalItem\FunctionalItemManager::getInstance()->registerFunctionalItem(new MyFunctionalItem());
功能物品
物品标志
标志
- 不可放置标志
将标志应用到功能物品上
//Basically do implements YourFlag class ExampleItem extends \Jibix\FuctionalItem\item\FunctionalItem implements ItemFlag{
物品功能
//Checks if $item equals the functional item //Example: ExampleItem::equals($player->getInventory()->getItemInHand()) public static function equals(Item $item): bool; //Removes the functional item from the player's inventory public static function remove(Inventory $inventory): void; //Returns the cooldown time (in ticks) until the item can be used again public function getCooldownTicks(Player $player, Item $item): int; //Called when the player right-clicks this item //If it returns false, the interaction will be canceled public function onUse(Player $player, ?Vector3 $useVector = null): bool; //Called when the player drops this item //If it returns false, the drop will be canceled public function onDrop(Player $player): bool; //Called when the player helds this item //If it returns false, the slot switch will be canceled public function onHeld(Player $player, int $slot): bool; //Called when the player clicks this item in their inventory //If it returns false, the inventory transaction will be canceled public function onInvClick(Player $player): bool; //Called when the player hits an entity with this item //If it returns false, the damage event will be canceled public function onHitEntity(Player $player, Entity $entity): bool; //Called when the player right-clicks an entity with this item //If it returns false, the interaction will be canceled public function onInteractEntity(Player $player, Entity $entity, Vector3 $clickPos): bool;
如何制作功能物品
class ExampleItem extends \Jibix\FuctionalItem\item\FunctionalItem{ private const USE_COOLDOWN = 5 * 20; //5 seconds public static function getItem(?Player $player = null, string $customName = "§bExample"): Item{ return self::getInternalItem(VanillaItems::STICK()->setCustomName($customName)); } public function getCooldownTicks(Player $player, Item $item): int{ return self::USE_COOLDOWN; } public function onDrop(Player $player): bool{ return false; //Can't be dropped } public function onUse(Player $player, ?Vector3 $useVector = null): bool{ $player->sendMessage("You just used the FunctionalItem example-stick!"); return true; } }
如何赋予功能物品
$player->getInventory()->addItem(MyFunctionalItem::getItem($player, ...$customArgs));