Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waypoints refactor #976

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.mining.crystalsWaypoints.enabled = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Float>createBuilder()
.name(Text.translatable("skyblocker.config.mining.crystalsWaypoints.textScale"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.mining.crystalsWaypoints.textScale.@Tooltip")))
.binding(defaults.mining.crystalsWaypoints.textScale,
() -> config.mining.crystalsWaypoints.textScale,
newValue -> config.mining.crystalsWaypoints.textScale = newValue)
.controller(FloatFieldControllerBuilder::create)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.mining.crystalsWaypoints.findInChat"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.mining.crystalsWaypoints.findInChat.@Tooltip")))
Expand Down Expand Up @@ -224,14 +216,6 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.mining.commissionWaypoints.mode = newValue)
.controller(ConfigUtils::createEnumCyclingListController)
.build())
.option(Option.<Float>createBuilder()
.name(Text.translatable("skyblocker.config.mining.commissionWaypoints.textScale"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.mining.commissionWaypoints.textScale.@Tooltip")))
.binding(defaults.mining.commissionWaypoints.textScale,
() -> config.mining.commissionWaypoints.textScale,
newValue -> config.mining.commissionWaypoints.textScale = newValue)
.controller(FloatFieldControllerBuilder::create)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.mining.commissionWaypoints.useColor"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.mining.commissionWaypoints.useColor.@Tooltip")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public static class CrystalsWaypoints {
@SerialEntry
public boolean enabled = true;

@Deprecated
@SerialEntry
public float textScale = 1;

Expand All @@ -116,6 +117,7 @@ public static class CommissionWaypoints {
@SerialEntry
public CommissionWaypointMode mode = CommissionWaypointMode.BOTH;

@Deprecated
@SerialEntry
public float textScale = 1;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
package de.hysky.skyblocker.skyblock.chat.chatcoords;
package de.hysky.skyblocker.skyblock.chat;

import com.mojang.brigadier.Command;
import de.hysky.skyblocker.annotations.Init;
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 net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ChatWaypointLocation {

private static final Logger LOGGER = LoggerFactory.getLogger(ChatWaypointLocation.class);
public class ChatPositionShare {
private static final Logger LOGGER = LoggerFactory.getLogger(ChatPositionShare.class);

private static final Pattern GENERIC_COORDS_PATTERN = Pattern.compile("x: (?<x>-?[0-9]+), y: (?<y>[0-9]+), z: (?<z>-?[0-9]+)");
private static final Pattern SKYBLOCKER_COORDS_PATTERN = Pattern.compile("x: (?<x>-?[0-9]+), y: (?<y>[0-9]+), z: (?<z>-?[0-9]+)(?: \\| (?<area>[^|]+))");
Expand All @@ -27,12 +35,20 @@ public class ChatWaypointLocation {

@Init
public static void init() {
ClientReceiveMessageEvents.GAME.register(ChatWaypointLocation::onMessage);
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
ClientCommandManager.literal("skyblocker").then(ClientCommandManager.literal("sharePosition").executes(context -> sharePlayerPosition(context.getSource())))
));
ClientReceiveMessageEvents.GAME.register(ChatPositionShare::onMessage);
}

private static int sharePlayerPosition(FabricClientCommandSource source) {
Vec3d pos = source.getPosition();
MessageScheduler.INSTANCE.sendMessageAfterCooldown("x: " + (int) pos.getX() + ", y: " + (int) pos.getY() + ", z: " + (int) pos.getZ() + " | " + Utils.getIslandArea(), true);
return Command.SINGLE_SUCCESS;
}

private static void onMessage(Text text, boolean overlay) {
if (Utils.isOnSkyblock() && SkyblockerConfigManager.get().uiAndVisuals.waypoints.enableWaypoints) {

String message = text.getString();

for (Pattern pattern : PATTERNS) {
Expand All @@ -42,25 +58,28 @@ private static void onMessage(Text text, boolean overlay) {
String x = matcher.group("x");
String y = matcher.group("y");
String z = matcher.group("z");
String area = matcher.group("area");
String area = matcher.namedGroups().containsKey("area") ? matcher.group("area") : "";
requestWaypoint(x, y, z, area);
} catch (Exception e) {
LOGGER.error("[SKYBLOCKER CHAT WAYPOINTS] Error creating chat waypoint: ", e);
LOGGER.error("[Skyblocker Chat Waypoints] Error creating chat waypoint: ", e);
}
break;
}
}
}
}

private static void requestWaypoint(String x, String y, String z, String area) {
private static void requestWaypoint(String x, String y, String z, @NotNull String area) {
String command = "/skyblocker waypoints individual " + x + " " + y + " " + z + " " + area;

Text text = Constants.PREFIX.get()
.append(Text.translatable("skyblocker.config.chat.waypoints.display").formatted(Formatting.AQUA)
.styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command))))
.append(Text.of(area != null ? " at " + area : ""));

MinecraftClient.getInstance().player.sendMessage(text, false);
MutableText requestMessage = Constants.PREFIX.get().append(Text.translatable("skyblocker.config.chat.waypoints.display").formatted(Formatting.AQUA)
.styled(style -> style
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.translatable("skyblocker.config.chat.waypoints.display")))
.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command))
)
);
if (!area.isEmpty()) {
requestMessage = requestMessage.append(" at ").append(Text.literal(area).formatted(Formatting.AQUA));
}
MinecraftClient.getInstance().player.sendMessage(requestMessage, false);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import de.hysky.skyblocker.skyblock.dungeon.secrets.DungeonManager;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.waypoint.NamedWaypoint;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
Expand Down Expand Up @@ -110,20 +111,15 @@ private static boolean shouldProcessMsgs() {
* @param waypoints The list of waypoints to operate on
* @param playerName The name of the player to check against
*/
private static void removeNearestWaypoint(ObjectArrayList<GoldorWaypoint> waypoints, String playerName) {
private static void removeNearestWaypoint(List<GoldorWaypoint> waypoints, String playerName) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.world == null) return;

// Get the position of the player with the given name
Optional<Vec3d> posOptional = client.world.getPlayers().stream().filter(player -> player.getGameProfile().getName().equals(playerName)).findAny().map(Entity::getPos);

if (posOptional.isPresent()) {
Vec3d pos = posOptional.get();

waypoints.stream().filter(GoldorWaypoint::shouldRender).min(Comparator.comparingDouble(waypoint -> waypoint.centerPos.squaredDistanceTo(pos))).map(waypoint -> {
waypoint.setShouldRender(false);
return null;
});
}
// Find the nearest waypoint to the player and hide it
posOptional.flatMap(pos -> waypoints.stream().filter(GoldorWaypoint::shouldRender).min(Comparator.comparingDouble(waypoint -> waypoint.centerPos.squaredDistanceTo(pos)))).ifPresent(Waypoint::setFound);
}

/**
Expand All @@ -143,7 +139,7 @@ private static void reset() {
* @param waypoints The set of waypoints to enable rendering for
*/
private static void enableAll(ObjectArrayList<GoldorWaypoint> waypoints) {
waypoints.forEach(waypoint -> waypoint.setShouldRender(true));
waypoints.forEach(Waypoint::setMissing);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.config.configs.DungeonsConfig;
import de.hysky.skyblocker.utils.render.RenderHelper;
import de.hysky.skyblocker.utils.waypoint.NamedWaypoint;
import de.hysky.skyblocker.utils.waypoint.DistancedNamedWaypoint;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.MinecraftClient;
import net.minecraft.command.argument.EnumArgumentType;
import net.minecraft.entity.Entity;
import net.minecraft.text.Text;
import net.minecraft.text.TextCodecs;
import net.minecraft.util.Formatting;
import net.minecraft.util.StringIdentifiable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -29,7 +25,7 @@
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;

public class SecretWaypoint extends NamedWaypoint {
public class SecretWaypoint extends DistancedNamedWaypoint {
private static final Logger LOGGER = LoggerFactory.getLogger(SecretWaypoint.class);
public static final Codec<SecretWaypoint> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("secretIndex").forGetter(secretWaypoint -> secretWaypoint.secretIndex),
Expand Down Expand Up @@ -94,7 +90,7 @@ public boolean equals(Object obj) {

@Override
protected boolean shouldRenderName() {
return CONFIG.get().showSecretText;
return super.shouldRenderName() && CONFIG.get().showSecretText;
}

/**
Expand All @@ -104,12 +100,6 @@ protected boolean shouldRenderName() {
public void render(WorldRenderContext context) {
//TODO In the future, shrink the box for wither essence and items so its more realistic
super.render(context);

if (CONFIG.get().showSecretText) {
Vec3d posUp = centerPos.add(0, 1, 0);
double distance = context.camera().getPos().distanceTo(centerPos);
RenderHelper.renderText(context, Text.literal(Math.round(distance) + "m").formatted(Formatting.YELLOW), posUp, 1, MinecraftClient.getInstance().textRenderer.fontHeight + 1, true);
}
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,17 @@ private static void render(DrawContext context, int hudX, int hudY) {

//if enabled add waypoint locations to map
if (SkyblockerConfigManager.get().mining.crystalsHud.showLocations) {
Map<String, MiningLocationLabel> ActiveWaypoints = CrystalsLocationsManager.activeWaypoints;

for (MiningLocationLabel waypoint : ActiveWaypoints.values()) {
int waypointColor = waypoint.category().getColor();
Vector2ic renderPos = transformLocation(waypoint.centerPos().getX(), waypoint.centerPos().getZ());
for (MiningLocationLabel waypoint : CrystalsLocationsManager.activeWaypoints.values()) {
MiningLocationLabel.Category category = waypoint.category();
Vector2ic renderPos = transformLocation(waypoint.centerPos.getX(), waypoint.centerPos.getZ());
int locationSize = SkyblockerConfigManager.get().mining.crystalsHud.locationSize;

if (SMALL_LOCATIONS.contains(waypoint.category().getName())) {//if small location half the location size
if (SMALL_LOCATIONS.contains(category.getName())) {//if small location half the location size
locationSize /= 2;
}

//fill square of size locationSize around the coordinates of the location
context.fill(renderPos.x() - locationSize / 2, renderPos.y() - locationSize / 2, renderPos.x() + locationSize / 2, renderPos.y() + locationSize / 2, waypointColor);
context.fill(renderPos.x() - locationSize / 2, renderPos.y() - locationSize / 2, renderPos.x() + locationSize / 2, renderPos.y() + locationSize / 2, category.getColor());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ public static int addWaypointFromCommand(FabricClientCommandSource source, Strin

public static int shareWaypoint(String place) {
if (activeWaypoints.containsKey(place)) {
Vec3d pos = activeWaypoints.get(place).centerPos();
MessageScheduler.INSTANCE.sendMessageAfterCooldown(Constants.PREFIX.get().getString() + " " + place + ": " + (int) pos.getX() + ", " + (int) pos.getY() + ", " + (int) pos.getZ());
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) {
Expand Down Expand Up @@ -349,7 +349,7 @@ private static void removeUnknownNear(BlockPos location) {
String name = MiningLocationLabel.CrystalHollowsLocationsCategory.UNKNOWN.getName();
MiningLocationLabel unknownWaypoint = activeWaypoints.getOrDefault(name, null);
if (unknownWaypoint != null) {
double distance = unknownWaypoint.centerPos().distanceTo(location.toCenterPos());
double distance = unknownWaypoint.centerPos.distanceTo(location.toCenterPos());
if (distance < REMOVE_UNKNOWN_DISTANCE) {
activeWaypoints.remove(name);
}
Expand Down
Loading