Skip to content

Commit 202d4fc

Browse files
authored
Fix: Transparency for block colors in blockesp (#208)
Now it has transparency when using the block color mode. And custom colors for portals and Ender Chests cuz they don't have good colors from the map color map.
1 parent 7b33dce commit 202d4fc

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/main/kotlin/com/lambda/module/modules/render/BlockESP.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ object BlockESP : Module(
5050
private val mesh by setting("Mesh", true, "Connect similar adjacent blocks") { searchBlocks }.onValueChange(::rebuildMesh)
5151

5252
private val useBlockColor by setting("Use Block Color", false, "Use the color of the block instead") { searchBlocks }.onValueChange(::rebuildMesh)
53+
private val blockColorAlpha by setting("Block Color Alpha", 0.3, 0.1..1.0, 0.05) { searchBlocks && useBlockColor }.onValueChange { _, _ -> ::rebuildMesh }
54+
5355
private val faceColor by setting("Face Color", Color(100, 150, 255, 51), "Color of the surfaces") { searchBlocks && drawFaces && !useBlockColor }.onValueChange(::rebuildMesh)
5456
private val outlineColor by setting("Outline Color", Color(100, 150, 255, 128), "Color of the outlines") { searchBlocks && drawOutlines && !useBlockColor }.onValueChange(::rebuildMesh)
5557
private val outlineWidth by setting("Outline Width", 1.0f, 0.5f..5.0f, 0.5f) { searchBlocks && drawOutlines }.onValueChange(::rebuildMesh)
@@ -77,13 +79,15 @@ object BlockESP : Module(
7779
} else DirectionMask.ALL
7880

7981
runSafe {
82+
// TODO: Add custom color option when map options are implemented
8083
val extractedColor = blockColor(state, position.toBlockPos())
84+
val finalColor = Color(extractedColor.red, extractedColor.green, extractedColor.blue, (blockColorAlpha * 255).toInt())
8185
val pos = position.toBlockPos()
8286
val shape = state.getOutlineShape(world, pos)
8387
val worldBox = if (shape.isEmpty) Box(pos) else shape.boundingBox.offset(pos)
8488
box(worldBox) {
8589
if (drawFaces)
86-
filled(if (useBlockColor) extractedColor else faceColor, sides)
90+
filled(if (useBlockColor) finalColor else faceColor, sides)
8791
if (drawOutlines)
8892
outline(if (useBlockColor) extractedColor else BlockESP.outlineColor, sides, BlockESP.outlineMode, thickness = outlineWidth)
8993
}

src/main/kotlin/com/lambda/util/extension/World.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ fun SafeContext.collisionShape(state: BlockState, pos: BlockPos): VoxelShape =
5353
fun SafeContext.outlineShape(state: BlockState, pos: BlockPos) =
5454
state.getOutlineShape(world, pos).offset(pos)
5555

56-
fun SafeContext.blockColor(state: BlockState, pos: BlockPos) =
57-
Color(state.getMapColor(world, pos).color)
56+
fun SafeContext.blockColor(state: BlockState, pos: BlockPos): Color {
57+
return when (state.block) {
58+
Blocks.ENDER_CHEST -> Color(0xFF00FF)
59+
Blocks.NETHER_PORTAL -> Color(0xaa00aa)
60+
Blocks.END_PORTAL -> Color(0xFF00FF)
61+
else ->
62+
Color(state.getMapColor(world, pos).color, false)
63+
}
64+
}
5865

5966
fun World.getBlockState(x: Int, y: Int, z: Int): BlockState {
6067
if (isOutOfHeightLimit(y)) return Blocks.VOID_AIR.defaultState

0 commit comments

Comments
 (0)