From a1fd28d3f057d7bdd490c5ddfece78a06b5014e9 Mon Sep 17 00:00:00 2001 From: flier268 Date: Sun, 19 Jul 2020 11:53:20 +0800 Subject: [PATCH] Use new API --- .../com/flier268/autoharvest/Configure.java | 3 +- .../autoharvest/KeyPressListener.java | 38 +++++++++---------- .../flier268/autoharvest/Plugin/ModMenu.java | 6 +-- .../flier268/autoharvest/TickListener.java | 4 +- .../assets/autoharvest/lang/zh_cn.json | 6 +-- 5 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/flier268/autoharvest/Configure.java b/src/main/java/com/flier268/autoharvest/Configure.java index afe4113..fbad238 100644 --- a/src/main/java/com/flier268/autoharvest/Configure.java +++ b/src/main/java/com/flier268/autoharvest/Configure.java @@ -17,8 +17,7 @@ public class Configure { public Configure() { this.configFile = FabricLoader .getInstance() - .getConfigDirectory() - .toPath() + .getConfigDir() .resolve("AutoHarvest.json") .toFile(); flowerISseed = false; diff --git a/src/main/java/com/flier268/autoharvest/KeyPressListener.java b/src/main/java/com/flier268/autoharvest/KeyPressListener.java index e688dad..5ad30bb 100644 --- a/src/main/java/com/flier268/autoharvest/KeyPressListener.java +++ b/src/main/java/com/flier268/autoharvest/KeyPressListener.java @@ -1,43 +1,39 @@ package com.flier268.autoharvest; import com.flier268.autoharvest.Plugin.ClothConfig; -import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; -import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry; -import net.fabricmc.fabric.api.event.client.ClientTickCallback; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.options.KeyBinding; import net.minecraft.client.util.InputUtil; -import net.minecraft.util.Identifier; import org.lwjgl.glfw.GLFW; public class KeyPressListener { - private FabricKeyBinding key_Switch, key_ModeChange, key_Config; + private KeyBinding key_Switch, key_ModeChange, key_Config; public KeyPressListener() { - KeyBindingRegistry.INSTANCE.addCategory(AutoHarvest.MOD_NAME); - key_ModeChange = FabricKeyBinding.Builder.create( - new Identifier(AutoHarvest.MOD_NAME, "modechange"), + + key_ModeChange = new KeyBinding("key.autoharvest.modechange", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_H, AutoHarvest.MOD_NAME - ).build(); - key_Switch = FabricKeyBinding.Builder.create( - new Identifier(AutoHarvest.MOD_NAME, "switch"), + ); + key_Switch = new KeyBinding("key.autoharvest.switch", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_J, AutoHarvest.MOD_NAME - ).build(); - key_Config = FabricKeyBinding.Builder.create( - new Identifier(AutoHarvest.MOD_NAME, "config"), + ); + key_Config = new KeyBinding("key.autoharvest.config", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, AutoHarvest.MOD_NAME - ).build(); - KeyBindingRegistry.INSTANCE.register(key_ModeChange); - KeyBindingRegistry.INSTANCE.register(key_Switch); - KeyBindingRegistry.INSTANCE.register(key_Config); - ClientTickCallback.EVENT.register(e -> - { + ); + KeyBindingHelper.registerKeyBinding(key_ModeChange); + KeyBindingHelper.registerKeyBinding(key_Switch); + KeyBindingHelper.registerKeyBinding(key_Config); + + ClientTickEvents.END_CLIENT_TICK.register(client -> { if (key_ModeChange.wasPressed()) onProcessKey(key_ModeChange); else if (key_Switch.wasPressed()) @@ -47,7 +43,7 @@ else if (key_Config.wasPressed()) }); } - public void onProcessKey(FabricKeyBinding key) { + public void onProcessKey(KeyBinding key) { if (key.equals(key_ModeChange)) { String modeName = AutoHarvest.instance.toNextMode().toString().toLowerCase(); AutoHarvest.msg("notify.switch_to." + modeName); diff --git a/src/main/java/com/flier268/autoharvest/Plugin/ModMenu.java b/src/main/java/com/flier268/autoharvest/Plugin/ModMenu.java index b8c8cce..81242ea 100644 --- a/src/main/java/com/flier268/autoharvest/Plugin/ModMenu.java +++ b/src/main/java/com/flier268/autoharvest/Plugin/ModMenu.java @@ -1,10 +1,8 @@ package com.flier268.autoharvest.Plugin; import com.flier268.autoharvest.AutoHarvest; +import io.github.prospector.modmenu.api.ConfigScreenFactory; import io.github.prospector.modmenu.api.ModMenuApi; -import net.minecraft.client.gui.screen.Screen; - -import java.util.function.Function; public class ModMenu implements ModMenuApi { @Override @@ -13,7 +11,7 @@ public String getModId() { } @Override - public Function getConfigScreenFactory() { + public ConfigScreenFactory getModConfigScreenFactory() { return ClothConfig::openConfigScreen; } } diff --git a/src/main/java/com/flier268/autoharvest/TickListener.java b/src/main/java/com/flier268/autoharvest/TickListener.java index c39ff9e..70e8f70 100644 --- a/src/main/java/com/flier268/autoharvest/TickListener.java +++ b/src/main/java/com/flier268/autoharvest/TickListener.java @@ -1,6 +1,6 @@ package com.flier268.autoharvest; -import net.fabricmc.fabric.api.event.client.ClientTickCallback; +import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -33,7 +33,7 @@ public class TickListener { public TickListener(int range, ClientPlayerEntity player) { this.range = range; this.p = player; - ClientTickCallback.EVENT.register(e -> + ClientTickEvents.END_CLIENT_TICK.register(e -> { if (AutoHarvest.instance.Switch) onTick(e.player); diff --git a/src/main/resources/assets/autoharvest/lang/zh_cn.json b/src/main/resources/assets/autoharvest/lang/zh_cn.json index 529743b..59acc3d 100644 --- a/src/main/resources/assets/autoharvest/lang/zh_cn.json +++ b/src/main/resources/assets/autoharvest/lang/zh_cn.json @@ -1,7 +1,7 @@ { - "key.autoharvest.switch":"切换自动收割启动/停止", - "key.autoharvest.modechange":"切换自动收割状态", - "key.autoharvest.config":"设置", + "key.switch":"切换自动收割启动/停止", + "key.modechange":"切换自动收割状态", + "key.config":"设置", "notify.turn.on": "自动收割已启动", "notify.turn.off": "自动收割已停止", "notify.switch_to.harvest":"已切换到 收割 模式",