package dev.lumareth.improvedAerodynamics.client; import com.mojang.blaze3d.platform.InputConstants; import dev.lumareth.improvedAerodynamics.ImprovedAerodynamics; import dev.lumareth.improvedAerodynamics.network.Network; import dev.lumareth.improvedAerodynamics.network.ToggleAutoTrimPacket; import net.minecraft.client.KeyMapping; import net.minecraft.client.Minecraft; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.RegisterKeyMappingsEvent; import net.minecraftforge.client.settings.KeyConflictContext; import net.minecraftforge.event.TickEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; import org.lwjgl.glfw.GLFW; public final class KeyBindings { public static final KeyMapping TOGGLE_AUTO_TRIM = new KeyMapping("key.improved_aerodynamics.toggle_auto_trim", KeyConflictContext.IN_GAME, InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_J, "key.categories.improved_aerodynamics"); private KeyBindings() { } @Mod.EventBusSubscriber(modid = ImprovedAerodynamics.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD) public static final class Registration { private Registration() { } @SubscribeEvent public static void onRegisterKeyMappings(RegisterKeyMappingsEvent event) { event.register(TOGGLE_AUTO_TRIM); } } @Mod.EventBusSubscriber(modid = ImprovedAerodynamics.MOD_ID, value = Dist.CLIENT) public static final class Handler { private Handler() { } @SubscribeEvent public static void onClientTick(TickEvent.ClientTickEvent event) { if (event.phase != TickEvent.Phase.END) { return; } Minecraft minecraft = Minecraft.getInstance(); while (TOGGLE_AUTO_TRIM.consumeClick()) { // Only while seated, and only if the server has this mod too if (minecraft.player != null && minecraft.player.getVehicle() != null && minecraft.getConnection() != null && Network.CHANNEL.isRemotePresent(minecraft.getConnection().getConnection())) { Network.CHANNEL.sendToServer(new ToggleAutoTrimPacket()); } } } } }