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

Problems with custom Pathfinders

Discussion in 'Development' started by Indexfire, Oct 16, 2017.

  1. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Im basically trying to implement Pathfinders like Bukkit into Pocketmine but im running into problems like how to activate the code everytime the server ticks the entity:

    PHP:
    interface Pathfinder{

        public function 
    tick() : bool();

        public function 
    execute();

    }
    PHP:
    class PathfinderExample implements Pathfinder{

        private 
    $entity;

        public function 
    __construct(Creature $entity){

            
    $this->entity $entity;

        }

        public function 
    tick() : bool{

            if(
    /*Condition met*/){
      
                return 
    true;
                } else {

                return 
    false;
                }
            }

        public function 
    execute{

            
    /*Do stuff*/

        
    }

    }
    Does anyone know where the code that ticks the entities is?
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    make your plugin extend the entity and then use entityBaseTick:
    Example for a Zombie (basically every Monster/Creature/Living or Entity which doesn't change constructor things)
    PHP:
    class Pathfinder extends Entitiy{
        public function 
    __construct(Level $levelCompoundTag $nbt){
            
    parent::__construct($level$nbt);
        }

        public function 
    entityBaseTick() : bool{
            if(
    /*Condition met*/){
                return 
    true;
            }else{
                return 
    false;
                }
            }

        public function 
    execute{
            
    /*Do stuff*/
        
    }
    }
     
    jasonwynn10 and Sandertv like this.
  3. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
  4. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PureEntitiesX is mostly pathfinder logic, considering it's required for mob AI
     
    Indexfire likes this.
  6. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    PHP:
    class Wither extends Monster{

        
    /*Left out all the parts     unimportant like getName() entity id
        And the width and height*/

        
    private $goalSelector = new PathfinderSelector();

        public function 
    __construct(Level $levelCompound $nbt){

            
    parent::__construct($level$nbt);
            
    $this->goalSelector->register(new PathfinderActPassive($this));

        }

    }
    It keeps throwing some squiggly error i cant read...
     
  7. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    1. You didn't show any useful code.
    2. You didn't display the error
    We cannot help you
     
    Indexfire and Jack Noordhuis like this.
  8. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    did you even read this @Indexfire?
     
    Indexfire likes this.
  9. Indexfire

    Indexfire Baby Zombie

    Messages:
    137
    GitHub:
    Indexfire
    Err well i did but... i made the PathfinderSelector and used it like the NMS for PC Servers does which does the same thing...

    Also i cant really figure that out cause then the Pathfinder would be an Entity itself..?
     
  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.