1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Edit players' reach

Discussion in 'Development' started by Lowkey, May 19, 2017.

  1. Lowkey

    Lowkey Slime

    Messages:
    94
    Is there any way to edit a player's reach? Really can't get my head around any way :oops:
     
  2. Defications2po

    Defications2po Witch

    Messages:
    51
    Really dont think thats possible maybe use a event that registers a hit???
    i realy am just guessing
     
  3. falk

    falk Slime Poggit Reviewer

    Messages:
    75
    GitHub:
    falkirks
    If you click on air, the PlayerInteractEvent is fired. So if you do some ray casting and find the block they are aiming at. This is far from perfect and I doubt it would satisfy your use case. But that is all I can think of off the top of my head.
     
    jasonwynn10, Lowkey and SOFe like this.
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    ^what falk said.
    You can accomplish it by using Player::getTargetBlock(distance) and firing PlayerInteractEvent; distance being the number of blocks.
    PHP:
    public function onInteract(PlayerInteractEvent $event){
        if(
    $event->getAction() === PlayerInteractEvent::LEFT_CLICK_AIR){
            
    $player $event->getPlayer();
            
    $maxdistance 10;
            
    $block $player->getTargetBlock($maxdistance);
            if(
    $block->getId() !== Block::AIR){
                
    $player->getServer()->getPluginManager()->callEvent(new PlayerInteractEvent(
                    
    $player,
                    
    $player->getInventory()->getItemInHand(),
                    
    $block,
                    
    $event->getFace(),
                    
    PlayerInteractEvent::LEFT_CLICK_BLOCK
                
    ));
            }
        }
    }
    But it won't work as it should be, I don't think that will allow player's to break blocks as far as 10m.
     
    jasonwynn10, Lowkey and SOFe like this.
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Block breaking is possible, but it must be instabreak.
    Also note that merely calling the event doesn't really simulate block clicking. (Simulate or emulate?)
     
  6. Legoboy0215

    Legoboy0215 Witch

    Messages:
    64
    GitHub:
    legoboy0215
    Simulate.
     
    jasonwynn10 and SOFe like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.