Skip to content

Commit

Permalink
do not use ModifyArgs
Browse files Browse the repository at this point in the history
fixes #18
  • Loading branch information
LemonCaramel committed Aug 14, 2024
1 parent ba49844 commit 9d86718
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package moe.caramel.chat.mixin;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import moe.caramel.chat.controller.ScreenController;
import moe.caramel.chat.wrapper.AbstractIMEWrapper;
import moe.caramel.chat.wrapper.WrapperSignEditScreen;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.font.TextFieldHelper;
import net.minecraft.client.gui.screens.inventory.AbstractSignEditScreen;
import net.minecraft.world.level.block.entity.SignBlockEntity;
Expand All @@ -14,11 +18,9 @@
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.ModifyArgs;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;
import java.util.function.Consumer;

/**
Expand Down Expand Up @@ -76,36 +78,36 @@ private boolean helperKeyPressed(final TextFieldHelper helper, final int key) {
return result;
}

@ModifyArgs(
@WrapOperation(
method = "renderSignText",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/gui/GuiGraphics;drawString(Lnet/minecraft/client/gui/Font;Ljava/lang/String;IIIZ)I",
ordinal = 0
)
)
private void renderCaret(final Args args) {
private int renderCaret(final GuiGraphics instance, final Font font, final String text, final int x, final int y, final int color, final boolean dropShadow, final Operation<Integer> original) {
// Check IME Status
final String original = args.get(1);
if (original.isEmpty() || caramelChat$wrapper.getStatus() == AbstractIMEWrapper.InputStatus.NONE) {
return;
if (text.isEmpty() || caramelChat$wrapper.getStatus() == AbstractIMEWrapper.InputStatus.NONE) {
return original.call(instance, font, text, x, y, color, dropShadow);
}

// Line Check (stupid way...)
final int lineHeight = this.sign.getTextLineHeight();
final int centerHeight = (4 * lineHeight / 2);
final int line = (((int) args.get(3) + centerHeight) / lineHeight);
final int line = ((y + centerHeight) / lineHeight);
if (line != this.line) {
return;
return original.call(instance, font, text, x, y, color, dropShadow);
}

// Render Caret
final int firstEndPos = caramelChat$wrapper.getFirstEndPos();
final int secondStartPos = caramelChat$wrapper.getSecondStartPos();

final String first = original.substring(0, firstEndPos);
final String input = original.substring(firstEndPos, secondStartPos);
final String second = original.substring(secondStartPos);
args.set(1, first + ChatFormatting.UNDERLINE + input + ChatFormatting.RESET + second); // OMG..
final String first = text.substring(0, firstEndPos);
final String input = text.substring(firstEndPos, secondStartPos);
final String second = text.substring(secondStartPos);
final String result = (first + ChatFormatting.UNDERLINE + input + ChatFormatting.RESET + second); // OMG..
return original.call(instance, font, result, x, y, color, dropShadow);
}
}

This file was deleted.

0 comments on commit 9d86718

Please sign in to comment.