aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinNetHandlerPlayClient.java
blob: 40f33342e894e87163cfbd30b722e3e8f487a269 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.thatgravyboat.skyblockhud.mixins;

import com.thatgravyboat.skyblockhud.SkyblockHud;
import com.thatgravyboat.skyblockhud.tracker.TrackerHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.PacketThreadUtil;
import net.minecraft.network.play.server.S2FPacketSetSlot;
import net.minecraft.network.play.server.S3EPacketTeams;
import net.minecraft.scoreboard.ScorePlayerTeam;
import net.minecraft.scoreboard.Scoreboard;
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.spongepowered.asm.mixin.injection.callback.LocalCapture;

@Mixin(NetHandlerPlayClient.class)
public class MixinNetHandlerPlayClient {

    @Inject(method = "handleSetSlot", at = @At("HEAD"))
    public void onHandleSetSlot(S2FPacketSetSlot packetIn, CallbackInfo ci) {
        if (SkyblockHud.hasSkyblockScoreboard()) {
            Minecraft mc = Minecraft.getMinecraft();
            PacketThreadUtil.checkThreadAndEnqueue(packetIn, mc.getNetHandler(), mc);
            if (packetIn.func_149175_c() == 0) {
                ItemStack stack = packetIn.func_149174_e();

                if (stack != null && stack.hasTagCompound()) {
                    if (stack.getTagCompound().hasKey("ExtraAttributes")) {
                        NBTTagCompound extraAttributes = stack.getTagCompound().getCompoundTag("ExtraAttributes");
                        String id = extraAttributes.getString("id");
                        ItemStack slotStack = Minecraft.getMinecraft().thePlayer.inventoryContainer.getSlot(packetIn.func_149173_d()).getStack();
                        int changeAmount = stack.stackSize - (slotStack == null ? 0 : slotStack.stackSize);
                        String specialId = null;
                        int number = -1;
                        if (extraAttributes.hasKey("enchantments")) {
                            NBTTagCompound enchantments = extraAttributes.getCompoundTag("enchantments");
                            if (enchantments.getKeySet().size() == 1) {
                                for (String e : enchantments.getKeySet()) {
                                    specialId = e;
                                    break;
                                }
                                if (specialId != null) number = enchantments.getInteger(specialId);
                            }
                        }
                        TrackerHandler.onItemAdded(id, changeAmount, specialId, number);
                    }
                }
            }
        }
    }

    @Inject(method = "handleTeams", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/network/play/server/S3EPacketTeams;getAction()I", ordinal = 0, shift = At.Shift.BEFORE), cancellable = true)
    public void handleTeams(S3EPacketTeams packetIn, CallbackInfo ci, Scoreboard scoreboard) {
        //This stops Hypixel from being stupid and spamming our logs because they dont have different ids for things.
        if (scoreboard.getTeam(packetIn.getName()) != null && packetIn.getAction() == 0) ci.cancel();
    }

    @Inject(method = "handleTeams", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(value = "INVOKE", target = "Lnet/minecraft/network/play/server/S3EPacketTeams;getAction()I", ordinal = 6, shift = At.Shift.BEFORE), cancellable = true)
    public void handleTeamRemove(S3EPacketTeams packetIn, CallbackInfo ci, Scoreboard scoreboard, ScorePlayerTeam scoreplayerteam) {
        //This stops Hypixel from being stupid and spamming our logs because they dont have different ids for things.
        if (scoreplayerteam == null) ci.cancel();
    }
}