diff options
author | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-02-21 13:37:58 +0100 |
---|---|---|
committer | hannibal2 <24389977+hannibal00212@users.noreply.github.com> | 2023-02-21 13:37:58 +0100 |
commit | 51f4ed20276b2ab75d5766dd4556c76f9e5eb415 (patch) | |
tree | b8fb751b5777d85da7f3da50d8647301f844b3c4 /src | |
parent | 7dc53e46d9816799d713a52015a986291c24f84b (diff) | |
download | skyhanni-51f4ed20276b2ab75d5766dd4556c76f9e5eb415.tar.gz skyhanni-51f4ed20276b2ab75d5766dd4556c76f9e5eb415.tar.bz2 skyhanni-51f4ed20276b2ab75d5766dd4556c76f9e5eb415.zip |
Show new visitors and fixed bugs.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt | 84 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorTimer.kt | 6 |
2 files changed, 61 insertions, 29 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt index 06dbd10ab..3d58a9714 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt @@ -2,10 +2,7 @@ package at.hannibal2.skyhanni.features.garden import at.hannibal2.skyhanni.SkyHanniMod import at.hannibal2.skyhanni.data.IslandType -import at.hannibal2.skyhanni.events.GuiRenderEvent -import at.hannibal2.skyhanni.events.InventoryOpenEvent -import at.hannibal2.skyhanni.events.PacketEvent -import at.hannibal2.skyhanni.events.withAlpha +import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper import at.hannibal2.skyhanni.utils.* import at.hannibal2.skyhanni.utils.ItemUtils.getLore @@ -16,7 +13,6 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates import net.minecraft.client.Minecraft import net.minecraft.entity.EntityLivingBase import net.minecraft.network.play.client.C02PacketUseEntity -import net.minecraft.network.play.server.S13PacketDestroyEntities import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.EventPriority import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -70,17 +66,33 @@ class GardenVisitorFeatures { display.clear() val requiredItems = mutableMapOf<String, Int>() - for ((_, visitor) in visitors) { - for ((itemName, amount) in visitor.items) { + val newVisitors = mutableListOf<String>() + for ((visitorName, visitor) in visitors) { + val items = visitor.items + if (items.isEmpty()) { + newVisitors.add(visitorName) + } + for ((itemName, amount) in items) { val old = requiredItems.getOrDefault(itemName, 0) requiredItems[itemName] = old + amount } } - if (requiredItems.isEmpty()) return - - display.add("Visitor Items Needed:") - for ((name, amount) in requiredItems) { - display.add(" -$name §8x$amount") + if (requiredItems.isNotEmpty()) { + display.add("Visitor items needed:") + for ((name, amount) in requiredItems) { + display.add(" -$name §8x$amount") + } + } + if (newVisitors.isNotEmpty()) { + if (requiredItems.isNotEmpty()) { + display.add("") + } + val amount = newVisitors.size + val visitorLabel = if (amount == 1) "visitor" else "visitors" + display.add("$amount new $visitorLabel:") + for (visitor in newVisitors) { + display.add(" -$visitor") + } } } @@ -158,6 +170,39 @@ class GardenVisitorFeatures { } } + @SubscribeEvent + fun onTick(event: TabListUpdateEvent) { + if (!isEnabled()) return + var found = false + val visitorsInTab = mutableListOf<String>() + for (line in event.tabList) { + if (line.startsWith("§b§lVisitors:")) { + found = true + continue + } + if (found) { + if (line.isEmpty()) { + found = false + continue + } + val name = line.substring(3) + visitorsInTab.add(name) + } + } + if (visitors.keys.removeIf { it !in visitorsInTab }) { + println("removed an npc") + update() + } + for (name in visitorsInTab) { + if (!visitors.containsKey(name)) { + visitors[name] = Visitor(-1) + // todo notification? (check world age first) + println("found an npc: '$name'") + update() + } + } + } + private fun checkVisitorsReady() { for (visitor in visitors.values) { var ready = true @@ -181,21 +226,6 @@ class GardenVisitorFeatures { } } - @SubscribeEvent - fun onReceiveEvent(event: PacketEvent.ReceiveEvent) { - val packet = event.packet - if (packet is S13PacketDestroyEntities) { - for (entityID in packet.entityIDs) { - for ((name, visitor) in visitors.toMutableMap()) { - if (visitor.entityId == entityID) { - visitors.remove(name) - update() - } - } - } - } - } - // TODO make event @SubscribeEvent fun onSendEvent(event: PacketEvent.SendEvent) { diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorTimer.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorTimer.kt index d8bbe2d6f..9ca5c4b13 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorTimer.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorTimer.kt @@ -15,6 +15,7 @@ class GardenVisitorTimer { private val patternVisitors = Pattern.compile("§b§lVisitors: §r§f\\((\\d)\\)") private var render = "" private var lastMillis = 0L + private var lastVisitors = 0 @SubscribeEvent fun onTick(event: TabListUpdateEvent) { @@ -36,15 +37,16 @@ class GardenVisitorTimer { } val diff = lastMillis - millis - if (diff == 0L) return + if (diff == 0L && visitorsAmount == lastVisitors) return lastMillis = millis + lastVisitors = visitorsAmount val extraSpeed = if (diff in 1001..10_000) { val factor = diff / 1000 "§f/§e" + TimeUtils.formatDuration(millis / factor) } else "" - val visitorLabel = if (visitorsAmount == 1) "Visitor" else "Visitors" + val visitorLabel = if (visitorsAmount == 1) "visitor" else "visitors" val formatDuration = TimeUtils.formatDuration(millis) render = "§b$visitorsAmount $visitorLabel §f(Next in §e$formatDuration$extraSpeed§f)" } |