From b34a52aa8ea364ce8feec1a7b3e4eab33ab326de Mon Sep 17 00:00:00 2001 From: Pyrofab Date: Sun, 22 Oct 2023 15:12:28 +0200 Subject: [PATCH] Fix EMI appearing on dialogue screen --- build.gradle | 3 +- gradle/libs.versions.toml | 4 +- .../impl/compat/BlabberMixinPlugin.java | 57 +++++++++++++++++++ .../blabber/impl/compat/package-info.java | 28 +++++++++ .../compat/emi/EmiScreenManagerMixin.java | 22 +++++++ .../impl/mixin/compat/emi/package-info.java | 28 +++++++++ src/main/resources/blabber.mixins.json | 5 +- 7 files changed, 144 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/ladysnake/blabber/impl/compat/BlabberMixinPlugin.java create mode 100644 src/main/java/org/ladysnake/blabber/impl/compat/package-info.java create mode 100644 src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/EmiScreenManagerMixin.java create mode 100644 src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/package-info.java diff --git a/build.gradle b/build.gradle index 0d342ba9..f2a48136 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,8 @@ dependencies { modIncludeImplementation(libs.cca.base) modIncludeImplementation(libs.cca.entity) modIncludeImplementation(libs.permissionsApi) - modLocalImplementation(libs.rei) + modLocalImplementation(libs.rei.api) + modLocalImplementation(libs.emi) compileOnly(libs.mcAnnotations) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index c1b67547..ee9c11aa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,7 @@ [versions] cca = "5.3.0" elmendorf = "0.12.0" +emi = "1.0.23+1.20.2" fpa = "0.2-SNAPSHOT" mcAnnotations = "1.0" modmenu = "8.0.0-beta.2" @@ -10,7 +11,8 @@ rei = "13.0.666" cca-base = { module = "dev.onyxstudios.cardinal-components-api:cardinal-components-base", version.ref = "cca" } cca-entity = { module = "dev.onyxstudios.cardinal-components-api:cardinal-components-entity", version.ref = "cca" } elmendorf = { module = "org.ladysnake:elmendorf", version.ref = "elmendorf" } +emi = { module = "dev.emi:emi-fabric", version.ref = "emi" } mcAnnotations = { module = "com.demonwav.mcdev:annotations", version.ref = "mcAnnotations" } modmenu = { module = "com.terraformersmc:modmenu", version.ref = "modmenu"} permissionsApi = { module = "me.lucko:fabric-permissions-api", version.ref = "fpa" } -rei = { module = "me.shedaniel:RoughlyEnoughItems-api-fabric", version.ref = "rei" } +rei-api = { module = "me.shedaniel:RoughlyEnoughItems-api-fabric", version.ref = "rei" } diff --git a/src/main/java/org/ladysnake/blabber/impl/compat/BlabberMixinPlugin.java b/src/main/java/org/ladysnake/blabber/impl/compat/BlabberMixinPlugin.java new file mode 100644 index 00000000..06df5f7a --- /dev/null +++ b/src/main/java/org/ladysnake/blabber/impl/compat/BlabberMixinPlugin.java @@ -0,0 +1,57 @@ +package org.ladysnake.blabber.impl.compat; + +import net.fabricmc.loader.api.FabricLoader; +import org.jetbrains.annotations.Nullable; +import org.objectweb.asm.tree.ClassNode; +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class BlabberMixinPlugin implements IMixinConfigPlugin { + private static final String COMPAT_PREFIX = "org.ladysnake.blabber.mixin.compat."; + private static final Pattern COMPAT_MIXIN_PATTERN = Pattern.compile(Pattern.quote(COMPAT_PREFIX) + "(?[a-z_]+?)\\..*"); + private final FabricLoader loader = FabricLoader.getInstance(); + + @Override + public void onLoad(String mixinPackage) { + // NO-OP + } + + @Override + public @Nullable String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + if (!mixinClassName.startsWith(COMPAT_PREFIX)) return true; + Matcher matcher = COMPAT_MIXIN_PATTERN.matcher(mixinClassName); + if (!matcher.matches()) throw new IllegalStateException("Bad compat mixin name " + mixinClassName); + String modId = matcher.group("modid"); + return loader.isModLoaded(modId); + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + // NO-OP + } + + @Override + public List getMixins() { + return List.of(); + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + // NO-OP + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + // NO-OP + } +} diff --git a/src/main/java/org/ladysnake/blabber/impl/compat/package-info.java b/src/main/java/org/ladysnake/blabber/impl/compat/package-info.java new file mode 100644 index 00000000..1eba1979 --- /dev/null +++ b/src/main/java/org/ladysnake/blabber/impl/compat/package-info.java @@ -0,0 +1,28 @@ +/* + * Blabber + * Copyright (C) 2022-2023 Ladysnake + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; If not, see . + */ +/** + * Definitions of the dialogue system + */ +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +@ApiStatus.Internal +package org.ladysnake.blabber.impl.compat; + +import net.minecraft.util.annotation.FieldsAreNonnullByDefault; +import net.minecraft.util.annotation.MethodsReturnNonnullByDefault; +import org.jetbrains.annotations.ApiStatus; \ No newline at end of file diff --git a/src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/EmiScreenManagerMixin.java b/src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/EmiScreenManagerMixin.java new file mode 100644 index 00000000..b72a243c --- /dev/null +++ b/src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/EmiScreenManagerMixin.java @@ -0,0 +1,22 @@ +package org.ladysnake.blabber.impl.mixin.compat.emi; + +import dev.emi.emi.screen.EmiScreenManager; +import net.minecraft.client.MinecraftClient; +import org.ladysnake.blabber.impl.client.BlabberDialogueScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(EmiScreenManager.class) +public class EmiScreenManagerMixin { + @Shadow private static MinecraftClient client; + + @Inject(method = "isDisabled", at = @At("HEAD"), cancellable = true, remap = false, require = 0) + private static void blabber$disableEmiInDialogues(CallbackInfoReturnable cir) { + if (client.currentScreen instanceof BlabberDialogueScreen) { + cir.setReturnValue(true); + } + } +} diff --git a/src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/package-info.java b/src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/package-info.java new file mode 100644 index 00000000..aacefc05 --- /dev/null +++ b/src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/package-info.java @@ -0,0 +1,28 @@ +/* + * Blabber + * Copyright (C) 2022-2023 Ladysnake + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; If not, see . + */ +/** + * Definitions of the dialogue system + */ +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +@ApiStatus.Internal +package org.ladysnake.blabber.impl.mixin.compat.emi; + +import net.minecraft.util.annotation.FieldsAreNonnullByDefault; +import net.minecraft.util.annotation.MethodsReturnNonnullByDefault; +import org.jetbrains.annotations.ApiStatus; \ No newline at end of file diff --git a/src/main/resources/blabber.mixins.json b/src/main/resources/blabber.mixins.json index 9e36143b..0848718b 100644 --- a/src/main/resources/blabber.mixins.json +++ b/src/main/resources/blabber.mixins.json @@ -3,7 +3,10 @@ "minVersion": "0.8", "package": "org.ladysnake.blabber.impl.mixin", "compatibilityLevel": "JAVA_17", - "mixins": [], + "plugin": "org.ladysnake.blabber.impl.compat.BlabberMixinPlugin", + "mixins": [ + "compat.emi.EmiScreenManagerMixin" + ], "injectors": { "defaultRequire": 1 }