Add Copyright & Rename Package

This commit is contained in:
Chaoscaot
2023-07-17 15:55:06 +02:00
parent 2d1c320792
commit 279042b987
12 changed files with 194 additions and 95 deletions

View File

@ -0,0 +1,53 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*/
package de.steamwar.advancedscripts.mixin;
import io.netty.buffer.Unpooled;
import net.minecraft.client.Keyboard;
import net.minecraft.client.MinecraftClient;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
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 {
@Unique
private static final Identifier channel = new Identifier("sw:hotkeys");
@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) {
PacketByteBuf byteBuf = new PacketByteBuf(Unpooled.buffer());
byteBuf.writeInt(key);
byteBuf.writeByte(action);
byteBuf.writeInt(modifiers);
CustomPayloadC2SPacket customPayloadC2SPacket = new CustomPayloadC2SPacket(channel,byteBuf);
client.getNetworkHandler().sendPacket(customPayloadC2SPacket);
}
}
}