37 use BlockInventoryTrait;
39 public const SLOT_INPUT = 0;
40 public const SLOT_LAPIS = 1;
43 private array $options = [];
45 public function __construct(
Position $holder){
46 $this->holder = $holder;
47 parent::__construct(2);
50 protected function onSlotChange(
int $index,
Item $before) :
void{
51 if($index === self::SLOT_INPUT){
52 foreach($this->viewers as $viewer){
54 $item = $this->getInput();
59 if(!$event->isCancelled() && count($event->getOptions()) > 0){
60 $this->options = array_values($event->getOptions());
61 $viewer->getNetworkSession()->getInvManager()?->syncEnchantingTableOptions($this->options);
66 parent::onSlotChange($index, $before);
69 public function getInput() :
Item{
70 return $this->
getItem(self::SLOT_INPUT);
73 public function getLapis() :
Item{
74 return $this->
getItem(self::SLOT_LAPIS);
77 public function getOutput(
int $optionId) : ?
Item{
78 $option = $this->getOption($optionId);
79 return $option ===
null ? null :
Helper::enchantItem($this->getInput(), $option->getEnchantments());
83 return $this->options[$optionId] ??
null;