From d72d1f1e471bf82dfca490ed5949eb5620ce5aa8 Mon Sep 17 00:00:00 2001 From: Wyvest Date: Thu, 6 May 2021 12:55:23 +0700 Subject: [PATCH] 2.0.0 Remake how the timer actually counts (instead of using ticks, an an ActionListener and Timer is used) The command now shows a GUI where you can edit the HUD and a button where you can access the Vigilance Config Update credits for VersionChecker Remove Lombok Set HUD Shadow to true as a default Remove Reset When World Exit and One Color Chroma Make Vigilance GUI look nicer --- build.gradle | 3 -- gradle.properties | 2 +- src/main/java/net/wyvest/timer/Timer.java | 47 ++++++++++++++++ src/main/java/net/wyvest/timer/TimerHUD.java | 29 +++------- .../wyvest/timer/command/TimerCommand.java | 6 ++- .../net/wyvest/timer/config/TimerConfig.kt | 54 ++++++++++++------- .../wyvest/timer/keybind/TimerKeybind.java | 8 ++- .../wyvest/timer/listener/TimerListener.java | 36 +++---------- .../wyvest/timer/others/VersionChecker.java | 21 +------- .../java/net/wyvest/timer/overlay/GUI.java | 33 +++++++++++- .../java/net/wyvest/timer/overlay/HUD.java | 13 +++-- src/main/resources/mcmod.info | 2 +- 12 files changed, 146 insertions(+), 108 deletions(-) create mode 100644 src/main/java/net/wyvest/timer/Timer.java diff --git a/build.gradle b/build.gradle index 7ee3651..97b110c 100644 --- a/build.gradle +++ b/build.gradle @@ -53,8 +53,6 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.72") implementation 'com.github.wyvest:WyLib:0d5efa2c9a' implementation("club.sk1er:Vigilance:100-10809-SNAPSHOT") - implementation('org.projectlombok:lombok:1.18.16') - annotationProcessor('org.projectlombok:lombok:1.18.16') } jar { @@ -95,7 +93,6 @@ shadowJar { dependencies { include(dependency('com.github.wyvest:WyLib:0d5efa2c9a')) include(dependency('club.sk1er:Vigilance:100-10809-SNAPSHOT')) - include(dependency('org.projectlombok:lombok:1.18.16')) include(dependency('club.sk1er:UniversalCraft:98-10809-SNAPSHOT')) include(dependency('club.sk1er:Elementa:255-10809-SNAPSHOT')) } diff --git a/gradle.properties b/gradle.properties index d1cd9db..e6123f8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ modGroup=net.wyvest -modVersion=1.5.2 +modVersion=2.0.0 modBaseName=TimerHUD forgeVersion=1.8.9-11.15.1.2318-1.8.9 mcpVersion=stable_22 diff --git a/src/main/java/net/wyvest/timer/Timer.java b/src/main/java/net/wyvest/timer/Timer.java new file mode 100644 index 0000000..4c55851 --- /dev/null +++ b/src/main/java/net/wyvest/timer/Timer.java @@ -0,0 +1,47 @@ +package net.wyvest.timer; + +import club.sk1er.mods.core.universal.UMinecraft; +import net.wyvest.lib.util.Multithreading; + +import java.awt.event.ActionListener; + +/** + * @author Wyvest + */ + +public class Timer { + int delay = 1000; //milliseconds + public int secondsPassed; + public boolean running; + public static Timer instance = new Timer(); + ActionListener timerTask = evt -> secondsPassed += 1; + javax.swing.Timer timer = new javax.swing.Timer(delay, timerTask); + + public void toggleTimer() { + Multithreading.runAsync(()-> { + if (!running) { + if (UMinecraft.getWorld() == null) return; + timer.start(); + running = true; + } else { + timer.stop(); + secondsPassed = 0; + running = false; + } + }); + } + + public void setTimer(boolean status) { + Multithreading.runAsync(()-> { + if (status) { + timer.start(); + running = true; + } else { + timer.stop(); + secondsPassed = 0; + running = false; + } + }); + } + +} diff --git a/src/main/java/net/wyvest/timer/TimerHUD.java b/src/main/java/net/wyvest/timer/TimerHUD.java index 3bc4108..8c9126b 100644 --- a/src/main/java/net/wyvest/timer/TimerHUD.java +++ b/src/main/java/net/wyvest/timer/TimerHUD.java @@ -1,8 +1,7 @@ package net.wyvest.timer; +import club.sk1er.mods.core.universal.UDesktop; import club.sk1er.vigilance.Vigilance; -import lombok.Getter; -import lombok.Setter; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; @@ -16,33 +15,26 @@ import net.wyvest.timer.config.TimerConfig; import net.wyvest.timer.keybind.TimerKeybind; import net.wyvest.timer.listener.TimerListener; -import net.wyvest.timer.others.JsonResponse; import net.wyvest.timer.others.VersionChecker; -import java.awt.*; import java.net.URI; /** * @author Wyvest */ -@Getter -@Mod(name = "TimerHUD", version = "1.5.2", modid = "timer") +@Mod(name = TimerHUD.modName, version = TimerHUD.version, modid = TimerHUD.modId) public class TimerHUD { - public String modName = "TimerHUD"; - public String version = "1.5.2"; - public String modId = "timer"; - @Setter @Getter private boolean running; - @Setter @Getter private JsonResponse onlineData; - - @Mod.Instance() - public static TimerHUD INSTANCE; + public static final String modName = "TimerHUD"; + public static final String version = "2.0.0"; + public static final String modId = "timer"; @Mod.EventHandler protected void onPreInit(FMLPreInitializationEvent event) { WyLib.getInstance().onForgePreInit(); VersionChecker.getVersion(); + Timer.instance.setTimer(false); } @Mod.EventHandler @@ -61,15 +53,8 @@ protected void onPostInit(FMLPostInitializationEvent event) { void openTab() { try { - Desktop.getDesktop().browse(URI.create("https://wyvest.net/checker")); + UDesktop.browse(URI.create("https://wyvest.net/timerhud")); } catch (Exception e) {e.printStackTrace();} } - public void toggleRunning() { - running = !running; - TimerListener.ticks = 0; - TimerListener.secondsPassed = 0; - } - - } \ No newline at end of file diff --git a/src/main/java/net/wyvest/timer/command/TimerCommand.java b/src/main/java/net/wyvest/timer/command/TimerCommand.java index ae37c86..9579083 100644 --- a/src/main/java/net/wyvest/timer/command/TimerCommand.java +++ b/src/main/java/net/wyvest/timer/command/TimerCommand.java @@ -8,6 +8,10 @@ import net.wyvest.timer.config.TimerConfig; import net.wyvest.timer.overlay.GUI; +/** + * @author Wyvest + */ + public class TimerCommand extends CommandBase { @Override public String getCommandName() { @@ -22,7 +26,7 @@ public String getCommandUsage(ICommandSender sender) { @Override public void processCommand(ICommandSender sender, String[] args) { if (args.length <= 0) { - GuiHelper.open(TimerConfig.INSTANCE.gui()); + GuiHelper.open(new GUI()); return; } switch (args[0].toLowerCase()) { diff --git a/src/main/java/net/wyvest/timer/config/TimerConfig.kt b/src/main/java/net/wyvest/timer/config/TimerConfig.kt index ed1b208..9b54623 100644 --- a/src/main/java/net/wyvest/timer/config/TimerConfig.kt +++ b/src/main/java/net/wyvest/timer/config/TimerConfig.kt @@ -9,9 +9,13 @@ import club.sk1er.vigilance.data.SortingBehavior import java.awt.Color import java.io.File +/** + * @author Wyvest + */ + object TimerConfig : Vigilant(File("./config/timerhud.toml"), "TimerHUD", sortingBehavior = ConfigSorting) { - @Property(type = PropertyType.TEXT, name = "Info", description = "You are using TimerHUD Version 1.5.1, made by Wyvest.", category = "General") + @Property(type = PropertyType.PARAGRAPH, name = "Info", description = "You are using TimerHUD Version 2.0.0, made by Wyvest.", category = "Information") var paragraph = "" @kotlin.jvm.JvmField @@ -24,32 +28,24 @@ object TimerConfig : Vigilant(File("./config/timerhud.toml"), "TimerHUD", sortin @kotlin.jvm.JvmField @Property(type = PropertyType.COLOR, name = "Text Color", description = "Change the text color for the HUD.", category = "Render", subcategory = "Color") - var color = Color.WHITE + var color: Color = Color.WHITE @kotlin.jvm.JvmField @Property(type = PropertyType.SWITCH, name = "Turn on Chroma", description = "Turn on Chroma. This overrides Text Color.", category = "Render", subcategory = "Color") var chroma = false - @kotlin.jvm.JvmField - @Property(type = PropertyType.SWITCH, name = "Make Chroma Text One Color", description = "Make the Chroma text one color that changes instead of each character being a different color.", category = "Render", subcategory = "Color") - var oneColorChroma = false - @kotlin.jvm.JvmField @Property(type = PropertyType.SWITCH, name = "Display Background", description = "Toggle the background of the HUD.", category = "Render") var displayBackground = false @kotlin.jvm.JvmField @Property(type = PropertyType.SWITCH, name = "Render Shadow", description = "Toggle the shadow of text in the timer.", category = "Render") - var renderShadow = false + var renderShadow = true @kotlin.jvm.JvmField @Property(type = PropertyType.SWITCH, name = "Show in GUIs", description = "Show in GUIs instead of hiding in GUIs.", category = "Render") var showinGui = false - @kotlin.jvm.JvmField - @Property(type = PropertyType.SWITCH, name = "Reset Timer When Exiting Worlds", description = "Reset the timer when a world is exited.", category = "General") - var resetWhenWorldExit = false - @kotlin.jvm.JvmField @Property(type = PropertyType.SWITCH, name = "Turn on Timer When Entering Worlds", description = "Turn on the timer when entering worlds.", category = "General") var turnOnTimerWhenWorldEnter = false @@ -62,24 +58,42 @@ object TimerConfig : Vigilant(File("./config/timerhud.toml"), "TimerHUD", sortin @Property(type = PropertyType.NUMBER, name = "y", category = "Render", hidden = true) var y = 0 - @Property(type = PropertyType.PARAGRAPH, name = "Credits", description = "This mod would not be possible without OSS projects and other forms of help. This page lists the people who helped make this mod.", category = "Credits") - var credits = "" - - @Property(type = PropertyType.TEXT, name = "LlamaLad7 and conor", description = "For helping on how to count.", category = "Credits") + @Property(type = PropertyType.PARAGRAPH, name = "LlamaLad7 and conor", description = "For helping on how to count.", category = "Information", subcategory = "Credits") var credits1 = "" - @Property(type = PropertyType.TEXT, name = "1fxe", description = "For many parts of the GUI.", category = "Credits") + @Property(type = PropertyType.PARAGRAPH, name = "1fxe", description = "For many parts of the GUI.", category = "Information", subcategory = "Credits") var credits2 = "" - @Property(type = PropertyType.TEXT, name = "pinkulu", description = "For the update checker.", category = "Credits") + @Property(type = PropertyType.PARAGRAPH, name = "pinkulu", description = "For the update checker.", category = "Information", subcategory = "Credits") var credits3 = "" - @Property(type = PropertyType.TEXT, name = "chachy", description = "For fixing parts of the build.gradle in v1.5.0.", category = "Credits") + @Property(type = PropertyType.PARAGRAPH, name = "chachy", description = "For fixing parts of the build.gradle in v1.5.0.", category = "Information", subcategory = "Credits") var credits4 = "" init { - ::oneColorChroma dependsOn ::chroma initialize() + setCategoryDescription( + "General", + "This category is for configuring general parts of the timer." + ) + setCategoryDescription( + "Render", + "This category is for configuring the HUD of the timer." + ) + setCategoryDescription( + "Information", + "This category is for general information about the mod." + ) + setSubcategoryDescription( + "Render", + "Color", + "This subcategory is for configuring the color of the HUD." + ) + setSubcategoryDescription( + "Information", + "Credits", + "This mod would not be possible without OSS projects and other forms of help. This page lists the people who helped make this mod." + ) } private object ConfigSorting : SortingBehavior() { @@ -87,7 +101,7 @@ object TimerConfig : Vigilant(File("./config/timerhud.toml"), "TimerHUD", sortin return Comparator { o1, o2 -> if (o1.name == "General") return@Comparator -1 if (o2.name == "General") return@Comparator 1 - else compareValuesBy(o2, o1) { + else compareValuesBy(o2,o1) { it.name } } diff --git a/src/main/java/net/wyvest/timer/keybind/TimerKeybind.java b/src/main/java/net/wyvest/timer/keybind/TimerKeybind.java index a3aa501..77c3320 100644 --- a/src/main/java/net/wyvest/timer/keybind/TimerKeybind.java +++ b/src/main/java/net/wyvest/timer/keybind/TimerKeybind.java @@ -1,9 +1,13 @@ package net.wyvest.timer.keybind; import net.wyvest.lib.util.betterkeybinds.KeyBind; -import net.wyvest.timer.TimerHUD; +import net.wyvest.timer.Timer; import org.lwjgl.input.Keyboard; +/** + * @author Wyvest + */ + public class TimerKeybind extends KeyBind { public TimerKeybind() { @@ -11,7 +15,7 @@ public TimerKeybind() { } @Override public void press() { - TimerHUD.INSTANCE.toggleRunning(); + Timer.instance.toggleTimer(); } @Override diff --git a/src/main/java/net/wyvest/timer/listener/TimerListener.java b/src/main/java/net/wyvest/timer/listener/TimerListener.java index 24a7185..86c3b82 100644 --- a/src/main/java/net/wyvest/timer/listener/TimerListener.java +++ b/src/main/java/net/wyvest/timer/listener/TimerListener.java @@ -4,59 +4,37 @@ import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -import net.minecraftforge.fml.common.gameevent.InputEvent; -import net.minecraftforge.fml.common.gameevent.TickEvent; -import net.wyvest.timer.TimerHUD; +import net.wyvest.timer.Timer; import net.wyvest.timer.config.TimerConfig; +import net.wyvest.timer.overlay.GUI; import net.wyvest.timer.overlay.HUD; -import org.lwjgl.input.Keyboard; -import org.lwjgl.input.Mouse; /** * @author Wyvest */ public class TimerListener { - public static int ticks = 0; - public static int secondsPassed; @SubscribeEvent public void onWorldLoad(WorldEvent.Load event) { if (!TimerConfig.turnOnTimerWhenWorldEnter) return; - TimerHUD.INSTANCE.setRunning(true); - ticks = 0; - secondsPassed = 0; + Timer.instance.setTimer(true); } @SubscribeEvent public void onWorldUnload(WorldEvent.Unload event) { - if (!TimerConfig.resetWhenWorldExit) return; - TimerHUD.INSTANCE.setRunning(false); - ticks = 0; - secondsPassed = 0; + Timer.instance.setTimer(false); } @SubscribeEvent protected void onGameOverlayRendered(RenderGameOverlayEvent.Post event) { if (event.type == RenderGameOverlayEvent.ElementType.ALL) { - if (TimerConfig.modToggled && (Minecraft.getMinecraft().currentScreen == null || TimerConfig.showinGui) && Minecraft.getMinecraft().thePlayer != null) { - HUD.drawTimer(secondsPassed); - } - } - } - - @SubscribeEvent - public void onTick(TickEvent.ClientTickEvent event) { - if (event.phase == TickEvent.Phase.START) { - if (TimerHUD.INSTANCE.isRunning()) { - ticks++; - if (ticks == 20) { - secondsPassed++; - ticks = 0; + if (TimerConfig.modToggled) { + if (((Minecraft.getMinecraft().currentScreen == null || TimerConfig.showinGui) && !(Minecraft.getMinecraft().currentScreen instanceof GUI)) && Minecraft.getMinecraft().thePlayer != null) { + HUD.drawTimer(Timer.instance.secondsPassed); } } } } - } \ No newline at end of file diff --git a/src/main/java/net/wyvest/timer/others/VersionChecker.java b/src/main/java/net/wyvest/timer/others/VersionChecker.java index 22f3dde..9925460 100644 --- a/src/main/java/net/wyvest/timer/others/VersionChecker.java +++ b/src/main/java/net/wyvest/timer/others/VersionChecker.java @@ -7,27 +7,8 @@ import java.io.IOException; import java.util.Objects; - /** - * @author Biscuit Development, under the MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * @author Pinkulu */ public class VersionChecker { diff --git a/src/main/java/net/wyvest/timer/overlay/GUI.java b/src/main/java/net/wyvest/timer/overlay/GUI.java index e0978cc..b11687e 100644 --- a/src/main/java/net/wyvest/timer/overlay/GUI.java +++ b/src/main/java/net/wyvest/timer/overlay/GUI.java @@ -1,7 +1,12 @@ package net.wyvest.timer.overlay; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; -import net.wyvest.timer.TimerHUD; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.util.EnumChatFormatting; +import net.wyvest.lib.util.GuiHelper; +import net.wyvest.timer.Timer; import net.wyvest.timer.config.TimerConfig; import java.io.IOException; @@ -9,19 +14,43 @@ /** * @author Filip, Wyvest */ + public class GUI extends GuiScreen { private boolean dragging; private int prevX, prevY; @Override public void initGui() { + this.buttonList.add(new GuiButton(0, this.width / 2 - 50, this.height - 20, 100, 20, "Close")); + this.buttonList.add(new GuiButton(1, this.width - 80, 0, 80, 20, "Config Editor")); super.initGui(); } + @Override + protected void actionPerformed(GuiButton button) { + switch (button.id) { + case 0: + Minecraft.getMinecraft().displayGuiScreen(null); + break; + case 1: + GuiHelper.open(TimerConfig.INSTANCE.gui()); + } + } + @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { updatePos(mouseX, mouseY); - HUD.drawTimer(1); + HUD.drawTimer(Timer.instance.secondsPassed); + int scale = 3; + GlStateManager.pushMatrix(); + GlStateManager.scale(scale, scale, 0); + drawCenteredString(this.fontRendererObj, EnumChatFormatting.GREEN + "TimerHUD", width / 2 / scale, 5 / scale + 10, -1); + GlStateManager.popMatrix(); + scale = 1; + GlStateManager.pushMatrix(); + GlStateManager.scale(scale, scale, 0); + drawCenteredString(this.fontRendererObj, EnumChatFormatting.WHITE + "(drag hud to edit position!)", width / 2 / scale, 5 / scale + 55, -1); + GlStateManager.popMatrix(); super.drawScreen(mouseX, mouseY, partialTicks); } diff --git a/src/main/java/net/wyvest/timer/overlay/HUD.java b/src/main/java/net/wyvest/timer/overlay/HUD.java index c2a1919..6d88f30 100644 --- a/src/main/java/net/wyvest/timer/overlay/HUD.java +++ b/src/main/java/net/wyvest/timer/overlay/HUD.java @@ -1,22 +1,21 @@ package net.wyvest.timer.overlay; -import lombok.Getter; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.Gui; import net.minecraft.client.renderer.GlStateManager; import net.wyvest.lib.util.ChromaUtils; -import net.wyvest.timer.TimerHUD; +import net.wyvest.timer.Timer; import net.wyvest.timer.config.TimerConfig; /** * @author Filip, Wyvest */ -@Getter + public class HUD { - @Getter public static HUD instance; + public static HUD instance; private static final Minecraft mc = Minecraft.getMinecraft(); private static final FontRenderer fontRenderer = mc.fontRendererObj; @@ -25,7 +24,7 @@ public HUD() { instance = this; } - public static void drawTimer(Integer seconds) { + public static void drawTimer(int seconds) { GlStateManager.pushMatrix(); int x = TimerConfig.x; int y = TimerConfig.y + 7; @@ -36,7 +35,7 @@ public static void drawTimer(Integer seconds) { return; } - if (!TimerHUD.INSTANCE.isRunning()) { + if (!Timer.instance.running) { if (TimerConfig.renderNothing) { text = ""; } else { @@ -49,7 +48,7 @@ public static void drawTimer(Integer seconds) { if (TimerConfig.modToggled) { - if (!TimerConfig.oneColorChroma && TimerConfig.chroma) { + if (TimerConfig.chroma) { ChromaUtils.drawChromaString(fontRenderer, text, Float.parseFloat(String.valueOf(x + 5)), Float.parseFloat(String.valueOf(y)), TimerConfig.renderShadow); }else { fontRenderer.drawString(text, x + 5, diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index 2ec3c6d..fabd47e 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -7,7 +7,7 @@ "url": "", "updateUrl": "", "authorList": ["Wyvest"], - "credits": "1fxe for the HUD rendering and SkyBlockAddons for Version Checker.", + "credits": "", "logoFile": "", "screenshots": [], "dependencies": []