Skip to content

Commit

Permalink
Each mode has a hotkey
Browse files Browse the repository at this point in the history
  • Loading branch information
flier268 committed Jul 19, 2020
1 parent 54f5eb7 commit 21d71fe
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 47 deletions.
10 changes: 9 additions & 1 deletion src/main/java/com/flier268/autoharvest/AutoHarvest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ private void setDisabled() {
listener = null;
}
}

public HarvestMode toSpecifiedMode(HarvestMode mode) {
//setDisabled();
if (listener == null) {
listener = new TickListener(3, MinecraftClient.getInstance().player);
} else
listener.Reset();
this.mode = mode;
return mode;
}
public HarvestMode toNextMode() {
//setDisabled();
if (listener == null) {
Expand Down
83 changes: 64 additions & 19 deletions src/main/java/com/flier268/autoharvest/KeyPressListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,95 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.minecraft.text.TranslatableText;
import org.lwjgl.glfw.GLFW;

public class KeyPressListener {

private KeyBinding key_Switch, key_ModeChange, key_Config;
private KeyBinding key_HARVEST, key_PLANT, key_Farmer, key_SEED, key_FEED, key_FISHING;

public KeyPressListener() {

key_ModeChange = new KeyBinding("key.autoharvest.modechange",
String categoryGeneral = new TranslatableText("key.category.general").getString();
String categorySwitchTo = new TranslatableText("key.category.switchTo").getString();
key_ModeChange = new KeyBinding("key.general.modechange",
InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_H,
AutoHarvest.MOD_NAME
categoryGeneral
);
key_Switch = new KeyBinding("key.autoharvest.switch",
key_Switch = new KeyBinding("key.general.switch",
GLFW.GLFW_KEY_J,
AutoHarvest.MOD_NAME
categoryGeneral
);
key_Config = new KeyBinding("key.autoharvest.config",
key_Config = new KeyBinding("key.general.config",
GLFW.GLFW_KEY_K,
AutoHarvest.MOD_NAME
categoryGeneral
);
key_HARVEST = new KeyBinding("harvest",
GLFW.GLFW_KEY_UNKNOWN,
categorySwitchTo
);
key_PLANT = new KeyBinding("plant",
GLFW.GLFW_KEY_UNKNOWN,
categorySwitchTo
);
key_Farmer = new KeyBinding("farmer",
GLFW.GLFW_KEY_UNKNOWN,
categorySwitchTo
);
key_SEED = new KeyBinding("seed",
GLFW.GLFW_KEY_UNKNOWN,
categorySwitchTo
);
key_FEED = new KeyBinding("feed",
GLFW.GLFW_KEY_UNKNOWN,
categorySwitchTo
);
key_FISHING = new KeyBinding("fishing",
GLFW.GLFW_KEY_UNKNOWN,
categorySwitchTo
);
KeyBindingHelper.registerKeyBinding(key_ModeChange);
KeyBindingHelper.registerKeyBinding(key_Switch);
KeyBindingHelper.registerKeyBinding(key_Config);
KeyBindingHelper.registerKeyBinding(key_HARVEST);
KeyBindingHelper.registerKeyBinding(key_PLANT);
KeyBindingHelper.registerKeyBinding(key_Farmer);
KeyBindingHelper.registerKeyBinding(key_SEED);
KeyBindingHelper.registerKeyBinding(key_FEED);
KeyBindingHelper.registerKeyBinding(key_FISHING);


ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (key_ModeChange.wasPressed())
onProcessKey(key_ModeChange);
else if (key_Switch.wasPressed())
onProcessKey(key_Switch);
else if (key_Config.wasPressed())
onProcessKey(key_Config);
onProcessKey();
});
}

public void onProcessKey(KeyBinding key) {
if (key.equals(key_ModeChange)) {
String modeName = AutoHarvest.instance.toNextMode().toString().toLowerCase();
AutoHarvest.msg("notify.switch_to." + modeName);
} else if (key.equals(key_Switch)) {
public void onProcessKey() {
if (key_Switch.wasPressed()) {
AutoHarvest.instance.Switch = !AutoHarvest.instance.Switch;
AutoHarvest.msg("notify.turn." + (AutoHarvest.instance.Switch ? "on" : "off"));
} else if (key.equals(key_Config)) {
} else if (key_Config.wasPressed()) {
MinecraftClient.getInstance().openScreen(ClothConfig.openConfigScreen(MinecraftClient.getInstance().currentScreen));
} else {
String modeName = null;
if (key_ModeChange.wasPressed()) {
modeName = AutoHarvest.instance.toNextMode().toString().toLowerCase();
} else if (key_HARVEST.wasPressed()) {
modeName = AutoHarvest.instance.toSpecifiedMode(AutoHarvest.HarvestMode.HARVEST).toString().toLowerCase();
} else if (key_PLANT.wasPressed()) {
modeName = AutoHarvest.instance.toSpecifiedMode(AutoHarvest.HarvestMode.PLANT).toString().toLowerCase();
} else if (key_Farmer.wasPressed()) {
modeName = AutoHarvest.instance.toSpecifiedMode(AutoHarvest.HarvestMode.Farmer).toString().toLowerCase();
} else if (key_SEED.wasPressed()) {
modeName = AutoHarvest.instance.toSpecifiedMode(AutoHarvest.HarvestMode.SEED).toString().toLowerCase();
} else if (key_FEED.wasPressed()) {
modeName = AutoHarvest.instance.toSpecifiedMode(AutoHarvest.HarvestMode.FEED).toString().toLowerCase();
} else if (key_FISHING.wasPressed()) {
modeName = AutoHarvest.instance.toSpecifiedMode(AutoHarvest.HarvestMode.FISHING).toString().toLowerCase();
}
if (modeName != null)
AutoHarvest.msg("notify.switch_to", new TranslatableText(modeName).getString());
}
}
}
21 changes: 12 additions & 9 deletions src/main/resources/assets/autoharvest/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"key.autoharvest.switch":"AutoHarvest Switch",
"key.autoharvest.modechange":"Switch AutoHarvest Mode",
"key.autoharvest.config":"Config GUI",
"key.category.general": "[AutoHarvest] General",
"key.category.switchTo": "[AutoHarvest] Switch to",
"key.general.switch":"AutoHarvest Switch",
"key.general.modechange":"Switch AutoHarvest Mode",
"key.general.config":"Config GUI",
"notify.turn.on": "AutoHarvest turned on",
"notify.turn.off": "AutoHarvest turned off",
"notify.switch_to.harvest":"Switch to: Harvest",
"notify.switch_to.plant":"Switch to: Plant",
"notify.switch_to.farmer":"Switch to: Farmer",
"notify.switch_to.seed":"Switch to: Seed",
"notify.switch_to.feed":"Switch to: Feed",
"notify.switch_to.fishing":"Switch to: Fishing",
"harvest": "Harvest mode",
"plant": "Plant mode",
"farmer": "Farmer mode",
"seed": "Seed mode",
"feed": "Feed mode",
"fishing": "Fishing mode",
"notify.switch_to":"Switch to: %s",
"notify.lack_of_seed":"You need more seeds",
"notify.prefix":"[AutoHarvest]",
"notify.tick_error":"Internal Error Happened",
Expand Down
21 changes: 12 additions & 9 deletions src/main/resources/assets/autoharvest/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"key.switch":"切换自动收割启动/停止",
"key.modechange":"切换自动收割状态",
"key.config":"设置",
"key.category.general": "[自动收割] 一般",
"key.category.switchTo": "[自动收割] 切换模式",
"key.general.switch":"切换 启动/停止",
"key.general.modechange":"切换模式",
"key.general.config":"设定",
"notify.turn.on": "自动收割已启动",
"notify.turn.off": "自动收割已停止",
"notify.switch_to.harvest":"已切换到 收割 模式",
"notify.switch_to.plant":"已切换到 种植 模式",
"notify.switch_to.farmer":"已切换到 农夫 模式",
"notify.switch_to.seed":"已切换到 除草 模式",
"notify.switch_to.feed":"已切换到 喂食 模式",
"notify.switch_to.fishing":"已切换到 钓鱼 模式",
"harvest": "收割 模式",
"plant": "种植 模式",
"farmer": "农夫 模式",
"seed": "除草 模式",
"feed": "喂食 模式",
"fishing": "钓鱼 模式",
"notify.switch_to":"已切换到 %s",
"notify.lack_of_seed":"缺少种子",
"notify.prefix":"[自动收割]",
"notify.tick_error":"发生错误",
Expand Down
21 changes: 12 additions & 9 deletions src/main/resources/assets/autoharvest/lang/zh_tw.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
{
"key.autoharvest.switch":"切換自動收割啟動/停止",
"key.autoharvest.modechange":"切換自動收割狀態",
"key.autoharvest.config":"設定",
"key.category.general": "[自動收割] 一般",
"key.category.switchTo": "[自動收割] 切換模式",
"key.general.switch":"切換 啟動/停止",
"key.general.modechange":"切換模式",
"key.general.config":"設定",
"notify.turn.on": "自動收割已啟動",
"notify.turn.off": "自動收割已停止",
"notify.switch_to.harvest":"已切換到 收割 模式",
"notify.switch_to.plant":"已切換到 種植 模式",
"notify.switch_to.farmer":"已切換到 農夫 模式",
"notify.switch_to.seed":"已切換到 除草 模式",
"notify.switch_to.feed":"已切換到 餵食 模式",
"notify.switch_to.fishing":"已切換到 釣魚 模式",
"harvest": "收割 模式",
"plant": "種植 模式",
"farmer": "農夫 模式",
"seed": "除草 模式",
"feed": "餵食 模式",
"fishing": "釣魚 模式",
"notify.switch_to":"已切換到 %s",
"notify.lack_of_seed":"缺少種子",
"notify.prefix":"[自動收割]",
"notify.tick_error":"發生錯誤",
Expand Down

0 comments on commit 21d71fe

Please sign in to comment.