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

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

The newest version!
package top.hendrixshen.magiclib.mixin.malilib.dev;

import fi.dy.masa.malilib.gui.GuiTextFieldGeneric;
import net.minecraft.class_342;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
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.api.dependency.DependencyType;
import top.hendrixshen.magiclib.api.dependency.annotation.Dependencies;
import top.hendrixshen.magiclib.api.dependency.annotation.Dependency;
import top.hendrixshen.magiclib.impl.mixin.BuiltInPredicates;

@Dependencies(
        require = {
                @Dependency(dependencyType = DependencyType.MOD_ID, value = "malilib", versionPredicates = "<0.18.2"),
                @Dependency(dependencyType = DependencyType.PREDICATE, predicate = BuiltInPredicates.DevMixinPredicate.class),
                @Dependency(dependencyType = DependencyType.PREDICATE, predicate = BuiltInPredicates.MojangMappingMixinPredicate.class)
        }
)
@Dependencies(
        require = {
                @Dependency(dependencyType = DependencyType.MOD_ID, value = "mafglib"),
                @Dependency(dependencyType = DependencyType.MOD_ID, value = "minecraft", versionPredicates = "<1.21"),
                @Dependency(dependencyType = DependencyType.PREDICATE, predicate = BuiltInPredicates.DevMixinPredicate.class),
                @Dependency(dependencyType = DependencyType.PREDICATE, predicate = BuiltInPredicates.MojangMappingMixinPredicate.class)
        },
        conflict = {
                @Dependency(dependencyType = DependencyType.MOD_ID, value = "mafglib", versionPredicates = ">0.1.8"),
                @Dependency(dependencyType = DependencyType.MOD_ID, value = "minecraft", versionPredicates = ">1.20.4"),
        }
)
@Mixin(value = GuiTextFieldGeneric.class, remap = false)
public class GuiTextFieldGenericMixin extends class_342 {
    @Unique
    private boolean magiclib$setCursorPositionCalled = false;

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

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

        this.magiclib$setCursorPositionCalled = true;
    }

    @Inject(
            method = "setCursorPosition",
            at = @At(
                    value = "RETURN"
            )
    )
    private void postSetCursorPosition(int pos, CallbackInfo ci) {
        this.magiclib$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