🧹 cleanup: 清理代码

This commit is contained in:
TheWhiteDog9487
2026-09-15 11:39:18 +08:00
parent bce136188a
commit 6f0f58a715
4 changed files with 6 additions and 19 deletions
@@ -3,13 +3,9 @@ package xyz.thewhitedog9487.client.mixin;
import xyz.thewhitedog9487.client.MiscellaneousKt; import xyz.thewhitedog9487.client.MiscellaneousKt;
import xyz.thewhitedog9487.client.SettingsKt; import xyz.thewhitedog9487.client.SettingsKt;
import xyz.thewhitedog9487.client.WhoProvideThisKeybindModClient; import xyz.thewhitedog9487.client.WhoProvideThisKeybindModClient;
import xyz.thewhitedog9487.client.ModInfo;
import net.minecraft.client.KeyMapping; import net.minecraft.client.KeyMapping;
import net.minecraft.client.gui.components.Button; 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.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.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@@ -10,26 +10,17 @@ import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.include.com.google.common.io.Files;
import xyz.thewhitedog9487.client.MiscellaneousKt; import xyz.thewhitedog9487.client.MiscellaneousKt;
import xyz.thewhitedog9487.client.ModInfo; import xyz.thewhitedog9487.client.ModInfo;
import xyz.thewhitedog9487.client.WhoProvideThisKeybindModClient;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import java.util.function.Function;
@Mixin(KeyMapping.class) @Mixin(KeyMapping.class)
public class KeyMappingMixin { public class KeyMappingMixin {
@Inject(method = "<init>(Ljava/lang/String;Lcom/mojang/blaze3d/platform/InputConstants$Type;ILnet/minecraft/client/KeyMapping$Category;I)V", @Inject(method = "<init>(Ljava/lang/String;Lcom/mojang/blaze3d/platform/InputConstants$Type;ILnet/minecraft/client/KeyMapping$Category;I)V",
at = @At("TAIL")) at = @At("TAIL"))
void DiscoverStackTrace(String name, InputConstants.Type type, int value, KeyMapping.Category category, int order, CallbackInfo ci) throws IOException, ClassNotFoundException { void DiscoverStackTrace(String name, InputConstants.Type type, int value, KeyMapping.Category category, int order, CallbackInfo ci) {
var StackTraceCLassNames = Arrays.stream(Thread.currentThread().getStackTrace()) var StackTraceCLassNames = Arrays.stream(Thread.currentThread().getStackTrace())
.map(StackTraceElement::getClassName) .map(StackTraceElement::getClassName)
.toList(); .toList();
@@ -7,7 +7,6 @@ import net.fabricmc.loader.api.FabricLoader
import java.nio.file.FileSystems import java.nio.file.FileSystems
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.StandardWatchEventKinds import java.nio.file.StandardWatchEventKinds
import java.nio.file.StandardWatchEventKinds.*
const val CurrentConfigurationVersionCode: Long = 0 const val CurrentConfigurationVersionCode: Long = 0
class Settings { class Settings {
@@ -80,7 +79,7 @@ class Settings {
var SettingsHandler: ConfigClassHandler<Settings>? = null var SettingsHandler: ConfigClassHandler<Settings>? = null
val ConfigFilePath = FabricLoader val ConfigFilePath: Path = FabricLoader
.getInstance() .getInstance()
.configDir .configDir
.resolve(WhoProvideThisKeybindModClient.FriendlyModID + ".json5") .resolve(WhoProvideThisKeybindModClient.FriendlyModID + ".json5")
@@ -96,7 +95,7 @@ fun RegisterConfigFileReloadWatcher() {
val ConfigDirectory = ConfigFilePath.parent val ConfigDirectory = ConfigFilePath.parent
try { try {
val WatchService = FileSystems.getDefault().newWatchService() 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) { while (!Thread.currentThread().isInterrupted) {
val WatchKey = WatchService.take() val WatchKey = WatchService.take()
var ShouldReload = false var ShouldReload = false
@@ -114,7 +113,7 @@ fun RegisterConfigFileReloadWatcher() {
WhoProvideThisKeybindModClient.ClientLogger.info("检测到配置文件变更,已重新加载设置。") } WhoProvideThisKeybindModClient.ClientLogger.info("检测到配置文件变更,已重新加载设置。") }
if (!WatchKey.reset()) { if (!WatchKey.reset()) {
break } } break } }
} catch (e: InterruptedException) { } catch (_: InterruptedException) {
Thread.currentThread().interrupt() Thread.currentThread().interrupt()
} catch (e: IOException) { } catch (e: IOException) {
throw RuntimeException(e) } } } throw RuntimeException(e) } } }
@@ -1,13 +1,14 @@
package xyz.thewhitedog9487.client package xyz.thewhitedog9487.client
import net.fabricmc.api.ClientModInitializer import net.fabricmc.api.ClientModInitializer
import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import xyz.thewhitedog9487.client.Event.RegisterClientLifecycleEvents import xyz.thewhitedog9487.client.Event.RegisterClientLifecycleEvents
object WhoProvideThisKeybindModClient : ClientModInitializer { object WhoProvideThisKeybindModClient : ClientModInitializer {
const val ModID: String = "whoprovidethiskeybind" const val ModID: String = "whoprovidethiskeybind"
const val FriendlyModID = "WhoProvideThisKeybind" const val FriendlyModID = "WhoProvideThisKeybind"
val ClientLogger = LoggerFactory.getLogger(FriendlyModID) val ClientLogger: Logger = LoggerFactory.getLogger(FriendlyModID)
override fun onInitializeClient() { override fun onInitializeClient() {
RegisterClientLifecycleEvents() } } RegisterClientLifecycleEvents() } }