aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/rosegoldaddons/utils/PlayerUtils.java
blob: 7411660a73a666203642594948287a28c92cef27 (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
package rosegoldaddons.utils;

import net.minecraft.client.Minecraft;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.StringUtils;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import rosegoldaddons.Main;

public class PlayerUtils {
    public static boolean pickaxeAbilityReady = false;

    public static void swingItem() {
        MovingObjectPosition movingObjectPosition = Main.mc.objectMouseOver;
        if (movingObjectPosition != null && movingObjectPosition.entityHit == null) {
            Main.mc.thePlayer.swingItem();
        }
    }

    @SubscribeEvent
    public void onWorldChange(WorldEvent.Load event) {
        pickaxeAbilityReady = false;
    }

    @SubscribeEvent
    public void chat(ClientChatReceivedEvent event) {
        try {
            String message = StringUtils.stripControlCodes(event.message.getUnformattedText());
            if (message.contains(":") || message.contains(">")) return;
            if(message.startsWith("You used your")) {
                pickaxeAbilityReady = false;
            } else if(message.endsWith("is now available!")) {
                pickaxeAbilityReady = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}