Old Ff

Develop a Minecraft Java Fabric 1.21.11 mod that enhances player movement by increasing the base speed to 50% faster than vanilla. Implement a controlled acceleration system where speed builds up as the player walks or sprints, capped at a maximum of 3 times vanilla sprint speed to prevent chunk loading issues. Include a feature that resets the speed to the modded baseline if the player remains stationary for 5 seconds, ensuring smooth gameplay and manageable performance.

Kodari AI
KodariSep 26 at 7:18 am 1
VelocityBoost
Enhances player movement with a 50% faster base speed. Implements a controlled acceleration system where speed builds while walking or sprinting, capped at 3x vanilla sprint speed to prevent chunk loading issues. Resets to the modded baseline after 5 seconds of standing still, ensuring smooth gameplay and manageable performance.
  1. Verify the 1.21.11 tick, player, and movement-attribute APIs and vanilla sprint scaling.

  2. Create a minimal Fabric project with per-player acceleration, a 3× sprint-speed ceiling, and a 5-second idle reset.

Created the momentum Fabric 1.21.11 mod project. Players start at 1.5× their original movement speed; movement builds acceleration at different rates for walking and sprinting, capped at 3× vanilla sprint speed. After 100 stationary ticks (5 seconds), speed returns to the modded baseline.

The project includes Fabric Loom setup and the mod entrypoint.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 169
src/main/java/com/kodari/momentum/MomentumMod.java
package com.kodari.momentum;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.server.network.ServerPlayerEntity;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

public class MomentumMod implements ModInitializer {
    private static final double BASELINE_MULTIPLIER = 1.5;
    private static final double MAX_MULTIPLIER = 3.0;
    private static final double WALK_ACCELERATION = 0.005;
    private static final double SPRINT_ACCELERATION = 0.01;
    private static final double MOVEMENT_THRESHOLD_SQUARED = 1.0E-6;
    private static final int STATIONARY_RESET_TICKS = 100;

    private final Map<UUID, MovementState> movementStates = new HashMap<>();

    @Override
    public void onInitialize() {
        ServerTickEvents.END_SERVER_TICK.register(server -> {
            Set<UUID> onlinePlayers = new HashSet<>();

            for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
                UUID playerId = player.getUuid();
                onlinePlayers.add(playerId);

                EntityAttributeInstance movementSpeed = player.getAttributeInstance(EntityAttributes.MOVEMENT_SPEED);
                if (movementSpeed == null) {
                    continue;
                }

                MovementState state = movementStates.computeIfAbsent(
                        playerId,
                        ignored -> new MovementState(movementSpeed.getBaseValue(), player.getX(), player.getZ())
                );

                double deltaX = player.getX() - state.lastX;
                double deltaZ = player.getZ() - state.lastZ;
                boolean moved = deltaX * deltaX + deltaZ * deltaZ > MOVEMENT_THRESHOLD_SQUARED;

                if (moved) {
                    state.stationaryTicks = 0;
                    state.speedMultiplier = Math.min(
                            MAX_MULTIPLIER,
                            state.speedMultiplier + (player.isSprinting() ? SPRINT_ACCELERATION : WALK_ACCELERATION)
                    );
                } else if (state.stationaryTicks < STATIONARY_RESET_TICKS) {
                    state.stationaryTicks++;
                    if (state.stationaryTicks == STATIONARY_RESET_TICKS) {
                        state.speedMultiplier = BASELINE_MULTIPLIER;
                    }
                }

                movementSpeed.setBaseValue(state.vanillaBaseSpeed * state.speedMultiplier);
                state.lastX = player.getX();
                state.lastZ = player.getZ();
            }

            movementStates.keySet().retainAll(onlinePlayers);
        });
    }

    private static final class MovementState {
        private final double vanillaBaseSpeed;
        private double speedMultiplier = BASELINE_MULTIPLIER;
        private double lastX;
        private double lastZ;
        private int stationaryTicks;

        private MovementState(double vanillaBaseSpeed, double lastX, double lastZ) {
            this.vanillaBaseSpeed = vanillaBaseSpeed;
            this.lastX = lastX;
            this.lastZ = lastZ;
        }
    }
}