Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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!

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.