Jump to content

Smooth ai entity movement possible?


26broadway

Recommended Posts

Hello,

 

When I add custom entities to my mod then add ai so that they move in a straight line (goal: continuous movement) they will move a few blocks (the x offset I provide) then wait before moving again.  I read somewhere that mobs have a delayed tick.  Is there a way around this?  How do I add AI entities that have smooth, continuous movement?

 

Thanks! 

Link to comment
Share on other sites

I read somewhere that mobs have a delayed tick.

have you actually tried it ?

 

I assume you are referring to movement not animation , by this i mean going to block 2,64,90 , then to block 5,55,96 etc

if this is the case all you have to do is set a new destination as soon as (or just before) they reach the the connecting point (it worked for me)

Link to comment
Share on other sites

Thanks for the reply Ewe.  Yes, I have tried it -> "they will move a few blocks (the x offset I provide) then wait before moving again."  I duplicated and modified the entity wander ai method so that it simply walks in a straight line instead of randomly.  Some of the code is still obfuscated but it doesn't seem to explicitely add a delay; here is what it looks like currently:

 

package com.dm.gatherer.ai;

import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.RandomPositionGenerator;
import net.minecraft.util.Vec3;

public class ChopTrees extends EntityAIBase
{
    private EntityCreature entity;
    private double xPosition;
    private double yPosition;
    private double zPosition;
    private double speed;
    private int field_179481_f;
    private boolean field_179482_g;
    private static final String __OBFID = "CL_00001608";

    public ChopTrees(EntityCreature p_i1648_1_, double p_i1648_2_)
    {
        this(p_i1648_1_, p_i1648_2_, 120);
    }

    public ChopTrees(EntityCreature p_i45887_1_, double p_i45887_2_, int p_i45887_4_)
    {
        this.entity = p_i45887_1_;
        this.speed = p_i45887_2_;
        this.field_179481_f = p_i45887_4_;
        this.setMutexBits(1);
    }

    /**
     * Returns whether the EntityAIBase should begin execution.
     */
    public boolean shouldExecute()
    {
        if (!this.field_179482_g)
        {
            if (this.entity.getAge() >= 100)
            {
                return false;
            }

            if (this.entity.getRNG().nextInt(this.field_179481_f) != 0)
            {
                return false;
            }
        }

        Vec3 vec3 = RandomPositionGenerator.findRandomTarget(this.entity, 10, 7);

        if (vec3 == null)
        {
            return false;
        }
        else
        {
            this.xPosition = vec3.xCoord;
            this.yPosition = vec3.yCoord;
            this.zPosition = vec3.zCoord;
            this.field_179482_g = false;
            return true;
        }
    }

    /**
     * Returns whether an in-progress EntityAIBase should continue executing
     */
    public boolean continueExecuting()
    {
        return !this.entity.getNavigator().noPath();
    }

    /**
     * Execute a one shot task or start executing a continuous task
     */
    public void startExecuting()
    {
    	//this.entity.moveEntity(3, 0, 0);
        this.entity.getNavigator().tryMoveToXYZ(this.entity.posX+3, this.entity.posY, this.entity.posZ, this.speed);
    }

    public void func_179480_f()
    {
        this.field_179482_g = true;
    }

    public void func_179479_b(int p_179479_1_)
    {
        this.field_179481_f = p_179479_1_;
    }
}

 

The only other ai method added to this particular entity on construction is the swimming ai; this custom ChopTrees ai method is priority 2. I'll try commenting out some of the conditionals in shouldExecute() to see if, perhaps, one of those is sending the false flag periodically.  Open to suggestions!

Link to comment
Share on other sites

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.