define it example, make leave drop iron on block break if event-getblock == leaveblocks drops = event->getdrops drops[] = new Item(ironingot) event->setdrop(drops) Warning: DO NOT COPY THIS IS A CONCEPT AND WILL NOT RUN IN PMMP
This would add an iron ingot to the existing iron ore drop, not in place of, so it would really be better to create a new array to add the drop to than to use the array from item->getDrops.
You don't really need the whole thing as long as you understand how arrays work. Try taking a look at pocketmine\event\block\BlockBreakEvent and it's functions. You can use $event->getDrops(); to get the current array of drops, and $event->setDrops($array); to set the drops. The rest is just listening for the event, checking the block id, defining items, etc.
OP never stated anything regarding to replace it or not, so i just figured i will use the add an iron ingot method
PHP: public $arrays = array(Item::get(ITEM::GOLD_ORE));//or(Item::get(14,0,0)); PHP: if ($e->getBlock() == (Item::get(14,0,1) {$drops = $e->getDrops();drops[] = new Item(Item::get(14,0,1));$e->setDrops($drops); Tried my hardest lol. Any errors?
I assumed you knew arrays and how to work with item objects and IDs. I was wrong. XD More like this: PHP: public function onBreak(BlockBreakEvent $event) { if($event->getBlock()->getId() === Block::IRON_ORE) { $drops = array(); $drops[] = Item::get(Item::IRON_INGOT, 0, 1); $event->setDrops($drops); } }
lol gg nice try! Here's some constructive criticism: If you are checking a block's type, you should check by ID instead of class. PHP: if ($e->getBlock()->getId() === 14) {} When you made the new Item class on line 4, it was unnecessary because Item::get() returns an item anyway If you were going to use a new Item instead, you would have to input the correct parameters PHP: new Item(14); Please don't take this the wrong way. I am just pointing these mistakes to help you learn
I want to make a plugin like this too, but my code doesn't work – please help: PHP: <?phpnamespace pmmp\DropIt;use pocketmine\event\block\BlockBreakEvent;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\Player;use pocketmine\inventory\Inventory;class Main extends PluginBase { public function onBreak(BlockBreakEvent $event) { if($event->getBlock()->getId() === 14) { $drops = array(); $drops[] = new Item(155); $event->setDrops($drops); } }}
Um, like this? PHP: <?phpnamespace pmmp\DropIt;use pocketmine\event\block\BlockBreakEvent;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\Player;use pocketmine\inventory\Inventory;use pocketmine\event\Listener;class Main extends PluginBase implements Listener { public function onBreak(BlockBreakEvent $event) { if($event->getBlock()->getId() === 14) { $drops = array(); $drops[] = Item::get(Item::IRON_INGOT, 0, 1); $event->setDrops($drops); } }}
OK, is this correct? PHP: <?phpnamespace pmmp\DropIt;use pocketmine\event\block\BlockBreakEvent;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\Player;use pocketmine\inventory\Inventory;use pocketmine\event\Listener;class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents(listener, plugin base); } public function onBreak(BlockBreakEvent $event) { if($event->getBlock()->getId() === 14) { $drops = array(); $drops[] = Item::get(Item::IRON_INGOT, 0, 1); $event->setDrops($drops); } }}
This? PHP: <?phpnamespace pmmp\DropIt;use pocketmine\event\block\BlockBreakEvent;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\Player;use pocketmine\inventory\Inventory;use pocketmine\event\Listener;class Main extends PluginBase implements Listener { $this->getServer()->getPluginManager()->registerEvents(listener, plugin base); public function onBreak(BlockBreakEvent $event) { if($event->getBlock()->getId() === 14) { $drops = array(); $drops[] = Item::get(Item::IRON_INGOT, 0, 1); $event->setDrops($drops); } }}
I tried breaking a Gold Ore (ID 14), but it doesn't drop a Quartz Block (ID 155). It drops a Gold Ore like always.
This is why you should learn PHP. I'm surprised you didn't get an error. PHP: <?phpnamespace pmmp\DropIt;use pocketmine\event\block\BlockBreakEvent;use pocketmine\plugin\PluginBase;use pocketmine\Server;use pocketmine\item\Item;use pocketmine\block\Block;use pocketmine\Player;use pocketmine\inventory\Inventory;use pocketmine\event\Listener;class Main extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onBreak(BlockBreakEvent $event) { if($event->getBlock()->getId() === 14) { $drops = array(); $drops[] = Item::get(Item::IRON_INGOT, 0, 1); $event->setDrops($drops); } }} I'll explain why this is correct and yours wasn't if you want, but I feel like it would be pointless at this point.