All Downloads are FREE. Search and download functionalities are using the official Maven repository.

top.hendrixshen.magiclib.malilib.mixin.dev.MixinGuiTextFieldGeneric Maven / Gradle / Ivy

There is a newer version: 0.7.398+fe2125a-beta
Show newest version
package top.hendrixshen.magiclib.malilib.mixin.dev;

import fi.dy.masa.malilib.gui.GuiTextFieldGeneric;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_342;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import top.hendrixshen.magiclib.dependency.api.annotation.Dependencies;
import top.hendrixshen.magiclib.dependency.api.annotation.Dependency;
import top.hendrixshen.magiclib.dependency.impl.MixinDependencyPredicates;

// Fix mojang mappings stackoverflow
@Environment(EnvType.CLIENT)
@Dependencies(and = @Dependency(value = "malilib"), predicate = MixinDependencyPredicates.DevMojangMixinPredicate.class)
@Mixin(value = GuiTextFieldGeneric.class, remap = false)
public abstract class MixinGuiTextFieldGeneric extends class_342 {
    private boolean setCursorPositionCalled = false;

    @SuppressWarnings("ConstantConditions")
    public MixinGuiTextFieldGeneric() {
        super(null, 0, 0, 0, 0, null);
    }

    @Inject(method = "setCursorPosition", at = @At(value = "HEAD"), cancellable = true)
    private void preSetCursorPosition(int pos, CallbackInfo ci) {
        if (setCursorPositionCalled) {
            super.method_1875(pos);
            ci.cancel();
        }

        setCursorPositionCalled = true;
    }

    @Inject(
            method = "setCursorPosition",
            at = @At(
                    value = "RETURN"
            )
    )
    private void postSetCursorPosition(int pos, CallbackInfo ci) {
        setCursorPositionCalled = false;
    }

    @Inject(
            method = "getCursorPosition",
            at = @At(
                    value = "HEAD"
            ),
            cancellable = true
    )
    private void preGetCursorPosition(@NotNull CallbackInfoReturnable cir) {
        cir.setReturnValue(super.method_1881());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy