top.hendrixshen.magiclib.malilib.mixin.dev.MixinGuiTextFieldGeneric Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of magiclib-1_14_4 Show documentation
Show all versions of magiclib-1_14_4 Show documentation
To beat magic with magic :(
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