Fucker module

Fucker: Minecraft 26.3 cheat module, full source for every implementation (1 client: LiquidBounce (Kotlin)).

1 implementationWORLD

Clients with this module

Full module source: 1 implementation

Every implementation below is the complete module file, verbatim. Expand a client to read its code.

LiquidBounce (Kotlin)WORLDsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/fucker/ModuleFucker.ktKotlin · 594 lines · 23.0 KB

Destroys or interacts with selected blocks around you.

SettingsRangeWallRangeBreakFreeSurroundingsTargetsDelayActionForceImmediateBreakIgnoreOpenInventoryIgnoreUsingItemNotDuringCombatPrioritizeOverKillAuraChestAsFullBlock
ModuleFucker.ktKotlin · Minecraft 26.2 · 594 lines · 23.0 KB · complete file, verbatimOriginal ↗
1
/*
2
 * This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
3
 *
4
 * Copyright (c) 2015 - 2026 CCBlueX
5
 *
6
 * LiquidBounce is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * LiquidBounce is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
18
 */
19
package net.ccbluex.liquidbounce.features.module.modules.world.fucker
20
21
import it.unimi.dsi.fastutil.longs.LongOpenHashSet
22
import net.ccbluex.liquidbounce.config.types.group.ToggleableValueGroup
23
import net.ccbluex.liquidbounce.config.types.list.Tagged
24
import net.ccbluex.liquidbounce.event.events.CancelBlockBreakingEvent
25
import net.ccbluex.liquidbounce.event.events.RotationUpdateEvent
26
import net.ccbluex.liquidbounce.event.handler
27
import net.ccbluex.liquidbounce.event.tickHandler
28
import net.ccbluex.liquidbounce.event.waitTicks
29
import net.ccbluex.liquidbounce.features.module.ClientModule
30
import net.ccbluex.liquidbounce.features.module.ModuleCategories
31
import net.ccbluex.liquidbounce.features.module.modules.player.ModuleBlink
32
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug
33
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug.debugGeometry
34
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug.debugParameter
35
import net.ccbluex.liquidbounce.features.module.modules.world.ModuleAutoTool
36
import net.ccbluex.liquidbounce.features.module.modules.world.packetmine.ModulePacketMine
37
import net.ccbluex.liquidbounce.render.engine.type.Color4b
38
import net.ccbluex.liquidbounce.utils.aiming.RotationManager
39
import net.ccbluex.liquidbounce.utils.aiming.RotationsValueGroup
40
import net.ccbluex.liquidbounce.utils.aiming.utils.raytraceBlockRotation
41
import net.ccbluex.liquidbounce.utils.block.DIRECTIONS_EXCLUDING_DOWN
42
import net.ccbluex.liquidbounce.utils.block.SwingMode
43
import net.ccbluex.liquidbounce.utils.block.bed.isSelfBedChoices
44
import net.ccbluex.liquidbounce.utils.block.doBreak
45
import net.ccbluex.liquidbounce.utils.block.getBlock
46
import net.ccbluex.liquidbounce.utils.block.isAnyChest
47
import net.ccbluex.liquidbounce.utils.math.distanceToSqr
48
import net.ccbluex.liquidbounce.utils.block.isNotBreakable
49
import net.ccbluex.liquidbounce.utils.block.outlineBox
50
import net.ccbluex.liquidbounce.utils.block.searchBlocksInRangeSorted
51
import net.ccbluex.liquidbounce.utils.block.outlineShape
52
import net.ccbluex.liquidbounce.utils.block.raycast
53
import net.ccbluex.liquidbounce.utils.block.state
54
import net.ccbluex.liquidbounce.utils.combat.CombatManager
55
import net.ccbluex.liquidbounce.utils.entity.shouldSwingHand
56
import net.ccbluex.liquidbounce.utils.inventory.Slots
57
import net.ccbluex.liquidbounce.utils.inventory.findBlocksEndingWith
58
import net.ccbluex.liquidbounce.utils.kotlin.Priority
59
import net.ccbluex.liquidbounce.utils.math.forAllFaces
60
import net.ccbluex.liquidbounce.utils.math.samplePointOnSide
61
import net.ccbluex.liquidbounce.utils.math.sq
62
import net.ccbluex.liquidbounce.utils.math.withLength
63
import net.ccbluex.liquidbounce.utils.raytracing.raytraceBlock
64
import net.ccbluex.liquidbounce.utils.render.BreakingProgress
65
import net.ccbluex.liquidbounce.utils.render.BreakingProgressRenderer
66
import net.ccbluex.liquidbounce.utils.render.placement.PlacementRenderer
67
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen
68
import net.minecraft.core.BlockPos
69
import net.minecraft.world.InteractionHand
70
import net.minecraft.world.level.ClipContext
71
import net.minecraft.world.level.block.BedBlock
72
import net.minecraft.world.level.block.state.BlockState
73
import net.minecraft.world.phys.AABB
74
import net.minecraft.world.phys.HitResult
75
import net.minecraft.world.phys.Vec3
76
import net.minecraft.world.phys.shapes.CollisionContext
77
import net.minecraft.world.phys.shapes.Shapes
78
import kotlin.math.max
79
80
/**
81
 * Fucker module
82
 *
83
 * Destroys/Uses selected blocks around you.
84
 */
85
object ModuleFucker : ClientModule(
86
    "Fucker",
87
    ModuleCategories.WORLD,
88
    aliases = listOf("BedBreaker", "IdNuker"),
89
), BreakingProgress.Provider {
90
91
    private val range by float("Range", 5F, 1F..6F)
92
    private val wallRange by float("WallRange", 0f, 0F..6F).onChange {
93
        minOf(range, it)
94
    }
95
96
    /**
97
     * Entrance requires the target block to have an entrance. It does not matter if we can see it or not.
98
     * If this condition is true, it will override the wall range to range
99
     * and act as if we were breaking normally.
100
     *
101
     * Useful for Hypixel and CubeCraft
102
     */
103
    private object FuckerEntrance : ToggleableValueGroup(this, "Entrance", false) {
104
        /**
105
         * Breaks the weakest block around target block and makes an entrance
106
         */
107
        val breakFree by boolean("BreakFree", true)
108
    }
109
110
    init {
111
        tree(FuckerEntrance)
112
    }
113
114
    private val surroundings by boolean("Surroundings", true)
115
    private val targets by blocks("Targets", findBlocksEndingWith("_BED", "DRAGON_EGG"))
116
    private val delay by int("Delay", 0, 0..20, "ticks")
117
    private val action by enumChoice("Action", DestroyAction.DESTROY).apply(::tagBy)
118
    private val forceImmediateBreak by boolean("ForceImmediateBreak", false)
119
120
    private val ignoreOpenInventory by boolean("IgnoreOpenInventory", true)
121
    private val ignoreUsingItem by boolean("IgnoreUsingItem", true)
122
    private val notDuringCombat by boolean("NotDuringCombat", false)
123
    private val prioritizeOverKillAura by boolean("PrioritizeOverKillAura", false)
124
125
    private val chestAsFullBlock by boolean("ChestAsFullBlock", false)
126
127
    private val isSelfBedMode = choices("SelfBed", 0, ::isSelfBedChoices)
128
129
    // Rotation
130
    private val rotations = tree(RotationsValueGroup(this))
131
    private val targetRenderer = tree(
132
        PlacementRenderer("TargetRendering", true, this,
133
            defaultColor = Color4b(255, 0, 0, 90)
134
        )
135
    )
136
    private val progressRenderer = targetRenderer.tree(
137
        BreakingProgressRenderer(targetRenderer, this)
138
    )
139
140
    private val availableToolSlots
141
        get() = if (ModuleAutoTool.isInventoryConsidered) Slots.HotbarAndInventory else Slots.Hotbar
142
143
    private fun miningDuration(pos: BlockPos, state: BlockState): Double {
144
        val bestMiningSpeed = availableToolSlots.maxOf { it.itemStack.getDestroySpeed(state) }
145
        return state.getDestroySpeed(world, pos).toDouble() / bestMiningSpeed.toDouble()
146
    }
147
148
    private var currentTarget: DestroyerTarget? = null
149
    private var oldTarget: DestroyerTarget? = null
150
151
    override fun breakingProgress(): BreakingProgress? {
152
        val target = currentTarget?.takeIf { it.action == DestroyAction.DESTROY } ?: return null
153
        if (ModulePacketMine.running) {
154
            return null
155
        }
156
157
        if (forceImmediateBreak) {
158
            return BreakingProgress(target.pos, 1f)
159
        }
160
161
        return BreakingProgress.Provider.Default.breakingProgress(target.pos)
162
    }
163
164
    private val targetPointProportions = doubleArrayOf(0.1, 0.3, 0.5, 0.7, 0.9)
165
    private const val MAX_SURROUNDING_PATH_BLOCKS = 8
166
    private const val RAYCAST_TARGET_EPSILON = 0.005
167
168
    override fun onDisabled() {
169
        clearCurrentTarget()
170
        oldTarget = null
171
        targetRenderer.clearSilently()
172
    }
173
174
    @Suppress("unused")
175
    private val targetUpdater = handler<RotationUpdateEvent> {
176
        if (!ignoreOpenInventory && mc.gui.screen() is AbstractContainerScreen<*>) {
177
            return@handler
178
        }
179
180
        if (!ignoreUsingItem && player.isUsingItem || notDuringCombat && CombatManager.isInCombat) {
181
            return@handler
182
        }
183
184
        oldTarget = currentTarget
185
        updateCurrentTarget()
186
    }
187
188
    @Suppress("unused")
189
    private val breaker = tickHandler {
190
        if (!ignoreOpenInventory && mc.gui.screen() is AbstractContainerScreen<*>) {
191
            return@tickHandler
192
        }
193
194
        // If we don't have any new target, and we had one before, stop breaking.
195
        if (oldTarget != null && currentTarget == null) {
196
            interaction.stopDestroyBlock()
197
            return@tickHandler
198
        } else if (oldTarget != currentTarget && delay > 0) {
199
            interaction.stopDestroyBlock()
200
            waitTicks(delay)
201
        }
202
203
        // Check if blink is enabled - if so, we don't want to do anything.
204
        if (ModuleBlink.running) {
205
            return@tickHandler
206
        }
207
208
        val destroyerTarget = currentTarget ?: return@tickHandler
209
        val currentRotation = RotationManager.serverRotation
210
        targetRenderer.addBlock(destroyerTarget.pos)
211
212
        if (ModulePacketMine.running && destroyerTarget.action == DestroyAction.DESTROY) {
213
            ModulePacketMine.setTarget(destroyerTarget.pos)
214
            return@tickHandler
215
        }
216
217
        // Check if we are already looking at the block
218
        val rayTraceResult = raytraceBlock(
219
            max(range, wallRange).toDouble(),
220
            currentRotation,
221
            destroyerTarget.pos,
222
            destroyerTarget.pos.state ?: return@tickHandler
223
        ) ?: return@tickHandler
224
225
        val raytracePos = rayTraceResult.blockPos
226
227
        // Check if the raytrace result includes a block, if not we don't want to deal with it.
228
        val raytraceState = raytracePos.state
229
        if (rayTraceResult.type != HitResult.Type.BLOCK || raytracePos != destroyerTarget.pos ||
230
            raytraceState == null || raytraceState.isNotBreakable(raytracePos)) {
231
            return@tickHandler
232
        }
233
234
        // Use action should be used if the block is the same as the current target and the action is set to use.
235
        if (destroyerTarget.action == DestroyAction.USE) {
236
            if (interaction.useItemOn(player, InteractionHand.MAIN_HAND, rayTraceResult).shouldSwingHand()) {
237
                SwingMode.DO_NOT_HIDE.swing(InteractionHand.MAIN_HAND)
238
            }
239
240
            waitTicks(delay)
241
        } else {
242
            doBreak(rayTraceResult, immediate = forceImmediateBreak)
243
        }
244
    }
245
246
    @Suppress("unused")
247
    private val cancelBlockBreakingHandler = handler<CancelBlockBreakingEvent> { event ->
248
        if (currentTarget != null && !ModulePacketMine.running) {
249
            event.cancelEvent()
250
        }
251
    }
252
253
    private fun updateCurrentTarget() {
254
        val possibleBlocks = searchPossibleTargetPositions()
255
256
        validateCurrentTarget(possibleBlocks)
257
258
        if (possibleBlocks.isEmpty()) {
259
            return
260
        }
261
262
        val range = range.toDouble()
263
264
        // Find direct targets first
265
        if (possibleBlocks.any { pos ->
266
            // If the block has an entrance, we should ignore the wall range and act as if we are breaking normally.
267
            val wallRange = if (FuckerEntrance.enabled && pos.hasEntrance) range else wallRange.toDouble()
268
            considerAsTarget(DestroyerTarget(pos, action, isTarget = true), range, wallRange) == true
269
        } || currentTarget != null) {
270
            return
271
        }
272
273
        // Surrounding / Entrance
274
        for (pos in possibleBlocks) {
275
            // Is there any block in the way?
276
            if (FuckerEntrance.enabled && FuckerEntrance.breakFree) {
277
                val weakBlock = pos.weakestNeighbor ?: continue
278
                considerAsTarget(DestroyerTarget(weakBlock, DestroyAction.DESTROY), range, range)
279
            } else if (surroundings) {
280
                updateSurroundings(pos)
281
            }
282
        }
283
    }
284
285
    private fun clearCurrentTarget() {
286
        interaction.stopDestroyBlock()
287
288
        currentTarget?.let { target ->
289
            targetRenderer.removeBlock(target.pos)
290
        }
291
        currentTarget = null
292
    }
293
294
    private fun searchPossibleTargetPositions(): List<BlockPos> {
295
        return player.eyePosition.searchBlocksInRangeSorted(range) { pos, state ->
296
            when (val block = state.block) {
297
                !in targets -> false
298
                is BedBlock if isSelfBedMode.activeMode.isSelfBed(block, pos) -> false
299
                else -> true
300
            }
301
        }.map { it.first }
302
    }
303
304
    private fun validateCurrentTarget(possibleBlocks: Collection<BlockPos>) {
305
        val currentTarget = currentTarget ?: return
306
307
        var removed = false
308
        val actualTargetPos = currentTarget.surroundingInfo?.actualTargetPos ?: currentTarget.pos
309
        if (actualTargetPos !in possibleBlocks) {
310
            removed = true
311
        }
312
        if (currentTarget.isTarget && currentTarget.action != action) {
313
            removed = true
314
        }
315
316
        // Stick with the current target because it's still valid.
317
        val validationResult =
318
            considerAsTarget(currentTarget, range.toDouble(), wallRange.toDouble(), isCurrentTarget = true)
319
320
        if (validationResult == false) {
321
            removed = true
322
        }
323
324
        if (removed) {
325
            clearCurrentTarget()
326
        }
327
    }
328
329
    /**
330
     * @return true if it is the best target, false if it's invalid and null if it's not better than the current target
331
     */
332
    private fun considerAsTarget(
333
        target: DestroyerTarget,
334
        range: Double,
335
        throughWallsRange: Double,
336
        isCurrentTarget: Boolean = false
337
    ): Boolean? {
338
        val state = target.pos.state?.takeUnless { it.isAir } ?: return false
339
340
        val raytrace = raytraceBlockRotation(
341
            eyes = player.eyePosition,
342
            pos = target.pos,
343
            state = state,
344
            range = range,
345
            wallsRange = throughWallsRange
346
        ) ?: return false
347
348
        val currentTarget = currentTarget
349
350
        if (!isCurrentTarget && currentTarget != null && target >= currentTarget) {
351
            return null
352
        }
353
354
        if (!ModulePacketMine.running) {
355
            RotationManager.setRotationTarget(
356
                rotation = raytrace.rotation,
357
                considerInventory = !ignoreOpenInventory,
358
                valueGroup = rotations,
359
                priority = if (prioritizeOverKillAura) {
360
                    Priority.IMPORTANT_FOR_USAGE_3
361
                } else {
362
                    Priority.IMPORTANT_FOR_USAGE_1
363
                },
364
                provider = this@ModuleFucker
365
            )
366
        }
367
368
        clearCurrentTarget()
369
        ModuleFucker.currentTarget = target
370
371
        return true
372
    }
373
374
    private fun updateSurroundings(initialPosition: BlockPos): Boolean {
375
        val eyePos = player.eyePosition
376
        val path = findBestSurroundingPath(initialPosition, eyePos) ?: return false
377
378
        debugGeometry("targetPoint") {
379
            ModuleDebug.DebuggedPoint(path.info.targetPoint, Color4b.RED.alpha(100))
380
        }
381
382
        debugGeometry("initialPosition") {
383
            ModuleDebug.DebuggedBox(initialPosition.outlineBox.move(initialPosition), Color4b.GREEN.alpha(50))
384
        }
385
386
        debugGeometry("raytraceResult") {
387
            ModuleDebug.DebuggedBox(path.firstBlock.outlineBox.move(path.firstBlock), Color4b.BLUE.alpha(50))
388
        }
389
390
        debugParameter("wayToTarget") { path.blocks }
391
392
        return considerAsTarget(
393
            DestroyerTarget(path.firstBlock, DestroyAction.DESTROY, path.info),
394
            range.toDouble(),
395
            wallRange.toDouble(),
396
        ) == true
397
    }
398
399
    @Suppress("CognitiveComplexMethod")
400
    private fun findBestSurroundingPath(target: BlockPos, eyePos: Vec3): SurroundingPath? {
401
        val rangeSquared = range.toDouble().sq()
402
403
        fun createSurroundingPath(targetPoint: Vec3): SurroundingPath? {
404
            val blocks = traceBlocksToTarget(target, eyePos, targetPoint)?.takeIf { it.isNotEmpty() } ?: return null
405
            var resistance = 0.0
406
407
            for (pos in blocks) {
408
                val state = pos.state?.takeUnless { it.isAir } ?: return null
409
                resistance += miningDuration(pos, state)
410
            }
411
412
            val firstBlock = blocks.first()
413
            return SurroundingPath(
414
                firstBlock = firstBlock,
415
                blocks = blocks,
416
                info = SurroundingInfo(
417
                    actualTargetPos = target,
418
                    targetPoint = targetPoint,
419
                    resistance = resistance,
420
                    blockerCount = blocks.size,
421
                    firstBlockDistanceToTarget = firstBlock.distToCenterSqr(targetPoint),
422
                    firstBlockDistanceToEyes = firstBlock.distToCenterSqr(eyePos),
423
                )
424
            )
425
        }
426
427
        var bestPath: SurroundingPath? = null
428
429
        val targetState = target.state ?: return bestPath
430
        val targetShape = if (chestAsFullBlock && targetState.isAnyChest) {
431
            Shapes.block()
432
        } else {
433
            targetState.getShape(world, target)
434
        }
435
436
        targetShape.move(target).forAllFaces { side, minX, minY, minZ, maxX, maxY, maxZ ->
437
            val face = AABB(minX, minY, minZ, maxX, maxY, maxZ)
438
            for (a in targetPointProportions) {
439
                for (b in targetPointProportions) {
440
                    val targetPoint = face.samplePointOnSide(side, a, b)
441
442
                    if (eyePos.distanceToSqr(targetPoint) <= rangeSquared) {
443
                        val path = createSurroundingPath(targetPoint) ?: continue
444
                        val currentBestPath = bestPath
445
                        if (currentBestPath == null || currentBestPath >= path) {
446
                            bestPath = path
447
                        }
448
                    }
449
                }
450
            }
451
        }
452
453
        return bestPath
454
    }
455
456
    private fun traceBlocksToTarget(target: BlockPos, eyePos: Vec3, targetPoint: Vec3): List<BlockPos>? {
457
        val direction = targetPoint.subtract(eyePos).withLength(RAYCAST_TARGET_EPSILON)
458
        val end = targetPoint.add(direction)
459
        val clipContext = ClipContext(eyePos, end, ClipContext.Block.OUTLINE, ClipContext.Fluid.NONE, player)
460
        val ignoredBlocks = ArrayList<BlockPos>(MAX_SURROUNDING_PATH_BLOCKS)
461
        val visited = LongOpenHashSet(MAX_SURROUNDING_PATH_BLOCKS)
462
        var reachedTarget = false
463
        var invalidPath = false
464
465
        while (!reachedTarget && !invalidPath) {
466
            val raytraceResult = world.raycast(
467
                context = clipContext,
468
                exclude = ignoredBlocks,
469
                include = null,
470
                maxBlastResistance = null,
471
            ).takeIf { result -> result.type == HitResult.Type.BLOCK }
472
473
            if (raytraceResult == null) {
474
                invalidPath = true
475
            } else {
476
                val blockPos = raytraceResult.blockPos
477
                reachedTarget = blockPos == target
478
479
                if (!reachedTarget) {
480
                    val state = blockPos.state
481
                    invalidPath = !visited.add(blockPos.asLong()) ||
482
                        state == null || state.isAir || state.isNotBreakable(blockPos) ||
483
                        ignoredBlocks.size >= MAX_SURROUNDING_PATH_BLOCKS
484
                    if (!invalidPath) {
485
                        ignoredBlocks += blockPos
486
                    }
487
                }
488
            }
489
        }
490
491
        return ignoredBlocks.takeIf { reachedTarget }
492
    }
493
494
    @JvmRecord
495
    private data class DestroyerTarget(
496
        val pos: BlockPos,
497
        val action: DestroyAction,
498
        val surroundingInfo: SurroundingInfo? = null,
499
        val isTarget: Boolean = false
500
    ) : Comparable<DestroyerTarget> {
501
        override fun compareTo(other: DestroyerTarget): Int {
502
            val currentSurrounding = this.surroundingInfo
503
            val otherSurrounding = other.surroundingInfo
504
505
            return when {
506
                this.isTarget && !other.isTarget -> -1
507
                !this.isTarget && other.isTarget -> 1
508
                this.isTarget && other.isTarget -> 0
509
                currentSurrounding == null && otherSurrounding != null -> -1
510
                currentSurrounding != null && otherSurrounding == null -> 1
511
                currentSurrounding == null && otherSurrounding == null -> 0
512
                currentSurrounding != null && otherSurrounding != null -> currentSurrounding.compareTo(otherSurrounding)
513
                else -> 0
514
            }
515
        }
516
    }
517
518
    /**
519
     * A candidate path that opens line of sight to a target outline point.
520
     *
521
     * @param firstBlock the block that should be broken first
522
     * @param blocks all blocks that need to be broken for the path
523
     * @param info scoring and target metadata for this path
524
     */
525
    private data class SurroundingPath(
526
        val firstBlock: BlockPos,
527
        val blocks: List<BlockPos>,
528
        val info: SurroundingInfo
529
    ) : Comparable<SurroundingPath> {
530
        override fun compareTo(other: SurroundingPath): Int = info.compareTo(other.info)
531
    }
532
533
    /**
534
     * @param actualTargetPos the target block this surrounding path opens
535
     * @param targetPoint the outline point that should become visible from the player's eyes
536
     * @param resistance proportional to the time it will take until the actual target is reached
537
     * @param blockerCount number of blocks that need to be broken for the path
538
     */
539
    private data class SurroundingInfo(
540
        val actualTargetPos: BlockPos,
541
        val targetPoint: Vec3,
542
        val resistance: Double,
543
        val blockerCount: Int,
544
        val firstBlockDistanceToTarget: Double,
545
        val firstBlockDistanceToEyes: Double,
546
    ) : Comparable<SurroundingInfo> {
547
        override fun compareTo(other: SurroundingInfo): Int = SURROUNDING_INFO_COMPARATOR.compare(this, other)
548
    }
549
550
    private val SURROUNDING_INFO_COMPARATOR = Comparator
551
        .comparingDouble<SurroundingInfo> { it.resistance }
552
        .thenComparingInt { it.blockerCount }
553
        .thenComparingDouble { it.firstBlockDistanceToTarget }
554
        .thenComparingDouble { it.firstBlockDistanceToEyes }
555
556
    private enum class DestroyAction(override val tag: String) : Tagged {
557
        DESTROY("Destroy"), USE("Use")
558
    }
559
560
    private val BlockPos.hasEntrance: Boolean
561
        get() {
562
            val block = this.getBlock()
563
            val cache = BlockPos.MutableBlockPos()
564
            return DIRECTIONS_EXCLUDING_DOWN.any {
565
                val neighbor = cache.setWithOffset(this, it)
566
                neighbor.outlineShape.isEmpty && neighbor.getBlock() !== block
567
            }
568
        }
569
570
    private val BlockPos.weakestNeighbor: BlockPos?
571
        get() {
572
            val block = this.getBlock()
573
            val cache = BlockPos.MutableBlockPos()
574
            val neighbors = DIRECTIONS_EXCLUDING_DOWN.mapNotNullTo(mutableListOf()) {
575
                val neighbor = cache.setWithOffset(this, it)
576
                val state = neighbor.state ?: return@mapNotNullTo null
577
                if (state.block !== block && !state.isAir) neighbor.immutable() to state else null
578
            }
579
580
            return neighbors.minWithOrNull(comparator)?.first
581
        }
582
583
    private val comparator: Comparator<Pair<BlockPos, BlockState>> = Comparator
584
        .comparingDouble<Pair<BlockPos, BlockState>> { (pos, state) ->
585
            miningDuration(pos, state)
586
        }
587
        .thenComparingDouble { (pos, state) ->
588
            state.getShape(world, pos, CollisionContext.of(player))
589
                .move(pos)
590
                .distanceToSqr(player.eyePosition)
591
        }
592
593
}
594