Skip to content

Commit

Permalink
Added Visitor Item Preview - Show the base type for the required item…
Browse files Browse the repository at this point in the history
…s next to new visitors (Note that some visitors may require any crop)
  • Loading branch information
hannibal002 committed Mar 25, 2023
1 parent 70b562a commit d1311f3
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
+ Added blocks/second display to crop milestone gui and made all crop milestone gui elements customizable/toggleable.
+ Added farming armor drops counter.
+ Added **Colored Name** - Show the visitor name in the color of the rarity.
+ Added **Visitor Item Preview** - Show the base type for the required items next to new visitors (Note that some visitors may require any crop)


### Features from other Mods
Expand Down
1 change: 1 addition & 0 deletions FEATURES.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
+ Blocks/Second display in crop milestone gui.
+ Farming armor drops counter
+ **Colored Name** - Show the visitor name in the color of the rarity.
+ **Visitor Item Preview** - Show the base type for the required items next to new visitors (Note that some visitors may require any crop)

## Commands
- /wiki (using hypixel-skyblock.fandom.com instead of Hypixel wiki)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ object Commands {
registerCommand("shreloadbingodata") { BingoCardDisplay.command() }
registerCommand("shprintbingohelper") { BingoNextStepHelper.command() }
registerCommand("shsetapikey") { ApiDataLoader.command(it) }
registerCommand("shtestgardenvisitors") { LorenzTest.testGardenVisitors() }
}

private fun registerCommand(name: String, function: (Array<String>) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public class Garden {
@ConfigAccordionId(id = 3)
public boolean visitorNeedsShowPrice = true;

@Expose
@ConfigOption(name = "Item Preview", desc = "Show the base type for the required items next to new visitors. §cNote that some visitors may require any crop.")
@ConfigEditorBoolean
@ConfigAccordionId(id = 3)
public boolean visitorItemPreview = true;

@Expose
@ConfigOption(name = "Visitor Inventory", desc = "")
@ConfigAccordionId(id = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ class DamageIndicatorManager {
270_000 / 2, 270_000 -> 1
0 -> 0
else -> {
LorenzTest.text = "thorn has ${LorenzUtils.formatDouble(realHealth.toDouble())} hp!"
LorenzTest.displayLine = "thorn has ${LorenzUtils.formatDouble(realHealth.toDouble())} hp!"
LorenzUtils.error(
"Unexpected health of thorn in m4! (${
LorenzUtils.formatDouble(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@ class GardenVisitorColorNames {
@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
try {
val map = mutableMapOf<String, String>()
val mapColor = mutableMapOf<String, String>()
val mapItems = mutableMapOf<String, List<String>>()
val garden = event.getConstant("Garden")!!
for ((name, element) in garden["visitors"].asJsonObject.entrySet()) {
val rarity = element.asJsonObject["rarity"].asString
map[name] = getColor(rarity)
val jsonObject = element.asJsonObject
val rarity = jsonObject["rarity"].asString
mapColor[name] = getColor(rarity)
mapItems[name] = jsonObject["need_items"].asJsonArray.map { it.asString }

}
visitorColor = map
visitorColor = mapColor
visitorItems = mapItems

} catch (e: Exception) {
e.printStackTrace()
LorenzUtils.error("error in RepositoryReloadEvent")
}
}

companion object{
companion object {
private var visitorColor = mapOf<String, String>() // name -> color code
var visitorItems = mapOf<String, List<String>>()

fun getColoredName(name: String): String {
if (!SkyHanniMod.feature.garden.visitorColoredName) return name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,28 @@ class GardenVisitorFeatures {
newDisplay.add(Collections.singletonList("§e$amount §7new $visitorLabel:"))
for (visitor in newVisitors) {
val displayName = GardenVisitorColorNames.getColoredName(visitor)
newDisplay.add(Collections.singletonList(" §7- $displayName"))

val list = mutableListOf<Any>()
list.add(" §7- $displayName")

if (config.visitorItemPreview) {
val items = GardenVisitorColorNames.visitorItems[visitor.removeColor()]!!
list.add(" ")
if (items.isEmpty()) {
list.add("§7(§fAny§7)")
} else {
for (item in items) {
try {
val internalName = NEUItems.getInternalName(item)
list.add(NEUItems.getItemStack(internalName))
} catch (e: Exception) {
list.add(" '$item' ")
}
}
}
}

newDisplay.add(list)
}
}

Expand Down
52 changes: 50 additions & 2 deletions src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.PlaySoundEvent
import at.hannibal2.skyhanni.events.ReceiveParticleEvent
import at.hannibal2.skyhanni.features.garden.GardenVisitorColorNames
import at.hannibal2.skyhanni.utils.*
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.event.entity.player.ItemTooltipEvent
Expand All @@ -16,7 +18,8 @@ import java.io.File
class LorenzTest {

companion object {
var text = ""
var displayLine = ""
var displayList = listOf<List<Any>>()

var a = 1.0
var b = 60.0
Expand Down Expand Up @@ -64,6 +67,50 @@ class LorenzTest {
// }
}

fun testGardenVisitors() {
if (displayList.isNotEmpty()) {
displayList = mutableListOf()
return
}

val bigList = mutableListOf<List<Any>>()
var list = mutableListOf<Any>()
var i = 0
var errors = 0
for (item in GardenVisitorColorNames.visitorItems) {
val name = item.key
i++
if (i == 5) {
i = 0
bigList.add(list)
list = mutableListOf()
}

val coloredName = GardenVisitorColorNames.getColoredName(name)
list.add("$coloredName§7 (")
for (itemName in item.value) {
try {
val internalName = NEUItems.getInternalName(itemName)
list.add(NEUItems.getItemStack(internalName))
} catch (e: Exception) {
LorenzUtils.debug("itemName '$itemName' is invalid for visitor '$name'")
errors++
}
}
if (item.value.isEmpty()) {
list.add("Any")
}
list.add("§7) ")
}
bigList.add(list)
displayList = bigList
if (errors == 0) {
LorenzUtils.debug("Test garden visitor renderer: no errors")
} else {
LorenzUtils.debug("Test garden visitor renderer: $errors errors")
}
}

fun reloadListeners() {
val blockedFeatures = try {
File("config/skyhanni/blocked-features.txt").readLines().toList()
Expand Down Expand Up @@ -131,7 +178,8 @@ class LorenzTest {
if (!LorenzUtils.inSkyBlock) return
if (!SkyHanniMod.feature.dev.debugEnabled) return

SkyHanniMod.feature.dev.debugPos.renderString(text, posLabel = "Test")
SkyHanniMod.feature.dev.debugPos.renderString(displayLine, posLabel = "Test")
SkyHanniMod.feature.dev.debugPos.renderStringsAndItems(displayList, posLabel = "Test Display")
}

@SubscribeEvent
Expand Down

0 comments on commit d1311f3

Please sign in to comment.