diff --git a/src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/ChestCounter.kt b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/ChestCounter.kt new file mode 100644 index 000000000..ebe67362d --- /dev/null +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/ChestCounter.kt @@ -0,0 +1,31 @@ +package com.lambda.client.gui.hudgui.elements.world + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.gui.hudgui.LabelHud +import com.lambda.client.manager.managers.ChestCountManager + +internal object ChestCounter : LabelHud( + name = "ChestCounter", + category = Category.WORLD, + description = "Displays the number of chests and shulkers currently loaded" +) { + private val dubs by setting("Count Dubs", true, description = "Counts double chests instead of individual chests") + private val shulkers by setting("Count Shulkers", true, description = "Counts shulkers in the world") + + override fun SafeClientEvent.updateText() { + if (dubs) { + displayText.add("Dubs:", primaryColor) + displayText.add("${ChestCountManager.dubsCount}", secondaryColor) + displayText.add("Chests:", primaryColor) + displayText.add("${ChestCountManager.chestCount - (ChestCountManager.dubsCount * 2)}", secondaryColor) + } else { + displayText.add("Chests:", primaryColor) + displayText.add("${ChestCountManager.chestCount}", secondaryColor) + } + + if (!shulkers) return + displayText.add("Shulkers:", primaryColor) + displayText.add("${ChestCountManager.shulkerCount}", secondaryColor) + } +} + diff --git a/src/main/kotlin/com/lambda/client/manager/managers/ChestCountManager.kt b/src/main/kotlin/com/lambda/client/manager/managers/ChestCountManager.kt new file mode 100644 index 000000000..7f0e48ebe --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/ChestCountManager.kt @@ -0,0 +1,49 @@ +package com.lambda.client.manager.managers + +import com.lambda.client.event.SafeClientEvent +import com.lambda.client.gui.hudgui.elements.world.ChestCounter +import com.lambda.client.manager.Manager +import com.lambda.client.module.modules.render.StorageESP +import com.lambda.client.util.TickTimer +import com.lambda.client.util.TimeUnit +import com.lambda.client.util.threads.defaultScope +import com.lambda.client.util.threads.safeListener +import kotlinx.coroutines.Job +import kotlinx.coroutines.launch +import net.minecraft.tileentity.TileEntityChest +import net.minecraft.tileentity.TileEntityShulkerBox +import net.minecraftforge.fml.common.gameevent.TickEvent + +object ChestCountManager : Manager { + private const val SEARCH_DELAY_TICKS = 5L + private val delayTimer: TickTimer = TickTimer(TimeUnit.TICKS) + var chestCount = 0 + private set + var dubsCount = 0 + private set + var shulkerCount = 0 + private set + private var chestCountSearchJob: Job? = null + + init { + safeListener { + if (it.phase != TickEvent.Phase.END) return@safeListener + if (!ChestCounter.visible && !StorageESP.chestCountSetting) return@safeListener + if (chestCountSearchJob?.isActive == true) return@safeListener + if (!delayTimer.tick(SEARCH_DELAY_TICKS)) return@safeListener + + chestCountSearchJob = defaultScope.launch { + searchLoadedTileEntities() + delayTimer.reset() + } + } + } + + private fun SafeClientEvent.searchLoadedTileEntities() { + val chests = world.loadedTileEntityList.filterIsInstance() + + dubsCount = chests.count { it.adjacentChestXPos != null || it.adjacentChestZPos != null } + chestCount = chests.size + shulkerCount = world.loadedTileEntityList.filterIsInstance().size + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/client/module/modules/render/StorageESP.kt b/src/main/kotlin/com/lambda/client/module/modules/render/StorageESP.kt index 36280c352..0dd121e15 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/render/StorageESP.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/render/StorageESP.kt @@ -3,6 +3,7 @@ package com.lambda.client.module.modules.render import com.lambda.client.event.SafeClientEvent import com.lambda.client.event.events.RenderWorldEvent import com.lambda.client.event.listener.listener +import com.lambda.client.manager.managers.ChestCountManager import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.util.color.ColorHolder @@ -39,7 +40,7 @@ object StorageESP : Module( private val dispenser by setting("Dispenser", false, { page == Page.TYPE }) private val hopper by setting("Hopper", false, { page == Page.TYPE }) private val cart by setting("Minecart", false, { page == Page.TYPE }) - private val infinite by setting("Infinite Range", true) // To avoid a hard to control range slider + private val infinite by setting("Infinite Range", true, { page == Page.TYPE }) // To avoid a hard to control range slider private val range by setting("Range", 64, 8..512, 1, { page == Page.TYPE && !infinite }, unit = " blocks") /* Color settings */ @@ -61,12 +62,18 @@ object StorageESP : Module( private val aTracer by setting("Tracer Alpha", 200, 0..255, 1, { page == Page.RENDER && tracer }) private val thickness by setting("Line Thickness", 2.0f, 0.25f..5.0f, 0.25f, { page == Page.RENDER }) + /* Count settings */ + val chestCountSetting by setting("Count", true, { page == Page.COUNT }) + private val dubs by setting("Dubs", true, visibility = { chestCountSetting && page == Page.COUNT}) + private enum class Page { - TYPE, COLOR, RENDER + TYPE, COLOR, RENDER, COUNT } override fun getHudInfo(): String { - return renderer.size.toString() + return if (chestCountSetting) + (if(dubs) "${ChestCountManager.dubsCount}" else "${ChestCountManager.chestCount}") + else "" } private var cycler = HueCycler(600)