aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal002@users.noreply.github.com>2023-06-05 22:17:04 +0200
committerGitHub <noreply@github.com>2023-06-05 22:17:04 +0200
commitf02e97e044bf6ab1dde5746952ec1dab92b22ed7 (patch)
tree43ae169e00e2244530830ebf3dfa5fb058880d6e /src/main/java/at/hannibal2/skyhanni/features
parentf72e776d5d3f7da6d23c48f6e72290f2ac58b3fe (diff)
downloadskyhanni-f02e97e044bf6ab1dde5746952ec1dab92b22ed7.tar.gz
skyhanni-f02e97e044bf6ab1dde5746952ec1dab92b22ed7.tar.bz2
skyhanni-f02e97e044bf6ab1dde5746952ec1dab92b22ed7.zip
Visitor Reward Warning (#179)
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/features')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt58
1 files changed, 51 insertions, 7 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
index 31654398e..0012e1a9e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt
@@ -27,6 +27,7 @@ import net.minecraft.client.gui.inventory.GuiEditSign
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.item.EntityArmorStand
+import net.minecraft.item.ItemStack
import net.minecraft.network.play.client.C02PacketUseEntity
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent
import net.minecraftforge.client.event.RenderLivingEvent
@@ -37,6 +38,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
import kotlin.math.round
+private val config get() = SkyHanniMod.feature.garden
+
class GardenVisitorFeatures {
private val visitors = mutableMapOf<String, Visitor>()
private var display = listOf<List<Any>>()
@@ -46,7 +49,7 @@ class GardenVisitorFeatures {
private val copperPattern = " §8\\+§c(?<amount>.*) Copper".toPattern()
private val gardenExperiencePattern = " §8\\+§2(?<amount>.*) §7Garden Experience".toPattern()
private val visitorChatMessagePattern = "§e\\[NPC] (§.)?(?<name>.*)§f: §r.*".toPattern()
- private val config get() = SkyHanniMod.feature.garden
+
private val logger = LorenzLogger("garden/visitors")
private var price = 0.0
@@ -101,6 +104,17 @@ class GardenVisitorFeatures {
val internalName = NEUItems.getInternalName(itemName)
visitor.items[internalName] = amount
}
+
+ readReward(offerItem)?.let { reward ->
+ if (visitor.reward == reward) return@let
+ visitor.reward = reward
+ visitor.hasReward()?.let {
+ if (config.visitorRewardWarning.notifyInChat) {
+ LorenzUtils.chat("§e[SkyHanni] Found Visitor Reward ${it.displayName}§e!")
+ }
+ }
+ }
+
if (visitor.status == VisitorStatus.NEW) {
val alreadyReady = event.inventoryItems[29]?.getLore()?.any { it == "§eClick to give!" } == true
if (alreadyReady) {
@@ -115,6 +129,17 @@ class GardenVisitorFeatures {
}
}
+ private fun readReward(offerItem: ItemStack): VisitorReward? {
+ for (line in offerItem.getLore()) {
+ for (reward in VisitorReward.values()) {
+ if (line.contains(reward.displayName)) {
+ return reward
+ }
+ }
+ }
+ return null
+ }
+
private fun updateDisplay() {
display = drawDisplay()
}
@@ -233,6 +258,16 @@ class GardenVisitorFeatures {
if (event.slotId == 33) {
if (event.slot.stack?.name != "§cRefuse Offer") return
+
+ visitor.hasReward()?.let {
+ if (config.visitorRewardWarning.preventRefusing) {
+ event.isCanceled = true
+ LorenzUtils.chat("§e[SkyHanni] §cBlocked refusing visitor ${visitor.visitorName} §7(${it.displayName}§7)")
+ Minecraft.getMinecraft().thePlayer.closeScreen()
+ return
+ }
+ }
+
changeStatus(visitor, VisitorStatus.REFUSED, "refused")
update()
GardenVisitorDropStatistics.deniedVisitors += 1
@@ -277,6 +312,12 @@ class GardenVisitorFeatures {
if (it.distanceToPlayer() < 15) {
val text = visitor.status.displayName
event.drawString(it.add(0.0, 2.23, 0.0), text)
+ if (config.visitorRewardWarning.showOverName) {
+ visitor.hasReward()?.let { reward ->
+ val name = reward.displayName
+ event.drawString(it.add(0.0, 2.73, 0.0), "§c!$name§c!")
+ }
+ }
}
}
}
@@ -336,7 +377,7 @@ class GardenVisitorFeatures {
val cropAmount = multiplier.second.toLong() * amount
val formatAmount = LorenzUtils.formatInteger(cropAmount)
val formatName = "§e$formatAmount§7x ${it.cropName} "
- val formatSpeed = it.getSpeed()?.let { speed ->
+ val formatSpeed = it.getSpeed()?.let { speed ->
val missingTimeSeconds = cropAmount / speed
val duration = TimeUtils.formatDuration(missingTimeSeconds * 1000)
"in §b$duration"
@@ -495,12 +536,12 @@ class GardenVisitorFeatures {
}
private fun hideVisitorMessage(message: String) = visitorChatMessagePattern.matchMatcher(message) {
- val name = group("name")
- if (name == "Spaceman") return false
- if (name == "Beth") return false
+ val name = group("name")
+ if (name == "Spaceman") return false
+ if (name == "Beth") return false
- return visitors.keys.any { it.removeColor() == name }
- } ?: false
+ return visitors.keys.any { it.removeColor() == name }
+ } ?: false
private fun update() {
checkVisitorsReady()
@@ -666,11 +707,14 @@ class GardenVisitorFeatures {
var nameTagEntityId: Int = -1,
var status: VisitorStatus,
var inSacks: Boolean = false,
+ var reward: VisitorReward? = null,
val items: MutableMap<String, Int> = mutableMapOf(),
) {
fun getEntity(): Entity? = Minecraft.getMinecraft().theWorld.getEntityByID(entityId)
fun getNameTagEntity(): Entity? = Minecraft.getMinecraft().theWorld.getEntityByID(nameTagEntityId)
+
+ fun hasReward() = reward?.let { if (config.visitorRewardWarning.drops.contains(it.ordinal)) it else null }
}
enum class VisitorStatus(val displayName: String, val color: Int) {