diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2024-03-08 19:35:56 -0500 |
---|---|---|
committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2024-05-24 19:51:46 -0400 |
commit | 7675f7569b381c8b9cbf36e2e69e716737455069 (patch) | |
tree | 30203444081474886e3741f0fea2fb378dbb3109 /src/main/java/de/hysky/skyblocker/utils | |
parent | f6ba429409ac73ee45992fd80e527c96b39e52e3 (diff) | |
download | Skyblocker-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')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/waypoint/NamedWaypoint.java | 16 | ||||
-rw-r--r-- | src/main/java/de/hysky/skyblocker/utils/waypoint/WaypointCategory.java | 17 |
2 files changed, 16 insertions, 17 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() { diff --git a/src/main/java/de/hysky/skyblocker/utils/waypoint/WaypointCategory.java b/src/main/java/de/hysky/skyblocker/utils/waypoint/WaypointCategory.java index d31455f6..b1ac6135 100644 --- a/src/main/java/de/hysky/skyblocker/utils/waypoint/WaypointCategory.java +++ b/src/main/java/de/hysky/skyblocker/utils/waypoint/WaypointCategory.java @@ -1,6 +1,5 @@ package de.hysky.skyblocker.utils.waypoint; -import com.google.gson.JsonObject; import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext; @@ -14,22 +13,16 @@ public record WaypointCategory(String name, String island, List<NamedWaypoint> w Codec.STRING.fieldOf("island").forGetter(WaypointCategory::island), NamedWaypoint.CODEC.listOf().fieldOf("waypoints").forGetter(WaypointCategory::waypoints) ).apply(instance, WaypointCategory::new)); + public static final Codec<WaypointCategory> SKYTILS_CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.fieldOf("name").forGetter(WaypointCategory::name), + Codec.STRING.fieldOf("island").forGetter(WaypointCategory::island), + NamedWaypoint.SKYTILS_CODEC.listOf().fieldOf("waypoints").forGetter(WaypointCategory::waypoints) + ).apply(instance, WaypointCategory::new)); public WaypointCategory(WaypointCategory waypointCategory) { this(waypointCategory.name(), waypointCategory.island(), new ArrayList<>(waypointCategory.waypoints())); } - public static WaypointCategory fromSkytilsJson(JsonObject waypointCategory) { - return new WaypointCategory( - waypointCategory.get("name").getAsString(), - waypointCategory.get("island").getAsString(), - waypointCategory.getAsJsonArray("waypoints").asList().stream() - .map(JsonObject.class::cast) - .map(NamedWaypoint::fromSkytilsJson) - .toList() - ); - } - public void render(WorldRenderContext context) { for (NamedWaypoint waypoint : waypoints) { waypoint.render(context); |