Log class of sent packages

Signed-off-by: PlexSheep <PlexSheep@protonmail.com>
This commit is contained in:
Christoph J. Scherr 2023-03-30 23:12:22 +02:00 committed by PlexSheep
parent c01f439ca0
commit db354524d1
1 changed files with 25 additions and 5 deletions

View File

@ -1,17 +1,37 @@
package de.cscherr.plextool.mixin;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
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;
import org.slf4j.Logger;
import java.time.Duration;
import de.cscherr.plextool.PlexTool;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.listener.ServerPlayPacketListener;
import net.minecraft.network.packet.Packet;
import java.util.function.BooleanSupplier;
import net.minecraft.util.Identifier;
@Mixin(TitleScreen.class)
@Mixin(ClientPlayNetworkHandler.class)
public class PlexToolMixin {
@Inject(at = @At("HEAD"), method = "init()V")
private void init(CallbackInfo info) {
PlexTool.LOGGER.info("This line is printed by my mod mixin!");
// 'V' is appended because the return type is void
// see https://fabricmc.net/wiki/tutorial:mixin_injects
public final Logger PLEX_LOGGER = PlexTool.LOGGER;
public boolean log_packets = true;
@Inject(at = @At("HEAD"), method = "sendPacket()V")
// Method signature is diffrent, but thats what the mixin library wants according to its errors.
// I could not find this in the documentation.
private void sendPacket(Packet<ServerPlayPacketListener> packet, CallbackInfo callInfo) {
// this works!
// I am now logging every packet i send! Yay me!
if log_packets {
this.PLEX_LOGGER.info("Sending Packet: " + packet.toString());
}
}
}