package com.r3944realms.leashedplayer.mixin.both;

import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.r3944realms.leashedplayer.LeashedPlayer;
import com.r3944realms.leashedplayer.modInterface.IEntityLeadExtension;
import net.minecraft.world.entity.Leashable;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(Leashable.class)
public interface MixinLeashable {
    @WrapMethod(method = "leashSnapDistance")
    default double leashSnapDistance(Operation<Double> original) {
        if (this instanceof IEntityLeadExtension entityLeadExtension) {
            int keepLeashTick = entityLeadExtension.getKeepLeashTick();
            if (keepLeashTick != 0)
                return Double.MAX_VALUE;
            return entityLeadExtension.getLeashLength() * LeashedPlayer.M1();
        }
        return original.call();
    }
    @WrapMethod(method = "leashElasticDistance")
    default double leashElasticDistance(Operation<Double> original) {
        if (this instanceof IEntityLeadExtension entityLeadExtension) {
            return entityLeadExtension.getLeashLength();
        }
        return original.call();
    }
}
