Jump to content

Recommended Posts

Posted

Good Evening,

I tried to give my OwnVillager an AI. But in the case of move it is like the Programm skips this.

my methode for move the Villager is:

 

    public void moveTo(double x, double y, double z) 
    {
        final BlockPos coords = new BlockPos(x, y, z);
        try {
            if (!this.getNavigator().tryMoveToXYZ((double)coords.getX(), (double)coords.getY(), (double)coords.getZ(), 0.5F)) 
            {
                final Vec3d vector = new Vec3d(coords.getX()+0.5D, coords.getY(), coords.getZ());
                final Vec3d vec3D = RandomPositionGenerator.findRandomTargetBlockTowards((EntityCreature)this, 10, 3, vector);
                this.setHomePosAndDistance(this.getPos(), 50);
             
                if (vec3D != null) 
                {
                   this.getNavigator().tryMoveToXYZ(vec3D.x, vec3D.y, vec3D.z, this.getAIMoveSpeed());
                }

            }
        }
        catch (NullPointerException ex) { 
            System.out.println(ex);
        }
    }


and the part of the AI:


 

 public void startExecuting()
    {
        
        switch(this.vil.currentWork)
        {
        case ALL_FULL:         this.vil.currentWork = EnumWork.WAIT;
        case IDLE:            searchTree();
        case SEARCH_MAT:    searchTree();
        case SEARCH_WORK:    work();
        case SEARCH_TOOL:    searchTool();
        case WORK:            work();
        case EMPTY_INV:     emptyInv();
        default:
        }
        this.vil.currentWork = EnumWork.IDLE;

    }

 

private void search() 
    {
        System.out.println(this.vil.getName()+" searches a tree - "+tree);
        if (this.target == null) 
        {
            System.out.println(this.vil.getName()+1);
            this.target = AIHelper.getRandCoords(this.vil, this.limit, this.lastRes);
        }
        if (this.target != null) 
        {
            this.vil.moveTo(this.target.getX(), this.target.getY(), this.target.getZ());
            System.out.println(this.vil.getName()+"2_1");

        }
        if (this.vil.searchBox != null && this.vil.world.isMaterialInBB(this.vil.searchBox, Material.WOOD))
        {
                System.out.println(this.vil.getName()+" founds wooden material");
                this.currentResource = this.getNewResource();
                if (this.currentResource != null) 
                {
                    this.searchLimit = 20;
                    this.vil.getNavigator().clearPath();
                }    
            
        }
        if (this.target != null && Math.abs(this.vil.posX - this.target.getX()) <= 5.0 && Math.abs(this.vil.posZ - this.target.getZ()) <= 5.0) 
        {
            System.out.println(this.vil.getName()+4);
            this.tree = target;
            this.target = null;
            this.searchLimit += 10;
            this.vil.currentWork = EnumWork.WORK;
            return;
        }
        
//        this.waitABit(20);

    }

 

 

I searched the skipped Code with the out.println() and during the game I get:

Aaron searches a tree - null
Aaron2_1

Aaron searches a tree - null
Aaron2_1

Aaron searches a tree - null
Aaron2_1

.....

 

and so on...

course this loop the chunks are corrupted and nobody moves ^^'


Thanks for help!

Posted

yes ok know i knew that this AI- class is totaly false I changed everything and noted the mistakes in the AI class because the executing methods and the problem because of the loops.

But I think, that I don't understand the moving. The moveTo-method in the Villager class is called but the Villager don't move. Needs this methode any time to be done? It is possible, that my continueEx. methode to search a target is canceling the move?

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.