37 use BlockInventoryTrait;
39 public const SLOT_INPUT = 0;
40 public const SLOT_LAPIS = 1;
46 private array $options = [];
48 public function __construct(
Position $holder){
49 $this->holder = $holder;
50 parent::__construct(2);
53 protected function onSlotChange(
int $index,
Item $before) :
void{
54 if($index === self::SLOT_INPUT){
55 foreach($this->viewers as $viewer){
57 $item = $this->getInput();
62 if(!$event->isCancelled() && count($event->getOptions()) > 0){
63 $this->options = array_values($event->getOptions());
64 $viewer->getNetworkSession()->getInvManager()?->syncEnchantingTableOptions($this->options);
69 parent::onSlotChange($index, $before);
72 public function getInput() :
Item{
73 return $this->
getItem(self::SLOT_INPUT);
76 public function getLapis() :
Item{
77 return $this->
getItem(self::SLOT_LAPIS);
80 public function getOutput(
int $optionId) : ?
Item{
81 $option = $this->getOption($optionId);
82 return $option ===
null ? null :
Helper::enchantItem($this->getInput(), $option->getEnchantments());
86 return $this->options[$optionId] ??
null;