From 70e1bcea4718a325fc23b8e926e4ec998482b396 Mon Sep 17 00:00:00 2001 From: hannibal2 <24389977+hannibal00212@users.noreply.github.com> Date: Mon, 1 May 2023 18:58:23 +0200 Subject: Added chum bucket hider --- src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt | 1 + .../skyhanni/config/features/Fishing.java | 24 ++++++ .../skyhanni/features/misc/ChumBucketHider.kt | 88 ++++++++++++++++++++++ .../java/at/hannibal2/skyhanni/utils/LorenzVec.kt | 2 + 4 files changed, 115 insertions(+) create mode 100644 src/main/java/at/hannibal2/skyhanni/features/misc/ChumBucketHider.kt diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt index 00da1d347..17a6a414e 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt @@ -265,6 +265,7 @@ class SkyHanniMod { loadModule(JacobContestFFNeededDisplay()) loadModule(GardenYawAndPitch()) loadModule(MovementSpeedDisplay()) + loadModule(ChumBucketHider()) init() diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java index 096c03f39..58fa58a84 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Fishing.java @@ -3,6 +3,7 @@ package at.hannibal2.skyhanni.config.features; import at.hannibal2.skyhanni.config.core.config.Position; import com.google.gson.annotations.Expose; import io.github.moulberry.moulconfig.annotations.*; +import io.github.moulberry.moulconfig.observer.Property; public class Fishing { @@ -96,6 +97,29 @@ public class Fishing { @ConfigAccordionId(id = 2) public int barnTimerAlertTime = 330; + @Expose + @ConfigOption(name = "Chum Bucket Hider", desc = "") + @Accordion + public ChumBucketHider chumBucketHider = new ChumBucketHider(); + + public static class ChumBucketHider { + + @Expose + @ConfigOption(name = "Enable", desc = "Hide the Chum Bucket name tags for other players.") + @ConfigEditorBoolean + public Property enabled = Property.of(true); + + @Expose + @ConfigOption(name = "Hide Bucket", desc = "Hide the Chum Bucket.") + @ConfigEditorBoolean + public Property hideBucket = Property.of(false); + + @Expose + @ConfigOption(name = "Hide Own", desc = "Hides your own Chum Bucket.") + @ConfigEditorBoolean + public Property hideOwn = Property.of(false); + } + @Expose @ConfigOption( name = "Shark Fish Counter", diff --git a/src/main/java/at/hannibal2/skyhanni/features/misc/ChumBucketHider.kt b/src/main/java/at/hannibal2/skyhanni/features/misc/ChumBucketHider.kt new file mode 100644 index 000000000..73281cddf --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/misc/ChumBucketHider.kt @@ -0,0 +1,88 @@ +package at.hannibal2.skyhanni.features.misc + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.CheckRenderEntityEvent +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.utils.ItemUtils.name +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.getLorenzVec +import net.minecraft.entity.Entity +import net.minecraft.entity.item.EntityArmorStand +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class ChumBucketHider { + private val config get() = SkyHanniMod.feature.fishing.chumBucketHider + private val titleEntity = mutableListOf() + private val hiddenEntities = mutableListOf() + + @SubscribeEvent + fun onWorldLoad(event: WorldEvent.Load) { + reset() + } + + @SubscribeEvent + fun onCheckRender(event: CheckRenderEntityEvent<*>) { + if (!LorenzUtils.inSkyBlock) return + if (!config.enabled.get()) return + + val entity = event.entity + if (entity !is EntityArmorStand) return + + if (entity in hiddenEntities) { + event.isCanceled = true + return + } + + val name = entity.name + + // First text line + if (name.endsWith("'s Chum Bucket")) { + if (name.contains(LorenzUtils.getPlayerName()) && !config.hideOwn.get()) return + titleEntity.add(entity) + hiddenEntities.add(entity) + event.isCanceled = true + return + } + + // Second text line + if (name.contains("/10 §aChums")) { + val entityLocation = entity.getLorenzVec() + for (title in titleEntity) { + if (entityLocation.equalsIgnoreY(title.getLorenzVec())) { + println("found lower chum entity") + hiddenEntities.add(entity) + event.isCanceled = true + return + } + } + } + + // Chum Bucket + if (config.hideBucket.get()) { + if (entity.inventory.any { it != null && it.name == "§fEmpty Chum Bucket" }) { + val entityLocation = entity.getLorenzVec() + for (title in titleEntity) { + if (entityLocation.equalsIgnoreY(title.getLorenzVec())) { + hiddenEntities.add(entity) + event.isCanceled = true + return + } + } + } + } + } + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + val function: (oldValue: Boolean, newValue: Boolean) -> Unit = { _, _ -> reset() } + config.enabled.whenChanged(function) + config.hideBucket.whenChanged(function) + config.hideOwn.whenChanged(function) + } + + private fun reset() { + titleEntity.clear() + hiddenEntities.clear() + } +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt index f973a4e6a..4c110cb6c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt @@ -90,6 +90,8 @@ data class LorenzVec( return arrayOf(x, y, z) } + fun equalsIgnoreY(other: LorenzVec) = x == other.x && z == other.z + companion object { fun getFromYawPitch(yaw: Double, pitch: Double): LorenzVec { val yaw: Double = (yaw + 90) * Math.PI / 180 -- cgit