I tried this: PHP: public function onInteract(PlayerInteractEvent $ev){ $player = $ev->getPlayer(); $item = $ev->getItem(); if($item->getId() == 310){ $use = new PlayerInteractEvent($ev->getPlayer(), Item::get(Item::FLINT_AND_STEEL, 0, 1), new \pocketmine\math\Vector3($ev->getBlock()->getX(), $ev->getBlock()->getY()+1, $ev->getBlock()->getZ()), $ev->getFace()); $player->getInventory()->setItemInHand(Item::get($ev->getItem()->getId(), $ev->getItem()->getDamage(), $ev->getItem()->getCount()-1)); } } don't work and don't have erros in console
When the player touches the diamond helmet on a block, I want to set fire to that block. Do not tell me why I want to do this so maybe I need to use this for future projects.
Actually I want to make a player interact with a block, which is in a different position from where the event is called
You already have the Event object, you can call it with $event->call(); or PluginManager->callEvent($event).
PHP: $use = new PlayerInteractEvent($ev->getPlayer(), Item::get(Item::FLINT_AND_STEEL, 0, 1), new \pocketmine\math\Vector3($ev->getBlock()->getX(), $ev->getBlock()->getY()+1, $ev->getBlock()->getZ()), $ev->getFace()); $this->getServer()->getPluginManager()->callEvent($use); don't work, yes i registred the event listener
I pick up the item with the id 310 and play with it on the floor. And does not put fire on the block that I touched, just takes the id item 310 from my inventory.
What code are you using to determine if the second event is called? Are you expecting calling the event to spawn fire on the block? Calling an event doesn't make the interaction happen. The event is most used internally so that plugins can modify the outcome. In this case, you aren't using the Event in a way that it will provide any use. You'll need to set the block yourself for that.
Or how about PHP: $item->setCount($item->getCount() - 1);$player->getInventory()->setItemInHand($item); That^ is much better because it'll make sure nothing happens to the item's NBT.
PHP: public function onInteract(PlayerInteractEvent $ev){ $player = $ev->getPlayer(); $item = $ev->getItem(); $level = $player->getLevel(); $damage = 1; $block = $ev->getBlock(); $x = $block->getX(); $y = $block->getY(); $z = $block->getZ(); if($item->getId() == 310){ $use = new PlayerInteractEvent($ev->getPlayer(), Item::get(Item::FLINT_AND_STEEL, 0, 1), new \pocketmine\math\Vector3($ev->getBlock()->getX(), $ev->getBlock()->getY()+1, $ev->getBlock()->getZ()), $ev->getFace()); $player->getInventory()->setItemInHand(Item::get($ev->getItem()->getId(), $ev->getItem()->getDamage(), $ev->getItem()->getCount()-1)); $level->setBlock(new Vector3($x, $y, $z + 1), new Fire($damage)); $ev->setCancelled(true); } }
Don't try to call the same event during the same event if you don't know what you're doing. You may end up with a Segmentation Fault if you make a loop out of it. You should also consider elaborating your question. What doesn't work? Lastly, you don't need to use == operator here, use ===. Though it'll do the same thing in this case, it's always better to know what the difference between those two operators are. The former checks whether two values are equal and the latter checks for whether the two values are equal and identical in types. Item:'getId() always returns an integer, not an integer in a string (such as 310 and not "310"). PHP: if($item->getId() === 310){ $block = $ev->getBlock(); $above = $block->add(0, 1, 0); if($block->getLevel()->getBlock($above)->getId() === Block::AIR){ $block->getLevel()->setBlock($above, Block::get(Block::FIRE)); $item->setCount($item->getCount() - 1); $player->getInventory()->setItemInHand($item); }} $above is the block right above $block ($block is the block being clicked). You are trying to set the block right above the block clicked, as air. For this, we'll need to check whether there is a block above the block clicked, to avoid problems. The $item->setCount(...) function will become simpler in the future. There will be an $item->pop() function in the future which will do the same thing the setCount() function in the above code is doing.