diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/config/features/Garden.java | 49 | ||||
-rw-r--r-- | src/main/java/at/hannibal2/skyhanni/features/garden/visitor/GardenVisitorFeatures.kt | 58 |
2 files changed, 100 insertions, 7 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 8d4355ed4..5c3a60c08 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -14,6 +14,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +@SuppressWarnings("deprecation") public class Garden { @Expose @@ -142,6 +143,53 @@ public class Garden { public boolean visitorExperiencePrice = false; @Expose + @ConfigOption(name = "Visitor Reward Warning", desc = "") + @ConfigAccordionId(id = 1) + @Accordion + public VisitorRewardWarning visitorRewardWarning = new VisitorRewardWarning(); + + public static class VisitorRewardWarning { + + @Expose + @ConfigOption(name = "Notify in Chat", desc = "Send a Chat message once you talk to a visitor with reward.") + @ConfigEditorBoolean + public boolean notifyInChat = true; + + @Expose + @ConfigOption(name = "Show over Name", desc = "Show the reward name above the visitor name.") + @ConfigEditorBoolean + public boolean showOverName = true; + + @Expose + @ConfigOption(name = "Prevent Refusing", desc = "Prevent the refusal of a visitor with reward.") + @ConfigEditorBoolean + public boolean preventRefusing = true; + + + /** + * Sync up with {at.hannibal2.skyhanni.features.garden.visitor.VisitorReward} + */ + @Expose + @ConfigOption( + name = "Items", + desc = "Warn for these reward items." + ) + @ConfigEditorDraggableList( + exampleText = { + "§9Flowering Bouquet", + "§9Overgrown Grass", + "§9Green Bandana", + "§9Dedication IV", + "§9Music Rune", + "§cSpace Helmet", + } + ) + public List<Integer> drops = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5)); + + + } + + @Expose @ConfigOption(name = "Notification Chat", desc = "Show in chat when a new visitor is visiting your island.") @ConfigEditorBoolean @ConfigAccordionId(id = 1) @@ -221,6 +269,7 @@ public class Garden { ) public List<Integer> textFormat = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12)); + @Expose @ConfigOption(name = "Display Numbers First", desc = "Determines whether the number or drop name displays first. " + "§eNote: Will not update the preview above!") 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) { |