diff options
| author | Kevin <92656833+kevinthegreat1@users.noreply.github.com> | 2025-02-15 10:11:37 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-15 10:11:37 +0800 |
| commit | 0cd860224d4a2a62118e125092a98b111d5b72a8 (patch) | |
| tree | 099ea305d070795c67ab73396bee78a4de9ac79b /src/main/java | |
| parent | 20645264c5d0ccbb0fcf856068b89edb20746d79 (diff) | |
| download | Skyblocker-0cd860224d4a2a62118e125092a98b111d5b72a8.tar.gz Skyblocker-0cd860224d4a2a62118e125092a98b111d5b72a8.tar.bz2 Skyblocker-0cd860224d4a2a62118e125092a98b111d5b72a8.zip | |
Add seen waypoint (#1108)
* Add seen waypoint
* Migrate EnderNodes
* Add Javadoc
* Fix detection
Diffstat (limited to 'src/main/java')
4 files changed, 100 insertions, 27 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/EggFinder.java b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/EggFinder.java index 5239ad1a..a1d011ad 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/EggFinder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/EggFinder.java @@ -9,9 +9,8 @@ import de.hysky.skyblocker.utils.*; 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; @@ -27,6 +26,7 @@ import net.minecraft.text.ClickEvent; 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; @@ -74,8 +74,11 @@ public class EggFinder { 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(); + } } } }); @@ -131,7 +134,7 @@ public class EggFinder { 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; } } @@ -143,7 +146,7 @@ public class EggFinder { 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); } } @@ -155,7 +158,7 @@ public class EggFinder { 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); } @@ -203,10 +206,9 @@ public class EggFinder { } 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(); @@ -216,7 +218,7 @@ public class EggFinder { .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); } @@ -226,15 +228,12 @@ public class EggFinder { } } - 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; } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/end/EnderNodes.java b/src/main/java/de/hysky/skyblocker/skyblock/end/EnderNodes.java index 118f480a..da1b8191 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/end/EnderNodes.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/end/EnderNodes.java @@ -5,7 +5,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; 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; @@ -88,7 +88,7 @@ public class EnderNodes { private static void update() { if (shouldProcess()) { for (EnderNode enderNode : enderNodes.values()) { - enderNode.updateParticles(); + enderNode.updateWaypoint(); } } } @@ -111,7 +111,7 @@ public class EnderNodes { 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), @@ -123,10 +123,11 @@ public class EnderNodes { 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; diff --git a/src/main/java/de/hysky/skyblocker/utils/waypoint/SeenWaypoint.java b/src/main/java/de/hysky/skyblocker/utils/waypoint/SeenWaypoint.java new file mode 100644 index 00000000..8f45c968 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/waypoint/SeenWaypoint.java @@ -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)); + if (blockHitResult.getType() == HitResult.Type.MISS || blockHitResult.getBlockPos().equals(pos)) { + seen = true; + } + } + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java b/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java index cd07ac58..f95f63ac 100644 --- a/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java +++ b/src/main/java/de/hysky/skyblocker/utils/waypoint/Waypoint.java @@ -157,6 +157,16 @@ public class Waypoint implements Renderable { } // 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> @@ -167,6 +177,15 @@ public class Waypoint implements Renderable { } /** + * 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> * Checks if the waypoint {@link #shouldRender() should be rendered}. @@ -176,22 +195,23 @@ public class Waypoint implements Renderable { @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() { |
