优化按键方法

This commit is contained in:
17146 2024-10-21 15:00:18 +08:00
parent eecf61168a
commit d70edf6967
2 changed files with 12 additions and 40 deletions

View file

@ -167,6 +167,9 @@ public class ClickHandler {
if (key == ModKeyMappings.CONFIG.getKey().getValue()) {
handleConfigScreen(player);
}
if (key == ModKeyMappings.RELOAD.getKey().getValue()) {
ModUtils.PACKET_HANDLER.sendToServer(new ReloadMessage(0));
}
if (key == ModKeyMappings.EDIT_MODE.getKey().getValue()) {
ModUtils.PACKET_HANDLER.sendToServer(new EditModeMessage(0));
}
@ -182,6 +185,12 @@ public class ClickHandler {
if (key == ModKeyMappings.EDIT_STOCK.getKey().getValue()) {
ModUtils.PACKET_HANDLER.sendToServer(new EditMessage(3));
}
if (key == ModKeyMappings.SENSITIVITY_INCREASE.getKey().getValue()) {
ModUtils.PACKET_HANDLER.sendToServer(new SensitivityMessage(true));
}
if (key == ModKeyMappings.SENSITIVITY_REDUCE.getKey().getValue()) {
ModUtils.PACKET_HANDLER.sendToServer(new SensitivityMessage(false));
}
}
}

View file

@ -16,18 +16,7 @@ import org.lwjgl.glfw.GLFW;
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
public class ModKeyMappings {
public static final KeyMapping RELOAD = new KeyMapping("key.superbwarfare.reload", GLFW.GLFW_KEY_R, "key.categories.superbwarfare") {
private boolean isDownOld = false;
@Override
public void setDown(boolean isDown) {
super.setDown(isDown);
if (isDownOld != isDown && isDown && Minecraft.getInstance().player != null) {
ModUtils.PACKET_HANDLER.sendToServer(new ReloadMessage(0));
}
isDownOld = isDown;
}
};
public static final KeyMapping RELOAD = new KeyMapping("key.superbwarfare.reload", GLFW.GLFW_KEY_R, "key.categories.superbwarfare");
public static final KeyMapping FIRE_MODE = new KeyMapping("key.superbwarfare.fire_mode", GLFW.GLFW_KEY_N, "key.categories.superbwarfare") {
private boolean isDownOld = false;
@ -43,31 +32,8 @@ public class ModKeyMappings {
}
};
public static final KeyMapping SENSITIVITY_INCREASE = new KeyMapping("key.superbwarfare.sensitivity_increase", GLFW.GLFW_KEY_PAGE_UP, "key.categories.superbwarfare") {
private boolean isDownOld = false;
@Override
public void setDown(boolean isDown) {
super.setDown(isDown);
if (isDownOld != isDown && isDown) {
ModUtils.PACKET_HANDLER.sendToServer(new SensitivityMessage(true));
}
isDownOld = isDown;
}
};
public static final KeyMapping SENSITIVITY_REDUCE = new KeyMapping("key.superbwarfare.sensitivity_reduce", GLFW.GLFW_KEY_PAGE_DOWN, "key.categories.superbwarfare") {
private boolean isDownOld = false;
@Override
public void setDown(boolean isDown) {
super.setDown(isDown);
if (isDownOld != isDown && isDown) {
ModUtils.PACKET_HANDLER.sendToServer(new SensitivityMessage(false));
}
isDownOld = isDown;
}
};
public static final KeyMapping SENSITIVITY_INCREASE = new KeyMapping("key.superbwarfare.sensitivity_increase", GLFW.GLFW_KEY_PAGE_UP, "key.categories.superbwarfare");
public static final KeyMapping SENSITIVITY_REDUCE = new KeyMapping("key.superbwarfare.sensitivity_reduce", GLFW.GLFW_KEY_PAGE_DOWN, "key.categories.superbwarfare");
public static final KeyMapping INTERACT = new KeyMapping("key.superbwarfare.interact", GLFW.GLFW_KEY_X, "key.categories.superbwarfare") {
private boolean isDownOld = false;
@ -130,10 +96,7 @@ public class ModKeyMappings {
@SubscribeEvent
public static void onClientTick(TickEvent.ClientTickEvent event) {
if (Minecraft.getInstance().screen == null) {
RELOAD.consumeClick();
FIRE_MODE.consumeClick();
SENSITIVITY_INCREASE.consumeClick();
SENSITIVITY_REDUCE.consumeClick();
INTERACT.consumeClick();
BREATH.consumeClick();
}