Skip to content

Commit

Permalink
Improve compatibility with EMI mod
Browse files Browse the repository at this point in the history
closes #11
  • Loading branch information
LemonCaramel committed Jan 28, 2024
1 parent 6a07341 commit 9f32074
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 1 deletion.
7 changes: 7 additions & 0 deletions common/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
repositories {
maven { url "https://maven.terraformersmc.com/" }
}

dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"

// Other mods
modCompileOnly "dev.emi:emi-xplat-intermediary:${emi_version}"
}

architectury {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package moe.caramel.chat.mixin.emi;

import dev.emi.emi.EmiPort;
import net.minecraft.network.chat.Component;
import net.minecraft.util.FormattedCharSequence;
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.CallbackInfoReturnable;

/**
* (EMI Mixin) Fix crash in PREVIEW mode.
*/
@Mixin(EmiPort.class)
public final class MixinPluginEmiPort {

@Inject(method = "ordered", at = @At("HEAD"), cancellable = true)
private static void fixCrashInPreviewMode(final Component text, final CallbackInfoReturnable<FormattedCharSequence> cir) {
if (text == null) {
cir.setReturnValue(FormattedCharSequence.EMPTY);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package moe.caramel.chat.mixin.emi;

import dev.emi.emi.screen.widget.EmiSearchWidget;
import moe.caramel.chat.controller.EditBoxController;
import net.minecraft.client.gui.components.EditBox;
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;

/**
* (EMI Mixin) Refresh the search results immediately.
*/
@Mixin(EmiSearchWidget.class)
public final class MixinPluginEmiSearchWidget {

@Inject(method = "<init>", at = @At("TAIL"))
private void init(final CallbackInfo ci) {
final EditBox editBox = ((EditBox) (Object) this);
EditBoxController.getWrapper(editBox)
.setInsertCallback(() -> {
if (editBox.responder != null) {
editBox.responder.accept(editBox.value);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ public final class Compatibilities {

private static final Map<String, Data> REGISTRY = new HashMap<>();

public static final Data EMI = register(
"EMI", "dev.emi.emi.screen.widget.EmiSearchWidget",
Set.of(
"moe.caramel.chat.mixin.emi.MixinPluginEmiPort",
"moe.caramel.chat.mixin.emi.MixinPluginEmiSearchWidget"
)
);

// ================================

/**
Expand Down
1 change: 1 addition & 0 deletions common/src/main/resources/caramelchat.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ accessible field net/minecraft/client/gui/components/EditBox maxLength I
accessible field net/minecraft/client/gui/components/EditBox bordered Z
accessible field net/minecraft/client/gui/components/EditBox cursorPos I
accessible field net/minecraft/client/gui/components/EditBox highlightPos I
accessible field net/minecraft/client/gui/components/EditBox responder Ljava/util/function/Consumer;

accessible field net/minecraft/client/gui/font/TextFieldHelper setMessageFn Ljava/util/function/Consumer;
mutable field net/minecraft/client/gui/font/TextFieldHelper setMessageFn Ljava/util/function/Consumer;
Expand Down
4 changes: 3 additions & 1 deletion common/src/main/resources/caramelchat.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"MixinMinecraft",
"MixinRecipeBookComponent",
"MixinSelectWorldScreen",
"MixinSignEditScreen"
"MixinSignEditScreen",
"emi.MixinPluginEmiPort",
"emi.MixinPluginEmiSearchWidget"
]
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ maven_group=moe.caramel
minecraft_version=1.20.1
fabric_loader_version=0.14.22
forge_version=1.20.1-47.1.44

# Other mods
emi_version=1.1.0+1.20.1

0 comments on commit 9f32074

Please sign in to comment.