Skip to content

Commit 14f21bb

Browse files
committed
fix esp block entities
1 parent 509f5b9 commit 14f21bb

File tree

3 files changed

+57
-18
lines changed

3 files changed

+57
-18
lines changed

src/main/kotlin/com/lambda/config/groups/EntityColorSettings.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ import com.lambda.friend.FriendManager.isFriend
2424
import com.lambda.util.EntityUtils
2525
import com.lambda.util.EntityUtils.entityGroup
2626
import com.lambda.util.NamedEnum
27+
import com.lambda.util.extension.blockColor
2728
import com.lambda.util.extension.entityColor
2829
import com.lambda.util.math.dist
2930
import com.lambda.util.math.lerp
31+
import net.minecraft.block.entity.BlockEntity
3032
import net.minecraft.client.network.OtherClientPlayerEntity
3133
import net.minecraft.entity.Entity
3234
import java.awt.Color
@@ -76,11 +78,15 @@ class EntityColorSettings(
7678
EntityUtils.EntityGroup.Projectile -> projectileColor
7779
EntityUtils.EntityGroup.Boss -> bossColor
7880
EntityUtils.EntityGroup.Decoration -> decorationColor
79-
EntityUtils.EntityGroup.Block -> blockColor
80-
EntityUtils.EntityGroup.Misc -> miscColor
81+
else -> miscColor
8182
}
8283
}
8384

85+
context(safeContext: SafeContext)
86+
fun getColor(blockEntity: BlockEntity): Color =
87+
if (useNaturalColors) safeContext.blockColor(blockEntity.cachedState, blockEntity.pos)
88+
else blockColor
89+
8490
private fun hasSpecialCase(entity: Entity, group: EntityUtils.EntityGroup) =
8591
group == EntityUtils.EntityGroup.Player &&
8692
((entity is OtherClientPlayerEntity && entity.isFriend && separateFriendColor) || playerDistanceGradient)

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

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ import com.lambda.config.applyEdits
2121
import com.lambda.config.groups.EntityColorSettings
2222
import com.lambda.config.groups.EntitySelectionSettings
2323
import com.lambda.config.groups.OutlineSettings
24-
import com.lambda.config.groups.ScreenLineSettings
2524
import com.lambda.config.groups.WorldLineSettings
25+
import com.lambda.graphics.mc.RenderBuilder
2626
import com.lambda.graphics.mc.renderer.ImmediateRenderer.Companion.immediateRenderer
2727
import com.lambda.graphics.util.DynamicAABB.Companion.interpolatedBox
2828
import com.lambda.module.Module
2929
import com.lambda.module.tag.ModuleTag
30-
import com.lambda.util.EntityUtils
3130
import com.lambda.util.NamedEnum
3231
import com.lambda.util.math.setAlpha
33-
import fi.dy.masa.malilib.render.RenderUtils.depthTest
34-
import net.minecraft.client.network.ClientPlayerEntity
32+
import net.minecraft.block.entity.BlockEntity
33+
import net.minecraft.entity.Entity
34+
import net.minecraft.util.math.Box
35+
import java.awt.Color
3536

3637
object ESP : Module(
3738
name = "ESP",
@@ -72,16 +73,45 @@ object ESP : Module(
7273
with(safeContext) {
7374
world.entities.forEach { entity ->
7475
if (!entitySettings.isSelected(entity)) return@forEach
75-
val entityColor = entityColors.getColor(entity)
76-
when (mode) {
77-
EspMode.Shader -> worldOutline(entity, outlineStyle.toStyle(entityColor))
78-
EspMode.Box -> {
79-
box(entity.interpolatedBox, boxOutlineSettings) {
80-
if (!drawFilled) hideFill()
81-
else if (!drawOutline) hideOutline()
82-
colors(entityColor.setAlpha(fillAlpha), entityColor.setAlpha(outlineAlpha))
83-
}
84-
}
76+
val color = entityColors.getColor(entity)
77+
drawEsp<Entity>(
78+
entity,
79+
color,
80+
{ worldOutline(it, outlineStyle.toStyle(color)) },
81+
{ listOf(it.interpolatedBox) }
82+
)
83+
}
84+
val chunkMap = world.chunkManager.chunks
85+
(0 until chunkMap.loadedChunkCount).forEach { chunk ->
86+
chunkMap.chunks.get(chunk)?.blockEntities?.values?.forEach { blockEntity ->
87+
if (!entitySettings.isSelected(blockEntity)) return@forEach
88+
val color = entityColors.getColor(blockEntity)
89+
drawEsp<BlockEntity>(
90+
blockEntity,
91+
color,
92+
{ worldOutline(it.pos, outlineStyle.toStyle(color)) },
93+
{ it.cachedState.getOutlineShape(world, it.pos).boundingBoxes }
94+
)
95+
}
96+
}
97+
}
98+
}
99+
}
100+
101+
private fun <T> RenderBuilder.drawEsp(
102+
entity: T,
103+
color: Color,
104+
outline: RenderBuilder.(T) -> Unit,
105+
boxes: (T) -> Collection<Box>
106+
) {
107+
when (mode) {
108+
EspMode.Shader -> outline(entity)
109+
EspMode.Box -> {
110+
boxes(entity).forEach { box ->
111+
box(box, boxOutlineSettings) {
112+
if (!drawFilled) hideFill()
113+
else if (!drawOutline) hideOutline()
114+
colors(color.setAlpha(fillAlpha), color.setAlpha(outlineAlpha))
85115
}
86116
}
87117
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ import org.joml.component2
4646
import java.awt.Color
4747
import kotlin.math.max
4848

49-
//ToDo: implement all settings
5049
object Nametags : Module(
5150
name = "Nametags",
5251
description = "Displays information about entities above them",
@@ -76,7 +75,11 @@ object Nametags : Module(
7675
private val itemNameScale by setting("Item Name Scale", 0.7f, 0.1f..1.0f, 0.01f) { itemName }.group(Group.General)
7776
private val itemCount by setting("Item Count", true).group(Group.General)
7877
private val durabilityMode by setting("Durability Mode", DurabilityMode.Text) { gear }.group(Group.General)
79-
private val entitySelectionSettings = EntitySelectionSettings(c = this, baseGroup = arrayOf(Group.Entities))
78+
private val entitySelectionSettings = EntitySelectionSettings(c = this, baseGroup = arrayOf(Group.Entities)).apply {
79+
applyEdits {
80+
hide(::blockEntities)
81+
}
82+
}
8083
private val background by setting("Background", true).group(Group.Background)
8184
private val backgroundColor by setting("Background Color", Color(0, 0, 0, 60)) { background }.group(Group.Background)
8285
private val backgroundSize by setting("Background Size", 1.0f, 1.0f..2.0f, 0.01f) { background }.group(Group.Background)

0 commit comments

Comments
 (0)