BedPlates module

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

1 implementationRENDER

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)RENDERsrc/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleBedPlates.ktKotlin · 266 lines · 10.8 KB

Allows you to see what blocks are around the bed

SettingsBackgroundColorOutlineMaxLayersShowBedTextShadowRenderOffsetMaxCountHighlightUnbreakableCompactPreventOverlapIgnoreAdjacentBlocksFilter
ModuleBedPlates.ktKotlin · Minecraft 26.2 · 266 lines · 10.8 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.render
20
21
import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet
22
import kotlinx.coroutines.Dispatchers
23
import net.ccbluex.fastutil.mapToArray
24
import net.ccbluex.liquidbounce.additions.drawStackCount
25
import net.ccbluex.liquidbounce.config.types.CurveValue.Axis.Companion.axis
26
import net.ccbluex.liquidbounce.config.types.group.Mode
27
import net.ccbluex.liquidbounce.config.types.group.ModeValueGroup
28
import net.ccbluex.liquidbounce.event.events.BedStateChangeEvent
29
import net.ccbluex.liquidbounce.event.events.GameTickEvent
30
import net.ccbluex.liquidbounce.event.events.OverlayRenderEvent
31
import net.ccbluex.liquidbounce.event.handler
32
import net.ccbluex.liquidbounce.event.suspendHandler
33
import net.ccbluex.liquidbounce.features.module.ClientModule
34
import net.ccbluex.liquidbounce.features.module.ModuleCategories
35
import net.ccbluex.liquidbounce.render.gui.ItemStackListRenderer.createItemStackForRendering
36
import net.ccbluex.liquidbounce.render.gui.ItemStackListRenderer.drawItemStackList
37
import net.ccbluex.liquidbounce.render.engine.type.Color4b
38
import net.ccbluex.liquidbounce.render.withPush
39
import net.ccbluex.liquidbounce.utils.block.bed.BedBlockTracker
40
import net.ccbluex.liquidbounce.utils.block.bed.BedState
41
import net.ccbluex.liquidbounce.utils.block.bed.SurroundingBlock
42
import net.ccbluex.liquidbounce.utils.block.bed.isSelfBedChoices
43
import net.ccbluex.liquidbounce.utils.collection.Filter
44
import net.ccbluex.liquidbounce.utils.collection.blockSortedSetOf
45
import net.ccbluex.liquidbounce.utils.entity.cameraDistance
46
import net.ccbluex.liquidbounce.utils.inventory.Slots
47
import net.ccbluex.liquidbounce.utils.kotlin.Minecraft
48
import net.ccbluex.liquidbounce.utils.kotlin.addAll
49
import net.ccbluex.liquidbounce.utils.render.WorldToScreen
50
import net.minecraft.core.BlockPos
51
import net.minecraft.world.item.ItemStack
52
import net.minecraft.world.level.block.Block
53
import net.minecraft.world.level.block.Blocks
54
import org.joml.Vector2f
55
import java.util.function.Predicate
56
57
object ModuleBedPlates : ClientModule("BedPlates", ModuleCategories.RENDER), BedBlockTracker.Subscriber {
58
    private val ROMAN_NUMERALS = arrayOf("", "I", "II", "III", "IV", "V", "VI", "VII", "VIII")
59
60
    private val backgroundColor by color("BackgroundColor", Color4b.DEFAULT_BG_COLOR)
61
    private val outline by boolean("Outline", false)
62
63
    override val maxLayers by int("MaxLayers", 5, 1..5).onChanged {
64
        BedBlockTracker.triggerRescan()
65
    }
66
    private val showBed by boolean("ShowBed", true)
67
    private val textShadow by boolean("TextShadow", true)
68
    private val renderOffset by vec3d("RenderOffset", useLocateButton = false)
69
    private val scale = curve(
70
        "Scale",
71
        mutableListOf(Vector2f(0f, 1f), Vector2f(200f, 1f)),
72
        xAxis = "Distance" axis 0f..200f,
73
        yAxis = "Scale" axis 0.25f..4f,
74
    )
75
    private val maxCount by int("MaxCount", 8, 1..64)
76
    private val highlightUnbreakable by boolean("HighlightUnbreakable", true)
77
    private val compact by boolean("Compact", true)
78
    private val preventOverlap by boolean("PreventOverlap", true)
79
    private val filterMode = choices("FilterMode", 0) {
80
        arrayOf(FilterMode.Predefined, FilterMode.Custom)
81
    }
82
    private val ignoreSelfBed = choices("IgnoreSelfBed", 0, ::isSelfBedChoices)
83
    private val ignoreAdjacent by boolean("IgnoreAdjacent", false)
84
85
    private sealed class FilterMode(name: String) : Mode(name), Predicate<Block> {
86
        final override val parent: ModeValueGroup<*>
87
            get() = filterMode
88
89
        object Predefined : FilterMode("Predefined") {
90
            private val WHITELIST_NON_SOLID: Set<Block> = ReferenceOpenHashSet.of(
91
                Blocks.LADDER,
92
93
                Blocks.WATER,
94
95
                Blocks.GLASS,
96
            ).apply {
97
                addAll(Blocks.STAINED_GLASS)
98
            }
99
100
            override fun test(block: Block): Boolean {
101
                val state = block.defaultBlockState()
102
                return !(state.isAir ||
103
                    !state.isRedstoneConductor(world, BlockPos.ZERO) && block !in WHITELIST_NON_SOLID)
104
            }
105
        }
106
107
        object Custom : FilterMode("Custom") {
108
            private val blocks by blocks("Blocks", blockSortedSetOf())
109
            private val filter by enumChoice("Filter", Filter.BLACKLIST)
110
111
            override fun test(block: Block): Boolean {
112
                return filter(block, blocks)
113
            }
114
        }
115
    }
116
117
    private data class BedStateRenderState(
118
        @JvmField val bedState: BedState,
119
        @JvmField var distance: Double,
120
        @JvmField var surrounding: List<SurroundingBlock>,
121
        @JvmField var itemStacksForRender: List<ItemStack>,
122
    ) : Comparable<BedStateRenderState> {
123
        constructor(bedState: BedState) : this(bedState, 0.0, emptyList(), emptyList())
124
125
        override fun compareTo(other: BedStateRenderState): Int {
126
            return distance.compareTo(other.distance)
127
        }
128
    }
129
130
    private val beds = ArrayList<BedStateRenderState>()
131
132
    private fun updateAndSortBeds() {
133
        beds.forEach { renderState ->
134
            val bedState = renderState.bedState
135
            renderState.distance = bedState.pos.cameraDistance()
136
137
            val surrounding = (if (compact) bedState.compactSurroundingBlocks else bedState.surroundingBlocks)
138
                .filter { filterMode.activeMode.test(it.block) }
139
            renderState.surrounding = surrounding
140
141
            renderState.itemStacksForRender = if (showBed) {
142
                val bedItemStack = bedState.block.asItem().defaultInstance
143
                if (surrounding.isEmpty()) {
144
                    listOf(bedItemStack)
145
                } else {
146
                    val list = ArrayList<ItemStack>(surrounding.size + 1)
147
                    list.add(bedItemStack) // Add bed itself at first
148
                    surrounding.mapTo(list) { it.block.createItemStackForRendering(it.count) }
149
                }
150
            } else {
151
                surrounding.mapToArray { it.block.createItemStackForRendering(it.count) }.asList()
152
            }
153
        }
154
        beds.sort()
155
    }
156
157
    @Suppress("unused")
158
    // Run on render thread because the scanner runs async
159
    private val bedStateChangeHandler = suspendHandler<BedStateChangeEvent>(Dispatchers.Minecraft) { event ->
160
        beds.clear()
161
        beds.ensureCapacity(event.bedStates.size)
162
        event.bedStates.mapTo(beds, ::BedStateRenderState)
163
        updateAndSortBeds()
164
    }
165
166
    @Suppress("unused")
167
    private val tickHandler = handler<GameTickEvent> {
168
        updateAndSortBeds()
169
    }
170
171
    @Suppress("unused")
172
    private val renderHandler = handler<OverlayRenderEvent> { event ->
173
        fun isAdjacentAndNotEquals(pos1: BlockPos, pos2: BlockPos): Boolean {
174
            return pos1 != pos2 && pos1.distManhattan(pos2) <= 1
175
        }
176
177
        beds.sort()
178
179
        var i = 0
180
        for ((bedState, distance, surrounding, itemStacksForRender) in beds) {
181
            if (i >= maxCount) {
182
                break
183
            }
184
185
            val currPos = bedState.trackedBlockPos
186
            val scale = scale.transform(distance.toFloat())
187
188
            if (scale < 0.01f ||
189
                ignoreSelfBed.activeMode.isSelfBed(bedState.block, currPos) ||
190
                ignoreAdjacent && beds.any { isAdjacentAndNotEquals(it.bedState.trackedBlockPos, currPos) }
191
            ) {
192
                continue
193
            }
194
195
            val screenPos = WorldToScreen.calculateScreenPos(bedState.pos.add(renderOffset)) ?: continue
196
197
            val outlineColor = if (outline) {
198
                Color4b.fullAlpha(bedState.block.color.mapColor.col)
199
            } else {
200
                Color4b.TRANSPARENT
201
            }
202
203
            event.context.drawItemStackList(itemStacksForRender)
204
                .rowLength(Int.MAX_VALUE)
205
                .scale(scale)
206
                .centerX(screenPos.x)
207
                .centerY(screenPos.y)
208
                .rectBackground(backgroundColor, outlineColor)
209
                .itemStackRenderer { textRenderer, index, stack, x, y ->
210
                    if (index == 0 && showBed) {
211
                        // bed
212
                        item(stack, x, y)
213
                        drawStackCount(textRenderer, stack, x, y, "${distance.toInt()}m")
214
                    } else {
215
                        val surroundingBlock = surrounding[if (showBed) index - 1 else index]
216
                        val defaultState = surroundingBlock.block.defaultBlockState()
217
                        val color =
218
                            if (highlightUnbreakable && defaultState.requiresCorrectToolForDrops()
219
                                && Slots.Hotbar.findSlot { s -> s.isCorrectToolForDrops(defaultState) } == null
220
                            ) {
221
                                Color4b.RED
222
                            } else {
223
                                Color4b.WHITE
224
                            }.argb
225
226
                        item(stack, x, y)
227
                        val countString = stack.count.toString()
228
                        pose().withPush {
229
                            // draw layer text
230
                            if (!compact) {
231
                                text(
232
                                    textRenderer,
233
                                    ROMAN_NUMERALS[surroundingBlock.layer],
234
                                    x,
235
                                    y,
236
                                    color,
237
                                    textShadow,
238
                                )
239
                            }
240
                            // drawStackCount, with custom color (copied from DrawContext)
241
                            text(
242
                                textRenderer,
243
                                countString,
244
                                x + 19 - 2 - textRenderer.width(countString),
245
                                y + 6 + 3,
246
                                color,
247
                                textShadow,
248
                            )
249
                        }
250
                    }
251
                }.draw(preventOverlap)
252
253
            i++
254
        }
255
    }
256
257
    override fun onEnabled() {
258
        BedBlockTracker.subscribe(this)
259
    }
260
261
    override fun onDisabled() {
262
        BedBlockTracker.unsubscribe(this)
263
        beds.clear()
264
    }
265
}
266