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

Please help with my setblock() issue

Discussion in 'Development' started by Khome, Jul 3, 2017.

  1. Khome

    Khome Spider Jockey

    Messages:
    44
    Hi, I have posted this issue in development but no one seems to answer. I would be grateful if you could help me.

    So what I'm trying to do is set a specific block in the players position as they move. As the player moves, a series of setting block to air and that block. So it looks like the block is following the player.

    But the issue I'm getting is that despite the player staying still (no physical movement given on the device) the player starts jiggering back and forth and so does the block. It does not stay still.

    This is the full code below

    PHP:
         * @param PlayerMoveEvent $e
         
    */
        public function 
    onMove(PlayerMoveEvent $event){
            
    $player $event->getPlayer();

                
    $this->main->moveHiderBlock $event->getPlayer (), $event->getFrom (), $event->getTo () );
            }

    /**
         *
         * @param Player $player           
         * @param Position $from           
         * @param Position $to           
         */
        
    public function moveHiderBlock(Player $playerPosition $fromPosition $to) {
            
    $blockid 58;

                
    $this->keepBlockMoving $player$from$to$blockid );
            
        
        }
                
        
    /**
         *
         * @param Player $player           
         * @param Vector3 $from           
         * @param Vector3 $to           
         * @param unknown $blockid           
         */
        
    public function keepBlockMoving(Player $playerVector3 $fromVector3 $to$blockid) {       
            
    $envbid $player->getLevel ()->getBlockIdAt $from->getX(), $from->getY(), $from->getZ() );
            if (
    $envbid === $blockid) {
                
    $player->getLevel ()->setBlock ( new Vector3 $from->getX(), $from->getY(), $from->getZ(), $player->getLevel () ), $block Item::get Item::AIR )->getBlock (), truefalse );
            }
            
    $envbid $player->getLevel ()->getBlockIdAt $player->getX(), $player->getY(), $player->getZ() );
            if (
    $envbid === Item::AIR || $envbid === Item::TALL_GRASS) {
                
    $player->getLevel ()->setBlock ( new Vector3 $player->getX(), $player->getY(), $player->getZ(), $player->getLevel ()) , Item::get $blockid )->getBlock (), truefalse );
            } elseif (
    $envbid === $blockid) {
                
    $player->getLevel ()->setBlock ( new Vector3 $player->getX(), $player->getY(), $player->getZ(), $player->getLevel ()), Item::get $blockid )->getBlock (), truefalse );
            }
            if (
    round $player->getX() ) != round $from->getX() ) || round $player->getY() ) != round $from->getY() ) || round $player->getZ()) != round $from->getZ())) {
                
    $envbid $player->level->getBlockIdAt $to->getX(), $to->getY(), $to->getZ() );
                if (
    $envbid === Item::AIR || $envbid === Item::TALL_GRASS) {
                    
    $player->level->setBlock $toItem::get $blockid )->getBlock (), truefalse );
                }
            }
        }
    Any help would be greatly appreciated.
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You need to set the block at $from->getOppositeSide($player->getDirection());
     
  3. Khome

    Khome Spider Jockey

    Messages:
    44
    Would this be correct?

    PHP:
         * @param PlayerMoveEvent $e
         
    */
        public function 
    onMove(PlayerMoveEvent $event){
            
    $player $event->getPlayer();

                
    $this->main->moveHiderBlock $event->getPlayer (), $event->getFrom (), $event->getTo () );
            }

    /**
         *
         * @param Player $player         
         * @param Position $from         
         * @param Position $to         
         */
        
    public function moveHiderBlock(Player $playerPosition $fromPosition $to) {
            
    $blockid 58;

                
    $this->keepBlockMoving $player$from$to$blockid );
          
     
        }
              
        
    /**
         *
         * @param Player $player         
         * @param Vector3 $from         
         * @param Vector3 $to         
         * @param unknown $blockid         
         */
        
    public function keepBlockMoving(Player $playerVector3 $fromVector3 $to$blockid) {     
            
    $envbid $player->getLevel ()->getBlockIdAt $from->getX(), $from->getY(), $from->getZ() );
            if (
    $envbid === $blockid) {
                
    $player->getLevel ()->setBlock $from->getOppositeSide($player->getDirection()), $block Item::get Item::AIR )->getBlock (), truefalse );
            }
            
    $envbid $player->getLevel ()->getBlockIdAt $player->getX(), $player->getY(), $player->getZ() );
            if (
    $envbid === Item::AIR || $envbid === Item::TALL_GRASS) {
                
    $player->getLevel ()->setBlock $from->getOppositeSide($player->getDirection()), Item::get $blockid )->getBlock (), truefalse );
            } elseif (
    $envbid === $blockid) {
                
    $player->getLevel ()->setBlock from->getOppositeSide($player->getDirection()), Item::get $blockid )->getBlock (), truefalse );
            }
            if (
    round $player->getX() ) != round $from->getX() ) || round $player->getY() ) != round $from->getY() ) || round $player->getZ()) != round $from->getZ())) {
                
    $envbid $player->level->getBlockIdAt $to->getX(), $to->getY(), $to->getZ() );
                if (
    $envbid === Item::AIR || $envbid === Item::TALL_GRASS) {
                    
    $player->level->setBlock $toItem::get $blockid )->getBlock (), truefalse );
                }
            }
        }
     
    Last edited: Jul 3, 2017
  4. Khome

    Khome Spider Jockey

    Messages:
    44
    How would I apply the $from->getOppositeSide($player->getDirection()) correctly to my code?
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It's not an add-on, you don't apply it. You understand that snippet and use it.
     
  6. Khome

    Khome Spider Jockey

    Messages:
    44
    I'm not sure how I would set the block at the opposite side of the players current direction. I'm quite new to coding. I've managed to do the other parts of the plugin which is a block hunt plugin. but this is the only bit I'm stuck on. The other block hunt plugins I've seen use the same initial code to set the block. But that block jiggering/moving issue persists. Iv also tried adding 1 to player->x so that the block is set some further distance behind the player. But this affects the players ability to move as the block gets in the way when turning around.
     
  7. Khome

    Khome Spider Jockey

    Messages:
    44
    Please help iv literally been trying for hours but can't figure it out..
     
  8. Khome

    Khome Spider Jockey

    Messages:
    44
    Is this even possible?

    I mean I don't think I've seen any plugins use setblock to make a block look like it's following the player. I don't know how mineplex and other servers do it with blockhunt but no matter what I do, the block does not properly follow the players direction. It keeps in one direction to the player therefore the block becomes an obstruction when the player changes direction.
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You haven't seen a plugin do it? https://github.com/Muirfield/ToyBox
     
    Khome likes 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.