From 41c2bc244a1b9a27ab77b3f54220ca7e3fa49668 Mon Sep 17 00:00:00 2001 From: MiranCZ Date: Thu, 11 Jul 2024 15:31:58 +0200 Subject: [PATCH] fixed bug in WaitForDragonAndPearlTask and removed logging statements --- .../speedrun/KillEnderDragonWithBedsTask.java | 5 +--- .../speedrun/WaitForDragonAndPearlTask.java | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/adris/altoclef/tasks/speedrun/KillEnderDragonWithBedsTask.java b/src/main/java/adris/altoclef/tasks/speedrun/KillEnderDragonWithBedsTask.java index 4ae5daaad..752db0d6d 100644 --- a/src/main/java/adris/altoclef/tasks/speedrun/KillEnderDragonWithBedsTask.java +++ b/src/main/java/adris/altoclef/tasks/speedrun/KillEnderDragonWithBedsTask.java @@ -135,19 +135,16 @@ Get in position (XZ) boolean perching = dragonPhase instanceof LandingPhase || dragonPhase instanceof LandingApproachPhase || dragonPhase.isSittingOrHovering(); if (dragon.getY() < endPortalTop.getY() + 2) { // Dragon is already perched. - Debug.logMessage("too close :("); perching = false; } - Debug.logMessage(dragonPhase.getType() + " : " + dragonPhase.isSittingOrHovering() + " : " + perching); + whenNotPerchingTask.setPerchState(perching); // When the dragon is not perching... if (whenNotPerchingTask.isActive() && !whenNotPerchingTask.isFinished(mod)) { - Debug.logMessage("When not perching not finished "+whenNotPerchingTask.isActive() + " : "+ !whenNotPerchingTask.isFinished(mod) ); setDebugState("Dragon not perching, performing special behavior..."); return whenNotPerchingTask; } if (perching) { - Debug.logMessage("Performing one cycle"); return performOneCycle(mod, dragon); } } diff --git a/src/main/java/adris/altoclef/tasks/speedrun/WaitForDragonAndPearlTask.java b/src/main/java/adris/altoclef/tasks/speedrun/WaitForDragonAndPearlTask.java index d30cde0d4..bd630ee66 100644 --- a/src/main/java/adris/altoclef/tasks/speedrun/WaitForDragonAndPearlTask.java +++ b/src/main/java/adris/altoclef/tasks/speedrun/WaitForDragonAndPearlTask.java @@ -21,7 +21,9 @@ import net.minecraft.entity.mob.EndermanEntity; import net.minecraft.entity.projectile.DragonFireballEntity; import net.minecraft.item.Items; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import java.util.Optional; import java.util.function.Predicate; @@ -118,7 +120,7 @@ protected Task onTick(AltoClef mod) { } // Our trigger to throw is that the dragon starts perching. We can be an arbitrary distance and we'll still do it lol - if (dragonIsPerching && LookHelper.cleanLineOfSight(mod.getPlayer(), targetToPearl.up(), 300)) { + if (dragonIsPerching && canThrowPearl(mod)) { Debug.logMessage("THROWING PEARL!!"); return throwPearlTask; } @@ -209,6 +211,31 @@ protected Task onTick(AltoClef mod) { return heightPillarTask; } + // basically same as LookHelper.cleanLineOfSight but edited so it has a small distance toleration + private boolean canThrowPearl(AltoClef mod) { + Vec3d targetPosition = WorldHelper.toVec3d(targetToPearl.up()); + + // Perform a raycast from the entity's camera position to the target position with the specified max range + BlockHitResult hitResult = LookHelper.raycast(mod.getPlayer(), LookHelper.getCameraPos(mod.getPlayer()), targetPosition, 300); + + if (hitResult == null) { + // No hit result, clear line of sight + return true; + } else { + return switch (hitResult.getType()) { + case MISS -> + // Missed the target, clear line of sight + true; + case BLOCK -> + // Hit a block, check if it's the same as the target block + hitResult.getBlockPos().isWithinDistance(targetToPearl.up(), 10); + case ENTITY -> + // Hit an entity, line of sight blocked + false; + }; + } + } + private boolean isFireballDangerous(AltoClef mod, Optional fireball) { if (fireball.isEmpty()) return false;