So i have this code PHP: public function fillChests() { $fillInv = function (ChestInventory $inv) { $fillSlot = function (ChestInventory $inv, int $slot) { $id = self::getChestItems()[$index = rand(0, 5)][rand(0, (int)(count(self::getChestItems()[$index])-1))]; switch ($index) { case 0: $count = 1; break; case 1: $count = 1; break; case 2: $count = rand(1, 2); break; case 3: $count = rand(1, 2); break; case 4: $count = rand(1, 64); case 5: $count = rand(1, 2); break; default: $count = 0; break; } $inv->setItem($slot, Item::get($id, 0, $count)); }; $inv->clearAll(); for($x = 0; $x <= 26; $x++) { if(rand(1, 3) == 1) { $fillSlot($inv, $x); } } }; And This code PHP: public static function getChestItems(): array { $chestItems = []; //Weapon $weapons = [ 276,267 ]; //TOOLS $tools = [ 258,279 ]; //THROWABLE $throwable = [ 344,332 ]; //FOOD $food = [ 260, 297,320,322,364,366 ]; //BLOCKS $blocks = [ 5,4,1 ]; //Armor $armors = [ 306,307,308,309,310,311,312,313 ]; $level5 = rand(1, 5); $level3 = rand(1, 3); $level2 = rand(1, 2); $Sharpness = Enchantment::getEnchantment(9); $Sharpness1 = new EnchantmentInstance($Sharpness, $level5); $Protection = Enchantment::getEnchantment(0); $Protection1 = new EnchantmentInstance($Protection, $level5); $Efficiency = Enchantment::getEnchantment(15); $Efficiency1 = new EnchantmentInstance($Efficiency, $level5); $Unbreaking = Enchantment::getEnchantment(17); $Unbreaking1 = new EnchantmentInstance($Unbreaking, $level3); $Fire = Enchantment::getEnchantment(13); $Fire1 = new EnchantmentInstance($Fire, $level2); foreach($weapons as $weapon){ Item::get($weapon)->addEnchantment($Sharpness1); Item::get($weapon)->addEnchantment($Unbreaking1); Item::get($weapon)->addEnchantment($Fire1); } array_push($chestItems, $weapons); //TOOLS Enchant foreach($tools as $tool){ Item::get($tool)->addEnchantment($Unbreaking1); Item::get($tool)->addEnchantment($Efficiency1); } array_push($chestItems, $tools); //Armors Enchant foreach($armors as $armor){ Item::get($armor)->addEnchantment($Protection1); Item::get($armor)->addEnchantment($Unbreaking1); array_push($chestItems, $armors); } return $chestItems; } It work but when the sw game start i didnt see any enchanted items just none enchant item and only tools + armor + weapon. Can someone help me at this?
You can add enchantment to item using Item->addEnchantment(EnchantmentInstance); and chose random enchant using rand() or array_rand() function.