package me.earthme.luminol.config.modules.optimizations;

import me.earthme.luminol.config.IConfigModule;
import me.earthme.luminol.config.flags.ConfigClassInfo;
import me.earthme.luminol.config.flags.ConfigInfo;
import me.earthme.luminol.enums.EnumConfigCategory;

/**
 * ESU - velocity (entity motion) packet reduction for living mobs.
 *
 * <p>Vanilla sends a {@code ClientboundSetEntityMotionPacket} for every tracked entity whose delta
 * movement changed by more than 1e-7 since the last send - i.e. basically every tick for every
 * walking mob. In dense scenes (many players fighting, large zombie hordes) this is the second
 * largest outbound bandwidth source after relative-move packets.
 *
 * <p>For ordinary living mobs the client already interpolates position from the move packets, and
 * velocity packets exist mostly for smoothing - sub-pixel velocity changes every tick carry almost
 * no visible information. This module suppresses a living mob's velocity packet when (a) the change
 * since the last send is below {@code min_delta_sqr}, or (b) it was sent too recently (fewer than
 * {@code min_interval_ticks} ticks ago) and the change isn't a large impulse.
 *
 * <p>Projectiles, fireballs, fall-flying players and impulse events are never throttled -
 * their velocity is gameplay-critical for client prediction, so this only touches walking AI mobs.
 * Folia-safe: pure per-entity state read on the entity's tracker tick.
 */
@ConfigClassInfo(category = EnumConfigCategory.OPTIMIZATIONS, name = "entity_velocity_packet")
public class EntityVelocityPacketConfig implements IConfigModule {

    @ConfigInfo(name = "enabled", comments = "Throttle velocity (motion) packets for ordinary living mobs. Projectiles are never affected.")
    public static boolean enabled = true;

    @ConfigInfo(name = "min_delta_sqr", comments = "Skip a mob's velocity packet when its motion changed by less than this (squared blocks/tick). 0.003 ~= a 0.055 b/t change; below that the client can't tell. Set 0 to only use the interval gate.")
    public static double minDeltaSqr = 0.003D;

    @ConfigInfo(name = "min_interval_ticks", comments = "Minimum ticks between velocity packets for the same mob, unless a large impulse occurs. 3 = at most ~7 motion packets/sec instead of 20.")
    public static int minIntervalTicks = 3;

    @ConfigInfo(name = "impulse_delta_sqr", comments = "A motion change at or above this (squared) is treated as a real impulse (knockback, explosion, fall) and sent immediately, bypassing the interval gate.")
    public static double impulseDeltaSqr = 0.04D;
}
