mirror of
https://github.com/TheWhiteDog9487/WhoProvideThisKeybind.git
synced 2026-09-16 23:10:28 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1593b3f86f | |||
| dc2b661d51 | |||
| 2882def6bc | |||
| 3de1313f9d | |||
| 106f531f0b | |||
| 16b1a01255 | |||
| 6f0f58a715 | |||
| bce136188a | |||
| 863bcfd0e2 | |||
| e0af7c05eb |
@@ -38,3 +38,6 @@ hs_err_*.log
|
||||
replay_*.log
|
||||
*.hprof
|
||||
*.jfr
|
||||
|
||||
# kotlin
|
||||
.kotlin
|
||||
+2
-2
@@ -20,8 +20,8 @@ Display hover text on the keybind modification button to show which mod provides
|
||||
|
||||
By default, to avoid disturbing users, information that is not useful to ordinary players is not shown.
|
||||
If you need it, you can enable additional features in the config screen.
|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
# Important Notes
|
||||
**This mod cannot guarantee 100% accuracy!**
|
||||
|
||||
@@ -52,6 +52,16 @@ dependencies {
|
||||
implementation("maven.modrinth:fuuu3xnx:bvFby61J")
|
||||
// https://modrinth.com/mod/controlling/versions?l=fabric
|
||||
implementation("maven.modrinth:xv94TkTM:rAp2jljs")
|
||||
// https://modrinth.com/mod/notenoughcrashes/versions?l=fabric
|
||||
implementation("maven.modrinth:yM94ont6:3oHxOFPT")
|
||||
// https://modrinth.com/mod/scoreboard-overhaul/versions
|
||||
implementation("maven.modrinth:2YIQkF2v:HI1qkixZ")
|
||||
// https://modrinth.com/plugin/plasmo-voice/versions?l=fabric
|
||||
implementation("maven.modrinth:1bZhdhsH:I0T9OQcy")
|
||||
// https://modrinth.com/mod/first-person-model/versions?l=fabric
|
||||
implementation("maven.modrinth:H5XMjpHi:6sgz2HEq")
|
||||
// https://modrinth.com/mod/entityculling/versions?l=fabric
|
||||
implementation("maven.modrinth:NNAgCjsB:iiF6U3Ne")
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ loom_version=1.17-SNAPSHOT
|
||||
fabric_kotlin_version=1.13.13+kotlin.2.4.10
|
||||
|
||||
# Mod Properties
|
||||
version=1.0.0
|
||||
version=1.2.0
|
||||
group=xyz.thewhitedog9487
|
||||
|
||||
OutputFileBasename=WhoProvideThisKeybind
|
||||
|
||||
@@ -3,13 +3,9 @@ package xyz.thewhitedog9487.client.mixin;
|
||||
import xyz.thewhitedog9487.client.MiscellaneousKt;
|
||||
import xyz.thewhitedog9487.client.SettingsKt;
|
||||
import xyz.thewhitedog9487.client.WhoProvideThisKeybindModClient;
|
||||
import xyz.thewhitedog9487.client.ModInfo;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import net.minecraft.client.gui.components.Button;
|
||||
import net.minecraft.client.gui.components.Tooltip;
|
||||
import net.minecraft.client.gui.screens.options.controls.KeyBindsList;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package xyz.thewhitedog9487.client.mixin;
|
||||
|
||||
import com.mojang.blaze3d.platform.InputConstants;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
import net.minecraft.client.KeyMapping;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
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.callback.CallbackInfo;
|
||||
import xyz.thewhitedog9487.client.MiscellaneousKt;
|
||||
import xyz.thewhitedog9487.client.ModInfo;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(KeyMapping.class)
|
||||
public class KeyMappingMixin {
|
||||
@Inject(method = "<init>(Ljava/lang/String;Lcom/mojang/blaze3d/platform/InputConstants$Type;ILnet/minecraft/client/KeyMapping$Category;I)V",
|
||||
at = @At("TAIL"))
|
||||
void DiscoverStackTrace(String name, InputConstants.Type type, int value, KeyMapping.Category category, int order, CallbackInfo ci) {
|
||||
var StackTraceCLassNames = Arrays.stream(Thread.currentThread().getStackTrace())
|
||||
.map(StackTraceElement::getClassName)
|
||||
.toList();
|
||||
for (String ClassName : StackTraceCLassNames) {
|
||||
if (IsFrameworkClass(ClassName)) continue;
|
||||
for (String PartOfClassName : ClassName.split("\\.")) {
|
||||
Optional<ModContainer> CandidateModContainer = FabricLoader.getInstance().getModContainer(PartOfClassName);
|
||||
if (CandidateModContainer.isPresent() && CandidateModContainer.get() != MiscellaneousKt.getVanillaMinecraftContainer()) {
|
||||
var ModInfo = new ModInfo(CandidateModContainer.get());
|
||||
MiscellaneousKt.getKeyMappingToMod().put((KeyMapping) (Object) this, ModInfo);
|
||||
return; } } } }
|
||||
|
||||
@Unique
|
||||
boolean IsFrameworkClass(@NotNull String ClassName) {
|
||||
return ClassName.startsWith("java.")
|
||||
|| ClassName.startsWith("jdk.")
|
||||
|| ClassName.startsWith("sun.")
|
||||
|| ClassName.startsWith("com.sun.")
|
||||
|| ClassName.startsWith("kotlin.")
|
||||
|| ClassName.startsWith("net.minecraft")
|
||||
|| ClassName.startsWith("net.fabricmc")
|
||||
|| ClassName.startsWith("org.spongepowered."); } }
|
||||
@@ -7,29 +7,38 @@ import net.minecraft.client.KeyMapping
|
||||
import net.minecraft.client.gui.components.Button
|
||||
import net.minecraft.client.gui.components.Tooltip
|
||||
import net.minecraft.network.chat.Component
|
||||
import kotlin.io.path.pathString
|
||||
|
||||
val VanillaMinecraftContainer: ModContainer = FabricLoader
|
||||
.getInstance()
|
||||
.getModContainer("minecraft")
|
||||
.get()
|
||||
|
||||
val KeyMappingToMod: HashMap<KeyMapping, ModInfo> = HashMap()
|
||||
|
||||
val KeyMapping.Provider: ModInfo get() {
|
||||
val KeyBindTranslationKey = name
|
||||
val CandidateModIds = KeyBindTranslationKey.split(".")
|
||||
if (CandidateModIds.size == 1){
|
||||
WhoProvideThisKeybindModClient.ClientLogger.warn("这是个什么东西,按键绑定ID只有一个部分,ID: $KeyBindTranslationKey")
|
||||
return ModInfo(null) }
|
||||
for (CandidateModId in CandidateModIds) {
|
||||
val ModContainer = FabricLoader.getInstance().getModContainer(CandidateModId)
|
||||
if (ModContainer.isPresent) {
|
||||
return ModContainer.map(::ModInfo).get() } }
|
||||
KeyMappingToMod[this]?.let { return it }
|
||||
if (CandidateModIds.size == 1){
|
||||
return ModInfo(null) }
|
||||
return ModInfo(VanillaMinecraftContainer) }
|
||||
|
||||
data class ModInfo(val ModContainerInstance: ModContainer?) {
|
||||
val ID: String = ModContainerInstance?.metadata?.id ?: Component.translatable("special_provider_UNKNOWN").string
|
||||
val ID: String = ModContainerInstance?.metadata?.id ?: Component.translatable("special_string_UNKNOWN").string
|
||||
val MetaData: ModMetadata? = ModContainerInstance?.metadata
|
||||
val DisplayName: String = MetaData?.name ?: Component.translatable("special_provider_UNKNOWN").string
|
||||
val HumanFriendlyName: Component = Component.translatableWithFallback("modmenu.nameTranslation." + (MetaData?.id ?: "unknown"), DisplayName) }
|
||||
val DisplayName: String = MetaData?.name ?: Component.translatable("special_string_UNKNOWN").string
|
||||
val HumanFriendlyName: Component = Component.translatableWithFallback("modmenu.nameTranslation." + (MetaData?.id ?: "unknown"), DisplayName)
|
||||
val FilePath: String get() {
|
||||
val ModOrigin = ModContainerInstance?.origin
|
||||
return try {
|
||||
ModOrigin?.paths?.joinToString("\n") { it.pathString } ?: Component.translatable("special_string_UNKNOWN").string }
|
||||
catch (_: UnsupportedOperationException) {
|
||||
Component.translatable("special_string_UNKNOWN").string } } }
|
||||
|
||||
fun Button.SetNewTooltip(Key: KeyMapping) {
|
||||
if (SettingsInstance.ModEnabled == false) return
|
||||
@@ -57,4 +66,9 @@ fun Button.SetNewTooltip(Key: KeyMapping) {
|
||||
.append(Component.translatable("tooltip.key_id",
|
||||
Component.literal(Key.name))) }
|
||||
|
||||
// 第四行:文件路径
|
||||
if (SettingsInstance.ShowFilePath) {
|
||||
NewTooltip.append(Component.literal("\n"))
|
||||
.append(Component.translatable("tooltip.mod_file_path", Mod.FilePath)) }
|
||||
|
||||
setTooltip(Tooltip.create(NewTooltip)) }
|
||||
@@ -18,29 +18,44 @@ class ModMenuEntryPoint: ModMenuApi {
|
||||
.name(Component.translatable("config.category.general"))
|
||||
.option {
|
||||
Option.createBuilder<Boolean>()
|
||||
.name(Component.translatable("option.ModEnabled"))
|
||||
.description { OptionDescription.of(Component.translatable("option.ModEnabled.description") ) }
|
||||
.name(Component.translatable("option.general.ModEnabled"))
|
||||
.description { OptionDescription.of(Component.translatable("option.general.ModEnabled.description") ) }
|
||||
.binding( true, { SettingsInstance.ModEnabled }, { SettingsInstance.ModEnabled = it } )
|
||||
.controller(BooleanControllerBuilder::create )
|
||||
.build() }
|
||||
.build() }
|
||||
.category {
|
||||
ConfigCategory.createBuilder()
|
||||
.name(Component.translatable("config.category.feature"))
|
||||
.option {
|
||||
Option.createBuilder<Boolean>()
|
||||
.name(Component.translatable("option.ShowModID"))
|
||||
.description { OptionDescription.of(Component.translatable("option.ShowModID.description") ) }
|
||||
.name(Component.translatable("option.feature.ShowModID"))
|
||||
.description { OptionDescription.of(Component.translatable("option.feature.ShowModID.description") ) }
|
||||
.binding( false, { SettingsInstance.ShowModID }, { SettingsInstance.ShowModID = it } )
|
||||
.controller(BooleanControllerBuilder::create )
|
||||
.build() }
|
||||
.option {
|
||||
Option.createBuilder<Boolean>()
|
||||
.name(Component.translatable("option.ShowKeybindID"))
|
||||
.description { OptionDescription.of(Component.translatable("option.ShowKeybindID.description") ) }
|
||||
.name(Component.translatable("option.feature.ShowKeybindID"))
|
||||
.description { OptionDescription.of(Component.translatable("option.feature.ShowKeybindID.description") ) }
|
||||
.binding( false, { SettingsInstance.ShowKeybindID }, { SettingsInstance.ShowKeybindID = it } )
|
||||
.controller(BooleanControllerBuilder::create )
|
||||
.build() }
|
||||
.option {
|
||||
Option.createBuilder<Boolean>()
|
||||
.name(Component.translatable("option.ShowDebugInfo"))
|
||||
.description { OptionDescription.of(Component.translatable("option.ShowDebugInfo.description") ) }
|
||||
.name(Component.translatable("option.feature.ShowFilePath"))
|
||||
.description { OptionDescription.of(Component.translatable("option.feature.ShowFilePath.description") ) }
|
||||
.binding( false, { SettingsInstance.ShowFilePath }, { SettingsInstance.ShowFilePath = it } )
|
||||
.controller(BooleanControllerBuilder::create )
|
||||
.build() }
|
||||
.build() }
|
||||
.category {
|
||||
ConfigCategory.createBuilder()
|
||||
.name(Component.translatable("config.category.debug"))
|
||||
.option {
|
||||
Option.createBuilder<Boolean>()
|
||||
.name(Component.translatable("option.debug.ShowDebugInfo"))
|
||||
.description { OptionDescription.of(Component.translatable("option.debug.ShowDebugInfo.description") ) }
|
||||
.binding( false, { SettingsInstance.ShowDebugInfo }, { SettingsInstance.ShowDebugInfo = it } )
|
||||
.controller(BooleanControllerBuilder::create )
|
||||
.build() }
|
||||
|
||||
@@ -7,9 +7,12 @@ import net.fabricmc.loader.api.FabricLoader
|
||||
import java.nio.file.FileSystems
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardWatchEventKinds
|
||||
import java.nio.file.StandardWatchEventKinds.*
|
||||
|
||||
const val CurrentConfigurationVersionCode: Long = 0
|
||||
|
||||
/**
|
||||
* @see ModMenuEntryPoint\
|
||||
*/
|
||||
class Settings {
|
||||
@SerialEntry(comment =
|
||||
"""
|
||||
@@ -57,11 +60,20 @@ class Settings {
|
||||
取值范围:true false
|
||||
默认值:false
|
||||
""")
|
||||
var ShowDebugInfo = false }
|
||||
var ShowDebugInfo = false
|
||||
|
||||
@SerialEntry(comment =
|
||||
"""
|
||||
是否在悬停信息中显示Mod的文件路径
|
||||
类型:布尔值
|
||||
取值范围:true false
|
||||
默认值:false
|
||||
""")
|
||||
var ShowFilePath = false }
|
||||
|
||||
var SettingsHandler: ConfigClassHandler<Settings>? = null
|
||||
|
||||
val ConfigFilePath = FabricLoader
|
||||
val ConfigFilePath: Path = FabricLoader
|
||||
.getInstance()
|
||||
.configDir
|
||||
.resolve(WhoProvideThisKeybindModClient.FriendlyModID + ".json5")
|
||||
@@ -77,7 +89,7 @@ fun RegisterConfigFileReloadWatcher() {
|
||||
val ConfigDirectory = ConfigFilePath.parent
|
||||
try {
|
||||
val WatchService = FileSystems.getDefault().newWatchService()
|
||||
ConfigDirectory.register(WatchService, ENTRY_CREATE, ENTRY_MODIFY, ENTRY_DELETE)
|
||||
ConfigDirectory.register(WatchService, StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY, StandardWatchEventKinds.ENTRY_DELETE)
|
||||
while (!Thread.currentThread().isInterrupted) {
|
||||
val WatchKey = WatchService.take()
|
||||
var ShouldReload = false
|
||||
@@ -95,7 +107,7 @@ fun RegisterConfigFileReloadWatcher() {
|
||||
WhoProvideThisKeybindModClient.ClientLogger.info("检测到配置文件变更,已重新加载设置。") }
|
||||
if (!WatchKey.reset()) {
|
||||
break } }
|
||||
} catch (e: InterruptedException) {
|
||||
} catch (_: InterruptedException) {
|
||||
Thread.currentThread().interrupt()
|
||||
} catch (e: IOException) {
|
||||
throw RuntimeException(e) } } }
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package xyz.thewhitedog9487.client
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import xyz.thewhitedog9487.client.Event.RegisterClientLifecycleEvents
|
||||
|
||||
object WhoProvideThisKeybindModClient : ClientModInitializer {
|
||||
const val ModID: String = "whoprovidethiskeybind"
|
||||
const val FriendlyModID = "WhoProvideThisKeybind"
|
||||
val ClientLogger = LoggerFactory.getLogger(FriendlyModID)
|
||||
val ClientLogger: Logger = LoggerFactory.getLogger(FriendlyModID)
|
||||
|
||||
override fun onInitializeClient() {
|
||||
RegisterClientLifecycleEvents() } }
|
||||
@@ -3,7 +3,8 @@
|
||||
"package": "xyz.thewhitedog9487.client.mixin",
|
||||
"compatibilityLevel": "JAVA_25",
|
||||
"client": [
|
||||
"KeyBindsListKeyEntryMixin"
|
||||
"KeyBindsListKeyEntryMixin",
|
||||
"KeyMappingMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -5,16 +5,21 @@
|
||||
"link.blog": "TheWhiteDog9487's Blog",
|
||||
"title.config": "Who Provides This Keybind?",
|
||||
"config.category.general": "General",
|
||||
"option.ModEnabled": "Enable Mod Functionality",
|
||||
"option.ModEnabled.description": "Changes take effect immediately after modification and save without restarting the game",
|
||||
"option.ShowModID": "Show Mod ID",
|
||||
"option.ShowModID.description": "Display the Mod ID of the provider in the tooltip",
|
||||
"option.ShowKeybindID": "Show Keybind ID",
|
||||
"option.ShowKeybindID.description": "Display the keybind's own ID in the tooltip",
|
||||
"option.ShowDebugInfo": "Show Debug Info",
|
||||
"option.ShowDebugInfo.description": "This information is used to troubleshoot issues related to this mod; it generally does not need to be enabled",
|
||||
"config.category.feature": "Feature",
|
||||
"config.category.debug": "Debug",
|
||||
"option.general.ModEnabled": "Enable Mod Functionality",
|
||||
"option.general.ModEnabled.description": "Changes take effect immediately after modification and save without restarting the game",
|
||||
"option.feature.ShowModID": "Show Mod ID",
|
||||
"option.feature.ShowModID.description": "Display the Mod ID of the provider in the tooltip",
|
||||
"option.feature.ShowKeybindID": "Show Keybind ID",
|
||||
"option.feature.ShowKeybindID.description": "Display the keybind's own ID in the tooltip",
|
||||
"option.feature.ShowFilePath": "Show File Path",
|
||||
"option.feature.ShowFilePath.description": "Display the mod file path in the information",
|
||||
"option.debug.ShowDebugInfo": "Show Debug Info",
|
||||
"option.debug.ShowDebugInfo.description": "This information is used to troubleshoot issues related to this mod; it generally does not need to be enabled",
|
||||
"tooltip.provided_by": "Provided by: %s",
|
||||
"tooltip.provider_mod_id": "Provider Mod ID: %s",
|
||||
"tooltip.key_id": "Keybind ID: %s",
|
||||
"special_provider_UNKNOWN": "Unknown"
|
||||
"tooltip.mod_file_path": "Mod File Path: %s",
|
||||
"special_string_UNKNOWN": "Unknown"
|
||||
}
|
||||
|
||||
@@ -5,16 +5,21 @@
|
||||
"link.blog": "TheWhiteDog9487的博客",
|
||||
"title.config": "谁在提供这个键位?",
|
||||
"config.category.general": "通用",
|
||||
"option.ModEnabled": "是否启用模组功能",
|
||||
"option.ModEnabled.description": "无需重启游戏,修改并保存后立刻生效",
|
||||
"option.ShowModID": "是否显示Mod ID",
|
||||
"option.ShowModID.description": "在提示信息中显示提供该按键的Mod的ID",
|
||||
"option.ShowKeybindID": "是否显示键位ID",
|
||||
"option.ShowKeybindID.description": "在提示信息中显示该按键本身的ID",
|
||||
"option.ShowDebugInfo": "是否显示调试信息",
|
||||
"option.ShowDebugInfo.description": "这些信息用于出现和本Mod相关的问题时进行排查,一般情况下不需要开启",
|
||||
"config.category.feature": "功能",
|
||||
"config.category.debug": "调试",
|
||||
"option.general.ModEnabled": "是否启用模组功能",
|
||||
"option.general.ModEnabled.description": "无需重启游戏,修改并保存后立刻生效",
|
||||
"option.feature.ShowModID": "是否显示Mod ID",
|
||||
"option.feature.ShowModID.description": "在提示信息中显示提供该按键的Mod的ID",
|
||||
"option.feature.ShowKeybindID": "是否显示键位ID",
|
||||
"option.feature.ShowKeybindID.description": "在提示信息中显示该按键本身的ID",
|
||||
"option.feature.ShowFilePath": "是否显示文件路径",
|
||||
"option.feature.ShowFilePath.description": "在信息中显示Mod的文件路径",
|
||||
"option.debug.ShowDebugInfo": "是否显示调试信息",
|
||||
"option.debug.ShowDebugInfo.description": "这些信息用于出现和本Mod相关的问题时进行排查,一般情况下不需要开启",
|
||||
"tooltip.provided_by": "提供者:%s",
|
||||
"tooltip.provider_mod_id": "提供者ID:%s",
|
||||
"tooltip.key_id": "键位ID:%s",
|
||||
"special_provider_UNKNOWN": "未知"
|
||||
"tooltip.mod_file_path": "Mod文件路径:%s",
|
||||
"special_string_UNKNOWN": "未知"
|
||||
}
|
||||
Reference in New Issue
Block a user