Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ private static boolean onChatMessage(Component text, boolean overlay) {
LOGGER.info("[Skyblocker Egg Finder] Not sharing this egg to the WebSocket - matches previous location");
return true;
}
WsMessageHandler.sendLocationMessage(Service.EGG_WAYPOINTS, new EggWaypointMessage(eggType, eggType.egg.pos));
WsMessageHandler.sendLocationMessage(Service.EGG_WAYPOINTS,
new EggWaypointMessage(eggType, eggType.egg.pos, Optional.empty()));
} catch (IllegalArgumentException e) {
LOGGER.error("[Skyblocker Egg Finder] Failed to process an egg!", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
import java.util.Optional;
import net.minecraft.core.BlockPos;

public record EggWaypointMessage(EggFinder.EggType eggType, BlockPos coordinates) implements Message<EggWaypointMessage> {
public record EggWaypointMessage(EggFinder.EggType eggType, BlockPos coordinates, Optional<Long> expirationEpoch) implements Message<EggWaypointMessage> {
private static final Codec<EggWaypointMessage> CODEC = RecordCodecBuilder.create(instance -> instance.group(
EggFinder.EggType.CODEC.fieldOf("eggType").forGetter(EggWaypointMessage::eggType),
BlockPos.CODEC.fieldOf("coordinates").forGetter(EggWaypointMessage::coordinates)
BlockPos.CODEC.fieldOf("coordinates").forGetter(EggWaypointMessage::coordinates),
Codec.LONG.optionalFieldOf("expirationEpoch").forGetter(EggWaypointMessage::expirationEpoch)
).apply(instance, EggWaypointMessage::new));

private static final Codec<List<EggWaypointMessage>> LIST_CODEC = CODEC.listOf();
Expand All @@ -30,8 +31,11 @@ public static void handle(Type type, Optional<Dynamic<?>> message) {
case Type.INITIAL_MESSAGE -> {
if (message.isEmpty()) return;
List<EggWaypointMessage> waypoints = LIST_CODEC.parse(message.get()).getOrThrow();
long now = System.currentTimeMillis();

RenderHelper.runOnRenderThread(() -> waypoints.forEach(EggFinder::onWebsocketMessage));
RenderHelper.runOnRenderThread(() -> waypoints.stream()
.filter(w -> w.expirationEpoch.isPresent() && w.expirationEpoch().get() > now)
.forEach(EggFinder::onWebsocketMessage));
}

default -> {}
Expand Down
Loading