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

AxisAlignedBB()->isVectorInside() not working.

Discussion in 'Development' started by RumDaDuMCPE, Aug 27, 2018.

  1. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    The code below should check if a player is in an arena before killing the player.
    PHP:
    /**
    * @param EntityDamageEvent $event
    */
    public function catchDamage(EntityDamageEvent $event)
    {
        if (
    $event->getEntity() instanceof Player) {
            if (
    $event instanceof EntityDamageByEntityEvent) {
                
    $player $event->getEntity();
                if (
    $this->getPlugin()->getRegion(1)->isInAnyArena($player)) {
                    
    /* Kill Player */
                    
    }
                }
            }
        }
    Get the class:
    PHP:
    public function getRegion(int $id)
    {
        
    $regions = [
            new 
    SpawnRegion(),
            new 
    ArenaRegion()
        ];
        return (
    $id > -&& $id <= count($regions)) ? $regions[$id] : echo 'lol class not found: '.$id.'. dafuq :/';
    }
    Check if the player is in the arena(s):
    PHP:
    class ArenaRegion
    {

        private 
    $y = [0255];

        
    /**
         * @param Player $player
         * @return bool
         */
        
    public function isInAnyArena(Player $player) : bool {
            if (
    $this->inDragon($player) || $this->inForest($player) || $this->inIce($player) || $this->inSteamPunk($player)) {
                return 
    true;
            }
            return 
    false;
        }

        
    /**
         * @param Player $player
         * @return bool
         */
        
    public function inIce(Player $player) : bool
        
    {
            
    $x = [211149];
            
    $z = [214294];

            
    $axis = new AxisAlignedBB(min($x), max($x), min($this->y), max($this->y), min($z), max($z));
            if (
    $axis->isVectorInside($player)) {
                return 
    true;
            }
            return 
    false;
        }

        
    /**
         * @param Player $player
         * @return bool
         */
        
    public function inDragon(Player $player): bool
        
    {
            
    $x = [216,287];
            
    $z = [301,358];

            
    $axis = new AxisAlignedBB(min($x), max($x), min($this->y), max($this->y), min($z), max($z));
            if (
    $axis->isVectorInside($player)) {
                return 
    true;
            }
            return 
    false;
        }

        
    /**
         * @param Player $player
         * @return bool
         */
        
    public function inSteamPunk(Player $player) : bool
        
    {
            
    $x = [301,213];
            
    $z = [216,161];

            
    $axis = new AxisAlignedBB(min($x), max($x), min($this->y), max($this->y), min($z), max($z));
            if (
    $axis->isVectorInside($player)) {
                return 
    true;
            }
            return 
    false;
        }

        
    /**
         * @param Player $player
         * @return bool
         */
        
    public function inForest(Player $player) : bool
        
    {
            
    $x = [301,360];
            
    $z = [288,228];

            
    $axis = new AxisAlignedBB(min($x), max($x), min($this->y), max($this->y), min($z), max($z));
            if (
    $axis->isVectorInside($player)) {
                return 
    true;
            }
            return 
    false;
        }
    The coordinates fed are accurate, there are no console errors. It's just the method call.
    Thanks for your help.
     
    Last edited: Aug 27, 2018
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    Did you debug this code yourself already?
    PHP:
    if ($this->getPlugin()->getRegion(1)->isInAnyArena($player)) {
         echo 
    "ArenaRegion::isInAnyArena($player->getName()) returned true \n";
    } else {
         echo 
    "ArenaRegion::isInAnyArena($player->getName()) returned false \n";
    }
    Then find out return values of the checks
    PHP:
    var_dump($this->inDragon($player), $this->inForest($player), $this->inIce($player), $this->inSteamPunk($player))
    Alternatively you can use debugger from IDE and avoid this all.
     
    OnTheVerge 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.