Skip to content

Commit

Permalink
Merge pull request #642 from olim88/share-waypoints
Browse files Browse the repository at this point in the history
add ability to share crystal waypoint locations
  • Loading branch information
AzureAaron authored Apr 9, 2024
2 parents b5775f7 + b945f15 commit fa97859
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.logging.LogUtils;

import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
Expand All @@ -24,7 +24,9 @@
import net.minecraft.text.ClickEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import org.slf4j.Logger;

import java.awt.*;
import java.util.Arrays;
Expand All @@ -35,11 +37,10 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import org.slf4j.Logger;

import static com.mojang.brigadier.arguments.StringArgumentType.getString;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
import static net.minecraft.command.CommandSource.suggestMatching;

public class CrystalsLocationsManager {
private static final Logger LOGGER = LogUtils.getLogger();
Expand Down Expand Up @@ -101,26 +102,34 @@ private static void extractLocationFromMessage(Text message, Boolean overlay) {
LOGGER.error("[Skyblocker Crystals Locations Manager] Encountered an exception while extracing a location from a chat message!", e);
}
}
protected static Boolean checkInCrystals(BlockPos pos){

protected static Boolean checkInCrystals(BlockPos pos) {
//checks if a location is inside crystal hollows bounds
return pos.getX() >= 202 && pos.getX() <= 823
&& pos.getZ() >= 202 && pos.getZ() <= 823
&& pos.getY() >= 31 && pos.getY() <= 188;
&& pos.getY() >= 31 && pos.getY() <= 188;
}

private static void registerWaypointLocationCommands(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
dispatcher.register(literal(SkyblockerMod.NAMESPACE)
.then(literal("crystalWaypoints")
.then(argument("pos", BlockPosArgumentType.blockPos())
.then(argument("place", StringArgumentType.greedyString())
.executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", PosArgument.class)))
.then(literal("crystalWaypoints")
.then(argument("pos", BlockPosArgumentType.blockPos())
.then(argument("place", StringArgumentType.greedyString())
.suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder))
.executes(context -> addWaypointFromCommand(context.getSource(), getString(context, "place"), context.getArgument("pos", PosArgument.class)))
)
)
.then(literal("share")
.then(argument("place", StringArgumentType.greedyString())
.suggests((context, builder) -> suggestMatching(WAYPOINT_LOCATIONS.keySet(), builder))
.executes(context -> shareWaypoint(getString(context, "place")))
)
)
)
)
);
}

protected static Text getSetLocationMessage(String location,BlockPos blockPos) {
protected static Text getSetLocationMessage(String location, BlockPos blockPos) {
MutableText text = Constants.PREFIX.get();
text.append(Text.literal("Added waypoint for "));
Color locationColor = WAYPOINT_LOCATIONS.get(location).color;
Expand Down Expand Up @@ -159,6 +168,21 @@ public static int addWaypointFromCommand(FabricClientCommandSource source, Strin
return Command.SINGLE_SUCCESS;
}

public static int shareWaypoint(String place) {
if (activeWaypoints.containsKey(place)) {
BlockPos pos = activeWaypoints.get(place).pos;
MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString() + " " + place + ": " + pos.getX() + ", " + pos.getY() + ", " + pos.getZ());
} else {
//send fail message
if (CLIENT.player == null || CLIENT.getNetworkHandler() == null) {
return 0;
}
CLIENT.player.sendMessage(Constants.PREFIX.get().append(Text.translatable("text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.shareFail").formatted(Formatting.RED)), false);
}

return Command.SINGLE_SUCCESS;
}


private static void addCustomWaypoint(String waypointName, BlockPos pos) {
CrystalsWaypoint.Category category = WAYPOINT_LOCATIONS.get(waypointName);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@
"text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.enabled.@Tooltip": "Show a waypoint (waypoint selected in general/waypoints) at important areas in the crystal hollows e.g. Jungle Temple and Fairy Grotto. ",
"text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat": "Find Waypoints In Chat",
"text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.findInChat.@Tooltip": "When in crystal hollows read the chat to see if coordinates are sent and extract these to show as waypoint or on the map",
"text.autoconfig.skyblocker.option.locations.dwarvenMines.crystalsWaypoints.shareFail": "Can only share waypoints you have found.",

"text.autoconfig.skyblocker.option.locations.rift": "The Rift",
"text.autoconfig.skyblocker.option.locations.rift.mirrorverseWaypoints": "Enable Mirrorverse Waypoints",
Expand Down

0 comments on commit fa97859

Please sign in to comment.