diff options
| author | hannibal2 <24389977+hannibal002@users.noreply.github.com> | 2024-04-23 23:57:56 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-23 23:57:56 +0200 |
| commit | 85b62f0192cc17c04dd2b7d2c5a3924393a68db0 (patch) | |
| tree | f165dd1ef570ce4088867006bda176a6651a17cc /src/main/java/at/hannibal2/skyhanni/features/misc | |
| parent | 26401e603dc2b966c8449f2db5679250921a6ba5 (diff) | |
| download | skyhanni-85b62f0192cc17c04dd2b7d2c5a3924393a68db0.tar.gz skyhanni-85b62f0192cc17c04dd2b7d2c5a3924393a68db0.tar.bz2 skyhanni-85b62f0192cc17c04dd2b7d2c5a3924393a68db0.zip | |
Feature: Hide Far Entities (#1064)
Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Co-authored-by: Cal <cwolfson58@gmail.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features/misc')
| -rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/misc/HideFarEntities.kt | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/HideFarEntities.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/HideFarEntities.kt new file mode 100644 index 000000000..cde4acdf4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/HideFarEntities.kt @@ -0,0 +1,39 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.CheckRenderEntityEvent +import at.hannibal2.skyhanni.events.LorenzTickEvent +import at.hannibal2.skyhanni.features.garden.GardenAPI +import at.hannibal2.skyhanni.utils.EntityUtils +import at.hannibal2.skyhanni.utils.LocationUtils.distanceToPlayer +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class HideFarEntities { + private val config get() = SkyHanniMod.feature.misc.hideFarEntities + + private var ignored = emptySet<Int>() + + @SubscribeEvent + fun onTick(event: LorenzTickEvent) { + if (!isEnabled()) return + + val maxAmount = config.maxAmount.coerceAtLeast(1) + val minDistance = config.minDistance.coerceAtLeast(3) + + ignored = EntityUtils.getAllEntities() + .map { it.entityId to it.distanceToPlayer() } + .filter { it.second > minDistance } + .sortedBy { it.second }.drop(maxAmount) + .map { it.first }.toSet() + } + + @SubscribeEvent + fun onCheckRender(event: CheckRenderEntityEvent<*>) { + if (isEnabled() && event.entity.entityId in ignored) { + event.cancel() + } + } + + fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled && !(GardenAPI.inGarden() && config.excludeGarden) +} |
