#Executing every tick for x ticks

5 messages · Page 1 of 1 (latest)

tulip rose
#

How to exececute "entity.setVelocity(Vec3d.ZERO);" every tick for x ticks? I tried for loop but that doesn't execute every tick, and I can't find anything online

coarse fox
#

that lets you run something every tick, but you'll have to figure out how to stop it

ornate badge
#

Let's say you have SetEntityVelocity class. Then do this:

package your.mod.name;

import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;

public class SetEntityVelocity {
    private static final Entity entity = null; // Your Entity
    private static final int tickAmount = 20;
    private static int tickCounter = 0;

    public static void register() {
        ClientTickEvents.END_CLIENT_TICK.register(
                client -> {
                    if (tickCounter >= tickAmount) return;
                    entity.setVelocity(Vec3d.ZERO);
                    tickCounter++;
                }
        );
    }
}

Then in your mod onInitializeClient (or onInitialize):

SetEntityVelocity.register();
tulip rose
#

tysm, for the last hour or so I was reinventing math 😂