aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron <51387595+AzureAaron@users.noreply.github.com>2023-10-21 05:20:11 -0400
committerAaron <51387595+AzureAaron@users.noreply.github.com>2023-10-21 05:20:11 -0400
commit2fd4ca4e9042329a9af4e7cce76c72a3225d656d (patch)
tree79568c95b13e8dde31346f954df7cceaa6ff2390
parenta2dde4ff3933cc53c19db0a447534b352194d1f4 (diff)
downloadSkyblocker-2fd4ca4e9042329a9af4e7cce76c72a3225d656d.tar.gz
Skyblocker-2fd4ca4e9042329a9af4e7cce76c72a3225d656d.tar.bz2
Skyblocker-2fd4ca4e9042329a9af4e7cce76c72a3225d656d.zip
Room Position Command
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/DungeonSecrets.java36
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java14
-rw-r--r--src/main/resources/assets/skyblocker/lang/en_us.json2
3 files changed, 51 insertions, 1 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 cb9615fb..d143a3c2 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,6 +7,10 @@ import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
+
+import it.unimi.dsi.fastutil.ints.IntRBTreeSet;
+import it.unimi.dsi.fastutil.ints.IntSortedSet;
+import it.unimi.dsi.fastutil.ints.IntSortedSets;
import it.unimi.dsi.fastutil.objects.Object2ByteMap;
import it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectIntPair;
@@ -37,6 +41,8 @@ import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
+import net.minecraft.util.hit.HitResult;
+import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.jetbrains.annotations.Contract;
@@ -149,7 +155,9 @@ public class DungeonSecrets {
UseBlockCallback.EVENT.register((player, world, hand, hitResult) -> onUseBlock(world, hitResult));
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal(SkyblockerMod.NAMESPACE).then(literal("dungeons").then(literal("secrets")
.then(literal("markAsFound").then(markSecretsCommand(true)))
- .then(literal("markAsMissing").then(markSecretsCommand(false)))))));
+ .then(literal("markAsMissing").then(markSecretsCommand(false)))
+ .then(literal("getPos").executes(context -> registerPosCommand(context.getSource(), false)))
+ .then(literal("getFacingPos").executes(context -> registerPosCommand(context.getSource(), true)))))));
ClientPlayConnectionEvents.JOIN.register(((handler, sender, client) -> reset()));
}
@@ -222,6 +230,32 @@ public class DungeonSecrets {
return Command.SINGLE_SUCCESS;
});
}
+
+ //TODO This logic can be split into a separate method for when we want to allow for adding custom waypoints
+ private static int registerPosCommand(FabricClientCommandSource source, boolean facing) {
+ if (currentRoom != null && currentRoom.getDirection() != null) {
+ MinecraftClient client = MinecraftClient.getInstance();
+
+ if (facing && (client.crosshairTarget == null || client.crosshairTarget.getType() != HitResult.Type.BLOCK)) {
+ source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.unableToFindPos")));
+
+ return Command.SINGLE_SUCCESS;
+ }
+
+ BlockPos blockToCheck = facing && client.crosshairTarget instanceof BlockHitResult blockHitResult ? blockHitResult.getBlockPos() : client.player.getBlockPos();
+ IntSortedSet segmentsX = IntSortedSets.unmodifiable(new IntRBTreeSet(currentRoom.getSegments().stream().mapToInt(Vector2ic::x).toArray()));
+ IntSortedSet segmentsY = IntSortedSets.unmodifiable(new IntRBTreeSet(currentRoom.getSegments().stream().mapToInt(Vector2ic::y).toArray()));
+ Vector2ic physicalCornerPos = DungeonMapUtils.getPhysicalCornerPos(currentRoom.getDirection(), segmentsX, segmentsY);
+
+ BlockPos relativePos = DungeonMapUtils.actualToRelative(currentRoom.getDirection(), physicalCornerPos, blockToCheck);
+
+ source.sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.posMessage", relativePos.getX(), relativePos.getY(), relativePos.getZ())));
+ } else {
+ source.sendError(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.unableToFindPos")));
+ }
+
+ return Command.SINGLE_SUCCESS;
+ }
/**
* Updates the dungeon. The general idea is similar to the Dungeon Rooms Mod.
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 dd7dc91e..6e7ee953 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
@@ -28,6 +28,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;
@@ -72,6 +73,7 @@ public class Room {
*/
private TriState matched = TriState.DEFAULT;
private Table<Integer, BlockPos, SecretWaypoint> secretWaypoints;
+ private Direction direction = null;
public Room(@NotNull Type type, @NotNull Vector2ic... physicalPositions) {
this.type = type;
@@ -91,6 +93,16 @@ public class Room {
public boolean isMatched() {
return matched == TriState.TRUE;
}
+
+ @Nullable
+ public Direction getDirection() {
+ return direction;
+ }
+
+ @NotNull
+ public Set<Vector2ic> getSegments() {
+ return segments;
+ }
@Override
public String toString() {
@@ -297,6 +309,8 @@ public class Room {
}
secretWaypoints = ImmutableTable.copyOf(secretWaypointsMutable);
matched = TriState.TRUE;
+ this.direction = direction;
+
DungeonSecrets.LOGGER.info("[Skyblocker] Room {} matched after checking {} block(s)", name, checkedBlocks.size());
}
diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json
index 4dbe210e..b42ab1e3 100644
--- a/src/main/resources/assets/skyblocker/lang/en_us.json
+++ b/src/main/resources/assets/skyblocker/lang/en_us.json
@@ -272,6 +272,8 @@
"skyblocker.dungeons.secrets.markSecretMissing": "§rMarked secret #%d as missing.",
"skyblocker.dungeons.secrets.markSecretFoundUnable": "§cUnable to mark secret #%d as found.",
"skyblocker.dungeons.secrets.markSecretMissingUnable": "§cUnable to mark secret #%d as missing.",
+ "skyblocker.dungeons.secrets.posMessage": "§rRoom Pos: X: %d, Y: %d, Z: %d",
+ "skyblocker.dungeons.secrets.unableToFindPos": "§cUnable to find room position! (Are you in a dungeon room, are you facing a block?)",
"skyblocker.fishing.reelNow": "Reel in now!",
"skyblocker.rift.healNow": "Heal now!",