How would you be able to trigger code when walking on a specific block? Say for example, LBSG has a emerald block that, when walked on, will boost you to the server selection. How can you achieve this?
Maby trigger code when entering an certain areas, cuz i dont think that emerald block has something to do with boost on LBSG.
Walking on the emerald block on LBSG will give boost. Walking on the left or on the right doesn't give boost. It's the block.
And the block will be wasted . Better is to setup an areas and i still dont think that the emerald block has to do something with the boost. When i will walk past just little bit further after that block it will still give me a boost!
If you just want to get the ID of the block below the player, PHP: public function onMove(PlayerMoveEvent $ev){ $block = $ev->getPlayer()->getLevel()->getBlock($ev->getPlayer()->floor()->subtract(0, 1)); if($block->getId() === Block::EMERALD_BLOCK){ }}
40 ticks = 2 seconds With 2 seconds you can cross 4 blocks that meens emerald block could be skipped does'nt getting the boost!
You are correct. Using PlayerMoveEvent is far more resource-consuming than running a scheduled, repeating task. I'm on a phone so can't test the code, but the way to do it by scheduler is something like: First create a new class that extends PluginTask. In the new class, let's call it MovementDetectionTask, override onRun($currentTick) method. PHP: public function onRun($currentTick) { if (somePlayer->getLevel()->getBlock(somePlayer->getLocation())->getSide(Vector3::SIDE_DOWN)->getId() === Block::EMERALD_BLOCK) { // Do something... }} Then, PHP: [plugin instance]->getServer()->getScheduler()->scheduleDelayedRepeatingTask(new MovementDetectionTask([plugin instance]), 20, 20); //This task will have a 20-tick delay and a 20-tick repeat interval.
PlayerMoveEvent is run thousands times per second. Avoid using PlayerMoveEvent because calling getBlock() thousands times per second isn't good for your server.