Skip to content

Commit f35a84b

Browse files
committed
Added support for personal best tracking. Starts counting after you hit the first secret in a room, ends when you get the last. PBs are invalid if you use the next / last secret keybinds. Sends a chat message (if toggled on) to send chat messages when you get a new PB for a room. PBs for all rooms can be viewed at .minecraft/config/SecretRoutes/personal_bests.json
1 parent 5ccc849 commit f35a84b

File tree

10 files changed

+290
-23
lines changed

10 files changed

+290
-23
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod_name=SecretRoutes
33
# Sets the id of your mod that mod loaders use to recognize it.
44
mod_id=secretroutesmod
55
# Sets the version of your mod. Make sure to update this when you make changes according to semver.
6-
mod_version=0.4.10
6+
mod_version=0.4.13
77
# Sets the name of the jar file that you put in your 'mods' folder.
88
mod_archives_name=SecretRoutes
99

src/main/java/xyz/yourboykyle/secretroutes/Main.java

+29-8
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,9 @@
1818

1919
package xyz.yourboykyle.secretroutes;
2020

21-
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.DungeonRooms;
22-
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.dungeons.catacombs.RoomDetection;
23-
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.handlers.PacketHandler;
24-
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.utils.Utils;
2521
import net.minecraft.client.Minecraft;
2622
import net.minecraft.util.EnumChatFormatting;
27-
import net.minecraft.util.ResourceLocation;
2823
import net.minecraftforge.client.ClientCommandHandler;
29-
import net.minecraftforge.client.event.sound.SoundEvent;
3024
import net.minecraftforge.common.MinecraftForge;
3125
import net.minecraftforge.fml.common.Mod;
3226
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
@@ -37,8 +31,11 @@
3731
import org.apache.commons.io.IOUtils;
3832
import xyz.yourboykyle.secretroutes.commands.*;
3933
import xyz.yourboykyle.secretroutes.config.SRMConfig;
34+
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.DungeonRooms;
35+
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.dungeons.catacombs.RoomDetection;
36+
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.handlers.PacketHandler;
37+
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.utils.Utils;
4038
import xyz.yourboykyle.secretroutes.events.*;
41-
import xyz.yourboykyle.secretroutes.events.OnMouseInput;
4239
import xyz.yourboykyle.secretroutes.utils.*;
4340
import xyz.yourboykyle.secretroutes.utils.autoupdate.UpdateManager;
4441

@@ -50,13 +47,13 @@
5047
import java.text.SimpleDateFormat;
5148

5249
import static xyz.yourboykyle.secretroutes.utils.ChatUtils.sendChatMessage;
53-
import static xyz.yourboykyle.secretroutes.utils.ChatUtils.sendVerboseMessage;
5450

5551
@Mod(modid = Main.MODID, name = Main.NAME, version = Main.VERSION)
5652
public class Main {
5753
public static final String MODID = "@ID@";
5854
public static final String NAME = "@NAME@";
5955
public static final String VERSION = "@VER@";
56+
public static final String CONFIG_FOLDER_PATH = Minecraft.getMinecraft().mcDataDir.getAbsolutePath() + File.separator + "config" + File.separator + "SecretRoutes";
6057
public static final String ROUTES_PATH = Minecraft.getMinecraft().mcDataDir.getAbsolutePath() + File.separator + "config" + File.separator + "SecretRoutes"+File.separator+"routes";
6158
public static final String COLOR_PROFILE_PATH = Minecraft.getMinecraft().mcDataDir.getAbsolutePath() + File.separator + "config" + File.separator + "SecretRoutes"+File.separator+"colorprofiles";
6259
public static final String tmpDir = Minecraft.getMinecraft().mcDataDir.getAbsolutePath() + File.separator + "SecretRoutes" + File.separator + "tmp";
@@ -133,6 +130,8 @@ public void init(FMLInitializationEvent e) {
133130
dungeonRooms.init(e);
134131
checkRoutesData();
135132
checkProfilesData();
133+
checkPBData();
134+
PBUtils.loadPBData();
136135

137136
// Register Events
138137
MinecraftForge.EVENT_BUS.register(new OnBlockPlace());
@@ -220,6 +219,28 @@ public static void checkRoutesData() {
220219
}
221220
}
222221

222+
public static void checkPBData() {
223+
try {
224+
String filePath = CONFIG_FOLDER_PATH + File.separator + "personal_bests.json";
225+
226+
// Check if the config directory exists
227+
File configDir = new File(CONFIG_FOLDER_PATH);
228+
if (!configDir.exists()) {
229+
configDir.mkdirs();
230+
}
231+
232+
File configFile = new File(filePath);
233+
if (!configFile.exists()) {
234+
configFile.createNewFile();
235+
FileWriter pbWriter = new FileWriter(configFile);
236+
pbWriter.write("{}");
237+
pbWriter.close();
238+
}
239+
} catch(Exception e) {
240+
LogUtils.error(e);
241+
}
242+
}
243+
223244
public static void updateRoutes(File configFile) {
224245
try {
225246
LogUtils.info("Downloading routes.json...");

src/main/java/xyz/yourboykyle/secretroutes/config/SRMConfig.java

+61
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import cc.polyfrost.oneconfig.config.data.ModType;
1010
import cc.polyfrost.oneconfig.config.data.OptionSize;
1111
import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
12+
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.dungeons.catacombs.RoomDetection;
1213
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.utils.Utils;
1314
import net.minecraft.client.Minecraft;
1415
import net.minecraft.util.BlockPos;
@@ -168,6 +169,66 @@ public class SRMConfig extends Config {
168169
}).start();
169170
};
170171

172+
@Switch(
173+
name = "Personal Best Tracking",
174+
description = "Tracks your personal best time for completing the secrets in each room",
175+
subcategory = "Personal Bests"
176+
)
177+
public static boolean trackPersonalBests = true;
178+
179+
@Switch(
180+
name = "Send Chat Messages For New PBs",
181+
description = "Sends chat messages when you beat your personal best",
182+
subcategory = "Personal Bests"
183+
)
184+
public static boolean sendChatMessages = true;
185+
186+
// I don't know why I added this lol
187+
/*@Button(
188+
name = "Reload Personal Bests",
189+
text = "Reload",
190+
description = "Reloads the personal bests from the personal_bests.json file",
191+
subcategory = "Personal Bests"
192+
)
193+
Runnable runnable18 = () -> {
194+
new Thread(() -> {
195+
if (PBUtils.loadPBData()) {
196+
sendChatMessage(EnumChatFormatting.DARK_GREEN + "Reloaded personal bests");
197+
}
198+
}).start();
199+
};*/
200+
201+
@Button(
202+
name = "Get personal best (current room)",
203+
text = "Get PB",
204+
description = "Gets your personal best time for the current room",
205+
subcategory = "Personal Bests"
206+
)
207+
Runnable runnable19 = () -> {
208+
new Thread(() -> {
209+
long pb = PBUtils.getPBForRoom(RoomDetection.roomName);
210+
if (pb != -1) {
211+
sendChatMessage("Personal best for " + RoomDetection.roomName + ": " + EnumChatFormatting.GREEN + PBUtils.formatTime(pb));
212+
} else {
213+
sendChatMessage(EnumChatFormatting.DARK_RED + "No personal best found for " + RoomDetection.roomName);
214+
}
215+
}).start();
216+
};
217+
218+
@Button(
219+
name = "Reset personal best (current room)",
220+
text = "Reset PB",
221+
description = "Reset your personal best time for the current room",
222+
subcategory = "Personal Bests"
223+
)
224+
Runnable runnable20 = () -> {
225+
new Thread(() -> {
226+
// Remove the PB from the JSON
227+
PBUtils.removePersonalBest(RoomDetection.roomName);
228+
sendChatMessage("Reset personal best for " + RoomDetection.roomName);
229+
}).start();
230+
};
231+
171232
@Switch(
172233
name = "Notify for new updates",
173234
description = "Automatically checks for updates on startup. WILL NOT AUTO UPDATE",

src/main/java/xyz/yourboykyle/secretroutes/events/OnItemPickedUp.java

-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818

1919
package xyz.yourboykyle.secretroutes.events;
2020

21-
import net.minecraft.client.Minecraft;
2221
import net.minecraft.util.BlockPos;
23-
import net.minecraft.util.ChatComponentText;
2422
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
2523
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
2624
import xyz.yourboykyle.secretroutes.Main;
2725
import xyz.yourboykyle.secretroutes.utils.LogUtils;
2826
import xyz.yourboykyle.secretroutes.utils.Room;
29-
import xyz.yourboykyle.secretroutes.utils.SecretSounds;
3027

3128
public class OnItemPickedUp {
3229
public static boolean itemSecretOnCooldown = false; // True: do not add item secret waypoint, False: add item secret waypoint
@@ -39,7 +36,6 @@ public void onPickupItem(PlayerEvent.ItemPickupEvent e) {
3936

4037
if (pos.getX() >= itemPos.getX() - 10 && pos.getX() <= itemPos.getX() + 10 && pos.getY() >= itemPos.getY() - 10 && pos.getY() <= itemPos.getY() + 10 && pos.getZ() >= itemPos.getZ() - 10 && pos.getZ() <= itemPos.getZ() + 10) {
4138
Main.currentRoom.nextSecret();
42-
SecretSounds.secretChime();
4339
LogUtils.info("Picked up item at " + itemPos);
4440
}
4541
}

src/main/java/xyz/yourboykyle/secretroutes/events/OnPlayerInteract.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public void onPlayerInteract(PlayerInteractEvent e) {
4040
if(block != Blocks.chest && block != Blocks.trapped_chest && block != Blocks.lever && block != Blocks.skull) {
4141
return;
4242
}
43-
SecretSounds.secretChime();
43+
44+
if (block == Blocks.lever) {
45+
SecretSounds.secretChime();
46+
}
47+
4448
if (Main.currentRoom.getSecretType() == Room.SECRET_TYPES.INTERACT) {
4549
BlockPos interactPos = Main.currentRoom.getSecretLocation();
4650

src/main/java/xyz/yourboykyle/secretroutes/events/OnPlayerTick.java

-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import xyz.yourboykyle.secretroutes.config.SRMConfig;
2727
import xyz.yourboykyle.secretroutes.utils.LogUtils;
2828
import xyz.yourboykyle.secretroutes.utils.Room;
29-
import xyz.yourboykyle.secretroutes.utils.SecretSounds;
3029

3130
public class OnPlayerTick {
3231
@SubscribeEvent
@@ -50,7 +49,6 @@ public void onPlayerTick(TickEvent.PlayerTickEvent e) {
5049
BlockPos batPos = Main.currentRoom.getSecretLocation();
5150

5251
if (pos.getX() >= batPos.getX() - 3 && pos.getX() <= batPos.getX() + 3 && pos.getY() >= batPos.getY() - 3 && pos.getY() <= batPos.getY() + 3 && pos.getZ() >= batPos.getZ() - 3 && pos.getZ() <= batPos.getZ() + 3) {
53-
SecretSounds.secretChime();
5452
Main.currentRoom.nextSecret();
5553
LogUtils.info("Went by bat at " + batPos);
5654
}
@@ -71,7 +69,6 @@ public void onPlayerTick(TickEvent.PlayerTickEvent e) {
7169
Thread.sleep(1500);
7270
if (Main.currentRoom.getSecretType() == Room.SECRET_TYPES.ITEM && itemPos.getX() == Main.currentRoom.getSecretLocation().getX() && itemPos.getY() == Main.currentRoom.getSecretLocation().getY() && itemPos.getZ() == Main.currentRoom.getSecretLocation().getZ()) {
7371

74-
SecretSounds.secretChime();
7572
Main.currentRoom.nextSecret();
7673
LogUtils.info("Picked up item at " + itemPos + " (Auto)");
7774
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package xyz.yourboykyle.secretroutes.events;
2+
3+
import xyz.yourboykyle.secretroutes.Main;
4+
import xyz.yourboykyle.secretroutes.deps.dungeonrooms.dungeons.catacombs.RoomDetection;
5+
import xyz.yourboykyle.secretroutes.utils.ChatUtils;
6+
import xyz.yourboykyle.secretroutes.utils.PBUtils;
7+
import xyz.yourboykyle.secretroutes.utils.SecretSounds;
8+
9+
public class OnSecretComplete {
10+
public static void onSecretCompleteNoKeybind() {
11+
// This is where you would put your code that you want to run when a secret is completed.
12+
SecretSounds.secretChime();
13+
14+
// PB Stuff
15+
if(Main.currentRoom.currentSecretIndex <= Main.currentRoom.currentSecretRoute.size() - 1) {
16+
// If the route hasn't been completed yet, log progress for debugging
17+
ChatUtils.sendVerboseMessage("Secret " + (Main.currentRoom.currentSecretIndex + 1) + "/" + (Main.currentRoom.currentSecretRoute.size()) + " in " + RoomDetection.roomName + " completed in §a" + ((Main.currentRoom.currentSecretIndex > 0) ? PBUtils.formatTime(System.currentTimeMillis() - PBUtils.startTime) : "0.000s"));
18+
}
19+
20+
if(Main.currentRoom.currentSecretIndex == 0) {
21+
ChatUtils.sendVerboseMessage("Starting timer for " + Main.currentRoom.name);
22+
PBUtils.pbIsValid = true;
23+
PBUtils.startRoute();
24+
} else if (Main.currentRoom.currentSecretIndex == Main.currentRoom.currentSecretRoute.size() - 1) {
25+
ChatUtils.sendVerboseMessage("Stopping timer for " + Main.currentRoom.name);
26+
PBUtils.stopRoute();
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)