How can I add a block(s) to Creative Block List? addCreativeItem() won't work because it must be be item to make it work. My error is: Code: TypeError: "Argument 1 passed to pocketmine\item\Item::addCreativeItem() must be an instance of pocketmine\item\Item
I understand the error, but I cannot find a addCreativeBlock() command. How can I do the same thing only for Blocks?
There isn't a "command" the error clearly states it couldn't pass due to the first args not being an instance of pocketmine\item\Item.
PHP: <?phpnamespace Extra;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\Player;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\utils\BlockIterator;class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this,$this); Block::$list[201] = PurpurBlock::class; Item::addCreativeItem(new PurpurBlock()); }} PurpurBlock is a block, not an item, and the function doesn't accept blocks, that's why it's called addCreativeItem()
setItem requires an integer for the first parameter, and I don't think that would work correctly for Creative inventories. Can we see your PurpurBlock class?
PHP: <?phpnamespace Extra;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\item\Tool;use pocketmine\block\Solid;class PurpurBlock extends Solid{ public function __construct($meta = 0, $count = 1){ parent::__construct(201, $meta, $count, "Purpur Block"); } public function getName(){ return "Purpur Block"; } public function getHardness(){ return 2; } public function getToolType(){ return Tool::TYPE_PICKAXE; }}
This is untrue. you can add a block to the creative inventory by making the class implement the ItemBlock class
Only need to change PHP: class PurpurBlock extends Solid to PHP: class PurpurBlock extends Solid implements BlockItem ? But where is the file called BlockItem? I cannot find one.
PHP: use pocketmine\item\ItemBlock;class PurpurBlock extends Solid implements BlockItem Code: ClassNotFoundException: "Class Extra\BlockItem not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 144 I know what the problem is, but I don't know how to fix...