diff options
6 files changed, 65 insertions, 30 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 736112434..b4e09a00c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ ### Garden Features + Added **Copper Price** - Show copper to coin prices inside the Sky Mart inventory. + Added **Visitor Display** - Show all items needed for the visitors. -+ Added **Highlight Ready** - Highlight the visitor when the required items are in the inventory. ++ Added **Visitor Highlight** - Highlight visitor when the required items are in the inventory or the visitor is new and needs to checked what items it needs. + Added **Show Price** - Show the bazaar price of the items required for the visitors. + Added **Crop Milestone** Number - Show the number of the crop milestone in the inventory. + Added **Crop Upgrades** Number - Show the number of upgrades in the crop upgrades inventory. diff --git a/FEATURES.md b/FEATURES.md index ad7556efb..b844e4d3b 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -162,7 +162,7 @@ ## Garden Features + **Copper Price** - Show copper to coin prices inside the Sky Mart inventory. + **Visitor Display** - Show all items needed for the visitors. -+ **Highlight Ready** - Highlight the visitor when the required items are in the inventory. ++ **Visitor Highlight** - Highlight visitor when the required items are in the inventory or the visitor is new and needs to checked what items it needs. + **Show Price** - Show the bazaar price of the items required for the visitors. + **Crop Milestone** Number - Show the number of the crop milestone in the inventory. + **Crop Upgrades** Number - Show the number of upgrades in the crop upgrades inventory. diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java index 2343773de..94a3b38cb 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -84,10 +84,10 @@ public class Garden { public boolean visitorNotification = true; @Expose - @ConfigOption(name = "Highlight Ready", desc = "Highlight the visitor when the required items are in the inventory.") + @ConfigOption(name = "Highlight", desc = "Highlight visitor when the required items are in the inventory or the visitor is new and needs to checked what items it needs.") @ConfigEditorBoolean @ConfigAccordionId(id = 1) - public boolean visitorHighlightReady = true; + public boolean visitorHighlight = true; @Expose @ConfigOption(name = "Show Price", desc = "Show the bazaar price of the items required for the visitors.") 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 035753ebd..fda108391 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems import at.hannibal2.skyhanni.utils.StringUtils.removeColor import net.minecraft.client.Minecraft import net.minecraft.entity.EntityLivingBase +import net.minecraft.entity.item.EntityArmorStand import net.minecraft.network.play.client.C02PacketUseEntity import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.SubscribeEvent @@ -50,9 +51,10 @@ class GardenVisitorFeatures { if (offerItem.name != "§aAccept Offer") return inVisitorInventory = true - if (!SkyHanniMod.feature.garden.visitorNeedsDisplay && !SkyHanniMod.feature.garden.visitorHighlightReady) return + if (!SkyHanniMod.feature.garden.visitorNeedsDisplay && !SkyHanniMod.feature.garden.visitorHighlight) return - val visitor = Visitor(lastClickedNpc) + val visitor = visitors[npcItem.name!!]!! + visitor.entityId = lastClickedNpc for (line in offerItem.getLore()) { if (line == "§7Items Required:") continue if (line.isEmpty()) break @@ -61,14 +63,12 @@ class GardenVisitorFeatures { if (itemName == null) continue visitor.items[itemName] = amount } + checkVisitorsReady() - val visitorName = npcItem.name!! - visitors[visitorName] = visitor - - update() + updateDisplay() } - private fun update() { + private fun updateDisplay() { val list = drawDisplay() display.clear() display.addAll(list) @@ -156,7 +156,7 @@ class GardenVisitorFeatures { fun onTick(event: TickEvent.ClientTickEvent) { if (!isEnabled()) return if (!SkyHanniMod.feature.garden.visitorNeedsDisplay && - !SkyHanniMod.feature.garden.visitorHighlightReady && + !SkyHanniMod.feature.garden.visitorHighlight && !SkyHanniMod.feature.garden.visitorShowPrice ) return if (tick++ % 60 != 0) return @@ -178,8 +178,7 @@ class GardenVisitorFeatures { val playerLocation = LocationUtils.playerLocation() nearby = list.map { playerLocation.distance(it) < 15 }.any { it } - - if (nearby && SkyHanniMod.feature.garden.visitorHighlightReady) { + if (nearby && SkyHanniMod.feature.garden.visitorHighlight) { checkVisitorsReady() } } @@ -204,7 +203,7 @@ class GardenVisitorFeatures { } } if (visitors.keys.removeIf { it !in visitorsInTab }) { - update() + updateDisplay() } for (name in visitorsInTab) { if (!visitors.containsKey(name)) { @@ -213,34 +212,57 @@ class GardenVisitorFeatures { SendTitleHelper.sendTitle("§eNew Visitor", 5_000) LorenzUtils.chat("§e[SkyHanni] $name §eis visiting your garden!") } - update() + updateDisplay() } } } private fun checkVisitorsReady() { - for (visitor in visitors.values) { - var ready = true - for ((name, need) in visitor.items) { - val cleanName = name.removeColor() - val having = InventoryUtils.countItemsInLowerInventory { it.name?.contains(cleanName) ?: false } - if (having < need) { - ready = false - } + for ((visitorName, visitor) in visitors) { + val entity = Minecraft.getMinecraft().theWorld.getEntityByID(visitor.entityId) + if (entity == null) { + findEntityByNametag(visitorName, visitor) } - if (ready) { - val world = Minecraft.getMinecraft().theWorld - val entity = world.getEntityByID(visitor.entityId) - if (entity is EntityLivingBase) { + if (entity is EntityLivingBase) { + if (visitor.items.isEmpty()) { + val color = LorenzColor.DARK_AQUA.toColor().withAlpha(120) + RenderLivingEntityHelper.setEntityColor(entity, color) + { SkyHanniMod.feature.garden.visitorHighlight } + } else if (isReady(visitor)) { val color = LorenzColor.GREEN.toColor().withAlpha(120) RenderLivingEntityHelper.setEntityColor(entity, color) - { SkyHanniMod.feature.garden.visitorHighlightReady } + { SkyHanniMod.feature.garden.visitorHighlight } + } else { + RenderLivingEntityHelper.removeEntityColor(entity) } } } } + private fun findEntityByNametag(visitorName: String, visitor: Visitor) { + Minecraft.getMinecraft().theWorld.loadedEntityList + .filter { it is EntityArmorStand && it.name == visitorName } + .forEach { entity -> + Minecraft.getMinecraft().theWorld.loadedEntityList + .filter { it !is EntityArmorStand } + .filter { entity.getLorenzVec().distanceIgnoreY(it.getLorenzVec()) == 0.0 } + .forEach { visitor.entityId = it?.entityId ?: 0 } + } + } + + private fun isReady(visitor: Visitor): Boolean { + var ready = true + for ((name, need) in visitor.items) { + val cleanName = name.removeColor() + val having = InventoryUtils.countItemsInLowerInventory { it.name?.contains(cleanName) ?: false } + if (having < need) { + ready = false + } + } + return ready + } + // TODO make event @SubscribeEvent fun onSendEvent(event: PacketEvent.SendEvent) { @@ -266,7 +288,7 @@ class GardenVisitorFeatures { SkyHanniMod.feature.garden.visitorNeedsPos.renderStringsAndItems(display) } - class Visitor(val entityId: Int, val items: MutableMap<String, Int> = mutableMapOf()) + class Visitor(var entityId: Int, val items: MutableMap<String, Int> = mutableMapOf()) private fun isEnabled() = LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.GARDEN }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderLivingEntityHelper.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderLivingEntityHelper.kt index 036c75627..530b37b6f 100644 --- a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderLivingEntityHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderLivingEntityHelper.kt @@ -24,6 +24,11 @@ class RenderLivingEntityHelper { private val entityNoHurTime = mutableListOf<EntityLivingBase>() private val entityNoHurTimeCondition = mutableMapOf<EntityLivingBase, () -> Boolean>() + fun <T : EntityLivingBase> removeEntityColor(entity: T) { + entityColorMap.remove(entity) + entityColorCondition.remove(entity) + } + fun <T : EntityLivingBase> setEntityColor(entity: T, color: Int, condition: () -> Boolean) { entityColorMap[entity] = color entityColorCondition[entity] = condition diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt index 6d55a9185..f973a4e6a 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt @@ -20,6 +20,8 @@ data class LorenzVec( fun toVec3(): Vec3 = Vec3(x, y, z) + fun distanceIgnoreY(other: LorenzVec): Double = distanceIgnoreYSq(other).pow(0.5) + fun distance(other: LorenzVec): Double = distanceSq(other).pow(0.5) fun distanceSq(x: Double, y: Double, z: Double): Double = distanceSq(LorenzVec(x, y, z)) @@ -33,6 +35,12 @@ data class LorenzVec( return (dx * dx + dy * dy + dz * dz) } + fun distanceIgnoreYSq(other: LorenzVec): Double { + val dx = (other.x - x) + val dz = (other.z - z) + return (dx * dx + dz * dz) + } + fun add(x: Double, y: Double, z: Double): LorenzVec = LorenzVec(this.x + x, this.y + y, this.z + z) fun add(x: Int, y: Int, z: Int): LorenzVec = LorenzVec(this.x + x, this.y + y, this.z + z) |