-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix EMI appearing on dialogue screen
- Loading branch information
Showing
7 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/org/ladysnake/blabber/impl/compat/BlabberMixinPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
src/main/java/org/ladysnake/blabber/impl/compat/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
22 changes: 22 additions & 0 deletions
22
src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/EmiScreenManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/org/ladysnake/blabber/impl/mixin/compat/emi/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters