LiquidFiller module

LiquidFiller: 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/ModuleLiquidFiller.ktKotlin · 265 lines · 9.2 KB

Places blocks inside of liquid source blocks within range of you.

SettingsPlaceInPlaceOrderUseSpongeFilterBlocks
ModuleLiquidFiller.ktKotlin · Minecraft 26.2 · 265 lines · 9.2 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
20
21
import net.ccbluex.fastutil.enumSetAllOf
22
import net.ccbluex.liquidbounce.config.types.list.Tagged
23
import net.ccbluex.liquidbounce.event.events.RotationUpdateEvent
24
import net.ccbluex.liquidbounce.event.handler
25
import net.ccbluex.liquidbounce.features.module.ClientModule
26
import net.ccbluex.liquidbounce.features.module.ModuleCategories
27
import net.ccbluex.liquidbounce.utils.block.hasAnySolidPlacementNeighbor
28
import net.ccbluex.liquidbounce.utils.block.isUnobstructed
29
import net.ccbluex.liquidbounce.utils.block.searchBlocksInCuboid
30
import net.ccbluex.liquidbounce.utils.block.placer.BlockPlacer
31
import net.ccbluex.liquidbounce.utils.block.state
32
import net.ccbluex.liquidbounce.utils.collection.Filter
33
import net.ccbluex.liquidbounce.utils.collection.getSlot
34
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
35
import net.ccbluex.liquidbounce.utils.inventory.Slots
36
import net.ccbluex.liquidbounce.utils.inventory.findClosestSlot
37
import net.ccbluex.liquidbounce.utils.inventory.findBlocksEndingWith
38
import net.ccbluex.liquidbounce.utils.kotlin.Priority
39
import net.ccbluex.liquidbounce.utils.math.center
40
import net.ccbluex.liquidbounce.utils.math.sq
41
import net.minecraft.core.BlockPos
42
import net.minecraft.core.Direction
43
import net.minecraft.tags.FluidTags
44
import net.minecraft.world.level.block.Blocks
45
import net.minecraft.world.level.block.BucketPickup
46
import net.minecraft.world.level.block.state.BlockState
47
import net.minecraft.world.item.Items
48
import net.minecraft.world.level.block.SpongeBlock
49
import net.minecraft.world.phys.Vec3
50
import kotlin.math.max
51
52
/**
53
 * LiquidFiller module
54
 *
55
 * Places blocks inside of liquid source blocks within range of you.
56
 */
57
object ModuleLiquidFiller : ClientModule("LiquidFiller", ModuleCategories.WORLD) {
58
59
    private val placeIn by multiEnumChoice("PlaceIn", enumSetAllOf<PlaceIn>(), canBeNone = false)
60
    private val placeOrder by enumChoice("PlaceOrder", PlaceOrder.FURTHER_FIRST)
61
    private val useSponge by boolean("UseSponge", false)
62
63
    private val filter by enumChoice("Filter", Filter.WHITELIST)
64
    private val blocks by blocks(
65
        "Blocks",
66
        findBlocksEndingWith("WOOL").apply {
67
            add(Blocks.DIRT)
68
            add(Blocks.COBBLESTONE)
69
            add(Blocks.STONE)
70
            add(Blocks.NETHERRACK)
71
            add(Blocks.DIORITE)
72
            add(Blocks.GRANITE)
73
            add(Blocks.ANDESITE)
74
        }
75
    )
76
77
    private val placer = tree(BlockPlacer(
78
        "Placer",
79
        this,
80
        Priority.NORMAL,
81
        ::findSlotForTarget,
82
        allowSupportPlacements = false
83
    ))
84
85
    override fun onDisabled() {
86
        placer.disable()
87
    }
88
89
    @Suppress("unused")
90
    private val targetUpdater = handler<RotationUpdateEvent> {
91
        if (findSlotForTarget(null) == null) {
92
            if (!placer.isDone()) {
93
                placer.clear()
94
            }
95
            return@handler
96
        }
97
98
        placer.update(findFillTargets())
99
    }
100
101
    private fun findFillTargets(): List<BlockPos> {
102
        val eyePos = player.eyePosition
103
        val scanRange = max(placer.range, placer.wallRange).toDouble()
104
        val rangeSq = scanRange.sq()
105
        val normalFillSlot = filter.getSlot(blocks)
106
        val spongeSlot = spongeSlot()
107
108
        val positions = eyePos.searchBlocksInCuboid(scanRange.toFloat()) { pos, state ->
109
            pos.distToCenterSqr(eyePos) <= rangeSq && shouldFill(state, normalFillSlot != null, spongeSlot != null)
110
        }.mapTo(mutableListOf()) { (pos, _) -> pos }
111
        placeOrder.sort(positions, eyePos)
112
113
        return positions.mapNotNull { target ->
114
            if (useSponge && world.isWaterAt(target)) {
115
                findSpongePlacement(target, scanRange)
116
            } else {
117
                target
118
            }
119
        }
120
    }
121
122
    private fun shouldFill(state: BlockState, hasNormalFiller: Boolean, hasSponge: Boolean): Boolean {
123
        if (!state.canBeReplaced()) {
124
            return false
125
        }
126
127
        val fluidState = state.fluidState
128
        if (fluidState.isEmpty || !fluidState.isSource) {
129
            return false
130
        }
131
132
        return when {
133
            PlaceIn.WATER in placeIn && fluidState.`is`(FluidTags.WATER) ->
134
                if (useSponge) hasSponge else hasNormalFiller
135
136
            PlaceIn.LAVA in placeIn && fluidState.`is`(FluidTags.LAVA) -> hasNormalFiller
137
            else -> false
138
        }
139
    }
140
141
    private fun findSlotForTarget(pos: BlockPos?): HotbarItemSlot? {
142
        val spongeSlot = spongeSlot()
143
        val normalFillSlot = filter.getSlot(blocks)
144
145
        if (pos == null) {
146
            return spongeSlot ?: normalFillSlot
147
        }
148
149
        return when {
150
            useSponge && world.isWaterAt(pos) -> spongeSlot
151
            else -> normalFillSlot
152
        }
153
    }
154
155
    private fun findSpongePlacement(waterPos: BlockPos, scanRange: Double): BlockPos? {
156
        return waterPos.center.searchBlocksInCuboid(SpongeBlock.MAX_DEPTH.toFloat()) { pos, state ->
157
            pos.distToCenterSqr(player.eyePosition) <= scanRange.sq() &&
158
                state.canBeReplaced() &&
159
                pos.hasAnySolidPlacementNeighbor() &&
160
                pos.isUnobstructed() &&
161
                canAbsorbWaterFrom(pos, waterPos)
162
        }.minByOrNull { (pos, _) -> pos.distToCenterSqr(player.eyePosition) }?.first
163
    }
164
165
    /**
166
     * @see SpongeBlock.removeWaterBreadthFirstSearch
167
     */
168
    @Suppress("CognitiveComplexMethod")
169
    private fun canAbsorbWaterFrom(spongePos: BlockPos, waterPos: BlockPos): Boolean {
170
        if (spongePos == waterPos) {
171
            return true
172
        }
173
174
        var reachedTarget = false
175
        BlockPos.breadthFirstTraversal(
176
            spongePos,
177
            SpongeBlock.MAX_DEPTH,
178
            SpongeBlock.MAX_COUNT + 1,
179
            { pos, consumer ->
180
                for (direction in Direction.entries) {
181
                    consumer.accept(pos.relative(direction))
182
                }
183
            },
184
            { pos ->
185
                if (pos == spongePos) {
186
                    return@breadthFirstTraversal BlockPos.TraversalNodeStatus.ACCEPT
187
                }
188
189
                val state = pos.state ?: return@breadthFirstTraversal BlockPos.TraversalNodeStatus.SKIP
190
                val fluidState = state.fluidState
191
                if (!fluidState.`is`(FluidTags.WATER)) {
192
                    return@breadthFirstTraversal BlockPos.TraversalNodeStatus.SKIP
193
                }
194
195
                if (pos == waterPos) {
196
                    reachedTarget = true
197
                    return@breadthFirstTraversal BlockPos.TraversalNodeStatus.STOP
198
                }
199
200
                when (val block = state.block) {
201
                    is BucketPickup -> BlockPos.TraversalNodeStatus.ACCEPT
202
203
                    else -> if (
204
                        block === Blocks.KELP ||
205
                        block === Blocks.KELP_PLANT ||
206
                        block === Blocks.SEAGRASS ||
207
                        block === Blocks.TALL_SEAGRASS
208
                    ) {
209
                        BlockPos.TraversalNodeStatus.ACCEPT
210
                    } else {
211
                        BlockPos.TraversalNodeStatus.SKIP
212
                    }
213
                }
214
            }
215
        )
216
217
        return reachedTarget
218
    }
219
220
    private fun spongeSlot() = if (useSponge) {
221
        Slots.OffhandWithHotbar.findClosestSlot(Items.SPONGE)
222
    } else {
223
        null
224
    }
225
226
    private enum class PlaceIn(override val tag: String) : Tagged {
227
        WATER("Water"),
228
        LAVA("Lava")
229
    }
230
231
    private enum class PlaceOrder(override val tag: String) : Tagged {
232
        RANDOM("Random") {
233
            override fun sort(positions: MutableList<BlockPos>, eyePos: Vec3) {
234
                positions.shuffle()
235
            }
236
        },
237
238
        CLOSER_FIRST("CloserFirst") {
239
            override fun sort(positions: MutableList<BlockPos>, eyePos: Vec3) {
240
                positions.sortBy { it.distToCenterSqr(eyePos) }
241
            }
242
        },
243
244
        FURTHER_FIRST("FurtherFirst") {
245
            override fun sort(positions: MutableList<BlockPos>, eyePos: Vec3) {
246
                positions.sortByDescending { it.distToCenterSqr(eyePos) }
247
            }
248
        },
249
250
        BOTTOM_TOP("BottomTop") {
251
            override fun sort(positions: MutableList<BlockPos>, eyePos: Vec3) {
252
                positions.sortBy { it.y }
253
            }
254
        },
255
256
        TOP_BOTTOM("TopBottom") {
257
            override fun sort(positions: MutableList<BlockPos>, eyePos: Vec3) {
258
                positions.sortByDescending { it.y }
259
            }
260
        };
261
262
        abstract fun sort(positions: MutableList<BlockPos>, eyePos: Vec3)
263
    }
264
}
265