Skip to content

Commit

Permalink
Use new API
Browse files Browse the repository at this point in the history
  • Loading branch information
flier268 committed Jul 19, 2020
1 parent 36d9409 commit a1fd28d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 32 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/flier268/autoharvest/Configure.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ public class Configure {
public Configure() {
this.configFile = FabricLoader
.getInstance()
.getConfigDirectory()
.toPath()
.getConfigDir()
.resolve("AutoHarvest.json")
.toFile();
flowerISseed = false;
Expand Down
38 changes: 17 additions & 21 deletions src/main/java/com/flier268/autoharvest/KeyPressListener.java
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/flier268/autoharvest/Plugin/ModMenu.java
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,7 +11,7 @@ public String getModId() {
}

@Override
public Function<Screen, ? extends Screen> getConfigScreenFactory() {
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return ClothConfig::openConfigScreen;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/flier268/autoharvest/TickListener.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/assets/autoharvest/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -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":"已切换到 收割 模式",
Expand Down

0 comments on commit a1fd28d

Please sign in to comment.