holder = $holder; parent::__construct(2); } protected function onSlotChange(int $index, Item $before) : void{ if($index === self::SLOT_INPUT){ foreach($this->viewers as $viewer){ $this->options = []; $item = $this->getInput(); $options = Helper::getEnchantOptions($this->holder, $item, $viewer->getEnchantmentSeed()); $event = new PlayerEnchantOptionsRequestEvent($viewer, $this, $options); $event->call(); if(!$event->isCancelled() && count($event->getOptions()) > 0){ $this->options = array_values($event->getOptions()); $viewer->getNetworkSession()->getInvManager()?->syncEnchantingTableOptions($this->options); } } } parent::onSlotChange($index, $before); } public function getInput() : Item{ return $this->getItem(self::SLOT_INPUT); } public function getLapis() : Item{ return $this->getItem(self::SLOT_LAPIS); } public function getOutput(int $optionId) : ?Item{ $option = $this->getOption($optionId); return $option === null ? null : Helper::enchantItem($this->getInput(), $option->getEnchantments()); } public function getOption(int $optionId) : ?EnchantOption{ return $this->options[$optionId] ?? null; } }