<?php namespace CM; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\block\Block; use pocketmine\item\Item; use pocketmine\math\Vector3; use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\inventory\ShapedRecipe; class Main extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $i = Item::get(Item::BONE); $i->setCustomName("Hyru-Sword"); $ench = new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::SHARPNESS)); $ench->setLevel(3); $i->addEnchantment($ench); $sword = new ShapedRecipe([" A "," A "," B "],["A"=>Item::get(Item::EMERALD),"B"=>Item::get(Item::STICK)],[$i]); $sword->registerToCraftingManager($this->getServer()->getCraftingManager()); } public function onDisable(){ $this->getLogger()->info("Desactiver"); } }
No it doesn't work. I just tried, If I am right, it's because you use BONE, change PHP: $i = Item::get(Item::BONE); for PHP: $i = Item::get(352,2,1); With this code, you can take it in your hand and use it. For the rest, everything works well. EDIT : Do not use magical ID's since they may change at any moments. Read comments below.
I had the same error haha, I've been working on a lot of new items. Always use ID, never the name, for kits, crafting or whatever you want, for real, its less trouble.. Little trick
no, please do not do this... if you use custom "damage" values on items, your code WILL break in future updates when those magic values no longer work. They are not supported by the game in any official capacity, and as such their behaviour is subject to change. Consider using an NBT tag instead, which is less likely to catch fire.
please don't do this either... you clearly haven't realized what an enormous headache it will create for anyone who has to maintain your code in the future. Those magic numbers will cease to work in a future update, and if you hardcoded numeric IDs everywhere your code is going to be very difficult to update.
using the item constants is the same as ids if you have ever took the time to look, for example PHP: BlockIds::GRASS = 2; (ItemIds implements BlockIds, Item implements ItemIds)