diff --git a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java index f3b235fc1..185f1b66a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/client/ClickHandler.java @@ -277,6 +277,10 @@ public class ClickHandler { switchZoom = !switchZoom; } } + + if (key == ModKeyMappings.BREATH.getKey().getValue()) { + PacketDistributor.sendToServer(new BreathMessage(true)); + } } else { if (player.hasEffect(ModMobEffects.SHOCK)) return; @@ -291,6 +295,10 @@ public class ClickHandler { if (key == ModKeyMappings.SWITCH_ZOOM.getKey().getValue() && !switchZoom) { handleWeaponZoomRelease(); } + + if (event.getAction() == GLFW.GLFW_RELEASE && key == ModKeyMappings.BREATH.getKey().getValue()) { + PacketDistributor.sendToServer(new BreathMessage(false)); + } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/init/ModKeyMappings.java b/src/main/java/com/atsuishio/superbwarfare/init/ModKeyMappings.java index 7e89afefb..2442a5433 100644 --- a/src/main/java/com/atsuishio/superbwarfare/init/ModKeyMappings.java +++ b/src/main/java/com/atsuishio/superbwarfare/init/ModKeyMappings.java @@ -1,18 +1,14 @@ package com.atsuishio.superbwarfare.init; import com.atsuishio.superbwarfare.Mod; -import com.atsuishio.superbwarfare.network.message.send.BreathMessage; import com.mojang.blaze3d.platform.InputConstants; import net.minecraft.client.KeyMapping; -import net.minecraft.client.Minecraft; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; -import net.neoforged.neoforge.client.event.ClientTickEvent; import net.neoforged.neoforge.client.event.RegisterKeyMappingsEvent; import net.neoforged.neoforge.client.settings.KeyConflictContext; import net.neoforged.neoforge.client.settings.KeyModifier; -import net.neoforged.neoforge.network.PacketDistributor; import org.lwjgl.glfw.GLFW; @EventBusSubscriber(modid = Mod.MODID, bus = EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) @@ -24,21 +20,7 @@ public class ModKeyMappings { 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"); public static final KeyMapping DISMOUNT = new KeyMapping("key.superbwarfare.dismount", GLFW.GLFW_KEY_LEFT_ALT, "key.categories.superbwarfare"); - - public static final KeyMapping BREATH = new KeyMapping("key.superbwarfare.breath", GLFW.GLFW_KEY_LEFT_CONTROL, "key.categories.superbwarfare") { - private boolean isDownOld = false; - - @Override - public void setDown(boolean isDown) { - super.setDown(isDown); - if (isDownOld != isDown && isDown) { - PacketDistributor.sendToServer(new BreathMessage(true)); - } else if (isDownOld != isDown) { - PacketDistributor.sendToServer(new BreathMessage(false)); - } - isDownOld = isDown; - } - }; + public static final KeyMapping BREATH = new KeyMapping("key.superbwarfare.breath", GLFW.GLFW_KEY_LEFT_CONTROL, "key.categories.superbwarfare"); public static final KeyMapping CONFIG = new KeyMapping("key.superbwarfare.config", KeyConflictContext.IN_GAME, KeyModifier.ALT, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_O, "key.categories.superbwarfare"); @@ -81,14 +63,4 @@ public class ModKeyMappings { event.register(MELEE); event.register(FREE_CAMERA); } - - @EventBusSubscriber(value = Dist.CLIENT) - public static class KeyEventListener { - @SubscribeEvent - public static void onClientTick(ClientTickEvent.Pre event) { - if (Minecraft.getInstance().screen == null) { - BREATH.consumeClick(); - } - } - } }