Skip to content

Commit

Permalink
shortened mayor keybind names
Browse files Browse the repository at this point in the history
  • Loading branch information
JR1811 committed Sep 19, 2024
1 parent d5e8d98 commit 2dddf5f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 30 deletions.
31 changes: 15 additions & 16 deletions src/main/java/io/fabricatedatelier/mayor/init/MayorKeyBindings.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
package io.fabricatedatelier.mayor.init;

import io.fabricatedatelier.mayor.util.KeyHelper;
import org.lwjgl.glfw.GLFW;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import org.lwjgl.glfw.GLFW;

@Environment(EnvType.CLIENT)
public class MayorKeyBindings {

private static final String MAYOR_CATEGORY = "key.categories.mayor";

public static final KeyBinding mayorViewBind = new KeyBinding("key.mayor.mayor_view", GLFW.GLFW_KEY_Y, MAYOR_CATEGORY);
public static final KeyBinding mayorViewSelectionBind = new KeyBinding("key.mayor.mayor_view_selection", GLFW.GLFW_KEY_U, MAYOR_CATEGORY);
public static final KeyBinding mayorView = new KeyBinding("key.mayor.mayor_view", GLFW.GLFW_KEY_Y, MAYOR_CATEGORY);
public static final KeyBinding mayorViewSelection = new KeyBinding("key.mayor.mayor_view_selection", GLFW.GLFW_KEY_U, MAYOR_CATEGORY);

public static final KeyBinding mayorRotateLeftKeyBind = new KeyBinding("key.mayor.structure_rotate_left", GLFW.GLFW_KEY_Q, MAYOR_CATEGORY);
public static final KeyBinding mayorRotateRightKeyBind = new KeyBinding("key.mayor.structure_rotate_right", GLFW.GLFW_KEY_E, MAYOR_CATEGORY);
public static final KeyBinding mayorCenterKeyBind = new KeyBinding("key.mayor.structure_center", GLFW.GLFW_KEY_R, MAYOR_CATEGORY);
public static final KeyBinding mayorUpwardKeyBind = new KeyBinding("key.mayor.structure_upward", GLFW.GLFW_KEY_PAGE_UP, MAYOR_CATEGORY);
public static final KeyBinding mayorDownwardKeyBind = new KeyBinding("key.mayor.structure_downward", GLFW.GLFW_KEY_PAGE_DOWN, MAYOR_CATEGORY);
public static final KeyBinding rotateLeft = new KeyBinding("key.mayor.structure_rotate_left", GLFW.GLFW_KEY_Q, MAYOR_CATEGORY);
public static final KeyBinding rotateRight = new KeyBinding("key.mayor.structure_rotate_right", GLFW.GLFW_KEY_E, MAYOR_CATEGORY);
public static final KeyBinding targetToCenter = new KeyBinding("key.mayor.structure_center", GLFW.GLFW_KEY_R, MAYOR_CATEGORY);
public static final KeyBinding upward = new KeyBinding("key.mayor.structure_upward", GLFW.GLFW_KEY_PAGE_UP, MAYOR_CATEGORY);
public static final KeyBinding downward = new KeyBinding("key.mayor.structure_downward", GLFW.GLFW_KEY_PAGE_DOWN, MAYOR_CATEGORY);

public static void initialize() {
KeyBindingHelper.registerKeyBinding(mayorViewBind);
KeyBindingHelper.registerKeyBinding(mayorViewSelectionBind);
KeyBindingHelper.registerKeyBinding(mayorRotateLeftKeyBind);
KeyBindingHelper.registerKeyBinding(mayorRotateRightKeyBind);
KeyBindingHelper.registerKeyBinding(mayorCenterKeyBind);
KeyBindingHelper.registerKeyBinding(mayorUpwardKeyBind);
KeyBindingHelper.registerKeyBinding(mayorDownwardKeyBind);
KeyBindingHelper.registerKeyBinding(mayorView);
KeyBindingHelper.registerKeyBinding(mayorViewSelection);
KeyBindingHelper.registerKeyBinding(rotateLeft);
KeyBindingHelper.registerKeyBinding(rotateRight);
KeyBindingHelper.registerKeyBinding(targetToCenter);
KeyBindingHelper.registerKeyBinding(upward);
KeyBindingHelper.registerKeyBinding(downward);

ClientTickEvents.END_CLIENT_TICK.register((client) -> {
KeyHelper.viewKey(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private static void onKeyPressedMixin(InputUtil.Key key, CallbackInfo info) {
MinecraftClient client = MinecraftClient.getInstance();
if (key.getCode() == 81 || key.getCode() == 69) {
if (client.player != null && ((MayorManagerAccess) client.player).getMayorManager().isInMajorView()) {
if ((key.getCode() == 81 && MayorKeyBindings.mayorRotateLeftKeyBind.isDefault()) || (key.getCode() == 69 && MayorKeyBindings.mayorRotateRightKeyBind.isDefault())) {
if ((key.getCode() == 81 && MayorKeyBindings.rotateLeft.isDefault()) || (key.getCode() == 69 && MayorKeyBindings.rotateRight.isDefault())) {
info.cancel();
}
}
Expand All @@ -43,11 +43,11 @@ private static void setKeyPressedMixin(InputUtil.Key key, boolean pressed, Callb
if (key.getCode() == 81 || key.getCode() == 69) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player != null && ((MayorManagerAccess) client.player).getMayorManager().isInMajorView()) {
if (key.getCode() == 81 && MayorKeyBindings.mayorRotateLeftKeyBind.isDefault()) {
MayorKeyBindings.mayorRotateLeftKeyBind.setPressed(pressed);
if (key.getCode() == 81 && MayorKeyBindings.rotateLeft.isDefault()) {
MayorKeyBindings.rotateLeft.setPressed(pressed);
info.cancel();
} else if (key.getCode() == 69 && MayorKeyBindings.mayorRotateRightKeyBind.isDefault()) {
MayorKeyBindings.mayorRotateRightKeyBind.setPressed(pressed);
} else if (key.getCode() == 69 && MayorKeyBindings.rotateRight.isDefault()) {
MayorKeyBindings.rotateRight.setPressed(pressed);
info.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ private void handleInputEventsMixin(CallbackInfo info) {
if (this.majorKeyBindTicks > 0) {
this.majorKeyBindTicks--;
info.cancel();
} else if (MayorKeyBindings.mayorRotateLeftKeyBind.isPressed()) {
} else if (MayorKeyBindings.rotateLeft.isPressed()) {
KeyHelper.rotateKey((MinecraftClient) (Object) this, true);
this.majorKeyBindTicks = 5;
info.cancel();
} else if (MayorKeyBindings.mayorRotateRightKeyBind.isPressed()) {
} else if (MayorKeyBindings.rotateRight.isPressed()) {
KeyHelper.rotateKey((MinecraftClient) (Object) this, false);
this.majorKeyBindTicks = 5;
info.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (MayorKeyBindings.mayorViewSelectionBind.matchesKey(keyCode, scanCode) || MayorKeyBindings.mayorViewBind.matchesKey(keyCode, scanCode)) {
if (MayorKeyBindings.mayorViewSelection.matchesKey(keyCode, scanCode) || MayorKeyBindings.mayorView.matchesKey(keyCode, scanCode)) {
this.close();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void tick() {

@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (MayorKeyBindings.mayorViewSelectionBind.matchesKey(keyCode, scanCode) || MayorKeyBindings.mayorViewBind.matchesKey(keyCode, scanCode) || this.client.options.inventoryKey.matchesKey(keyCode, scanCode)) {
if (MayorKeyBindings.mayorViewSelection.matchesKey(keyCode, scanCode) || MayorKeyBindings.mayorView.matchesKey(keyCode, scanCode) || this.client.options.inventoryKey.matchesKey(keyCode, scanCode)) {
this.client.setScreen(new MayorScreen(this.mayorManager));
return true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/fabricatedatelier/mayor/util/KeyHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void rotateKey(MinecraftClient client, boolean rotateLeft) {
}

public static void centerKey(MinecraftClient client) {
if (MayorKeyBindings.mayorCenterKeyBind.wasPressed()) {
if (MayorKeyBindings.targetToCenter.wasPressed()) {
if (client.player != null) {
MayorManager mayorManager = ((MayorManagerAccess) client.player).getMayorManager();
if (client.player != null && mayorManager.isInMajorView()) {
Expand All @@ -32,14 +32,14 @@ public static void centerKey(MinecraftClient client) {
}

public static void heightKey(MinecraftClient client) {
if (MayorKeyBindings.mayorUpwardKeyBind.wasPressed()) {
if (MayorKeyBindings.upward.wasPressed()) {
if (client.player != null) {
MayorManager mayorManager = ((MayorManagerAccess) client.player).getMayorManager();
if (client.player != null && mayorManager.isInMajorView() && mayorManager.getStructureOriginBlockPos() != null) {
mayorManager.setStructureOriginBlockPos(mayorManager.getStructureOriginBlockPos().up());
}
}
} else if (MayorKeyBindings.mayorDownwardKeyBind.wasPressed()) {
} else if (MayorKeyBindings.downward.wasPressed()) {
if (client.player != null) {
MayorManager mayorManager = ((MayorManagerAccess) client.player).getMayorManager();
if (client.player != null && mayorManager.isInMajorView() && mayorManager.getStructureOriginBlockPos() != null) {
Expand All @@ -50,12 +50,12 @@ public static void heightKey(MinecraftClient client) {
}

public static void viewKey(MinecraftClient client) {
if (MayorKeyBindings.mayorViewBind.wasPressed()) {
if (MayorKeyBindings.mayorView.wasPressed()) {
if (client.player != null) {
MayorManager mayorManager = ((MayorManagerAccess) client.player).getMayorManager();
new MayorViewPacket(!mayorManager.isInMajorView()).sendClientPacket();
}
} else if (MayorKeyBindings.mayorViewSelectionBind.wasPressed()) {
} else if (MayorKeyBindings.mayorViewSelection.wasPressed()) {
if (client.player != null) {
MayorManager mayorManager = ((MayorManagerAccess) client.player).getMayorManager();

Expand Down

0 comments on commit 2dddf5f

Please sign in to comment.