Skip to content
This repository has been archived by the owner on Dec 24, 2023. It is now read-only.

Commit

Permalink
2.0.0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Wyvest committed May 6, 2021
1 parent bdc313d commit d72d1f1
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 108 deletions.
3 changes: 0 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'))
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
47 changes: 47 additions & 0 deletions src/main/java/net/wyvest/timer/Timer.java
Original file line number Diff line number Diff line change
@@ -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;
}
});
}

}
29 changes: 7 additions & 22 deletions src/main/java/net/wyvest/timer/TimerHUD.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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
Expand All @@ -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;
}


}
6 changes: 5 additions & 1 deletion src/main/java/net/wyvest/timer/command/TimerCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()) {
Expand Down
54 changes: 34 additions & 20 deletions src/main/java/net/wyvest/timer/config/TimerConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -62,32 +58,50 @@ 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() {
override fun getCategoryComparator(): Comparator<in Category> {
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
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/wyvest/timer/keybind/TimerKeybind.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
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() {
super("Toggle Timer", Keyboard.KEY_B, "TimerHUD");
}
@Override
public void press() {
TimerHUD.INSTANCE.toggleRunning();
Timer.instance.toggleTimer();
}

@Override
Expand Down
36 changes: 7 additions & 29 deletions src/main/java/net/wyvest/timer/listener/TimerListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}


}
21 changes: 1 addition & 20 deletions src/main/java/net/wyvest/timer/others/VersionChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit d72d1f1

Please sign in to comment.