aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/rosegoldaddons/features/BlockBreakAura.java
blob: e8b7219262ca1602c3517aa5498d0354cb9f7be9 (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
package rosegoldaddons.features;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.init.Blocks;
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.RenderUtils;
import rosegoldaddons.utils.RotationUtils;

import java.awt.*;
import java.lang.reflect.Method;
import java.util.ArrayList;

public class BlockBreakAura {
    BlockPos gem = null;
    private Thread thread;
    private boolean breaking = false;

    @SubscribeEvent
    public void onTick(TickEvent.ClientTickEvent event) {
        if(!Main.gemNukeToggle) {
            if(breaking) {
                KeyBinding.setKeyBindState(Minecraft.getMinecraft().gameSettings.keyBindAttack.getKeyCode(), false);
                breaking = false;
            }
            return;
        }
        if(event.phase.toString().equals("START") && gem != null) {
            RotationUtils.facePos(new Vec3(gem.getX()+0.5, gem.getY()-1, gem.getZ()+0.5));
            MovingObjectPosition objectMouseOver = Minecraft.getMinecraft().objectMouseOver;
            if(objectMouseOver != null && objectMouseOver.typeOfHit.toString() == "BLOCK") {
                BlockPos pos = objectMouseOver.getBlockPos();
                Block gem = Minecraft.getMinecraft().theWorld.getBlockState(pos).getBlock();
                if(gem == Blocks.stained_glass || gem == Blocks.stained_glass_pane) {
                    if(!breaking) {
                        KeyBinding.setKeyBindState(Minecraft.getMinecraft().gameSettings.keyBindAttack.getKeyCode(), true);
                        breaking = true;
                    }
                } else {
                    if(breaking) {
                        KeyBinding.setKeyBindState(Minecraft.getMinecraft().gameSettings.keyBindAttack.getKeyCode(), false);
                        breaking = false;
                    }
                }

            }
        }
    }

    @SubscribeEvent
    public void renderWorld(RenderWorldLastEvent event) {
        if(!Main.gemNukeToggle) return;
        gem = closestGemstone();
        if (gem != null) {
            RenderUtils.drawBlockBox(gem, Color.RED, true, event.partialTicks);
        }
    }

    private BlockPos closestGemstone() {
        int r = 4;
        BlockPos playerPos = Minecraft.getMinecraft().thePlayer.getPosition();
        playerPos.add(0, 1, 0);
        Vec3 playerVec = Minecraft.getMinecraft().thePlayer.getPositionVector();
        Vec3i vec3i = new Vec3i(r, r, r);
        ArrayList<Vec3> chests = new ArrayList<Vec3>();
        if (playerPos != null) {
            for (BlockPos blockPos : BlockPos.getAllInBox(playerPos.add(vec3i), playerPos.subtract(vec3i))) {
                IBlockState blockState = Minecraft.getMinecraft().theWorld.getBlockState(blockPos);
                //Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText(blockState.getBlock().toString()));
                if (blockState.getBlock() == Blocks.stained_glass) {
                    chests.add(new Vec3(blockPos.getX() + 0.5, blockPos.getY(), blockPos.getZ() + 0.5));
                }
            }
        }
        double smallest = 9999;
        Vec3 closest = null;
        for (int i = 0; i < chests.size(); i++) {
            double dist = chests.get(i).distanceTo(playerVec);
            if (dist < smallest) {
                smallest = dist;
                closest = chests.get(i);
            }
        }
        if (closest != null && smallest < 4) {
            return new BlockPos(closest.xCoord, closest.yCoord, closest.zCoord);
        }
        return null;
    }

}