My code: PHP: <?phpnamespace Extra;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 getHardness(){ return 2; } public function getToolType(){ return Tool::TYPE_PICKAXE; }} My 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 This is because he doesn't know any block with the ID 201. But how can I create that ID and set the Purpur Block to it?
1. Line 13, not 30. 2. How can I now add that blocks to creative? 3. How do I add the block's ID (201) to the BlockIDs? The error wants me to change this PHP: parent::__construct(201, $meta, $count, "Purpur Block"); to this PHP: parent::__construct(Block::get(201), $meta, $count, "Purpur Block"); I think. But there's no block with ID 201, but how do I add it? Or do I not need to do it? I tried adding the Shulder Shell ID (445), and it worked, it appeared in the Creative List. But then I tried typing in the ID of Purpur Block (201), and it crashes my server, no crashdump. Plus, this code won't add my block to the Creative List: PHP: Item::addCreativeItem(new PurpurBlock());
PHP: ItemBlock::addCreativeItem(new PurpurItem()); Why PurpurItem? PurpurBlock you mean? There's no class with that name.
I put the main class in Main.php and the classes PurpurBlock and PurpurItem are in a file called PurpurBlock.php. Code: ClassNotFoundException: "Class Extra\PurpurItem not found" (EXCEPTION) in "/src/spl/BaseClassLoader" at line 144 I tried use Extra\PurpurBlock; but that didn't fix my problem.
I made the Item and Block classes separate because, as I previously stated, they need to be separate.
Don't just copy code. The script I made was designed to run as a single-file plugin script, not as a phar plugin. You will need to separate the classes into their own files for it to work in the folder/phar format
As previously stated, you will need to separate the classes into their own files for it to work in the folder/phar format.
You can get it's indexed position, but I don't think it can be changed. https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L300
I tried adding the End Rod and the Ender Pearl to Creative, but they disppear after placing, and Ender Pearls can't be thrown.
ender pearls are items and entities, not blocks. that is more complex. End rods need proper metadata for direction and position.
I don't know how to do it. 1. My End Rod code: PHP: <?phpnamespace Extra;use pocketmine\block\Block;use pocketmine\block\Solid;use pocketmine\Player;use pocketmine\block\Flowable;use pocketmine\item\ItemBlock;class EndRod extends Flowable { public function __construct() { parent::__construct(208); } public function getHardness() { return 0; } public function getName(){ return "End Rod"; } public function getLightLevel(){ return 14; } public function getResistance(){ return 0; } public function place(Item $item, Block $block, Block $target, $face, $fx, $fy, $fz, Player $player = null){ $faces = [ 0 => 0, 1 => 1, 2 => 3, 3 => 2, 4 => 5, 5 => 4, ]; $this->meta = ($target->getId() === 208 && $faces[$face] == $target->getDamage()) ? Vector3::getOppositeSide($faces[$face]) : $faces[$face]; $this->getLevel()->setBlock($block, $this, true, true); return true; }} 2. My Ender Pearl code: PHP: <?phpnamespace Extra;use pocketmine\item\Item;class EnderPearl extends Item{ public function __construct($meta = 0, $count = 1){ parent::__construct(368, $meta, $count, "Ender Pearl"); } public function getMaxStackSize() : int { return 16; }}
end rod should extend Transparent, not flowable. The Ender pearl will not work on it's own as an item. in order to be able to throw it, you need to make it's corresponding entity class and link it to the Item class.