Jump to content

Recommended Posts

Posted

Hello everyone. I am trying to make a status effect that heals you when you stand still on the ground. For this I have to somehow extract the speed the entity is currently moving with and check if it's zero. The closest thing to that I have been able to find is the getDeltaMovement() method, but for some reason it returns zero on the x and z axis regardless of the actual velocity of the entity.
Here is the code I use for the effect application.

    @Override
    public void applyEffectTick(@NotNull LivingEntity entity, int amplifier){
        if (!entity.level.isClientSide) {
            if (entity.getHealth() < entity.getMaxHealth()) {
                Vec3 movement = entity.getDeltaMovement();

                System.out.println(movement);
                if (movement.x == 0.0D && entity.isOnGround() && movement.z == 0.0D) {
                    entity.heal(1.0F);
                }
            }
        }
    }

Also, getDeltaMovement() method seems to return non-zero values on the client side when moving, but you cannot heal on the client side.
I have seen some posts about getting the position of the entity in the previous tick to determine its velocity, but I have not found any methods to do so. What I can do to determine an entity's velocity or just if it is standing still or not?

Posted
43 minutes ago, Lithanarianaren said:

What I can do to determine an entity's velocity or just if it is standing still or not?

you can check if the old position (Entity.xOld, Entity.yOld, Entity.zOld) equals the current position (Entity#getX, Entity#getY, Entity#getZ)

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.