aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/utils/waypoint/NamedWaypoint.java
diff options
context:
space:
mode:
authorKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-03-08 19:35:56 -0500
committerKevinthegreat <92656833+kevinthegreat1@users.noreply.github.com>2024-05-24 19:51:46 -0400
commit7675f7569b381c8b9cbf36e2e69e716737455069 (patch)
tree30203444081474886e3741f0fea2fb378dbb3109 /src/main/java/de/hysky/skyblocker/utils/waypoint/NamedWaypoint.java
parentf6ba429409ac73ee45992fd80e527c96b39e52e3 (diff)
downloadSkyblocker-7675f7569b381c8b9cbf36e2e69e716737455069.tar.gz
Skyblocker-7675f7569b381c8b9cbf36e2e69e716737455069.tar.bz2
Skyblocker-7675f7569b381c8b9cbf36e2e69e716737455069.zip
Update Skytils format to codecs
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils/waypoint/NamedWaypoint.java')
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/waypoint/NamedWaypoint.java16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/waypoint/NamedWaypoint.java b/src/main/java/de/hysky/skyblocker/utils/waypoint/NamedWaypoint.java
index db95634b..f959de78 100644
--- a/src/main/java/de/hysky/skyblocker/utils/waypoint/NamedWaypoint.java
+++ b/src/main/java/de/hysky/skyblocker/utils/waypoint/NamedWaypoint.java
@@ -1,12 +1,11 @@
package de.hysky.skyblocker.utils.waypoint;
import com.google.common.primitives.Floats;
-import com.google.gson.JsonObject;
+import com.mojang.datafixers.util.Either;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
-import de.hysky.skyblocker.utils.PosUtils;
import de.hysky.skyblocker.utils.render.RenderHelper;
import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
import net.minecraft.text.Text;
@@ -26,6 +25,14 @@ public class NamedWaypoint extends Waypoint {
).fieldOf("colorComponents").forGetter(secretWaypoint -> secretWaypoint.colorComponents),
Codec.BOOL.fieldOf("shouldRender").forGetter(Waypoint::shouldRender)
).apply(instance, NamedWaypoint::new));
+ public static final Codec<NamedWaypoint> SKYTILS_CODEC = RecordCodecBuilder.create(instance -> instance.group(
+ Codec.INT.fieldOf("x").forGetter(waypoint -> waypoint.pos.getX()),
+ Codec.INT.fieldOf("y").forGetter(waypoint -> waypoint.pos.getY()),
+ Codec.INT.fieldOf("z").forGetter(waypoint -> waypoint.pos.getZ()),
+ Codec.either(Codec.STRING, Codec.INT).xmap(either -> either.map(str -> str, Object::toString), Either::left).fieldOf("name").forGetter(waypoint -> waypoint.name.getString()),
+ Codec.INT.fieldOf("color").forGetter(waypoint -> (int) (waypoint.colorComponents[0] * 255) << 16 | (int) (waypoint.colorComponents[1] * 255) << 8 | (int) (waypoint.colorComponents[2] * 255)),
+ Codec.BOOL.fieldOf("enabled").forGetter(Waypoint::shouldRender)
+ ).apply(instance, NamedWaypoint::fromSkytils));
protected final Text name;
protected final Vec3d centerPos;
@@ -55,9 +62,8 @@ public class NamedWaypoint extends Waypoint {
this.centerPos = pos.toCenterPos();
}
- public static NamedWaypoint fromSkytilsJson(JsonObject waypointJson) {
- int color = waypointJson.get("color").getAsInt();
- return new NamedWaypoint(PosUtils.parsePosJson(waypointJson), waypointJson.get("name").getAsString(), () -> SkyblockerConfigManager.get().general.waypoints.waypointType, new float[]{((color & 0x00FF0000) >> 16) / 255f, ((color & 0x0000FF00) >> 8) / 255f, (color & 0x000000FF) / 255f}, waypointJson.get("enabled").getAsBoolean());
+ public static NamedWaypoint fromSkytils(int x, int y, int z, String name, int color, boolean enabled) {
+ return new NamedWaypoint(new BlockPos(x, y, z), name, new float[]{((color & 0x00FF0000) >> 16) / 255f, ((color & 0x0000FF00) >> 8) / 255f, (color & 0x000000FF) / 255f}, enabled);
}
public Text getName() {