29 protected int $selectedIndex = 0;
35 protected ObjectSet $selectedIndexChangeListeners;
37 public function __construct(
40 $this->selectedIndexChangeListeners =
new ObjectSet();
43 public function isHotbarSlot(
int $slot) :
bool{
44 return $slot >= 0 && $slot < $this->
getSize();
50 private function throwIfNotHotbarSlot(
int $slot) :
void{
51 if(!$this->isHotbarSlot($slot)){
52 throw new \InvalidArgumentException(
"$slot is not a valid hotbar slot index (expected 0 - " . ($this->
getSize() - 1) .
")");
60 return $this->selectedIndex;
71 $this->throwIfNotHotbarSlot($hotbarSlot);
73 $oldIndex = $this->selectedIndex;
74 $this->selectedIndex = $hotbarSlot;
76 foreach($this->selectedIndexChangeListeners as $callback){