This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
forked from BleachDev/BleachHack
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutoBedtrap.java
176 lines (154 loc) · 5.88 KB
/
AutoBedtrap.java
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package bleach.hack.module.mods;
import bleach.hack.event.events.EventTick;
import bleach.hack.module.Category;
import bleach.hack.module.Module;
import bleach.hack.setting.base.SettingSlider;
import bleach.hack.setting.base.SettingToggle;
import bleach.hack.setting.other.SettingRotate;
import bleach.hack.util.BleachLogger;
import bleach.hack.util.world.WorldUtils;
import com.google.common.eventbus.Subscribe;
import net.minecraft.block.BedBlock;
import net.minecraft.item.Items;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
/**
* @author CUPZYY | https://github.com/CUPZYY
*/
public class AutoBedtrap extends Module {
BlockPos lookingCoords;
Direction bed2direction;
BlockPos bed2;
int cap = 0;
boolean bed;
boolean working = false;
public AutoBedtrap() {
super("AutoBedtrap", KEY_UNBOUND, Category.WORLD, "Automatically places obsidian around bed",
new SettingSlider("BPT", 1, 8, 2, 0).withDesc("Blocks per tick, how many blocks to place per tick"),
new SettingToggle("Keep on", true).withDesc("Keeps the module on after placing the obsidian"),
new SettingRotate(false).withDesc("Rotates when placing"));
}
public void onEnable() {
super.onEnable();
assert mc.crosshairTarget != null;
if (!working) {
lookingCoords = mc.crosshairTarget.getType() == HitResult.Type.BLOCK ? ((BlockHitResult) mc.crosshairTarget).getBlockPos() : null;
if (lookingCoords == null && (!getSetting(1).asToggle().state)) {
BleachLogger.errorMessage("Not looking at a bed");
setEnabled(false);
return;
}
else if (lookingCoords == null) {
return;
}
bed = mc.world.getBlockState(lookingCoords).getBlock().getName().toString().toUpperCase().contains("_BED");
}
if ((!bed || lookingCoords == null) && (!getSetting(1).asToggle().state)){
BleachLogger.errorMessage("Not looking at a bed");
setEnabled(false);
return;
}
int obby = -1;
for (int i = 0; i < 9; i++) {
assert mc.player != null;
if (mc.player.getInventory().getStack(i).getItem() == Items.OBSIDIAN) {
obby = i;
break;
}
}
if (obby == -1) {
BleachLogger.errorMessage("No obsidian in hotbar!");
setEnabled(false);
}
}
public void onDisable() {
super.onDisable();
working = false;
cap = 0;
lookingCoords = null;
}
@Subscribe
public void onTick(EventTick event) {
assert mc.crosshairTarget != null;
if (!working) {
lookingCoords = mc.crosshairTarget.getType() == HitResult.Type.BLOCK ? ((BlockHitResult) mc.crosshairTarget).getBlockPos() : null;
}
assert lookingCoords != null;
assert mc.world != null;
assert mc.world.getBlockState(lookingCoords).getBlock().getName().toString() != null;
if ((!getSetting(1).asToggle().state) && ((lookingCoords == null) || (!bed))) {
setEnabled(false);
return;
}
try {
if (!working) {
bed = mc.world.getBlockState(lookingCoords).getBlock().getName().toString().toUpperCase().contains("_BED");
}
} catch (NullPointerException e) {
return;
}
if (bed || working) {
BlockPos bed1 = lookingCoords;
bed2direction = BedBlock.getOppositePartDirection(mc.world.getBlockState(bed1));
if (bed2direction == Direction.EAST) {
bed2 = lookingCoords.east(1);
} else if (bed2direction == Direction.NORTH) {
bed2 = lookingCoords.north(1);
} else if (bed2direction == Direction.SOUTH) {
bed2 = lookingCoords.south(1);
} else if (bed2direction == Direction.WEST) {
bed2 = lookingCoords.west(1);
}
int obby = -1;
for (int i = 0; i < 9; i++) {
assert mc.player != null;
if (mc.player.getInventory().getStack(i).getItem() == Items.OBSIDIAN) {
obby = i;
break;
}
}
if (obby == -1) {
BleachLogger.errorMessage("Ran out of obsidian!");
setEnabled(false);
return;
}
placeTickAround(obby, bed1);
placeTickAround(obby, bed2);
}
}
public void placeTickAround(int obsidian, BlockPos block) {
working = true;
for (BlockPos b : new BlockPos[]{
block.up(), block.west(),
block.north(), block.south(),
block.east(), block.down()}) {
if (cap >= getSetting(0).asSlider().getValueInt()) {
cap = 0;
return;
}
for (int i = 0; i < 9; i++) {
assert mc.player != null;
if (mc.player.getInventory().getStack(i).getItem() == Items.OBSIDIAN) {
obsidian = i;
break;
}
}
if (!(mc.player.getInventory().getStack(obsidian).getItem() == Items.OBSIDIAN)) {
BleachLogger.errorMessage("Ran out of obsidian!");
setEnabled(false);
return;
}
if (WorldUtils.canPlaceBlock(b)) {
WorldUtils.placeBlock(b, obsidian, getSetting(2).asRotate(), false, false, true);
cap++;
if (cap >= getSetting(0).asSlider().getValueInt()) {
return;
}
}
}
working = false;
cap = 0;
}
}