/* * This file is a part of the SteamWar software. * * Copyright (C) 2023 SteamWar.de-Serverteam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package de.steamwar.advancedscripts.mixin; import de.steamwar.advancedscripts.KeyAction; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.minecraft.client.Keyboard; import net.minecraft.client.MinecraftClient; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(Keyboard.class) public class KeyboardMixin { @Inject(method = "onKey", at = @At("HEAD")) public void sendKeyPress(long window, int key, int scancode, int action, int modifiers, CallbackInfo ci) { MinecraftClient client = ((Keyboard) (Object)this).client; if(client.currentScreen == null && action != 2) { ClientPlayNetworking.send(new KeyAction(key, (byte) action, modifiers)); } } }