aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-10-27 12:53:38 -0400
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-10-28 00:51:25 -0400
commit16467d786b89cc628e932b7e2091ab304d1b6b46 (patch)
tree838f866ea4d80da24852c482288e6639683c7bef /src/main/java/de/hysky/skyblocker/skyblock
parent58ba4ddfdca59d359100c0e42c97a0e6727ea9fa (diff)
downloadSkyblocker-16467d786b89cc628e932b7e2091ab304d1b6b46.tar.gz
Skyblocker-16467d786b89cc628e932b7e2091ab304d1b6b46.tar.bz2
Skyblocker-16467d786b89cc628e932b7e2091ab304d1b6b46.zip
Add custom waypoints removing
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java55
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java47
2 files changed, 88 insertions, 14 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java
index 81e73e1a..eda08cf6 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java
@@ -7,7 +7,6 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.IntegerArgumentType;
-import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.context.CommandContext;
@@ -32,6 +31,7 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.command.argument.PosArgument;
+import net.minecraft.command.argument.TextArgumentType;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.AmbientEntity;
@@ -179,6 +179,14 @@ public class DungeonSecrets {
}
/**
+ * @see #customWaypoints
+ */
+ @Nullable
+ public static SecretWaypoint removeCustomWaypoint(String room, BlockPos pos) {
+ return customWaypoints.remove(room, pos);
+ }
+
+ /**
* Loads the dungeon secrets asynchronously from {@code /assets/skyblocker/dungeons}.
* Use {@link #isRoomsLoaded()} to check for completion of loading.
*/
@@ -202,8 +210,10 @@ public class DungeonSecrets {
.then(literal("markAsMissing").then(markSecretsCommand(false)))
.then(literal("getRelativePos").executes(DungeonSecrets::getRelativePos))
.then(literal("getRelativeTargetPos").executes(DungeonSecrets::getRelativeTargetPos))
- .then(literal("addWaypoint").then(addWaypointCommand(false)))
- .then(literal("addWaypointRelatively").then(addWaypointCommand(true)))
+ .then(literal("addWaypoint").then(addCustomWaypointCommand(false)))
+ .then(literal("addWaypointRelatively").then(addCustomWaypointCommand(true)))
+ .then(literal("removeWaypoint").then(removeCustomWaypointCommand(false)))
+ .then(literal("removeWaypointRelatively").then(removeCustomWaypointCommand(true)))
))));
ClientPlayConnectionEvents.JOIN.register(((handler, sender, client) -> reset()));
}
@@ -291,8 +301,8 @@ public class DungeonSecrets {
}
private static ArgumentBuilder<FabricClientCommandSource, RequiredArgumentBuilder<FabricClientCommandSource, Integer>> markSecretsCommand(boolean found) {
- return argument("secret", IntegerArgumentType.integer()).executes(context -> {
- int secretIndex = IntegerArgumentType.getInteger(context, "secret");
+ return argument("secretIndex", IntegerArgumentType.integer()).executes(context -> {
+ int secretIndex = IntegerArgumentType.getInteger(context, "secretIndex");
if (markSecrets(secretIndex, found)) {
context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable(found ? "skyblocker.dungeons.secrets.markSecretFound" : "skyblocker.dungeons.secrets.markSecretMissing", secretIndex)));
} else {
@@ -326,11 +336,11 @@ public class DungeonSecrets {
return Command.SINGLE_SUCCESS;
}
- private static ArgumentBuilder<FabricClientCommandSource, RequiredArgumentBuilder<FabricClientCommandSource, PosArgument>> addWaypointCommand(boolean relative) {
+ private static ArgumentBuilder<FabricClientCommandSource, RequiredArgumentBuilder<FabricClientCommandSource, PosArgument>> addCustomWaypointCommand(boolean relative) {
return argument("pos", BlockPosArgumentType.blockPos())
.then(argument("secretIndex", IntegerArgumentType.integer())
.then(argument("category", SecretWaypoint.Category.CategoryArgumentType.category())
- .then(argument("name", StringArgumentType.greedyString()).executes(context -> {
+ .then(argument("name", TextArgumentType.text()).executes(context -> {
// TODO Less hacky way with custom ClientBlockPosArgumentType
BlockPos pos = context.getArgument("pos", PosArgument.class).toAbsoluteBlockPos(new ServerCommandSource(null, context.getSource().getPosition(), context.getSource().getRotation(), null, 0, null, null, null, null));
return relative ? addCustomWaypointRelative(context, pos) : addCustomWaypoint(context, pos);
@@ -358,6 +368,34 @@ public class DungeonSecrets {
return Command.SINGLE_SUCCESS;
}
+ private static ArgumentBuilder<FabricClientCommandSource, RequiredArgumentBuilder<FabricClientCommandSource, PosArgument>> removeCustomWaypointCommand(boolean relative) {
+ return argument("pos", BlockPosArgumentType.blockPos())
+ .executes(context -> {
+ // TODO Less hacky way with custom ClientBlockPosArgumentType
+ BlockPos pos = context.getArgument("pos", PosArgument.class).toAbsoluteBlockPos(new ServerCommandSource(null, context.getSource().getPosition(), context.getSource().getRotation(), null, 0, null, null, null, null));
+ return relative ? removeCustomWaypointRelative(context, pos) : removeCustomWaypoint(context, pos);
+ });
+ }
+
+ private static int removeCustomWaypoint(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
+ Room room = getRoomAtPhysical(pos);
+ if (isRoomMatched(room)) {
+ room.removeCustomWaypoint(context, room.actualToRelative(pos));
+ } else {
+ context.getSource().sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.notMatched")));
+ }
+ return Command.SINGLE_SUCCESS;
+ }
+
+ private static int removeCustomWaypointRelative(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
+ if (isCurrentRoomMatched()) {
+ currentRoom.removeCustomWaypoint(context, pos);
+ } else {
+ context.getSource().sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.notMatched")));
+ }
+ return Command.SINGLE_SUCCESS;
+ }
+
/**
* Updates the dungeon. The general idea is similar to the Dungeon Rooms Mod.
* <p></p>
@@ -431,8 +469,7 @@ public class DungeonSecrets {
}
switch (type) {
case ENTRANCE, PUZZLE, TRAP, MINIBOSS, FAIRY, BLOOD -> room = newRoom(type, physicalPos);
- case ROOM ->
- room = newRoom(type, DungeonMapUtils.getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, DungeonMapUtils.getRoomSegments(map, mapPos, mapRoomSize, type.color)));
+ case ROOM -> room = newRoom(type, DungeonMapUtils.getPhysicalPosFromMap(mapEntrancePos, mapRoomSize, physicalEntrancePos, DungeonMapUtils.getRoomSegments(map, mapPos, mapRoomSize, type.color)));
}
}
if (room != null && currentRoom != room) {
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java
index 7b7fe4c0..ecfcf496 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java
@@ -5,7 +5,6 @@ import com.google.common.collect.Table;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.brigadier.arguments.IntegerArgumentType;
-import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
@@ -32,6 +31,7 @@ import net.minecraft.world.World;
import org.apache.commons.lang3.tuple.MutableTriple;
import org.apache.commons.lang3.tuple.Triple;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import org.joml.Vector2i;
import org.joml.Vector2ic;
@@ -159,12 +159,12 @@ public class Room {
}
/**
- * @see #addCustomWaypoint(int, SecretWaypoint.Category, String, BlockPos)
+ * @see #addCustomWaypoint(int, SecretWaypoint.Category, Text, BlockPos)
*/
protected void addCustomWaypoint(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
int secretIndex = IntegerArgumentType.getInteger(context, "secretIndex");
SecretWaypoint.Category category = SecretWaypoint.Category.CategoryArgumentType.getCategory(context, "category");
- String waypointName = StringArgumentType.getString(context, "name");
+ Text waypointName = context.getArgument("name", Text.class);
addCustomWaypoint(secretIndex, category, waypointName, pos);
context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.customWaypointAdded", pos.getX(), pos.getY(), pos.getZ(), name, secretIndex, category, waypointName)));
}
@@ -178,14 +178,14 @@ public class Room {
* @param pos the position of the secret waypoint relative to this room
*/
@SuppressWarnings("JavadocReference")
- private void addCustomWaypoint(int secretIndex, SecretWaypoint.Category category, String waypointName, BlockPos pos) {
+ private void addCustomWaypoint(int secretIndex, SecretWaypoint.Category category, Text waypointName, BlockPos pos) {
SecretWaypoint waypoint = new SecretWaypoint(secretIndex, category, waypointName, pos);
DungeonSecrets.addCustomWaypoint(name, waypoint);
DungeonSecrets.getRoomsStream().filter(r -> name.equals(r.getName())).forEach(r -> r.addCustomWaypoint(waypoint));
}
/**
- * Adds a custom waypoint relative to this room to this room.
+ * Adds a custom waypoint relative to this room to this instance of the room.
*
* @param relativeWaypoint the secret waypoint relative to this room to add
*/
@@ -195,6 +195,43 @@ public class Room {
}
/**
+ * @see #removeCustomWaypoint(BlockPos)
+ */
+ protected void removeCustomWaypoint(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
+ SecretWaypoint waypoint = removeCustomWaypoint(pos);
+ if (waypoint != null) {
+ context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.customWaypointRemoved", pos.getX(), pos.getY(), pos.getZ(), name, waypoint.secretIndex, waypoint.category, waypoint.name)));
+ } else {
+ context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.customWaypointNotFound", pos.getX(), pos.getY(), pos.getZ(), name)));
+ }
+ }
+
+ /**
+ * Removes a custom waypoint relative to this room from {@link DungeonSecrets#customWaypoints} and all existing instances of this room.
+ * @param pos the position of the secret waypoint relative to this room
+ * @return the removed secret waypoint or {@code null} if there was no secret waypoint at the given position
+ */
+ @SuppressWarnings("JavadocReference")
+ @Nullable
+ private SecretWaypoint removeCustomWaypoint(BlockPos pos) {
+ SecretWaypoint waypoint = DungeonSecrets.removeCustomWaypoint(name, pos);
+ if (waypoint != null) {
+ DungeonSecrets.getRoomsStream().filter(r -> name.equals(r.getName())).forEach(r -> r.removeCustomWaypoint(waypoint.secretIndex, pos));
+ }
+ return waypoint;
+ }
+
+ /**
+ * Removes a custom waypoint relative to this room from this instance of the room.
+ * @param secretIndex the index of the secret waypoint
+ * @param relativePos the position of the secret waypoint relative to this room
+ */
+ private void removeCustomWaypoint(int secretIndex, BlockPos relativePos) {
+ BlockPos actualPos = relativeToActual(relativePos);
+ secretWaypoints.remove(secretIndex, actualPos);
+ }
+
+ /**
* Updates the room.
* <p></p>
* This method returns immediately if any of the following conditions are met: