aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-01-26 00:12:07 -0500
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-05-24 19:51:15 -0400
commit92bb441b31cd72d142adee578cc253708cf0101c (patch)
tree774b4c2d6147164289513f5e9fbcc0c17c4384c7 /src/main/java/de/hysky/skyblocker/skyblock
parent5d5d1347644a798551100d22feddc92d4049cb59 (diff)
downloadSkyblocker-92bb441b31cd72d142adee578cc253708cf0101c.tar.gz
Skyblocker-92bb441b31cd72d142adee578cc253708cf0101c.tar.bz2
Skyblocker-92bb441b31cd72d142adee578cc253708cf0101c.zip
Add NamedWaypoint and WaypointCategory
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock')
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/Room.java4
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/dungeon/secrets/SecretWaypoint.java15
-rw-r--r--src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java25
3 files changed, 35 insertions, 9 deletions
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 e6a8b9d1..3f07ccf2 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
@@ -208,7 +208,7 @@ public class Room implements Tickable, Renderable {
SecretWaypoint.Category category = SecretWaypoint.Category.CategoryArgumentType.getCategory(context, "category");
Text waypointName = context.getArgument("name", Text.class);
addCustomWaypoint(secretIndex, category, waypointName, pos);
- context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.stringifiedTranslatable("skyblocker.dungeons.secrets.customWaypointAdded", pos.getX(), pos.getY(), pos.getZ(), name, secretIndex, category, waypointName)));
+ context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.customWaypointAdded", pos.getX(), pos.getY(), pos.getZ(), name, secretIndex, category.asString(), waypointName)));
}
/**
@@ -242,7 +242,7 @@ public class Room implements Tickable, Renderable {
protected void removeCustomWaypoint(CommandContext<FabricClientCommandSource> context, BlockPos pos) {
SecretWaypoint waypoint = removeCustomWaypoint(pos);
if (waypoint != null) {
- context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.stringifiedTranslatable("skyblocker.dungeons.secrets.customWaypointRemoved", pos.getX(), pos.getY(), pos.getZ(), name, waypoint.secretIndex, waypoint.category, waypoint.name)));
+ context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.customWaypointRemoved", pos.getX(), pos.getY(), pos.getZ(), name, waypoint.secretIndex, waypoint.category.asString(), waypoint.getName())));
} else {
context.getSource().sendFeedback(Constants.PREFIX.get().append(Text.translatable("skyblocker.dungeons.secrets.customWaypointNotFound", pos.getX(), pos.getY(), pos.getZ(), name)));
}
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 42fe6dbe..0e4f5f1d 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
@@ -9,6 +9,7 @@ import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.config.configs.DungeonsConfig;
import de.hysky.skyblocker.utils.render.RenderHelper;
+import de.hysky.skyblocker.utils.waypoint.NamedWaypoint;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.client.MinecraftClient;
@@ -29,7 +30,7 @@ import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.ToDoubleFunction;
-public class SecretWaypoint extends Waypoint {
+public class SecretWaypoint extends NamedWaypoint {
private 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),
@@ -43,8 +44,6 @@ public class SecretWaypoint extends Waypoint {
static final Supplier<Type> TYPE_SUPPLIER = () -> CONFIG.get().waypointType;
final int secretIndex;
final Category category;
- final Text name;
- private final Vec3d centerPos;
SecretWaypoint(int secretIndex, JsonObject waypoint, String name, BlockPos pos) {
this(secretIndex, Category.get(waypoint), name, pos);
@@ -55,11 +54,9 @@ public class SecretWaypoint extends Waypoint {
}
SecretWaypoint(int secretIndex, Category category, Text name, BlockPos pos) {
- super(pos, TYPE_SUPPLIER, category.colorComponents);
+ super(pos, name, TYPE_SUPPLIER, category.colorComponents);
this.secretIndex = secretIndex;
this.category = category;
- this.name = name;
- this.centerPos = pos.toCenterPos();
}
static ToDoubleFunction<SecretWaypoint> getSquaredDistanceToFunction(Entity entity) {
@@ -96,6 +93,11 @@ public class SecretWaypoint extends Waypoint {
return super.equals(obj) || obj instanceof SecretWaypoint other && secretIndex == other.secretIndex && category == other.category && name.equals(other.name) && pos.equals(other.pos);
}
+ @Override
+ protected boolean shouldRenderName() {
+ return CONFIG.get().showSecretText;
+ }
+
/**
* Renders the secret waypoint, including a waypoint through {@link Waypoint#render(WorldRenderContext)}, the name, and the distance from the player.
*/
@@ -106,7 +108,6 @@ public class SecretWaypoint extends Waypoint {
if (CONFIG.get().showSecretText) {
Vec3d posUp = centerPos.add(0, 1, 0);
- RenderHelper.renderText(context, name, posUp, true);
double distance = context.camera().getPos().distanceTo(centerPos);
RenderHelper.renderText(context, Text.literal(Math.round(distance) + "m").formatted(Formatting.YELLOW), posUp, 1, MinecraftClient.getInstance().textRenderer.fontHeight + 1, true);
}
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java
new file mode 100644
index 00000000..070cacaa
--- /dev/null
+++ b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java
@@ -0,0 +1,25 @@
+package de.hysky.skyblocker.skyblock.waypoint;
+
+import com.google.gson.JsonObject;
+import com.mojang.serialization.Codec;
+import de.hysky.skyblocker.SkyblockerMod;
+import de.hysky.skyblocker.utils.waypoint.WaypointCategory;
+
+import java.util.*;
+
+public class Waypoints {
+ Codec<List<WaypointCategory>> CODEC = WaypointCategory.CODEC.listOf();
+ private static final Map<String, WaypointCategory> waypoints = new HashMap<>();
+
+ public static Collection<WaypointCategory> fromSkytilsBase64(String base64) {
+ return fromSkytilsJson(new String(Base64.getDecoder().decode(base64)));
+ }
+
+ public static Collection<WaypointCategory> fromSkytilsJson(String waypointCategories) {
+ JsonObject waypointCategoriesJson = SkyblockerMod.GSON.fromJson(waypointCategories, JsonObject.class);
+ return waypointCategoriesJson.getAsJsonArray("categories").asList().stream()
+ .map(JsonObject.class::cast)
+ .map(WaypointCategory::fromSkytilsJson)
+ .toList();
+ }
+}