Jump to content

[1.19.3] Getting an entity to move somewhere


Kaboom Roads

Recommended Posts

I am using a modified MeleeAttackGoal to make an entity pick a random button, go to it and press it. But after a while it just stops and stares at the current button target. I found out that it's just staring at it because it's too far away to press it.  And its's not moving because the current path in the mob navigation is "done". If I move it further away it recalculates a non weird path and fixes itself. If I push it towards the button so it can press it, it sets the target to null, so it once again calculates a new path and fixes itself. What is causing the path to be "done"? And how can I fix this?

This is the tick method in the custom goal class:

public void tick() {
        if (mob.buttonTarget != null) {
            float x = mob.buttonTarget.getX();
            float y = mob.buttonTarget.getY();
            float z = mob.buttonTarget.getZ();
            float hx = x + 0.5f;
            float hy = y + 0.5f;
            float hz = z + 0.5f;
            mob.getLookControl().setLookAt(hx, hy, hz, 30.0F, 30.0F);
            double distSqr = mob.distanceToSqr(hx, hy, hz);
            ticksUntilNextPathRecalculation = Math.max(ticksUntilNextPathRecalculation - 1, 0);
            if ((followingTargetEvenIfNotSeen || hasLineOfSight(mob, mob.buttonTarget)) && ticksUntilNextPathRecalculation <= 0 && ((pathedTargetX == 0.0D && pathedTargetY == 0.0D && pathedTargetZ == 0.0D) || mob.buttonTarget.distSqr(new Vec3i(pathedTargetX, pathedTargetY, pathedTargetZ)) >= 1.0D || mob.getRandom().nextFloat() < 0.05F)) {
                pathedTargetX = hx;
                pathedTargetY = hy;
                pathedTargetZ = hz;
                ticksUntilNextPathRecalculation = 4 + mob.getRandom().nextInt(7);
                if (distSqr > 1024.0D) ticksUntilNextPathRecalculation += 10;
                else if (distSqr > 256.0D) ticksUntilNextPathRecalculation += 5;
                Path newPath = mob.getNavigation().createPath(mob.buttonTarget, 0);
                if (newPath != null && !newPath.canReach()) {
                    mob.buttonTarget = null;
                    return;
                }
                if (!mob.getNavigation().moveTo(newPath, speedModifier)) ticksUntilNextPathRecalculation += 15;
                ticksUntilNextPathRecalculation = adjustedTickDelay(ticksUntilNextPathRecalculation);
            }
            ticksUntilNextAttack = Math.max(getTicksUntilNextAttack() - 1, 0);
            checkAndPerformAttack(mob.buttonTarget, distSqr);
        }
    }

 

Link to comment
Share on other sites

It doesn't seem to be canContinueToUse, especially since it's just a check for if the button still exists.

But the moveTo method in the tick method returns false when in this broken state, it usually returns true.

It seems to be because mob.getNavigation().getPath() is "done", but I don't know how to fix it.

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.