Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Commands on Block Walking

Comments in 'Plugin Development' started by HotFireyDeath, May 18, 2015.

  1. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    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?
    Primus and Jon like this.
  2. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Maby trigger code when entering an certain areas, cuz i dont think that emerald block has something to do with boost on LBSG.
  3. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Get the block ID on PlayerMoveEvent and then do what you want :)
    HotFireyDeath and Jon like this.
  4. ToNeX
    Offline

    ToNeX New Member

    Joined:
    Jan 19, 2015
    Posts:
    39
    Minecraft User:
    AnThOnEx
    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.
    HotFireyDeath likes this.
  5. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    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!
    PEMapModder likes this.
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    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(01));
      if(
    $block->getId() === Block::EMERALD_BLOCK){
      }
    }
    Last edited: May 20, 2015
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Don't you need to provide what floor to get? Like floorY, floorX e.t.c. And what does subtract does?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No, read the documentation for Vector3::floor() and Vector3::subtract().
    HotFireyDeath likes this.
  9. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    You misspelled function.
    PEMapModder likes this.
  10. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    I think use Player Move Event is not a best way to do it:(
  11. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Yeah "better" use PlayerDeathEvent :D. So tell us other way. Well i supose there is'nt!
  12. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    For me =_= I will use task to do it;)
  13. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    But you would need to check every player location and block even if player is moving or not !
  14. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    :)Whatever
    If you set it to 40 ticks per check, if will be better than check player move
    PEMapModder likes this.
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    40 ticks = 2 seconds
    With 2 seconds you can cross 4 blocks that meens emerald block could be skipped does'nt getting the boost!
  16. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    but if you use player move event, it will more hurt the server
    PEMapModder likes this.
  17. TigerHix
    Offline

    TigerHix Active Member

    Joined:
    May 11, 2015
    Posts:
    61
    Minecraft User:
    TigerHix
    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]), 2020); //This task will have a 20-tick delay and a 20-tick repeat interval.
    Last edited: May 20, 2015
    PEMapModder and xiaoq like this.
  18. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Where does that getBlock() come from?
    TigerHix likes this.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    PlayerMoveEvent is run thousands times per second. Avoid using PlayerMoveEvent because calling getBlock() thousands times per second isn't good for your server.
    xiaoq and TigerHix like this.
  20. TigerHix
    Offline

    TigerHix Active Member

    Joined:
    May 11, 2015
    Posts:
    61
    Minecraft User:
    TigerHix
    Oops :p There is a getBlock() in Bukkit API, shouldn't have presumed that! Code fixed.
    PEMapModder likes this.

Share This Page

Advertisement