-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Location Share & Waypoint] Share position and set waypoint (#916)
Co-authored-by: Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>
- Loading branch information
1 parent
5ed09f8
commit dd5f0d3
Showing
7 changed files
with
193 additions
and
9 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
src/main/java/de/hysky/skyblocker/skyblock/chat/chatcoords/ChatLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package de.hysky.skyblocker.skyblock.chat.chatcoords; | ||
|
||
import com.mojang.brigadier.Command; | ||
import de.hysky.skyblocker.annotations.Init; | ||
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; | ||
|
||
public class ChatLocation { | ||
@Init | ||
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; | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/de/hysky/skyblocker/skyblock/chat/chatcoords/ChatWaypointLocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package de.hysky.skyblocker.skyblock.chat.chatcoords; | ||
|
||
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 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); | ||
|
||
@Init | ||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/main/java/de/hysky/skyblocker/skyblock/waypoint/IndividualWaypoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.annotations.Init; | ||
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.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; | ||
|
||
@Init | ||
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters