37 use DestructorCallbackTrait;
40 private array $creative = [];
43 private ObjectSet $contentChangedCallbacks;
45 private function __construct(){
46 $this->contentChangedCallbacks =
new ObjectSet();
48 BedrockDataFiles::CREATIVEITEMS_JSON,
51 foreach($creativeItems as $data){
52 $item = CraftingManagerFromDataHelper::deserializeItemStack($data);
67 $this->onContentChange();
74 return
Utils::cloneObjectArray($this->creative);
77 public function getItem(
int $index) : ?
Item{
78 return isset($this->creative[$index]) ? clone $this->creative[$index] : null;
81 public function getItemIndex(Item $item) : int{
82 foreach($this->creative as $i => $d){
83 if($item->equals($d,
true,
false)){
96 $this->creative[] = clone $item;
97 $this->onContentChange();
104 public function remove(
Item $item) : void{
105 $index = $this->getItemIndex($item);
107 unset($this->creative[$index]);
108 $this->onContentChange();
112 public function contains(Item $item) : bool{
113 return $this->getItemIndex($item) !== -1;
118 return $this->contentChangedCallbacks;
121 private function onContentChange() : void{
122 foreach($this->contentChangedCallbacks as $callback){