aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-02-27 01:55:21 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-02-27 01:55:21 +0100
commitba89091207331b588d727685ca3949fcb9063b07 (patch)
tree6375d96b73e5eb95e6ead22c0017495f5a1fd6ea /src
parent9bb15c6cb1003b40dda07f14bf3abbe50652cb1d (diff)
downloadskyhanni-ba89091207331b588d727685ca3949fcb9063b07.tar.gz
skyhanni-ba89091207331b588d727685ca3949fcb9063b07.tar.bz2
skyhanni-ba89091207331b588d727685ca3949fcb9063b07.zip
Highlight new visitor NPCs.
Diffstat (limited to 'src')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Garden.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt74
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/hooks/RenderLivingEntityHelper.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt8
4 files changed, 63 insertions, 28 deletions
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)