Skip to content

Commit 7165d1a

Browse files
committed
ChestCounter HUD element and StorageESP module list info
1 parent 59752a3 commit 7165d1a

File tree

3 files changed

+94
-3
lines changed

3 files changed

+94
-3
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.lambda.client.gui.hudgui.elements.world
2+
3+
import com.lambda.client.event.SafeClientEvent
4+
import com.lambda.client.gui.hudgui.LabelHud
5+
import com.lambda.client.manager.managers.ChestCountManager
6+
7+
internal object ChestCounter : LabelHud(
8+
name = "ChestCounter",
9+
category = Category.WORLD,
10+
description = "Displays the number of chests and shulkers currently loaded"
11+
) {
12+
private val dubs by setting("Count Dubs", true, description = "Counts double chests instead of individual chests")
13+
private val shulkers by setting("Count Shulkers", true, description = "Counts shulkers in the world")
14+
15+
override fun SafeClientEvent.updateText() {
16+
displayText.add(if (dubs) "Dubs:" else "Chests:", primaryColor)
17+
displayText.add(if (dubs) "${ChestCountManager.dubsCount}" else "${ChestCountManager.chestCount}", secondaryColor)
18+
if (!shulkers) return
19+
displayText.add("Shulkers:", primaryColor)
20+
displayText.add("${ChestCountManager.shulkerCount}", secondaryColor)
21+
}
22+
}
23+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.lambda.client.manager.managers
2+
3+
import com.lambda.client.LambdaMod
4+
import com.lambda.client.event.SafeClientEvent
5+
import com.lambda.client.gui.hudgui.elements.world.ChestCounter
6+
import com.lambda.client.manager.Manager
7+
import com.lambda.client.module.modules.render.StorageESP
8+
import com.lambda.client.util.TickTimer
9+
import com.lambda.client.util.TimeUnit
10+
import com.lambda.client.util.threads.defaultScope
11+
import com.lambda.client.util.threads.safeListener
12+
import kotlinx.coroutines.Job
13+
import kotlinx.coroutines.launch
14+
import net.minecraft.tileentity.TileEntityChest
15+
import net.minecraft.tileentity.TileEntityShulkerBox
16+
import net.minecraftforge.fml.common.gameevent.TickEvent
17+
18+
object ChestCountManager : Manager {
19+
private const val searchDelayTicks = 5L
20+
private val delayTimer: TickTimer = TickTimer(TimeUnit.TICKS)
21+
var chestCount = 0
22+
private set
23+
var dubsCount = 0
24+
private set
25+
var shulkerCount = 0
26+
private set
27+
private var chestCountSearchJob: Job? = null
28+
29+
init {
30+
safeListener<TickEvent.ClientTickEvent> {
31+
if (it.phase != TickEvent.Phase.END) return@safeListener
32+
if (!ChestCounter.visible && !StorageESP.chestCountSetting) return@safeListener
33+
if (chestCountSearchJob?.isActive == true) return@safeListener
34+
if (delayTimer.tick(searchDelayTicks)) {
35+
chestCountSearchJob = defaultScope.launch {
36+
searchLoadedTileEntities()
37+
delayTimer.reset()
38+
}
39+
}
40+
}
41+
}
42+
43+
private fun SafeClientEvent.searchLoadedTileEntities() {
44+
try {
45+
var dubsC = 0
46+
var chestC = 0
47+
var shulkC = 0
48+
for (tileEntity in world.loadedTileEntityList) {
49+
if (tileEntity is TileEntityChest) {
50+
chestC++
51+
if (tileEntity.adjacentChestXPos != null || tileEntity.adjacentChestZPos != null) dubsC++
52+
} else if (tileEntity is TileEntityShulkerBox) shulkC++
53+
}
54+
dubsCount = dubsC
55+
chestCount = chestC
56+
shulkerCount = shulkC
57+
} catch (e: Exception) {
58+
LambdaMod.LOG.error("ChestCounter: Error searching loaded tile entities", e)
59+
}
60+
}
61+
}

src/main/kotlin/com/lambda/client/module/modules/render/StorageESP.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.lambda.client.module.modules.render
33
import com.lambda.client.event.SafeClientEvent
44
import com.lambda.client.event.events.RenderWorldEvent
55
import com.lambda.client.event.listener.listener
6+
import com.lambda.client.manager.managers.ChestCountManager
67
import com.lambda.client.module.Category
78
import com.lambda.client.module.Module
89
import com.lambda.client.util.color.ColorHolder
@@ -39,7 +40,7 @@ object StorageESP : Module(
3940
private val dispenser by setting("Dispenser", false, { page == Page.TYPE })
4041
private val hopper by setting("Hopper", false, { page == Page.TYPE })
4142
private val cart by setting("Minecart", false, { page == Page.TYPE })
42-
private val infinite by setting("Infinite Range", true) // To avoid a hard to control range slider
43+
private val infinite by setting("Infinite Range", true, { page == Page.TYPE}) // To avoid a hard to control range slider
4344
private val range by setting("Range", 64, 8..512, 1, { page == Page.TYPE && !infinite }, unit = " blocks")
4445

4546
/* Color settings */
@@ -61,12 +62,18 @@ object StorageESP : Module(
6162
private val aTracer by setting("Tracer Alpha", 200, 0..255, 1, { page == Page.RENDER && tracer })
6263
private val thickness by setting("Line Thickness", 2.0f, 0.25f..5.0f, 0.25f, { page == Page.RENDER })
6364

65+
/* Count settings */
66+
val chestCountSetting by setting("Count", true, { page == Page.COUNT })
67+
private val dubs by setting("Dubs", true, visibility = { chestCountSetting && page == Page.COUNT})
68+
6469
private enum class Page {
65-
TYPE, COLOR, RENDER
70+
TYPE, COLOR, RENDER, COUNT
6671
}
6772

6873
override fun getHudInfo(): String {
69-
return renderer.size.toString()
74+
return if (chestCountSetting)
75+
(if(dubs) "${ChestCountManager.dubsCount}" else "${ChestCountManager.chestCount}")
76+
else ""
7077
}
7178

7279
private var cycler = HueCycler(600)

0 commit comments

Comments
 (0)