diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt index cf9b6141c..30a55a0ea 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/fishing/FishingHookDisplay.kt @@ -12,22 +12,25 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderString import at.hannibal2.skyhanni.utils.getLorenzVec import net.minecraft.client.entity.EntityPlayerSP import net.minecraft.entity.item.EntityArmorStand -import net.minecraft.entity.item.EntityXPOrb import net.minecraft.entity.projectile.EntityFishHook import net.minecraftforge.event.entity.EntityJoinWorldEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent class FishingHookDisplay { private val config get() = SkyHanniMod.feature.fishing.fishingHookDisplay + private var bobber: EntityFishHook? = null private var bobberLocation: LorenzVec? = null private var armorStand: EntityArmorStand? = null + private val potentionArmorStands = mutableListOf<EntityArmorStand>() private var display = "" @SubscribeEvent fun onWorldChange(event: LorenzWorldChangeEvent) { display = "" bobberLocation = null + bobber = null armorStand = null + potentionArmorStands.clear() } @SubscribeEvent @@ -35,22 +38,37 @@ class FishingHookDisplay { if (!isEnabled()) return if (!event.isMod(config.debugUpdateInterval)) return + if (armorStand == null) { + val filter = potentionArmorStands.filter { it.hasCustomName() && it.hasCorrectName() } + if (filter.size == 1) { + armorStand = filter[0] + } + } + val entities = EntityUtils.getEntities<EntityFishHook>() - bobberLocation = entities.firstOrNull { it.angler is EntityPlayerSP }?.getLorenzVec() + val foundBobber = entities.firstOrNull { it.angler is EntityPlayerSP } + if (foundBobber != bobber) { + bobber = foundBobber + potentionArmorStands.clear() + armorStand = null + } + + if (bobber != null) { + bobberLocation = bobber?.getLorenzVec() + } } @SubscribeEvent fun onJoinWorld(event: EntityJoinWorldEvent) { if (!isEnabled()) return val entity = event.entity ?: return - if (entity is EntityXPOrb) return + if (entity !is EntityArmorStand) return val bobberLocation = bobberLocation ?: return val distance = entity.getLorenzVec().distance(bobberLocation) if (distance > config.debugMaxDistance) return - if (entity is EntityArmorStand) { - armorStand = entity - } + + potentionArmorStands.add(entity) } @SubscribeEvent @@ -74,5 +92,16 @@ class FishingHookDisplay { config.position.renderString(armorStand.name, posLabel = "Fishing Hook Display") } + private fun EntityArmorStand.hasCorrectName(): Boolean { + if (name == "§c§l!!!") { + return true + } + if (name.startsWith("§e§l")) { + return true + } + + return false + } + fun isEnabled() = LorenzUtils.inSkyBlock && config.enabled && FishingAPI.hasFishingRodInHand() } |