Skip to content

Commit

Permalink
hare position and set waypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BigloBot committed Aug 24, 2024
1 parent 7a9fbeb commit bd5154b
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import de.hysky.skyblocker.skyblock.calculators.CalculatorCommand;
import de.hysky.skyblocker.skyblock.chat.ChatRulesHandler;
import de.hysky.skyblocker.skyblock.chat.SkyblockXpMessages;
import de.hysky.skyblocker.skyblock.chat.chatcoords.ChatLocation;
import de.hysky.skyblocker.skyblock.chat.chatcoords.ChatWaypointLocation;
import de.hysky.skyblocker.skyblock.chocolatefactory.EggFinder;
import de.hysky.skyblocker.skyblock.chocolatefactory.TimeTowerReminder;
import de.hysky.skyblocker.skyblock.crimson.dojo.DojoManager;
Expand Down Expand Up @@ -216,6 +218,9 @@ public void onInitializeClient() {
MobGlow.init();
MayorUtils.init();
SlayerEntitiesGlow.init();
ChatLocation.init();
ChatWaypointLocation.init();
IndividualWaypoint.init();

Scheduler.INSTANCE.scheduleCyclic(Utils::update, 20);
Scheduler.INSTANCE.scheduleCyclic(DiscordRPCManager::updateDataAndPresence, 200);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package de.hysky.skyblocker.skyblock.chat.chatcoords;

import com.mojang.brigadier.Command;
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.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;

import java.util.Random;
import java.util.UUID;

public class ChatLocation {

public static void init() {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
ClientCommandManager.literal("skyblocker").then(ClientCommandManager.literal("location").executes(context -> sharePlayerLocation()))
));
}

private static int sharePlayerLocation() {
ClientPlayerEntity thePlayer = MinecraftClient.getInstance().player;
MessageScheduler.INSTANCE.sendMessageAfterCooldown("x: " + (int) thePlayer.getX() + ", y: " + (int) thePlayer.getY() + ", z: " + (int) thePlayer.getZ() + " | " + Utils.getIslandArea(), true);
return Command.SINGLE_SUCCESS;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package de.hysky.skyblocker.skyblock.chat.chatcoords;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.Utils;
import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
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);

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>[^|]+))");
private static final Pattern SKYHANNI_DIANA_PATTERN = Pattern.compile("A MINOS INQUISITOR has spawned near \\[(?<area>[^]]*)] at Coords (?<x>-?[0-9]+) (?<y>[0-9]+) (?<z>-?[0-9]+)");
private static final List<Pattern> PATTERNS = List.of(SKYBLOCKER_COORDS_PATTERN, SKYHANNI_DIANA_PATTERN, GENERIC_COORDS_PATTERN);

public static void init() {
ClientReceiveMessageEvents.GAME.register(ChatWaypointLocation::onMessage);
}

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

String message = text.getString();

for (Pattern pattern : PATTERNS) {
Matcher matcher = pattern.matcher(message);
if (matcher.find()) {
try {
String x = matcher.group("x");
String y = matcher.group("y");
String z = matcher.group("z");
String area = matcher.group("area");
requestWaypoint(x, y, z, area);
} catch (Exception e) {
LOGGER.error("[SKYBLOCKER CHAT WAYPOINTS] Error creating chat waypoint: ", e);
}
break;
}
}
}
}

private static void requestWaypoint(String x, String y, String z, 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ public boolean onMatch(Text message, Matcher matcher) {
}

private void sendCommand(String command, int delay) {
MessageScheduler.INSTANCE.queueMessage(command, delay * BASE_DELAY);
MessageScheduler.INSTANCE.queueMessage(command, false, delay * BASE_DELAY);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package de.hysky.skyblocker.skyblock.waypoint;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.ColorUtils;
import de.hysky.skyblocker.utils.waypoint.NamedWaypoint;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

import java.awt.*;

public class IndividualWaypoint extends NamedWaypoint {

private static IndividualWaypoint waypoint;

public static void init() {

ClientTickEvents.END_CLIENT_TICK.register(IndividualWaypoint::onTick);

WorldRenderEvents.AFTER_TRANSLUCENT.register(context -> { if (waypoint != null) waypoint.render(context); });

ClientPlayConnectionEvents.JOIN.register((ignore, ignore2, ignore3) -> waypoint = null);

ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
ClientCommandManager.literal(SkyblockerMod.NAMESPACE)
.then(ClientCommandManager.literal("waypoints")
.then(ClientCommandManager.literal("individual")
.then(ClientCommandManager.argument("x", IntegerArgumentType.integer(Integer.MIN_VALUE))
.then(ClientCommandManager.argument("y", IntegerArgumentType.integer(Integer.MIN_VALUE))
.then(ClientCommandManager.argument("z", IntegerArgumentType.integer(Integer.MIN_VALUE))
.then(ClientCommandManager.argument("area", StringArgumentType.greedyString())
.executes(context -> setWaypoint(
IntegerArgumentType.getInteger(context, "x"),
IntegerArgumentType.getInteger(context, "y"),
IntegerArgumentType.getInteger(context, "z"),
StringArgumentType.getString(context, "area")
))
)
)
)
)
)
)
));
}

public IndividualWaypoint(BlockPos pos, Text name, float[] colorComponents) {
super(pos, name, colorComponents, 0.5f, true);
}

private static int setWaypoint(int x, int y, int z, String area) {
String waypointName = area != null && !area.isEmpty() ? area : "Waypoint";

Text waypointDisplay;
if (waypointName.charAt(0) == '⏣') {
waypointDisplay = Text.literal("⏣").formatted(Formatting.DARK_PURPLE)
.append(Text.literal(waypointName.substring(1)).formatted(Formatting.AQUA));
} else {
waypointDisplay = Text.literal(waypointName).formatted(Formatting.AQUA);
}

waypoint = new IndividualWaypoint(new BlockPos(x, y, z), waypointDisplay, ColorUtils.getFloatComponents(Color.GREEN.getRGB()));
return Command.SINGLE_SUCCESS;
}

private static void onTick(MinecraftClient c) {
if (waypoint != null && c.player.getPos().distanceTo(Vec3d.ofCenter(waypoint.pos)) <= 8) {
waypoint = null;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,20 @@ protected MessageScheduler() {
*
* @param message the message to send
*/
public void sendMessageAfterCooldown(String message) {
public void sendMessageAfterCooldown(String message, boolean hide) {
if (lastMessage + MIN_DELAY < System.currentTimeMillis()) {
sendMessage(message);
sendMessage(message,hide);
lastMessage = System.currentTimeMillis();
} else {
queueMessage(message, 0);
queueMessage(message, hide, 0);
}
}

private void sendMessage(String message) {
public void sendMessageAfterCooldown(String message) {
sendMessageAfterCooldown(message, false);
}

private void sendMessage(String message, boolean hide) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player == null) {
Scheduler.LOGGER.error("[Skyblocker Message Scheduler] Tried to send a message while player is null: {}", message);
Expand All @@ -45,7 +49,7 @@ private void sendMessage(String message) {
if (message.startsWith("/")) {
client.player.networkHandler.sendCommand(message.substring(1));
} else {
client.inGameHud.getChatHud().addToMessageHistory(message);
if (!hide) client.inGameHud.getChatHud().addToMessageHistory(message);
client.player.networkHandler.sendChatMessage(message);
}
}
Expand All @@ -56,8 +60,8 @@ private void sendMessage(String message) {
* @param message the message to send
* @param delay the delay before sending the message in ticks
*/
public void queueMessage(String message, int delay) {
schedule(() -> sendMessage(message), delay);
public void queueMessage(String message, boolean hide, int delay) {
schedule(() -> sendMessage(message, hide), delay);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.mojang.serialization.codecs.RecordCodecBuilder;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.utils.ColorUtils;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.render.RenderHelper;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -114,7 +115,8 @@ protected boolean shouldRenderName() {
public void render(WorldRenderContext context) {
super.render(context);
if (shouldRenderName()) {
RenderHelper.renderText(context, name, centerPos.add(0, 1, 0), true);
float scale = (float) (context.camera().getPos().distanceTo(centerPos) / 10);
RenderHelper.renderText(context, name, centerPos.add(0, 1, 0), scale, true);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@
"skyblocker.config.chat.chatRules.screen.ruleScreen.sounds.pling": "Pling",
"skyblocker.config.chat.chatRules.screen.ruleScreen.sounds.zombie": "Zombie",
"skyblocker.config.chat.chatRules.screen.ruleScreen.true": "True",
"skyblocker.config.chat.waypoints.display": "[Display Waypoint]",


"skyblocker.config.chat.filter": "Filter",
"skyblocker.config.chat.filter.chatFilterResult.ACTION_BAR": "Move to action bar",
Expand Down

0 comments on commit bd5154b

Please sign in to comment.