修快捷键
This commit is contained in:
parent
ecd6e66b9e
commit
9bbac5d8a1
@ -6,7 +6,7 @@ minecraft_version=1.21.4
|
||||
yarn_mappings=1.21.4+build.8
|
||||
loader_version=0.16.10
|
||||
# Mod Properties
|
||||
mod_version=1.14.514.002
|
||||
mod_version=1.14.514.003
|
||||
maven_group=org.example1
|
||||
archives_base_name=elytraboostmod
|
||||
# Dependencies
|
||||
|
@ -7,6 +7,7 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||
import net.fabricmc.fabric.api.event.player.UseBlockCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.FireworkRocketItem;
|
||||
import net.minecraft.text.Text;
|
||||
@ -15,7 +16,7 @@ import net.minecraft.util.Hand;
|
||||
|
||||
public class ElytraBoostNotPlaceModClient implements ClientModInitializer {
|
||||
private static ModConfig config;
|
||||
private static boolean lastToggleState = true;
|
||||
private static boolean keyWasPressed = false;
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
@ -23,26 +24,34 @@ public class ElytraBoostNotPlaceModClient implements ClientModInitializer {
|
||||
AutoConfig.register(ModConfig.class, JanksonConfigSerializer::new);
|
||||
config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
|
||||
|
||||
// TODO 注册快捷键,待修复
|
||||
// KeyBindingHelper.registerKeyBinding(config.toggleKey);
|
||||
// 注册快捷键
|
||||
KeyBinding toggleKeyBinding = KeyBindingHelper.registerKeyBinding(config.toggleKey);
|
||||
|
||||
// 每tick检查快捷键
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (config.toggleKey.wasPressed()) {
|
||||
if (toggleKeyBinding.wasPressed()) {
|
||||
if (!keyWasPressed) {
|
||||
keyWasPressed = true;
|
||||
config.modEnabled = !config.modEnabled;
|
||||
|
||||
// 异步保存配置
|
||||
new Thread(() -> {
|
||||
AutoConfig.getConfigHolder(ModConfig.class).save();
|
||||
}).start();
|
||||
|
||||
// 显示通知
|
||||
if (client.player != null) {
|
||||
String status = config.modEnabled ? "§a启用" : "§c禁用";
|
||||
client.player.sendMessage(
|
||||
Text.translatable(config.modEnabled ?
|
||||
"message.elytraboostnotplace.enabled" :
|
||||
"message.elytraboostnotplace.disabled"),
|
||||
"notification.elytraboostnotplace.enabled" :
|
||||
"notification.elytraboostnotplace.disabled"),
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
keyWasPressed = false;
|
||||
}
|
||||
});
|
||||
|
||||
// 拦截右键点击方块事件
|
||||
|
@ -16,8 +16,7 @@ public class ModConfig implements ConfigData {
|
||||
public KeyBinding toggleKey = new KeyBinding(
|
||||
"key.elytraboostnotplace.toggle",
|
||||
InputUtil.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_UNKNOWN,
|
||||
GLFW.GLFW_KEY_B,
|
||||
"category.elytraboostnotplace.main"
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user