Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add seen waypoint #1108

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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 @@ -9,9 +9,8 @@
import de.hysky.skyblocker.utils.command.argumenttypes.EggTypeArgumentType;
import de.hysky.skyblocker.utils.command.argumenttypes.blockpos.ClientBlockPosArgumentType;
import de.hysky.skyblocker.utils.command.argumenttypes.blockpos.ClientPosArgument;
import de.hysky.skyblocker.utils.render.FrustumUtils;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import de.hysky.skyblocker.utils.waypoint.SeenWaypoint;
import it.unimi.dsi.fastutil.objects.ObjectImmutableList;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
Expand All @@ -27,6 +26,7 @@
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.math.BlockPos;
import org.apache.commons.text.WordUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -74,8 +74,11 @@ public static void init() {
if (!isLocationCorrect || SkyblockTime.skyblockSeason.get() != SkyblockTime.Season.SPRING) return;
for (EggType type : EggType.entries) {
Egg egg = type.egg;
if (egg != null && !egg.seen && FrustumUtils.isVisible(egg.entity.getBoundingBox()) && client.player.canSee(egg.entity)) {
type.setSeen();
if (egg != null && !egg.isSeen()) {
egg.tick(client);
if (egg.isSeen()) {
type.setSeen();
}
}
}
});
Expand Down Expand Up @@ -131,7 +134,7 @@ private static void handleArmorStand(ArmorStandEntity armorStand) {
ItemUtils.getHeadTextureOptional(itemStack).ifPresent(texture -> {
for (EggType type : EggType.entries) { //Compare blockPos rather than entity to avoid incorrect matches when the entity just moves rather than a new one being spawned elsewhere
if (texture.equals(type.texture) && (type.egg == null || !type.egg.entity.getBlockPos().equals(armorStand.getBlockPos()))) {
type.egg = new Egg(armorStand, new Waypoint(armorStand.getBlockPos().up(2), SkyblockerConfigManager.get().helpers.chocolateFactory.waypointType, ColorUtils.getFloatComponents(type.color)), false);
type.egg = new Egg(armorStand, armorStand.getBlockPos().up(2), SkyblockerConfigManager.get().helpers.chocolateFactory.waypointType, ColorUtils.getFloatComponents(type.color));
return;
}
}
Expand All @@ -143,7 +146,7 @@ private static void renderWaypoints(WorldRenderContext context) {
if (!SkyblockerConfigManager.get().helpers.chocolateFactory.enableEggFinder) return;
for (EggType type : EggType.entries) {
Egg egg = type.egg;
if (egg != null && egg.waypoint.shouldRender() && egg.seen) egg.waypoint.render(context);
if (egg != null) egg.render(context);
}
}

Expand All @@ -155,7 +158,7 @@ private static void onChatMessage(Text text, boolean overlay) {
EggType eggType = EggType.valueOf(matcher.group(1).toUpperCase());
eggType.collected = true;
Egg egg = eggType.egg;
if (egg != null) egg.waypoint.setFound();
if (egg != null) egg.setFound();
} catch (IllegalArgumentException e) {
logger.error("[Skyblocker Egg Finder] Failed to find egg type for egg found message. Tried to match against: {}", matcher.group(0), e);
}
Expand Down Expand Up @@ -203,10 +206,9 @@ public enum EggType {
}

public void setSeen() {
egg.seen = true;
if (!SkyblockerConfigManager.get().helpers.chocolateFactory.sendEggFoundMessages || System.currentTimeMillis() - messageLastSent < 1000) return;
if (collected) {
egg.waypoint.setFound();
egg.setFound();
return;
}
messageLastSent = System.currentTimeMillis();
Expand All @@ -216,7 +218,7 @@ public void setSeen() {
.append(Text.literal("Chocolate " + this + " Egg")
.withColor(color))
.append(" at " + egg.entity.getBlockPos().up(2).toShortString() + "!")
.styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker eggFinder shareLocation " + PosUtils.toSpaceSeparatedString(egg.waypoint.pos) + " " + this))
.styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/skyblocker eggFinder shareLocation " + PosUtils.toSpaceSeparatedString(egg.pos) + " " + this))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Text.literal("Click to share the location in chat!").formatted(Formatting.GREEN)))), false);
}

Expand All @@ -226,15 +228,12 @@ public String toString() {
}
}

static class Egg {
static class Egg extends SeenWaypoint {
private final ArmorStandEntity entity;
private final Waypoint waypoint;
private boolean seen;

Egg(ArmorStandEntity entity, Waypoint waypoint, boolean seen) {
Egg(ArmorStandEntity entity, BlockPos pos, Type type, float[] colorComponents) {
super(pos, type, colorComponents);
this.entity = entity;
this.waypoint = waypoint;
this.seen = seen;
}
}
}
11 changes: 6 additions & 5 deletions src/main/java/de/hysky/skyblocker/skyblock/end/EnderNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import de.hysky.skyblocker.utils.ColorUtils;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
import de.hysky.skyblocker.utils.waypoint.Waypoint;
import de.hysky.skyblocker.utils.waypoint.SeenWaypoint;
import it.unimi.dsi.fastutil.ints.IntIntMutablePair;
import it.unimi.dsi.fastutil.ints.IntIntPair;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents;
Expand Down Expand Up @@ -88,7 +88,7 @@ public static void onParticle(ParticleS2CPacket packet) {
private static void update() {
if (shouldProcess()) {
for (EnderNode enderNode : enderNodes.values()) {
enderNode.updateParticles();
enderNode.updateWaypoint();
}
}
}
Expand All @@ -111,7 +111,7 @@ private static void reset() {
enderNodes.clear();
}

public static class EnderNode extends Waypoint {
public static class EnderNode extends SeenWaypoint {
private final Map<Direction, IntIntPair> particles = Map.of(
Direction.UP, new IntIntMutablePair(0, 0),
Direction.DOWN, new IntIntMutablePair(0, 0),
Expand All @@ -123,10 +123,11 @@ Direction.NORTH, new IntIntMutablePair(0, 0)
private long lastConfirmed;

private EnderNode(BlockPos pos) {
super(pos, () -> SkyblockerConfigManager.get().uiAndVisuals.waypoints.waypointType.withoutBeacon(), ColorUtils.getFloatComponents(DyeColor.CYAN), false);
super(pos, () -> SkyblockerConfigManager.get().uiAndVisuals.waypoints.waypointType, ColorUtils.getFloatComponents(DyeColor.CYAN));
}

private void updateParticles() {
private void updateWaypoint() {
tick(client);
long currentTimeMillis = System.currentTimeMillis();
if (lastConfirmed + 2000 > currentTimeMillis || client.world == null || !particles.entrySet().stream().allMatch(entry -> entry.getValue().leftInt() >= 5 && entry.getValue().rightInt() >= 5 || !client.world.getBlockState(pos.offset(entry.getKey())).isAir())) return;
lastConfirmed = currentTimeMillis;
Expand Down
53 changes: 53 additions & 0 deletions src/main/java/de/hysky/skyblocker/utils/waypoint/SeenWaypoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.hysky.skyblocker.utils.waypoint;

import de.hysky.skyblocker.utils.Tickable;
import de.hysky.skyblocker.utils.render.FrustumUtils;
import net.minecraft.client.MinecraftClient;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.RaycastContext;

import java.util.function.Supplier;

/**
* A waypoint that renders without beacon beams and does not render through walls until it is seen.
* <p>After being seen, it will render through walls and optionally render beacon beams based on the waypoint type.
* It is the caller's responsibility to call {@link #tick(MinecraftClient)} to check if the waypoint is seen.
*/
public class SeenWaypoint extends Waypoint implements Tickable {
private boolean seen = false;

public SeenWaypoint(BlockPos pos, Type type, float[] colorComponents) {
super(pos, type, colorComponents);
}

public SeenWaypoint(BlockPos pos, Supplier<Type> typeSupplier, float[] colorComponents) {
super(pos, typeSupplier, colorComponents);
}

public boolean isSeen() {
return seen;
}

@Override
public Type getRenderType() {
return seen ? super.getRenderType() : super.getRenderType().withoutBeacon();
}

@Override
public boolean shouldRenderThroughWalls() {
return seen;
}

@Override
public void tick(MinecraftClient client) {
if (!seen && shouldRender() && client.world != null && client.player != null && FrustumUtils.isVisible(pos.getX(), pos.getY(), pos.getZ(), pos.getX() + 1, pos.getY() + 1, pos.getZ() + 1)) {
BlockHitResult blockHitResult = client.world.raycast(new RaycastContext(client.player.getEyePos(), Vec3d.ofCenter(pos), RaycastContext.ShapeType.COLLIDER, RaycastContext.FluidHandling.NONE, client.player));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it should have to be seen for a certain number of seconds to count, too often with egg waypoints I spin my camera briefly not even noticing the egg and it shows me the waypoint.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that could be added at a later point. I made it like this since it's supposed to help you see things.

if (blockHitResult.getType() == HitResult.Type.MISS || blockHitResult.getBlockPos().equals(pos)) {
seen = true;
}
}
}
}
32 changes: 26 additions & 6 deletions src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ public final void setEnabled(boolean enabled) {
}
// endregion

// region Rendering
/**
* Returns the render type of the waypoint.
* <p>
* Override this method for custom behavior.
*/
public Type getRenderType() {
return typeSupplier.get();
}

/**
* Returns the render time color components of the waypoint.
* <p>
Expand All @@ -162,6 +172,15 @@ public float[] getRenderColorComponents() {
return colorComponents;
}

/**
* Returns whether the waypoint should be rendered through walls.
* <p>
* Override this method for custom behavior.
*/
public boolean shouldRenderThroughWalls() {
return throughWalls;
}

/**
* Renders the waypoint.
* <p>
Expand All @@ -172,22 +191,23 @@ public float[] getRenderColorComponents() {
@Override
public void render(WorldRenderContext context) {
if (!shouldRender()) return;
switch (typeSupplier.get()) {
case WAYPOINT -> RenderHelper.renderFilledWithBeaconBeam(context, pos, getRenderColorComponents(), alpha, throughWalls);
final float[] colorComponents = getRenderColorComponents();
final boolean throughWalls = shouldRenderThroughWalls();
switch (getRenderType()) {
case WAYPOINT -> RenderHelper.renderFilledWithBeaconBeam(context, pos, colorComponents, alpha, throughWalls);
case OUTLINED_WAYPOINT -> {
float[] colorComponents = getRenderColorComponents();
RenderHelper.renderFilledWithBeaconBeam(context, pos, colorComponents, alpha, throughWalls);
RenderHelper.renderOutline(context, pos, colorComponents, lineWidth, throughWalls);
}
case HIGHLIGHT -> RenderHelper.renderFilled(context, pos, getRenderColorComponents(), alpha, throughWalls);
case HIGHLIGHT -> RenderHelper.renderFilled(context, pos, colorComponents, alpha, throughWalls);
case OUTLINED_HIGHLIGHT -> {
float[] colorComponents = getRenderColorComponents();
RenderHelper.renderFilled(context, pos, colorComponents, alpha, throughWalls);
RenderHelper.renderOutline(context, pos, colorComponents, lineWidth, throughWalls);
}
case OUTLINE -> RenderHelper.renderOutline(context, pos, getRenderColorComponents(), lineWidth, throughWalls);
case OUTLINE -> RenderHelper.renderOutline(context, pos, colorComponents, lineWidth, throughWalls);
}
}
// endregion

@Override
public int hashCode() {
Expand Down
Loading