37 use DestructorCallbackTrait;
43 private array $creative = [];
46 private ObjectSet $contentChangedCallbacks;
48 private function __construct(){
49 $this->contentChangedCallbacks =
new ObjectSet();
51 BedrockDataFiles::CREATIVEITEMS_JSON,
54 foreach($creativeItems as $data){
55 $item = CraftingManagerFromDataHelper::deserializeItemStack($data);
70 $this->onContentChange();
78 return
Utils::cloneObjectArray($this->creative);
81 public function getItem(
int $index) : ?
Item{
82 return isset($this->creative[$index]) ? clone $this->creative[$index] : null;
85 public function getItemIndex(Item $item) : int{
86 foreach($this->creative as $i => $d){
87 if($item->equals($d,
true,
false)){
100 $this->creative[] = clone $item;
101 $this->onContentChange();
108 public function remove(
Item $item) : void{
109 $index = $this->getItemIndex($item);
111 unset($this->creative[$index]);
112 $this->onContentChange();
116 public function contains(Item $item) : bool{
117 return $this->getItemIndex($item) !== -1;
122 return $this->contentChangedCallbacks;
125 private function onContentChange() : void{
126 foreach($this->contentChangedCallbacks as $callback){