aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-11-12 17:42:00 -0500
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2023-11-12 17:42:00 -0500
commit35d02596389b2516d62fbd1298b5b90e69b57fa5 (patch)
treedabdb22fd86b689fad22972f5a0e4ebb11bfc3ee
parent2abfcece13208818ae86dd83f44a257daba23506 (diff)
downloadSkyblocker-35d02596389b2516d62fbd1298b5b90e69b57fa5.tar.gz
Skyblocker-35d02596389b2516d62fbd1298b5b90e69b57fa5.tar.bz2
Skyblocker-35d02596389b2516d62fbd1298b5b90e69b57fa5.zip
Add secret waypoint tests
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java13
-rw-r--r--src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java79
2 files changed, 87 insertions, 5 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java
index fdfa88c3..43f624f6 100644
--- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java
+++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java
@@ -20,6 +20,8 @@ import net.minecraft.util.dynamic.Codecs;
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;
import java.util.List;
import java.util.function.Predicate;
@@ -27,6 +29,7 @@ import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
public class SecretWaypoint extends Waypoint {
+ protected 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),
Category.CODEC.fieldOf("category").forGetter(secretWaypoint -> secretWaypoint.category),
@@ -35,8 +38,8 @@ public class SecretWaypoint extends Waypoint {
).apply(instance, SecretWaypoint::new));
public static final Codec<List<SecretWaypoint>> LIST_CODEC = CODEC.listOf();
static final List<String> SECRET_ITEMS = List.of("Decoy", "Defuse Kit", "Dungeon Chest Key", "Healing VIII", "Inflatable Jerry", "Spirit Leap", "Training Weights", "Trap", "Treasure Talisman");
- private static final SkyblockerConfig.SecretWaypoints CONFIG = SkyblockerConfigManager.get().locations.dungeons.secretWaypoints;
- private static final Supplier<Type> TYPE_SUPPLIER = () -> CONFIG.waypointType;
+ private static final Supplier<SkyblockerConfig.SecretWaypoints> CONFIG = () -> SkyblockerConfigManager.get().locations.dungeons.secretWaypoints;
+ private static final Supplier<Type> TYPE_SUPPLIER = () -> CONFIG.get().waypointType;
final int secretIndex;
final Category category;
final Text name;
@@ -95,7 +98,7 @@ public class SecretWaypoint extends Waypoint {
//TODO In the future, shrink the box for wither essence and items so its more realistic
super.render(context);
- if (CONFIG.showSecretText) {
+ if (CONFIG.get().showSecretText) {
Vec3d posUp = centerPos.add(0, 1, 0);
RenderHelper.renderText(context, name, posUp, true);
double distance = context.camera().getPos().distanceTo(centerPos);
@@ -135,8 +138,8 @@ public class SecretWaypoint extends Waypoint {
}
}
- private static Category get(JsonObject waypointJson) {
- return CODEC.parse(JsonOps.INSTANCE, waypointJson.get("category")).resultOrPartial(DungeonSecrets.LOGGER::error).orElse(Category.DEFAULT);
+ static Category get(JsonObject waypointJson) {
+ return CODEC.parse(JsonOps.INSTANCE, waypointJson.get("category")).resultOrPartial(LOGGER::error).orElse(Category.DEFAULT);
}
boolean needsInteraction() {
diff --git a/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java
new file mode 100644
index 00000000..0870e744
--- /dev/null
+++ b/src/test/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypointTest.java
@@ -0,0 +1,79 @@
+package de.hysky.skyblocker.skyblock.dungeon.secrets;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.mojang.serialization.JsonOps;
+import net.minecraft.util.math.BlockPos;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+public class SecretWaypointTest {
+ private final Gson gson = new Gson();
+
+ @Test
+ void testCodecSerialize() {
+ SecretWaypoint waypoint = new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", BlockPos.ORIGIN);
+ JsonElement json = SecretWaypoint.CODEC.encodeStart(JsonOps.INSTANCE, waypoint).result().orElseThrow();
+ String expectedJson = "{\"secretIndex\":0,\"category\":\"default\",\"name\":{\"text\":\"name\"},\"pos\":[0,0,0]}";
+
+ Assertions.assertEquals(expectedJson, json.toString());
+ }
+
+ @Test
+ void testCodecDeserialize() {
+ String json = "{\"secretIndex\":0,\"category\":\"default\",\"name\":{\"text\":\"name\"},\"pos\":[0,0,0]}";
+ SecretWaypoint waypoint = SecretWaypoint.CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).result().orElseThrow();
+ SecretWaypoint expectedWaypoint = new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", BlockPos.ORIGIN);
+
+ equal(expectedWaypoint, waypoint);
+ }
+
+ @Test
+ void testListCodecSerialize() {
+ List<SecretWaypoint> waypoints = List.of(new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", BlockPos.ORIGIN), new SecretWaypoint(1, SecretWaypoint.Category.CHEST, "name", new BlockPos(-1, 0, 1)));
+ JsonElement json = SecretWaypoint.LIST_CODEC.encodeStart(JsonOps.INSTANCE, waypoints).result().orElseThrow();
+ String expectedJson = "[{\"secretIndex\":0,\"category\":\"default\",\"name\":{\"text\":\"name\"},\"pos\":[0,0,0]},{\"secretIndex\":1,\"category\":\"chest\",\"name\":{\"text\":\"name\"},\"pos\":[-1,0,1]}]";
+
+ Assertions.assertEquals(expectedJson, json.toString());
+ }
+
+ @Test
+ void testListCodecDeserialize() {
+ String json = "[{\"secretIndex\":0,\"category\":\"default\",\"name\":{\"text\":\"name\"},\"pos\":[0,0,0]},{\"secretIndex\":1,\"category\":\"chest\",\"name\":{\"text\":\"name\"},\"pos\":[-1,0,1]}]";
+ List<SecretWaypoint> waypoints = SecretWaypoint.LIST_CODEC.parse(JsonOps.INSTANCE, gson.fromJson(json, JsonElement.class)).result().orElseThrow();
+ List<SecretWaypoint> expectedWaypoints = List.of(new SecretWaypoint(0, SecretWaypoint.Category.DEFAULT, "name", BlockPos.ORIGIN), new SecretWaypoint(1, SecretWaypoint.Category.CHEST, "name", new BlockPos(-1, 0, 1)));
+
+ Assertions.assertEquals(expectedWaypoints.size(), waypoints.size());
+ for (int i = 0; i < expectedWaypoints.size(); i++) {
+ SecretWaypoint expectedWaypoint = expectedWaypoints.get(i);
+ SecretWaypoint waypoint = waypoints.get(i);
+ equal(expectedWaypoint, waypoint);
+ }
+ }
+
+ @Test
+ void testGetCategory() {
+ JsonObject waypointJson = new JsonObject();
+ waypointJson.addProperty("category", "chest");
+ SecretWaypoint.Category category = SecretWaypoint.Category.get(waypointJson);
+ Assertions.assertEquals(SecretWaypoint.Category.CHEST, category);
+ }
+
+ @Test
+ void testGetCategoryDefault() {
+ JsonObject waypointJson = new JsonObject();
+ waypointJson.addProperty("category", "");
+ SecretWaypoint.Category category = SecretWaypoint.Category.get(waypointJson);
+ Assertions.assertEquals(SecretWaypoint.Category.DEFAULT, category);
+ }
+
+ private static void equal(SecretWaypoint expectedWaypoint, SecretWaypoint waypoint) {
+ Assertions.assertEquals(expectedWaypoint.secretIndex, waypoint.secretIndex);
+ Assertions.assertEquals(expectedWaypoint.category, waypoint.category);
+ Assertions.assertEquals(expectedWaypoint.name, waypoint.name);
+ Assertions.assertEquals(expectedWaypoint.pos, waypoint.pos);
+ }
+}