From 7165d1a4b6c3e05d9dc3de1775eaa59019008293 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Thu, 13 Jul 2023 02:04:22 -0700 Subject: [PATCH 1/2] ChestCounter HUD element and StorageESP module list info --- .../gui/hudgui/elements/world/ChestCounter.kt | 23 +++++++ .../manager/managers/ChestCountManager.kt | 61 +++++++++++++++++++ .../module/modules/render/StorageESP.kt | 13 +++- 3 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/ChestCounter.kt create mode 100644 src/main/kotlin/com/lambda/client/manager/managers/ChestCountManager.kt 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..4b98b257c --- /dev/null +++ b/src/main/kotlin/com/lambda/client/gui/hudgui/elements/world/ChestCounter.kt @@ -0,0 +1,23 @@ +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() { + displayText.add(if (dubs) "Dubs:" else "Chests:", primaryColor) + displayText.add(if (dubs) "${ChestCountManager.dubsCount}" else "${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..319332914 --- /dev/null +++ b/src/main/kotlin/com/lambda/client/manager/managers/ChestCountManager.kt @@ -0,0 +1,61 @@ +package com.lambda.client.manager.managers + +import com.lambda.client.LambdaMod +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 searchDelayTicks = 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(searchDelayTicks)) { + chestCountSearchJob = defaultScope.launch { + searchLoadedTileEntities() + delayTimer.reset() + } + } + } + } + + private fun SafeClientEvent.searchLoadedTileEntities() { + try { + var dubsC = 0 + var chestC = 0 + var shulkC = 0 + for (tileEntity in world.loadedTileEntityList) { + if (tileEntity is TileEntityChest) { + chestC++ + if (tileEntity.adjacentChestXPos != null || tileEntity.adjacentChestZPos != null) dubsC++ + } else if (tileEntity is TileEntityShulkerBox) shulkC++ + } + dubsCount = dubsC + chestCount = chestC + shulkerCount = shulkC + } catch (e: Exception) { + LambdaMod.LOG.error("ChestCounter: Error searching loaded tile entities", e) + } + } +} \ 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..3e982afbf 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) From c97a47dc7931f41f8bba2793b95ffb6aa61e0071 Mon Sep 17 00:00:00 2001 From: Constructor Date: Tue, 8 Aug 2023 01:50:36 +0200 Subject: [PATCH 2/2] Refactor --- .../gui/hudgui/elements/world/ChestCounter.kt | 12 +++++-- .../manager/managers/ChestCountManager.kt | 34 ++++++------------- .../module/modules/render/StorageESP.kt | 2 +- 3 files changed, 22 insertions(+), 26 deletions(-) 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 index 4b98b257c..ebe67362d 100644 --- 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 @@ -13,8 +13,16 @@ internal object ChestCounter : LabelHud( private val shulkers by setting("Count Shulkers", true, description = "Counts shulkers in the world") override fun SafeClientEvent.updateText() { - displayText.add(if (dubs) "Dubs:" else "Chests:", primaryColor) - displayText.add(if (dubs) "${ChestCountManager.dubsCount}" else "${ChestCountManager.chestCount}", secondaryColor) + 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 index 319332914..7f0e48ebe 100644 --- a/src/main/kotlin/com/lambda/client/manager/managers/ChestCountManager.kt +++ b/src/main/kotlin/com/lambda/client/manager/managers/ChestCountManager.kt @@ -1,6 +1,5 @@ package com.lambda.client.manager.managers -import com.lambda.client.LambdaMod import com.lambda.client.event.SafeClientEvent import com.lambda.client.gui.hudgui.elements.world.ChestCounter import com.lambda.client.manager.Manager @@ -16,7 +15,7 @@ import net.minecraft.tileentity.TileEntityShulkerBox import net.minecraftforge.fml.common.gameevent.TickEvent object ChestCountManager : Manager { - private const val searchDelayTicks = 5L + private const val SEARCH_DELAY_TICKS = 5L private val delayTimer: TickTimer = TickTimer(TimeUnit.TICKS) var chestCount = 0 private set @@ -31,31 +30,20 @@ object ChestCountManager : Manager { if (it.phase != TickEvent.Phase.END) return@safeListener if (!ChestCounter.visible && !StorageESP.chestCountSetting) return@safeListener if (chestCountSearchJob?.isActive == true) return@safeListener - if (delayTimer.tick(searchDelayTicks)) { - chestCountSearchJob = defaultScope.launch { - searchLoadedTileEntities() - delayTimer.reset() - } + if (!delayTimer.tick(SEARCH_DELAY_TICKS)) return@safeListener + + chestCountSearchJob = defaultScope.launch { + searchLoadedTileEntities() + delayTimer.reset() } } } private fun SafeClientEvent.searchLoadedTileEntities() { - try { - var dubsC = 0 - var chestC = 0 - var shulkC = 0 - for (tileEntity in world.loadedTileEntityList) { - if (tileEntity is TileEntityChest) { - chestC++ - if (tileEntity.adjacentChestXPos != null || tileEntity.adjacentChestZPos != null) dubsC++ - } else if (tileEntity is TileEntityShulkerBox) shulkC++ - } - dubsCount = dubsC - chestCount = chestC - shulkerCount = shulkC - } catch (e: Exception) { - LambdaMod.LOG.error("ChestCounter: Error searching loaded tile entities", e) - } + 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 3e982afbf..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 @@ -40,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, { page == Page.TYPE}) // 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 */