Skip to content

Commit

Permalink
feat: BlockIn (#5533)
Browse files Browse the repository at this point in the history
  • Loading branch information
MukjepScarlet authored Feb 5, 2025
1 parent 70c4a62 commit a3ea8c1
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ object ModuleManager : EventListener, Iterable<ClientModule> by modules {
ModuleNuker,
ModuleExtinguish,
ModuleBedDefender,
ModuleBlockIn,
ModuleSurround,
ModulePacketMine,
ModuleHoleFiller,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2015 - 2025 CCBlueX
*
* LiquidBounce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidBounce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*/
package net.ccbluex.liquidbounce.features.module.modules.world

import net.ccbluex.liquidbounce.event.events.NotificationEvent
import net.ccbluex.liquidbounce.event.events.PlayerMovementTickEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.event.tickHandler
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.ClientModule
import net.ccbluex.liquidbounce.utils.block.getState
import net.ccbluex.liquidbounce.utils.block.placer.BlockPlacer
import net.ccbluex.liquidbounce.utils.client.notification
import net.ccbluex.liquidbounce.utils.collection.Filter
import net.ccbluex.liquidbounce.utils.inventory.HotbarItemSlot
import net.ccbluex.liquidbounce.utils.inventory.Slots
import net.ccbluex.liquidbounce.utils.item.getBlock
import net.ccbluex.liquidbounce.utils.kotlin.Priority
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Direction
import kotlin.random.Random

/**
* BlockIn module
*
* Builds blocks to cover yourself.
*/
object ModuleBlockIn : ClientModule("BlockIn", Category.WORLD, disableOnQuit = true) {
private val blockPlacer = tree(BlockPlacer("Placer", this, Priority.NORMAL, ::slotFinder))
private val autoDisable by boolean("AutoDisable", true)
private val filter by enumChoice("Filter", Filter.BLACKLIST)
private val blocks by blocks("Blocks", hashSetOf())

private val startPos = BlockPos.Mutable()
private var rotateClockwise = false
private var blockList = emptySet<BlockPos>()

override fun disable() {
startPos.set(BlockPos.ORIGIN)
blockList = emptySet()
blockPlacer.disable()
}

override fun enable() {
startPos.set(player.blockPos)
rotateClockwise = Random.nextBoolean()
getPositions()
}

private fun Direction.next() = if (rotateClockwise) {
rotateYClockwise()
} else {
rotateYCounterclockwise()
}

private fun getPositions() {
// Rotate clockwise from player facing
blockList = sequence<BlockPos> {
var direction = player.horizontalFacing

repeat(4) {
val value = startPos.offset(direction)
yield(value)
yield(value.up())
direction = direction.next()
}

yield(startPos.up(2))
}.filterTo(linkedSetOf()) { // keep order
it.getState()!!.isReplaceable
}
}

@Suppress("unused")
private val tickHandler = tickHandler {
blockPlacer.update(blockList)
waitUntil(blockPlacer::isDone)

if (autoDisable) {
notification(name, message("filled"), NotificationEvent.Severity.SUCCESS)
enabled = false
}
getPositions()
}

@Suppress("unused")
private val movementHandler = handler<PlayerMovementTickEvent> {
val currentPos = player.blockPos

if (currentPos != startPos && currentPos != startPos.up()) {
notification(name, message("positionChanged"), NotificationEvent.Severity.ERROR)
enabled = false
}
}

private fun slotFinder(pos: BlockPos?): HotbarItemSlot? {
val blockSlots = Slots.Hotbar.mapNotNull {
it to (it.itemStack.getBlock()?.takeIf { b -> filter(b, blocks) } ?: return@mapNotNull null)
}

return if (pos in blockList) {
blockSlots.maxByOrNull { (_, block) -> block.hardness }
} else {
blockSlots.minByOrNull { (_, block) -> block.hardness }
}?.first
}

}
3 changes: 3 additions & 0 deletions src/main/resources/resources/liquidbounce/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,9 @@
"liquidbounce.module.autoBuild.messages.noFlintAndSteel": "No flint-and-steel found, disabling...",
"liquidbounce.module.dupe.description": "Attempts to Auto-Dupe items from your inventory by using exploits.",
"liquidbounce.module.surround.description": "Builds holes that protect you from explosion damage.",
"liquidbounce.module.blockIn.description": "Builds blocks to cover yourself.",
"liquidbounce.module.blockIn.messages.filled": "Filled!",
"liquidbounce.module.blockIn.messages.positionChanged": "Your position is changed!",
"liquidbounce.module.packetMine.description": "Allows you to mine blocks by clicking them once.",
"liquidbounce.module.fastExp.description": "Automatically repairs your armor.",
"liquidbounce.module.bookBot.description": "Automatically writes in books.",
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/resources/liquidbounce/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@
"liquidbounce.module.autoBuild.messages.noFlintAndSteel": "没有打火石,无法启动传送门, 关闭中...",
"liquidbounce.module.dupe.description": "尝试利用漏洞从物品栏中自动复制物品。",
"liquidbounce.module.surround.description": "自动在周围建造安全方块,保护你免受爆炸伤害。",
"liquidbounce.module.blockIn.description": "自动在周围建造方块覆盖自己。",
"liquidbounce.module.blockIn.messages.filled": "放置完成!",
"liquidbounce.module.blockIn.messages.positionChanged": "你的位置变了!已自动关闭模块。",
"liquidbounce.module.packetMine.description": "使你能通过单次点击破坏方块。",
"liquidbounce.module.fastExp.description": "自动用经验瓶修复你的装备。",
"liquidbounce.module.bookBot.description": "自动在书中写字。",
Expand Down

0 comments on commit a3ea8c1

Please sign in to comment.