aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/thatgravyboat/skyblockhud/mixins/MixinNetHandlerPlayClient.java
blob: e5c1aa05ab64209746d49968597e1c35261ba9ad (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
package com.thatgravyboat.skyblockhud.mixins;

import net.minecraft.client.network.NetHandlerPlayClient;
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 {

    /* DISABLE UNTIL NEW SYSTEM
    @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 eId = null;
                        int eLvl = -1;
                        if (extraAttributes.hasKey("enchantments")) {
                            NBTTagCompound enchantments = extraAttributes.getCompoundTag("enchantments");
                            if (enchantments.getKeySet().size() == 1) {
                                for (String e : enchantments.getKeySet()) { eId = e; break; }
                                if (eId != null) eLvl = enchantments.getInteger(eId);
                            }
                        }
                        TrackerHandler.onItemAdded(id, changeAmount, eId, eLvl);
                    }
                }
            }
        }
    }
     */

    @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){
        if (scoreplayerteam == null) ci.cancel();
    }

}