diff options
Diffstat (limited to 'src')
4 files changed, 78 insertions, 4 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index bb82c5cc6..58720c0e4 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -231,6 +231,7 @@ public class SkyHanniMod { loadModule(new WrongFungiCutterWarning()); loadModule(new FarmingArmorDrops()); loadModule(new JoinCrystalHollows()); + loadModule(new GardenVisitorColorNames()); Commands.INSTANCE.init(); 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 d630f8259..559bb68d3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java @@ -137,6 +137,12 @@ public class Garden { public int visitorHighlightStatus = 2; @Expose + @ConfigOption(name = "Colored Name", desc = "Show the visitor name in the color of the rarity.") + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean visitorColoredName = true; + + @Expose @ConfigOption(name = "Numbers", desc = "") @ConfigEditorAccordion(id = 5) public boolean numbers = false; diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorColorNames.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorColorNames.kt new file mode 100644 index 000000000..090cfd1b5 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorColorNames.kt @@ -0,0 +1,49 @@ +package at.hannibal2.skyhanni.features.garden + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.RepositoryReloadEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class GardenVisitorColorNames { + + @SubscribeEvent + fun onRepoReload(event: RepositoryReloadEvent) { + try { + val map = mutableMapOf<String, String>() + val garden = event.getConstant("Garden")!! + for ((name, element) in garden["visitors"].asJsonObject.entrySet()) { + val rarity = element.asJsonObject["rarity"].asString + map[name] = getColor(rarity) + } + visitorColor = map + + } catch (e: Exception) { + e.printStackTrace() + LorenzUtils.error("error in RepositoryReloadEvent") + } + } + + companion object{ + private var visitorColor = mapOf<String, String>() // name -> color code + + fun getColoredName(name: String): String { + if (!SkyHanniMod.feature.garden.visitorColoredName) return name + + val cleanName = name.removeColor() + val color = visitorColor[cleanName] ?: return name + return color + cleanName + } + } + + + private fun getColor(rarity: String) = when (rarity) { + "uncommon" -> "§a" + "rare" -> "§9" + "legendary" -> "§6" + "special" -> "§c" + + else -> throw RuntimeException("Unknown rarity for '$rarity'") + } +}
\ No newline at end of file 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 f292c087b..16edfec89 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt @@ -19,6 +19,7 @@ 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.client.event.RenderLivingEvent import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.event.entity.player.ItemTooltipEvent import net.minecraftforge.fml.common.eventhandler.EventPriority @@ -112,7 +113,7 @@ class GardenVisitorFeatures { if (requiredItems.isNotEmpty()) { newDisplay.add(Collections.singletonList("§7Visitor items needed:")) for ((internalName, amount) in requiredItems) { - val name = NEUItems.getItemStack(internalName).name + val name = NEUItems.getItemStack(internalName).name!! val itemStack = NEUItems.getItemStack(internalName) val list = mutableListOf<Any>() @@ -137,7 +138,8 @@ class GardenVisitorFeatures { val visitorLabel = if (amount == 1) "visitor" else "visitors" newDisplay.add(Collections.singletonList("§e$amount §7new $visitorLabel:")) for (visitor in newVisitors) { - newDisplay.add(Collections.singletonList(" §7- $visitor")) + val displayName = GardenVisitorColorNames.getColoredName(visitor) + newDisplay.add(Collections.singletonList(" §7- $displayName")) } } @@ -325,7 +327,8 @@ class GardenVisitorFeatures { SendTitleHelper.sendTitle("§eNew Visitor", 5_000) } if (config.visitorNotificationChat) { - LorenzUtils.chat("§e[SkyHanni] $name §eis visiting your garden!") + val displayName = GardenVisitorColorNames.getColoredName(name) + LorenzUtils.chat("§e[SkyHanni] $displayName §eis visiting your garden!") } updateDisplay() } @@ -388,7 +391,10 @@ class GardenVisitorFeatures { Minecraft.getMinecraft().theWorld.loadedEntityList .filter { it !is EntityArmorStand } .filter { entity.getLorenzVec().distanceIgnoreY(it.getLorenzVec()) == 0.0 } - .forEach { visitor.entityId = it?.entityId ?: 0 } + .forEach { + visitor.entityId = it?.entityId ?: 0 + visitor.nameTagEntityId = entity.entityId + } } } @@ -429,8 +435,20 @@ class GardenVisitorFeatures { config.visitorNeedsPos.renderStringsAndItems(display, posLabel = "Visitor Items Needed") } + @SubscribeEvent(priority = EventPriority.HIGH) + fun onRenderLivingB(event: RenderLivingEvent.Specials.Pre<EntityLivingBase>) { + val entity = event.entity + val entityId = entity.entityId + for (visitor in visitors.values) { + if (visitor.nameTagEntityId == entityId) { + entity.customNameTag = GardenVisitorColorNames.getColoredName(entity.name) + } + } + } + class Visitor( var entityId: Int = -1, + var nameTagEntityId: Int = -1, var status: VisitorStatus, val items: MutableMap<String, Int> = mutableMapOf(), ) |