I tried this, but it totally crashed my server: PHP: class PurpurBlock extends Solid implements ItemBlock Code: Extra\PurpurBlock cannot implement pocketmine\item\ItemBlock - it is not an interface
That looks better. I believe that is can be added to the creative inventory at this point. Try testing a few things on your own.
Server Crashdump: Code: Error: Cannot override final method pocketmine\item\Item::getName() File: /Extra/src/Extra/PurpurBlock Line: 0 Type: E_COMPILE_ERROR THIS CRASH WAS CAUSED BY A PLUGIN BAD PLUGIN: Extra v2 Code: [1] <?php [2] [3] namespace Extra; [4] [5] use pocketmine\item\Item; [6] use pocketmine\block\Block; [7] use pocketmine\item\Tool; [8] use pocketmine\block\Solid; [9] use pocketmine\item\ItemBlock; [10] PHP: <?phpnamespace Extra;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\item\Tool;use pocketmine\block\Solid;use pocketmine\item\ItemBlock;class PurpurBlock extends ItemBlock{ 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; }}
you seem to be lacking knowledge of OOP like you dont know keywords of final and what's not implemented, you are advised to learn more on OOP if you dont care and just want to know how to fix it, Spoiler remove getname() should do it, i hope...
But if I remove getName(), the block won't have a name? I removed getName(), the error: Code: TypeError: "Argument 1 passed to pocketmine\item\ItemBlock::__construct() must be an instance of pocketmine\block\Block, integer given, called in /home/mcpe/plugins/Extra/src/Extra/PurpurBlock.php on line 13" (EXCEPTION) in "/src/pocketmine/item/ItemBlock" at line 30 I understand the error, but a mistake in every single line? Maybe it's impossible to add a new block with a plugin?
Uh, I not a single idea how to do that. I know how to create a class, but I don't know what to put where. Shall I put the constructor into Block or ItemBlock?What should be the class name of ItemBlock? What should be the class name of Block? Where shall I put things like getHardness() and etc.?
Maybe like this? PHP: 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; }}class PurpurBlock extends ItemBlock{ public function __construct($meta = 0, $count = 1){ parent::__construct(201, $meta, $count, "Purpur Block"); } public function getHardness(){ return 2; } public function getToolType(){ return Tool::TYPE_PICKAXE; }} Sorry if this is only to you. I learned PHP in Codecademy, but it won't help me much with this.
Extend an auctual block, you cannot create blocks that do not exist. I can't create my own block but I can extend a block ex) Stone and give it a damage value and it could be used for something. It would be a new block. You can also add items to the creative inventory with Item::addCreativeItem();. You don't register new ItemBlocks either, PM creates an "ItemBlock" automatically when you give a player an item with an ID over 256.
Yes, but what will the whole right code be? So many errors! Explaining won't help me. I'm an extremely beginner I don't know anything.
PHP: namespace MyPlugin;use pocketmine/block/Block;class MyBlock extends Block{protected $id = 201;public function __construct($meta = 1)//use 1 because we are using a block that exists{ $this-meta = $meta;}} My apologies for the formatting there (hard to code on a phone).
it's probably because there's more error again a file can have more then one errors beginner or not PHP OOP and namespace are needed to even begin making PMMP plugin regardless of a beginner or advance mountain climber they both will carry necessary tools, advance ones may carry extra tools to make their climb easier but these aren't required and no one should ever attempt to climb a mountain bringing nothing you dont just go climbing by copying what others are doing