Skip to content

Commit

Permalink
Add the cwaypoint command (#513)
Browse files Browse the repository at this point in the history
* Add the cwaypoint command

* Remove unnecessary code

* Implement saving to a file

* Port to mojmap

* Make waypoints storage future-proof + rely on level id for data persistence

* Fix ordering of translation keys

* Widen exception bound

* Remove leading space from translation

* Add null check

* Render augmented waypoint name at the top of the screen

* Move rendering code to WaypointCommand.java

* Render box with name when waypoint is in loaded chunks

* Adjust size slightly

* Replace y offset with distance in top screen display

* Use records instead of pairs

* No idea how this happened

* Replace map with list

* Make comment clearer

* Sort waypoint lines based on distance

* Undo sorting because it did not work

* Bracket labels and make them yellow

* Add dimension check for waypoint boxes

* Format coordinates nicely

* Widen exception bound in throws clause

* Replace priority queue with list

* Return amount of waypoints in list subcommand

* Replace AtomicInteger with singleton array

* Introduce WaypointCommand.registerEvents method

* Add unit test for loading waypoint file

---------

Co-authored-by: joe <[email protected]>
  • Loading branch information
xpple and Earthcomputer authored Jan 17, 2025
1 parent 55b46c4 commit 918f592
Show file tree
Hide file tree
Showing 11 changed files with 530 additions and 25 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ org.gradle.jvmargs=-Xmx2G
# also check this on https://fabricmc.net/develop/
fabric_version=0.110.5+1.21.4
clientarguments_version=1.10.1
betterconfig_version=2.1.2
betterconfig_version=2.3.0
seedfinding_core_version=1.200.1
seedfinding_biome_version=1.171.1
seedfinding_feature_version=1.171.9
Expand Down
43 changes: 24 additions & 19 deletions src/main/java/net/earthcomputer/clientcommands/ClientCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.commands.CommandBuildContext;
import org.slf4j.Logger;
Expand All @@ -37,25 +36,11 @@

public class ClientCommands implements ClientModInitializer {
private static final Logger LOGGER = LogUtils.getLogger();
public static Path configDir;
public static final Path CONFIG_DIR = FabricLoader.getInstance().getConfigDir().resolve("clientcommands");
private static final Set<String> clientcommandsCommands = new HashSet<>();
private static final Set<String> COMMANDS_TO_NOT_SEND_TO_SERVER = Set.of("cwe", "cnote"); // could contain private information

public static final boolean SCRAMBLE_WINDOW_TITLE = Util.make(() -> {
String playerUUID = String.valueOf(Minecraft.getInstance().getUser().getProfileId());

Set<String> victims = Set.of(
"fa68270b-1071-46c6-ac5c-6c4a0b777a96", // Earthcomputer
"d4557649-e553-413e-a019-56d14548df96", // Azteched
"8dc3d945-cf90-47c1-a122-a576319d05a7", // samnrad
"c5d72740-cabc-42d1-b789-27859041d553", // allocator
"e4093360-a200-4f99-aa13-be420b8d9a79", // Rybot666
"083fb87e-c9e4-4489-8fb7-a45b06bfca90", // Kerbaras
"973e8f6e-2f51-4307-97dc-56fdc71d194f" // KatieTheQt
);

return victims.contains(playerUUID) || Boolean.getBoolean("clientcommands.scrambleWindowTitle");
});
public static boolean scrambleWindowTitle = false;

private static final Set<String> CHAT_COMMAND_USERS = Set.of(
"b793c3b9-425f-4dd8-a056-9dec4d835e24", // wsb
Expand All @@ -65,10 +50,11 @@ public class ClientCommands implements ClientModInitializer {

@Override
public void onInitializeClient() {
setupScrambleWindowTitle();

// Config
configDir = FabricLoader.getInstance().getConfigDir().resolve("clientcommands");
try {
Files.createDirectories(configDir);
Files.createDirectories(CONFIG_DIR);
} catch (IOException e) {
LOGGER.error("Failed to create config dir", e);
}
Expand All @@ -91,6 +77,24 @@ public void onInitializeClient() {
FishingCracker.registerEvents();
PlayerRandCracker.registerEvents();
ServerBrandManager.registerEvents();
WaypointCommand.registerEvents();
}

private static void setupScrambleWindowTitle() {
// can't set this up during class initializer, because Minecraft.getInstance() is null during automated tests
String playerUUID = String.valueOf(Minecraft.getInstance().getUser().getProfileId());

Set<String> victims = Set.of(
"fa68270b-1071-46c6-ac5c-6c4a0b777a96", // Earthcomputer
"d4557649-e553-413e-a019-56d14548df96", // Azteched
"8dc3d945-cf90-47c1-a122-a576319d05a7", // samnrad
"c5d72740-cabc-42d1-b789-27859041d553", // allocator
"e4093360-a200-4f99-aa13-be420b8d9a79", // Rybot666
"083fb87e-c9e4-4489-8fb7-a45b06bfca90", // Kerbaras
"973e8f6e-2f51-4307-97dc-56fdc71d194f" // KatieTheQt
);

scrambleWindowTitle = victims.contains(playerUUID) || Boolean.getBoolean("clientcommands.scrambleWindowTitle");
}

private static Set<String> getCommands(CommandDispatcher<?> dispatcher) {
Expand Down Expand Up @@ -173,6 +177,7 @@ public static void registerCommands(CommandDispatcher<FabricClientCommandSource>
UsageTreeCommand.register(dispatcher);
UuidCommand.register(dispatcher);
VarCommand.register(dispatcher);
WaypointCommand.register(dispatcher);
WeatherCommand.register(dispatcher);
WhisperEncryptedCommand.register(dispatcher);
WikiCommand.register(dispatcher);
Expand Down
Loading

0 comments on commit 918f592

Please sign in to comment.