aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/rosegoldaddons/features/AutoGhostBlock.java
blob: 76ca1853033e33160c846c4c1aa2edf706237768 (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.state.BlockState;
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.util.BlockPos;
import net.minecraft.util.Vec3;
import net.minecraft.util.Vec3i;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import rosegoldaddons.Main;

public class AutoGhostBlock {
    private final KeyBinding sneakBind = Minecraft.getMinecraft().gameSettings.keyBindSneak;
    private final KeyBinding jumpBind = Minecraft.getMinecraft().gameSettings.keyBindJump;

    @SubscribeEvent
    public void onPlayerTick(TickEvent.PlayerTickEvent event) {
        if(Main.mc.thePlayer == null || Main.mc.theWorld == null) return;
        if(Main.configFile.ghostIndex == 0) {
            if (!Main.configFile.AutoGB || !Main.configFile.AutoGBTopStair) return;
            if (sneakBind.isKeyDown() && Main.configFile.AutoGB) {
                BlockPos playerPos = Main.mc.thePlayer.getPosition();
                Vec3 playerVec = Main.mc.thePlayer.getPositionVector();
                Vec3i vec3i = new Vec3i(3, 1, 3);
                Vec3i vec3i2 = new Vec3i(3, 2, 3);
                for (BlockPos blockPos : BlockPos.getAllInBox(playerPos.add(vec3i), playerPos.subtract(vec3i2))) {
                    double diffX = Math.abs(blockPos.getX() + 0.5D - playerVec.xCoord);
                    double diffZ = Math.abs(blockPos.getZ() + 0.5D - playerVec.zCoord);
                    double diffY = blockPos.getY() - playerVec.yCoord;
                    if (diffX < 1 && diffZ < 1) {
                        IBlockState blockState = Main.mc.theWorld.getBlockState(blockPos);
                        if (isStair(blockState) && diffY == -0.5) {
                            Main.mc.theWorld.setBlockToAir(blockPos);
                        }
                        if (Main.configFile.AutoGBMisc) {
                            if (blockState.getBlock() == Blocks.skull && diffY == 0 && diffX < 0.5 && diffZ < 0.5) {
                                Main.mc.theWorld.setBlockToAir(blockPos);
                            } else if (blockState.getBlock() == Blocks.hopper && diffY == -0.625) {
                                Main.mc.theWorld.setBlockToAir(blockPos);
                            } else if (isFence(blockState) && diffY <= 0 && diffX < 0.5 && diffZ < 0.5) {
                                Main.mc.theWorld.setBlockToAir(blockPos);
                            }
                        }
                    }
                }
            }
        }
        if(jumpBind.isKeyDown() && Main.configFile.AutoGBTopStair) {
            BlockPos playerPos = Main.mc.thePlayer.getPosition();
            Vec3 playerVec = Main.mc.thePlayer.getPositionVector();
            Vec3i vec3i = new Vec3i(3, 2, 3);
            Vec3i vec3i2 = new Vec3i(3, 0, 3);
            for (BlockPos blockPos : BlockPos.getAllInBox(playerPos.add(vec3i), playerPos.subtract(vec3i2))) {
                double diffX = Math.abs(blockPos.getX() + 0.5D - playerVec.xCoord);
                double diffZ = Math.abs(blockPos.getZ() + 0.5D - playerVec.zCoord);
                double diffY = blockPos.getY() - playerVec.yCoord;
                if(diffX < 1 && diffZ < 1) {
                    IBlockState blockState = Main.mc.theWorld.getBlockState(blockPos);
                    if(isStair(blockState) && diffY > 1.2 && diffY < 1.3) {
                        Main.mc.theWorld.setBlockToAir(blockPos);
                    }
                }
            }
        }
    }

    @SubscribeEvent
    public void onKeyPress(InputEvent.KeyInputEvent event) {
        if(Main.mc.thePlayer == null || Main.mc.theWorld == null) return;
        if(Main.configFile.ghostIndex == 0) return;
        if(!Main.configFile.AutoGB || !Main.configFile.AutoGBTopStair) return;
        if(sneakBind.isPressed() && Main.configFile.AutoGB) {
            BlockPos playerPos = Main.mc.thePlayer.getPosition();
            Vec3 playerVec = Main.mc.thePlayer.getPositionVector();
            Vec3i vec3i = new Vec3i(3, 1, 3);
            Vec3i vec3i2 = new Vec3i(3, 2, 3);
            for (BlockPos blockPos : BlockPos.getAllInBox(playerPos.add(vec3i), playerPos.subtract(vec3i2))) {
                double diffX = Math.abs(blockPos.getX() + 0.5D - playerVec.xCoord);
                double diffZ = Math.abs(blockPos.getZ() + 0.5D - playerVec.zCoord);
                double diffY = blockPos.getY() - playerVec.yCoord;
                if(diffX < 1 && diffZ < 1) {
                    IBlockState blockState = Main.mc.theWorld.getBlockState(blockPos);
                    if(isStair(blockState) && diffY == -0.5) {
                        Main.mc.theWorld.setBlockToAir(blockPos);
                    }
                    if(Main.configFile.AutoGBMisc) {
                        if(blockState.getBlock() == Blocks.skull && diffY == 0 && diffX < 0.5 && diffZ < 0.5) {
                            Main.mc.theWorld.setBlockToAir(blockPos);
                        }
                        else if(blockState.getBlock() == Blocks.hopper && diffY == -0.625) {
                            Main.mc.theWorld.setBlockToAir(blockPos);
                        }
                        else if(isFence(blockState) && diffY <= 0 && diffX < 0.5 && diffZ < 0.5) {
                            Main.mc.theWorld.setBlockToAir(blockPos);
                        }
                    }
                }
            }
        }
        if(jumpBind.isPressed() && Main.configFile.AutoGBTopStair) {
            BlockPos playerPos = Main.mc.thePlayer.getPosition();
            Vec3 playerVec = Main.mc.thePlayer.getPositionVector();
            Vec3i vec3i = new Vec3i(3, 2, 3);
            Vec3i vec3i2 = new Vec3i(3, 0, 3);
            for (BlockPos blockPos : BlockPos.getAllInBox(playerPos.add(vec3i), playerPos.subtract(vec3i2))) {
                double diffX = Math.abs(blockPos.getX() + 0.5D - playerVec.xCoord);
                double diffZ = Math.abs(blockPos.getZ() + 0.5D - playerVec.zCoord);
                double diffY = blockPos.getY() - playerVec.yCoord;
                if(diffX < 1 && diffZ < 1) {
                    IBlockState blockState = Main.mc.theWorld.getBlockState(blockPos);
                    if(isStair(blockState) && diffY > 1.2 && diffY < 1.3) {
                        Main.mc.theWorld.setBlockToAir(blockPos);
                    }
                }
            }
        }
    }

    private boolean isStair(IBlockState blockState) {
        if(blockState.getBlock() == Blocks.acacia_stairs || blockState.getBlock() == Blocks.birch_stairs ||
                blockState.getBlock() == Blocks.brick_stairs || blockState.getBlock() == Blocks.stone_brick_stairs ||
                blockState.getBlock() == Blocks.stone_stairs || blockState.getBlock() == Blocks.dark_oak_stairs ||
                blockState.getBlock() == Blocks.jungle_stairs || blockState.getBlock() == Blocks.spruce_stairs ||
                blockState.getBlock() == Blocks.red_sandstone_stairs || blockState.getBlock() == Blocks.sandstone_stairs ||
                blockState.getBlock() == Blocks.nether_brick_stairs || blockState.getBlock() == Blocks.oak_stairs ||
                blockState.getBlock() == Blocks.quartz_stairs)
            return true;
        return false;
    }

    private boolean isFence(IBlockState blockState) {
        if(blockState.getBlock() == Blocks.acacia_fence || blockState.getBlock() == Blocks.birch_fence ||
                blockState.getBlock() == Blocks.cobblestone_wall || blockState.getBlock() == Blocks.dark_oak_fence ||
                blockState.getBlock() == Blocks.jungle_fence || blockState.getBlock() == Blocks.spruce_fence ||
                blockState.getBlock() == Blocks.oak_fence || blockState.getBlock() == Blocks.nether_brick_fence)
            return true;
        return false;
    }
}