aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/moe/nea/firmament/mixins/devenv/DisableCommonPacketWarnings.java
blob: 2744fb491d0dacfbf9cbcb80e0718a59594ef73e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package moe.nea.firmament.mixins.devenv;

import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
import net.minecraft.resources.ResourceLocation;
import org.slf4j.Logger;
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.Objects;

@Mixin(ClientPacketListener.class)
public class DisableCommonPacketWarnings {

    @Inject(method = "handleUnknownCustomPayload", at = @At("HEAD"), cancellable = true)
    public void onCustomPacketError(CustomPacketPayload customPayload, CallbackInfo ci) {
        if (Objects.equals(customPayload.type(), ResourceLocation.fromNamespaceAndPath("badlion", "mods"))) {
            ci.cancel();
        }
    }

    @Redirect(method = "handleSetEntityPassengersPacket", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;)V", remap = false))
    public void onUnknownPassenger(Logger instance, String s) {
        // Ignore passenger data for unknown entities, since HyPixel just sends a lot of those.
    }

    @Redirect(method = "handleSetPlayerTeamPacket", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;[Ljava/lang/Object;)V", remap = false))
    public void onOnTeam(Logger instance, String s, Object[] objects) {
        // Ignore data for unknown teams, since HyPixel just sends a lot of invalid team data.
    }

    @Redirect(method = "handlePlayerInfoUpdate", at = @At(value = "INVOKE", target = "Lorg/slf4j/Logger;warn(Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V", remap = false))
    public void onOnPlayerList(Logger instance, String s, Object o, Object o2) {
        // Ignore invalid player info, since HyPixel just sends a lot of invalid player info
    }

}