This repository was archived by the owner on Dec 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Expand file tree
/
Copy pathBurrow.kt
More file actions
293 lines (242 loc) · 11.3 KB
/
Burrow.kt
File metadata and controls
293 lines (242 loc) · 11.3 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
package com.lambda.client.module.modules.combat
import com.lambda.client.commons.interfaces.DisplayEnum
import com.lambda.client.event.SafeClientEvent
import com.lambda.client.manager.managers.TimerManager.modifyTimer
import com.lambda.client.mixin.extension.isInWeb
import com.lambda.client.module.Category
import com.lambda.client.module.Module
import com.lambda.client.util.items.block
import com.lambda.client.util.items.firstItem
import com.lambda.client.util.items.hotbarSlots
import com.lambda.client.util.math.RotationUtils
import com.lambda.client.util.threads.safeListener
import net.minecraft.entity.EntityLivingBase
import net.minecraft.init.Blocks
import net.minecraft.inventory.Slot
import net.minecraft.item.ItemBlock
import net.minecraft.network.play.client.CPacketAnimation
import net.minecraft.network.play.client.CPacketHeldItemChange
import net.minecraft.network.play.client.CPacketPlayer
import net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock
import net.minecraft.util.EnumFacing
import net.minecraft.util.EnumHand
import net.minecraft.util.math.AxisAlignedBB
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3d
import net.minecraftforge.fml.common.gameevent.TickEvent
import kotlin.math.abs
import kotlin.math.hypot
object Burrow : Module(
name = "Burrow",
alias = arrayOf("SelfFill", "SelfBlock", "RubberFill", "RubberBlock", "FootConcrete", "BlockLag"),
description = "Automatically burrows you in a hole",
category = Category.COMBAT
) {
// behaviour
private val nearby by setting("Nearby", true,
description = "Burrows only if a player is nearby")
private val range by setting("Range", 4.25f, 0.25f..6f, 0.25f,
description = "Range to search for a player", visibility = { nearby })
private val cancel by setting("Cancel On ", Cancel.NONE,
description = "When to disable burrow", visibility = { nearby })
private val autoDisable by setting("Auto Disable", true,
description = "Automatically disables when burrowed")
// bypass
private val packetMode by setting("Rubberband Mode", PacketMode.SMART,
description = "The method to use to rubberband")
private val offset by setting("Offset", 2.0, -25.0..25.0, 1.0,
description = "Offset to send to the server", visibility = { packetMode == PacketMode.DUMB })
private val strength by setting("Strength", 20, 1..50, 1,
description = "Strength of the rubberband, higher meaning more likely to work but flags more afterwards",
visibility = { packetMode == PacketMode.ALTERNATIVE || packetMode == PacketMode.SPIN })
// QOL
private val smooth by setting("Smooth", true,
description = "Smooths out the rubberbanding", visibility = { packetMode != PacketMode.NONE })
private val noTimerFlag by setting("No Timer Flag", true,
description = "Prevents flagging for timer",
visibility = { packetMode != PacketMode.ALTERNATIVE })
// generic
private val rotate by setting("Rotate", true,
description = "Rotates towards the block",)
private val noPeerRotate by setting("No Peer Rotate", true,
description = "Prevents peers from seeing our rotation",
visibility = { rotate })
private var lastBurrow = 0L
enum class Cancel(override val displayName: String, val should: () -> Boolean) : DisplayEnum {
NONE("None", { false }),
// this returns true when moved up by knockback or a piston
JUMP("Jump", { mc.player.motionY > 0 }),
// this is a larger distance than a block
MOVE("Move", { hypot(mc.player.posX - mc.player.prevPosX,
mc.player.posZ - mc.player.prevPosZ) > .2 || JUMP.should.invoke() }),
}
enum class PacketMode(override val displayName: String, val rubberband: Runnable) : DisplayEnum {
NONE("None", {
// we just want to jump up and place to surprise the enemy gamer, this shouldn't flag at all
}),
DUMB("Dumb", {
// offset by a given amount
sendPos(offset + 1)
}),
WEIRD("Weird", {
// this moves us back into the block we placed
sendPos(0.42)
sendPos(0.75)
}),
SMART("Smart", {
// offset an amount that doesn't collide with a block and isn't our position
for (i in -5..5) {
// offset too close won't rubberband
if (abs(i) <= 1)
continue
if (!mc.world.collidesWithAnyBlock(mc.player.entityBoundingBox
.offset(0.0, 1 + i.toDouble(), 0.0))) {
sendPos(1 + i.toDouble())
break
}
}
}),
HORIZONTAL("Horizontal", {
// we want to rubberband horizontally, so we check X and Z
for (x in -5..5)
for (z in -5..5)
if (!mc.world.collidesWithAnyBlock(mc.player.entityBoundingBox
.offset(x.toDouble(), 1.0, z.toDouble()))) {
mc.player.connection.sendPacket(
CPacketPlayer.Position(
mc.player.posX + x,
mc.player.posY + 1.0,
mc.player.posZ + z,
mc.player.onGround)
)
break
}
}),
ALTERNATIVE("Alternative", {
// this flags for timer, which used to bypass 2b2tpvp and .cc and likely bypasses other rubbish patches
for (i in 0..strength / 2) {
sendPos(1.0 + Math.random() * 0.1)
sendPos(1.0)
}
}),
SPIN("Rotations", {
// this flags for timer, which used to bypass 2b2tpvp and .cc and likely bypasses other rubbish patches
for (i in 0..strength) {
mc.player.connection.sendPacket(
CPacketPlayer.Rotation(
RotationUtils.normalizeAngle(
mc.player.rotationYaw + Math.random().toFloat() * 360f
), mc.player.rotationPitch, mc.player.onGround)
)
}
}),
}
var packets = 0
init {
safeListener<TickEvent.ClientTickEvent> { event ->
if (event.phase.equals(TickEvent.Phase.START))
return@safeListener
// we don't want to burrow more than once a second, to give time to catch up with the server. Re-burrowing
// within 1 second is always either instant mine or we never burrowed in the first place. Allowing NONE
// means it can be used as a tower and without the timer setting also bypassed 2b2tpvp at one point.
if (System.currentTimeMillis() - lastBurrow < 1000 && packetMode != PacketMode.NONE)
return@safeListener
// if we should disable due to motion or anything
if (cancel.should.invoke()) {
disable()
return@safeListener
}
if (!player.onGround)
return@safeListener
// check we aren't in an invalid position to burrow
if (mc.player.isInWeb || mc.player.isInLava || mc.player.isInWater || mc.player.isInLava
|| world.collidesWithAnyBlock(player.entityBoundingBox)) {
if (autoDisable)
disable()
return@safeListener
}
// check that we are near players or don't care
if (nearby && world.playerEntities.none {
Vec3d(BlockPos(player.positionVector)).add(.0, 1.0, .0)
.squareDistanceTo(it.posX, it.posY, it.posZ) <= range * range && it != player
})
return@safeListener
// check any colliding entities
if (world.getEntitiesWithinAABB(EntityLivingBase::class.java,
AxisAlignedBB(BlockPos(player.posX, player.posY, player.posZ))).any { it != player })
return@safeListener
// get slot
val slot = player.hotbarSlots.firstItem<ItemBlock, Slot> {
it.item is ItemBlock && it.item.block.let { b -> b == Blocks.OBSIDIAN || b == Blocks.ENDER_CHEST }
} ?: return@safeListener
burrow(slot.slotIndex)
}
onDisable {
packets = 0
}
}
private fun SafeClientEvent.burrow(slot: Int) {
// basically No003
if (smooth)
sendPos(0.0)
// start of a jump
sendPos(0.42)
sendPos(0.75)
// Vanilla would have us go to ~1.01 but if we aren't rubberbanding we want 1.0 so that we don't have to fall
if (packetMode != PacketMode.NONE) {
sendPos(1.01)
sendPosRot(1.16)
} else {
sendPosRot(1.0)
}
// swap to block
if (player.inventory.currentItem != slot)
connection.sendPacket(CPacketHeldItemChange(slot))
// swing arm to place
connection.sendPacket(CPacketAnimation(EnumHand.MAIN_HAND))
// place block, we don't need to use the util since we don't need to check for collision with ourself
connection.sendPacket(CPacketPlayerTryUseItemOnBlock(
BlockPos(mc.player.posX, mc.player.posY, mc.player.posZ).offset(EnumFacing.DOWN),
EnumFacing.UP, EnumHand.MAIN_HAND, 0.5f, 1f, 0.5f
))
// we want to return our rotation so other players can't see we rotated.
// this is kinda useless but means its slightly less obvious that we burrowed
// slightly.
// todo: if we are rotating from another module we don't need to do this
if (noPeerRotate)
connection.sendPacket(CPacketPlayer.Rotation(mc.player.rotationYaw, mc.player.rotationPitch, mc.player.onGround))
// set last burrow
lastBurrow = System.currentTimeMillis()
// swap back
if (player.inventory.currentItem != slot)
connection.sendPacket(CPacketHeldItemChange(player.inventory.currentItem))
// rubberband
packetMode.rubberband.run()
// we don't do this in the rubberband since we need the slot
if (packetMode == PacketMode.NONE) {
world.setBlockState(BlockPos(player.posX, player.posY, player.posZ),
(player.hotbarSlots[slot].stack.item as ItemBlock).block.defaultState)
player.setPosition(player.posX, player.posY + 1, player.posZ)
}
// account for timer, alternative needs us to flag timer so we don't care about it
if (noTimerFlag && packetMode != PacketMode.ALTERNATIVE) {
modifyTimer(50f * packets)
packets = 0
}
// we might not want to disable
if (autoDisable) disable()
}
private fun sendPos(y: Double) {
mc.player.connection.sendPacket(CPacketPlayer.Position(mc.player.posX, mc.player.posY + y, mc.player.posZ,
false))
packets++
}
private fun sendPosRot(y: Double) {
if (rotate)
mc.player.connection.sendPacket(CPacketPlayer.PositionRotation(mc.player.posX, mc.player.posY + y, mc.player.posZ,
mc.player.rotationYaw, 90f, false))
else
sendPos(y)
packets++
}
}