diff options
Diffstat (limited to 'src/main/java/at')
19 files changed, 344 insertions, 70 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index e366c9e2c..0bccba373 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -1,5 +1,6 @@ package at.hannibal2.skyhanni; +import at.hannibal2.skyhanni.config.ConfigManager; import at.hannibal2.skyhanni.config.Features; import at.hannibal2.skyhanni.config.gui.commands.Commands; import at.hannibal2.skyhanni.data.ApiKeyGrabber; @@ -30,8 +31,6 @@ import at.hannibal2.skyhanni.features.nether.ashfang.AshfangFreezeCooldown; import at.hannibal2.skyhanni.features.nether.ashfang.AshfangGravityOrbs; import at.hannibal2.skyhanni.features.nether.ashfang.AshfangNextResetCooldown; import at.hannibal2.skyhanni.test.LorenzTest; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; import net.minecraftforge.common.MinecraftForge; @@ -41,9 +40,6 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; -import java.io.*; -import java.nio.charset.StandardCharsets; - @Mod(modid = SkyHanniMod.MODID, version = SkyHanniMod.VERSION) public class SkyHanniMod { @@ -51,12 +47,9 @@ public class SkyHanniMod { public static final String VERSION = "0.4.2"; public static Features feature; - private File configFile; - - public static final Gson gson = new GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create(); - public static File configDirectory; public static RepoManager repo; + public static ConfigManager configManager; @EventHandler public void preInit(FMLPreInitializationEvent event) { @@ -104,29 +97,12 @@ public class SkyHanniMod { registerEvent(new LorenzTest()); registerEvent(new ButtonOnPause()); - configDirectory = new File("config/skyhanni"); - try { - //noinspection ResultOfMethodCallIgnored - configDirectory.mkdir(); - } catch (Exception ignored) { - } + configManager = new ConfigManager(this); + configManager.firstLoad(); - configFile = new File(configDirectory, "config.json"); + Runtime.getRuntime().addShutdownHook(new Thread(configManager::saveConfig)); - if (configFile.exists()) { - try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(configFile), StandardCharsets.UTF_8))) { - feature = gson.fromJson(reader, Features.class); - } catch (Exception ignored) { - } - } - - if (feature == null) { - feature = new Features(); - saveConfig(); - } - Runtime.getRuntime().addShutdownHook(new Thread(this::saveConfig)); - - repo = new RepoManager(configDirectory); + repo = new RepoManager(configManager.getConfigDirectory()); repo.loadRepoInformation(); } @@ -139,18 +115,6 @@ public class SkyHanniMod { System.out.println("Done after " + duration + " ms!"); } - public void saveConfig() { - try { - //noinspection ResultOfMethodCallIgnored - configFile.createNewFile(); - - try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(configFile), StandardCharsets.UTF_8))) { - writer.write(gson.toJson(feature)); - } - } catch (IOException ignored) { - } - } - public static GuiScreen screenToOpen = null; private static int screenTicks = 0; diff --git a/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt new file mode 100644 index 000000000..66a9f67c6 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/config/ConfigManager.kt @@ -0,0 +1,54 @@ +package at.hannibal2.skyhanni.config + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import com.google.gson.GsonBuilder +import java.io.* +import java.nio.charset.StandardCharsets + +class ConfigManager(val mod: SkyHanniMod) { + companion object { + val gson = GsonBuilder().setPrettyPrinting().excludeFieldsWithoutExposeAnnotation().create() + } + + var configDirectory = File("config/skyhanni") + private var configFile: File? = null + + + fun firstLoad() { + try { + configDirectory.mkdir() + } catch (ignored: Exception) { + } + + configFile = File(configDirectory, "config.json") + + if (configFile!!.exists()) { + try { + BufferedReader(InputStreamReader(FileInputStream(configFile!!), StandardCharsets.UTF_8)).use { reader -> + SkyHanniMod.feature = gson.fromJson(reader, + Features::class.java) + } + ConfigLoadEvent().postAndCatch() + } catch (e: Exception) { + e.printStackTrace() + } + } + + if (SkyHanniMod.feature == null) { + SkyHanniMod.feature = Features() + saveConfig() + } + } + + fun saveConfig() { + try { + configFile!!.createNewFile() + BufferedWriter(OutputStreamWriter(FileOutputStream(configFile!!), StandardCharsets.UTF_8)).use { writer -> + writer.write(gson.toJson(SkyHanniMod.feature)) + } + } catch (e: IOException) { + e.printStackTrace() + } + } +}
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java index 2c2472917..eef96aa56 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java @@ -2,6 +2,9 @@ package at.hannibal2.skyhanni.config.features; import com.google.gson.annotations.Expose; +import java.util.HashMap; +import java.util.Map; + public class Hidden { @Expose @@ -9,4 +12,7 @@ public class Hidden { @Expose public String currentPet = ""; + + @Expose + public Map<String, Long> minions = new HashMap<>(); } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java b/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java index d851c7436..7ce23a260 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Minions.java @@ -1,16 +1,18 @@ package at.hannibal2.skyhanni.config.features; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorBoolean; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorColour; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigEditorSlider; -import at.hannibal2.skyhanni.config.gui.core.config.annotations.ConfigOption; +import at.hannibal2.skyhanni.config.gui.core.config.annotations.*; import com.google.gson.annotations.Expose; public class Minions { + @ConfigOption(name = "Last Clicked", desc = "") + @ConfigEditorAccordion(id = 0) + public boolean lastMinion = false; + @Expose @ConfigOption(name = "Last Minion Display", desc = "Show the last opened minion on your island") @ConfigEditorBoolean + @ConfigAccordionId(id = 0) public boolean lastOpenedMinionDisplay = false; @Expose @@ -19,6 +21,7 @@ public class Minions { desc = "The colour in which the last minion should be displayed" ) @ConfigEditorColour + @ConfigAccordionId(id = 0) public String lastOpenedMinionColor = "0:245:85:255:85"; @Expose @@ -31,5 +34,29 @@ public class Minions { maxValue = 120, minStep = 1 ) + @ConfigAccordionId(id = 0) public int lastOpenedMinionTime = 20; + + @ConfigOption(name = "Emptied Time", desc = "") + @ConfigEditorAccordion(id = 1) + public boolean emptiedTime = false; + + @Expose + @ConfigOption(name = "Emptied Time Display", desc = "Show the time when the hopper in the minion was last empties") + @ConfigEditorBoolean + @ConfigAccordionId(id = 1) + public boolean emptiedTimeDisplay = false; + + @Expose + @ConfigOption( + name = "Emptied Time Distance", + desc = "At what distance is this text displayed" + ) + @ConfigEditorSlider( + minValue = 3, + maxValue = 30, + minStep = 1 + ) + @ConfigAccordionId(id = 1) + public int emptiedTimeDistance = 10; } diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java index 50e99729c..f04d6db26 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Misc.java @@ -44,7 +44,7 @@ public class Misc { public boolean realTime = false; @Expose - @ConfigOption(name = "Ashfang Freeze Position", desc = "") + @ConfigOption(name = "Real Time Position", desc = "") @ConfigEditorButton(runnableId = "realTime", buttonText = "Edit") public Position realTimePos = new Position(10, 10, false, true); }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/config/gui/commands/Commands.java b/src/main/java/at/hannibal2/skyhanni/config/gui/commands/Commands.java index 17609296e..9aca72ec3 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/gui/commands/Commands.java +++ b/src/main/java/at/hannibal2/skyhanni/config/gui/commands/Commands.java @@ -77,5 +77,15 @@ public class Commands { } ) ); + ClientCommandHandler.instance.registerCommand( + new SimpleCommand( + "shconfigsave", + new SimpleCommand.ProcessCommandRunnable() { + public void processCommand(ICommandSender sender, String[] args) { + SkyHanniMod.configManager.saveConfig(); + } + } + ) + ); } } diff --git a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt index f8ee0a299..98370fee7 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/HypixelData.kt @@ -1,9 +1,11 @@ package at.hannibal2.skyhanni.data +import at.hannibal2.skyhanni.events.LocationChangeEvent import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.events.PacketEvent import at.hannibal2.skyhanni.events.ProfileJoinEvent import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import at.hannibal2.skyhanni.utils.TabListUtils import net.minecraft.client.Minecraft import net.minecraft.network.play.server.S38PacketPlayerListItem import net.minecraftforge.event.world.WorldEvent @@ -17,6 +19,7 @@ class HypixelData { var hypixel = false var skyblock = false var dungeon = false + var mode: String = "" } @SubscribeEvent @@ -74,23 +77,48 @@ class HypixelData { } } - var timerTick = 0 + var tick = 0 @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { if (!hypixel) return if (event.phase != TickEvent.Phase.START) return - timerTick++ + tick++ - if (timerTick % 5 != 0) return + if (tick % 5 != 0) return val newState = checkScoreboard() - if (newState == skyblock) return + if (newState) { + checkMode() + } + if (newState == skyblock) return skyblock = newState } + private fun checkMode() { + var location = "" + var guesting = false + for (line in TabListUtils.getTabList()) { + if (line.startsWith("§r§b§lArea: ")) { + location = line.split(": ")[1].removeColor() + } + if (line == "§r Status: §r§9Guest§r") { + guesting = true + } + } + if (guesting) { + location = "$location guesting" + } + + if (mode != location) { + LocationChangeEvent(location, mode).postAndCatch() + println("SkyHanni location change: '$location'") + mode = location + } + } + private fun checkScoreboard(): Boolean { val minecraft = Minecraft.getMinecraft() val world = minecraft.theWorld ?: return false diff --git a/src/main/java/at/hannibal2/skyhanni/data/OtherMod.kt b/src/main/java/at/hannibal2/skyhanni/data/OtherMod.kt index 04f2a4d4f..391d66975 100644 --- a/src/main/java/at/hannibal2/skyhanni/data/OtherMod.kt +++ b/src/main/java/at/hannibal2/skyhanni/data/OtherMod.kt @@ -1,6 +1,6 @@ package at.hannibal2.skyhanni.data -import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.config.ConfigManager import com.google.gson.JsonObject import java.io.BufferedReader @@ -38,5 +38,5 @@ enum class OtherMod(val modName: String, val configPath: String, val readKey: (B } fun getJson(reader: BufferedReader): JsonObject { - return SkyHanniMod.gson.fromJson(reader, com.google.gson.JsonObject::class.java) + return ConfigManager.gson.fromJson(reader, com.google.gson.JsonObject::class.java) }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/ConfigLoadEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/ConfigLoadEvent.kt new file mode 100644 index 000000000..fa9da852a --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/ConfigLoadEvent.kt @@ -0,0 +1,3 @@ +package at.hannibal2.skyhanni.events + +class ConfigLoadEvent: LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/LocationChangeEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/LocationChangeEvent.kt new file mode 100644 index 000000000..b8f9c0fef --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/LocationChangeEvent.kt @@ -0,0 +1,3 @@ +package at.hannibal2.skyhanni.events + +class LocationChangeEvent(val newMode: String, val oldMode: String?) : LorenzEvent()
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionHelper.kt b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionHelper.kt index 7bf198f1a..4e67ebeae 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/minion/MinionHelper.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/minion/MinionHelper.kt @@ -1,8 +1,12 @@ package at.hannibal2.skyhanni.features.minion import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ConfigLoadEvent +import at.hannibal2.skyhanni.events.LorenzChatEvent import at.hannibal2.skyhanni.test.GriffinUtils.drawWaypointFilled import at.hannibal2.skyhanni.utils.* +import at.hannibal2.skyhanni.utils.LorenzUtils.matchRegex +import at.hannibal2.skyhanni.utils.RenderUtils.drawString import net.minecraft.client.Minecraft import net.minecraftforge.client.event.RenderWorldLastEvent import net.minecraftforge.event.world.WorldEvent @@ -14,11 +18,22 @@ import java.awt.Color class MinionHelper { - var lastLocation: LorenzVec? = null + var lastClickedEntity: LorenzVec? = null var lastMinion: LorenzVec? = null var lastMinionOpened = 0L var minionInventoryOpen = false + var lastCoinsRecived = 0L + val minions = mutableMapOf<LorenzVec, Long>() + + @SubscribeEvent + fun onConfigLoad(event: ConfigLoadEvent) { + for (minion in SkyHanniMod.feature.hidden.minions) { + val vec = LorenzVec.decodeFromString(minion.key) + minions[vec] = minion.value + } + } + @SubscribeEvent fun onClick(event: InputEvent.MouseInputEvent) { if (!LorenzUtils.inSkyblock) return @@ -31,7 +46,7 @@ class MinionHelper { if (eventButton == 1) { val entity = minecraft.pointedEntity if (entity != null) { - lastLocation = entity.getLorenzVec().add(-0.5, 0.0, -0.5) + lastClickedEntity = entity.getLorenzVec() } } } @@ -49,7 +64,7 @@ class MinionHelper { if (loc != null) { val time = SkyHanniMod.feature.minions.lastOpenedMinionTime * 1_000 if (lastMinionOpened + time > System.currentTimeMillis()) { - event.drawWaypointFilled(loc, color) + event.drawWaypointFilled(loc.add(-0.5, 0.0, -0.5), color, true) } } } @@ -57,9 +72,9 @@ class MinionHelper { @SubscribeEvent fun onTick(event: TickEvent.ClientTickEvent) { if (InventoryUtils.currentlyOpenInventory().contains("Minion")) { - if (lastLocation != null) { - lastMinion = lastLocation - lastLocation = null + if (lastClickedEntity != null) { + lastMinion = lastClickedEntity + lastClickedEntity = null minionInventoryOpen = true lastMinionOpened = 0 } @@ -67,15 +82,52 @@ class MinionHelper { if (minionInventoryOpen) { minionInventoryOpen = false lastMinionOpened = System.currentTimeMillis() + + val duration = System.currentTimeMillis() - lastCoinsRecived + if (duration < 2_000) { + val loc = lastMinion + if (loc != null) { + minions[loc] = System.currentTimeMillis() + SkyHanniMod.feature.hidden.minions[loc.encodeToString()] = System.currentTimeMillis() + } + } } } } @SubscribeEvent fun onWorldChange(event: WorldEvent.Load) { - lastLocation = null + lastClickedEntity = null lastMinion = null lastMinionOpened = 0L minionInventoryOpen = false } + + @SubscribeEvent + fun onChatMessage(event: LorenzChatEvent) { + if (!LorenzUtils.inSkyblock) return + + if (event.message.matchRegex("§aYou received §r§6(.*) coins§r§a!")) { + lastCoinsRecived = System.currentTimeMillis() + } + } + + @SubscribeEvent + fun onWorldRender(event: RenderWorldLastEvent) { + if (!LorenzUtils.inSkyblock) return + if (!SkyHanniMod.feature.minions.emptiedTimeDisplay) return + if (LorenzUtils.skyBlockIsland != "Private Island") return + + val playerLocation = LocationUtils.playerLocation() + for (minion in minions) { + val location = minion.key + if (playerLocation.distance(location) < SkyHanniMod.feature.minions.emptiedTimeDistance) { + val duration = System.currentTimeMillis() - minion.value + val format = StringUtils.formatDuration(duration / 1000) + + val text = "§eLast emptied: $format" + event.drawString(location.add(0.0, 2.0, 0.0), text, true) + } + } + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/AccessorGuiPlayerTabOverlay.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/AccessorGuiPlayerTabOverlay.java new file mode 100644 index 000000000..41091580e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/AccessorGuiPlayerTabOverlay.java @@ -0,0 +1,12 @@ +package at.hannibal2.skyhanni.mixins.transformers; + +import net.minecraft.client.gui.GuiPlayerTabOverlay; +import net.minecraft.util.IChatComponent; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(GuiPlayerTabOverlay.class) +public interface AccessorGuiPlayerTabOverlay { + @Accessor("footer") + IChatComponent getFooter(); +} diff --git a/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt b/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt index bfbb95302..70ebb954f 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/GriffinUtils.kt @@ -16,14 +16,17 @@ object GriffinUtils { GriffinJavaUtils.drawWaypoint(location, partialTicks, color.toColor(), beacon) } - fun RenderWorldLastEvent.drawWaypointFilled(location: LorenzVec, color: Color, beacon: Boolean = false) { + fun RenderWorldLastEvent.drawWaypointFilled(location: LorenzVec, color: Color, seeThroughBlocks: Boolean = false, beacon: Boolean = false) { val (viewerX, viewerY, viewerZ) = RenderUtils.getViewerPos(partialTicks) val x = location.x - viewerX val y = location.y - viewerY val z = location.z - viewerZ val distSq = x * x + y * y + z * z - GlStateManager.disableDepth() - GlStateManager.disableCull() + + if (seeThroughBlocks) { + GlStateManager.disableDepth() + GlStateManager.disableCull() + } RenderUtils.drawFilledBoundingBox( AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1).expandBlock(), color, @@ -33,8 +36,11 @@ object GriffinUtils { if (distSq > 5 * 5 && beacon) RenderUtils.renderBeaconBeam(x, y + 1, z, color.rgb, 1.0f, partialTicks) GlStateManager.disableLighting() GlStateManager.enableTexture2D() - GlStateManager.enableDepth() - GlStateManager.enableCull() + + if (seeThroughBlocks) { + GlStateManager.enableDepth() + GlStateManager.enableCull() + } } fun RenderWorldLastEvent.draw3DLine( diff --git a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt index 67f00bee9..851a8c207 100644 --- a/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt +++ b/src/main/java/at/hannibal2/skyhanni/test/LorenzTest.kt @@ -37,7 +37,17 @@ class LorenzTest { } fun testCommand(args: Array<String>) { - togglePacketLog = !togglePacketLog +// togglePacketLog = !togglePacketLog + +// for (line in (Minecraft.getMinecraft().ingameGUI.tabList as AccessorGuiPlayerTabOverlay).footer.unformattedText +// .split("\n")) { +// println("footer: '$line'") +// } +// +// +// for (line in TabListUtils.getTabList()) { +// println("tablist: '$line'") +// } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt index 4a7dfbcd8..0bb869bac 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzUtils.kt @@ -20,6 +20,9 @@ object LorenzUtils { val inDungeons: Boolean get() = inSkyblock && HypixelData.dungeon + val skyBlockIsland: String + get() = HypixelData.mode + const val DEBUG_PREFIX = "[Debug] §7" private val log = LorenzLogger("chat/mod_sent") diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt index 5d5c03c4d..95ab29433 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt @@ -69,6 +69,11 @@ data class LorenzVec( return sqrt(x * x + y * y + z * z) } + //TODO make this class json serializable + fun encodeToString(): String { + return "$x:$y:$z" + } + companion object { fun getFromYawPitch(yaw: Double, pitch: Double): LorenzVec { val yaw: Double = (yaw + 90) * Math.PI / 180 @@ -79,6 +84,15 @@ data class LorenzVec( val z = cos(pitch) return LorenzVec(x, z, y) } + + //TODO make this class json serializable + fun decodeFromString(string: String): LorenzVec { + val split = string.split(":") + val x = split[0].toDouble() + val y = split[1].toDouble() + val z = split[2].toDouble() + return LorenzVec(x, y, z) + } } } diff --git a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt index b75180a5c..d27391a6b 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/RenderUtils.kt @@ -240,7 +240,7 @@ object RenderUtils { tessellator.draw() } - fun RenderWorldLastEvent.drawString(location: LorenzVec, text: String, seeThroughBlocks: Boolean = false) { + fun RenderWorldLastEvent.drawString(location: LorenzVec, text: String, seeThroughBlocks: Boolean = false, color: Color? = null) { GlStateManager.alphaFunc(516, 0.1f) GlStateManager.pushMatrix() val viewer = Minecraft.getMinecraft().renderViewEntity @@ -263,6 +263,10 @@ object RenderUtils { GlStateManager.translate(x, y, z) GlStateManager.translate(0f, viewer.eyeHeight, 0f) + val c = color + if (c != null) { + GlStateManager.color(c.red.toFloat(), c.green.toFloat(), c.blue.toFloat()) + } drawNametag(text) GlStateManager.rotate(-renderManager.playerViewY, 0.0f, 1.0f, 0.0f) GlStateManager.rotate(renderManager.playerViewX, 1.0f, 0.0f, 0.0f) diff --git a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt index 7d68afea6..ea88f8eb8 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt @@ -1,7 +1,11 @@ package at.hannibal2.skyhanni.utils +import java.text.DecimalFormat + object StringUtils { + private val durationFormat = DecimalFormat("00") + fun String.firstLetterUppercase(): String { if (isEmpty()) return this @@ -30,7 +34,40 @@ object StringUtils { return builder.toString() } -// fun cleanColour(`in`: String): String? { -// return `in`.replace("(?i)\\u00A7.".toRegex(), "") -// } + fun formatDuration(seconds: Long): String { + var sec: Long = seconds + + var minutes: Long = sec / 60 + sec %= 60 + + var hours = minutes / 60 + minutes %= 60 + + val days = hours / 24 + hours %= 24 + + + val formatHours = durationFormat.format(hours) + val formatMinutes = durationFormat.format(minutes) + val formatSeconds = durationFormat.format(sec) + + if (days > 0) { + return "" + days + "d " + formatHours + ":" + formatMinutes + ":" + formatSeconds + } + if (hours > 0) { + return "$formatHours:$formatMinutes:$formatSeconds" + } + if (minutes > 0) { + return "$formatMinutes:$formatSeconds" + } + if (sec > 0) { + return if (sec == 1L) { + "$formatSeconds second" + } else { + "$formatSeconds seconds" + } + } + + return "Now" + } }
\ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TabListUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TabListUtils.kt new file mode 100644 index 000000000..15b5a10ef --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/utils/TabListUtils.kt @@ -0,0 +1,41 @@ +package at.hannibal2.skyhanni.utils + +import com.google.common.collect.ComparisonChain +import com.google.common.collect.Ordering +import net.minecraft.client.Minecraft +import net.minecraft.client.network.NetworkPlayerInfo +import net.minecraft.world.WorldSettings +import net.minecraftforge.fml.relauncher.Side +import net.minecraftforge.fml.relauncher.SideOnly + +object TabListUtils { + + private val playerOrdering = Ordering.from(PlayerComparator()) + + @SideOnly(Side.CLIENT) + internal class PlayerComparator : Comparator<NetworkPlayerInfo> { + override fun compare(o1: NetworkPlayerInfo, o2: NetworkPlayerInfo): Int { + val team1 = o1.playerTeam + val team2 = o2.playerTeam + return ComparisonChain.start().compareTrueFirst( + o1.gameType != WorldSettings.GameType.SPECTATOR, + o2.gameType != WorldSettings.GameType.SPECTATOR + ) + .compare( + if (team1 != null) team1.registeredName else "", + if (team2 != null) team2.registeredName else "" + ) + .compare(o1.gameProfile.name, o2.gameProfile.name).result() + } + } + + fun getTabList(): List<String> { + val players = playerOrdering.sortedCopy(Minecraft.getMinecraft().thePlayer.sendQueue.playerInfoMap) + val result: MutableList<String> = ArrayList() + for (info in players) { + val name = Minecraft.getMinecraft().ingameGUI.tabList.getPlayerName(info) + result.add(name) + } + return result + } +}
\ No newline at end of file |