mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-04 17:06:16 +00:00
* Implemented InventoryEventProcessor, fixes #1986 Event processors can now be registered and unregistered at will. Entity inventory/armor change events are now handled by event processors instead of the inventories themselves, which allows enabling/disabling the calling of these events at will. This now avoids stupid things happening when initializing inventory contents, since the callers for those events are now registered _after_ the contents are initialized.
This commit is contained in:
@ -29,6 +29,8 @@ use pocketmine\event\inventory\FurnaceBurnEvent;
|
||||
use pocketmine\event\inventory\FurnaceSmeltEvent;
|
||||
use pocketmine\inventory\FurnaceInventory;
|
||||
use pocketmine\inventory\FurnaceRecipe;
|
||||
use pocketmine\inventory\Inventory;
|
||||
use pocketmine\inventory\InventoryEventProcessor;
|
||||
use pocketmine\inventory\InventoryHolder;
|
||||
use pocketmine\item\Item;
|
||||
use pocketmine\item\ItemFactory;
|
||||
@ -79,6 +81,20 @@ class Furnace extends Spawnable implements InventoryHolder, Container, Nameable{
|
||||
|
||||
$this->inventory = new FurnaceInventory($this);
|
||||
$this->loadItems($nbt);
|
||||
|
||||
$this->inventory->setEventProcessor(new class($this) implements InventoryEventProcessor{
|
||||
/** @var Furnace */
|
||||
private $furnace;
|
||||
|
||||
public function __construct(Furnace $furnace){
|
||||
$this->furnace = $furnace;
|
||||
}
|
||||
|
||||
public function onSlotChange(Inventory $inventory, int $slot, Item $oldItem, Item $newItem) : ?Item{
|
||||
$this->furnace->scheduleUpdate();
|
||||
return $newItem;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function writeSaveData(CompoundTag $nbt) : void{
|
||||
|
Reference in New Issue
Block a user