aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/rosegoldaddons/features/MithrilMacro.java
blob: e2645c5811349d3c5f7da94d20d068b48ffe0119 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package rosegoldaddons.features;

import net.minecraft.block.BlockHardenedClay;
import net.minecraft.block.BlockStainedGlass;
import net.minecraft.block.BlockStone;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.network.play.client.C07PacketPlayerDigging;
import net.minecraft.util.*;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import rosegoldaddons.Main;
import rosegoldaddons.utils.*;

import java.awt.*;
import java.util.ArrayList;
import java.util.Random;

public class MithrilMacro {
    private Vec3 vec = null;
    private int currentDamage;
    private BlockPos blockPos = null;
    private Vec3 lastVec = null;
    private BlockPos lastBlockPos = null;
    private final KeyBinding lc = Main.mc.gameSettings.keyBindAttack;
    private boolean holdingLeft = false;

    @SubscribeEvent
    public void onTick(TickEvent.ClientTickEvent event) {
        if (event.phase == TickEvent.Phase.END) return;
        if(Main.mc.thePlayer == null || Main.mc.theWorld == null) return;
        if (Main.mc.currentScreen != null) return;
        if (!Main.mithrilMacro) {
            if (holdingLeft) {
                KeyBinding.setKeyBindState(lc.getKeyCode(), false);
                holdingLeft = false;
            }
            currentDamage = 0;
            return;
        }
        if (PlayerUtils.pickaxeAbilityReady) {
            KeyBinding.setKeyBindState(lc.getKeyCode(), false);
            Main.mc.playerController.sendUseItem(Main.mc.thePlayer, Main.mc.theWorld, Main.mc.thePlayer.inventory.getStackInSlot(Main.mc.thePlayer.inventory.currentItem));
            PlayerUtils.pickaxeAbilityReady = false;
        }
        if (currentDamage > 100) {
            KeyBinding.setKeyBindState(lc.getKeyCode(), false);
            currentDamage = 0;
        }
        lastBlockPos = blockPos;
        blockPos = closestMithril();
        if (lastBlockPos != null && blockPos != null && !lastBlockPos.equals(blockPos)) {
            currentDamage = 0;
        }
        if (blockPos != null) {
            ArrayList<Vec3> vec3s = BlockUtils.whereToMineBlock(blockPos);
            if (vec3s.size() > 0) {
                vec = vec3s.get(0);
                if (vec != null) {
                    ShadyRotation.smoothLook(ShadyRotation.vec3ToRotation(vec), Main.configFile.smoothLookVelocity, () -> {});
                    lastVec = vec;
                    KeyBinding.setKeyBindState(lc.getKeyCode(), true);
                    holdingLeft = true;
                }

                currentDamage += 1;
            }
        }

    }

    @SubscribeEvent
    public void onRender(RenderWorldLastEvent event) {
        if (!Main.mithrilMacro) return;
        if (vec != null) {
            RenderUtils.drawPixelBox(vec, Color.RED, 0.01, event.partialTicks);
        }
        if (blockPos != null) {
            RenderUtils.drawBlockBox(blockPos, Color.CYAN, true, event.partialTicks);
        }
    }

    private BlockPos closestMithril() {
        int r = 6;
        if (Main.mc.thePlayer == null || Main.mc.theWorld == null) return null;
        BlockPos playerPos = Main.mc.thePlayer.getPosition().add(0, 1, 0);
        Vec3 playerVec = Main.mc.thePlayer.getPositionVector();
        Vec3i vec3i = new Vec3i(r, r, r);
        ArrayList<Vec3> blocks = new ArrayList<Vec3>();
        if (playerPos != null) {
            for (BlockPos blockPos : BlockPos.getAllInBox(playerPos.add(vec3i), playerPos.subtract(vec3i))) {
                IBlockState blockState = Main.mc.theWorld.getBlockState(blockPos);
                if (isMithril(blockState)) {
                    if (BlockUtils.whereToMineBlock(blockPos).size() > 0) {
                        blocks.add(new Vec3(blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5));
                    }
                }
            }
        }
        double smallest = 9999;
        Vec3 closest = null;
        for (Vec3 block : blocks) {
            double dist = block.distanceTo(playerVec);
            if (lastBlockPos != null) {
                dist = block.distanceTo(new Vec3(lastBlockPos.getX() + 0.5, lastBlockPos.getY() + 0.5, lastBlockPos.getZ() + 0.5));
            }
            if (dist < smallest) {
                smallest = dist;
                closest = block;
            }
        }
        if (closest != null && smallest < 5) {
            return new BlockPos(closest.xCoord, closest.yCoord, closest.zCoord);
        }
        return null;
    }

    private boolean isMithril(IBlockState blockState) {
        if (!Main.configFile.onlyOres) {
            if (blockState.getBlock() == Blocks.prismarine) {
                return true;
            } else if (blockState.getBlock() == Blocks.wool && (blockState.getValue(BlockStainedGlass.COLOR) == EnumDyeColor.LIGHT_BLUE || blockState.getValue(BlockStainedGlass.COLOR) == EnumDyeColor.GRAY)) {
                return true;
            } else if (blockState.getBlock() == Blocks.stained_hardened_clay && blockState.getValue(BlockStainedGlass.COLOR) == EnumDyeColor.CYAN) {
                return true;
            } else if (!Main.configFile.ignoreTitanium && blockState.getBlock() == Blocks.stone && blockState.getValue(BlockStone.VARIANT) == BlockStone.EnumType.DIORITE_SMOOTH) {
                return true;
            } else if (blockState.getBlock() == Blocks.gold_block) {
                return true;
            }
        }

        if (Main.configFile.includeOres || Main.configFile.onlyOres) {
            return blockState.getBlock() == Blocks.coal_ore || blockState.getBlock() == Blocks.diamond_ore || blockState.getBlock() == Blocks.gold_ore || blockState.getBlock() == Blocks.redstone_ore || blockState.getBlock() == Blocks.iron_ore || blockState.getBlock() == Blocks.lapis_ore || blockState.getBlock() == Blocks.emerald_ore || blockState.getBlock() == Blocks.netherrack;
        }

        return false;
    }
}