Skip to content

Commit

Permalink
Fix EMI appearing on dialogue screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Oct 22, 2023
1 parent b8908c7 commit b34a52a
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 3 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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" }
Original file line number Diff line number Diff line change
@@ -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) + "(?<modid>[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<String> myTargets, Set<String> otherTargets) {
// NO-OP
}

@Override
public List<String> 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
}
}
28 changes: 28 additions & 0 deletions src/main/java/org/ladysnake/blabber/impl/compat/package-info.java
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses>.
*/
/**
* 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;
Original file line number Diff line number Diff line change
@@ -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<Boolean> cir) {
if (client.currentScreen instanceof BlabberDialogueScreen) {
cir.setReturnValue(true);
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses>.
*/
/**
* 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;
5 changes: 4 additions & 1 deletion src/main/resources/blabber.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b34a52a

Please sign in to comment.