Skip to content

Commit

Permalink
fixed bug in WaitForDragonAndPearlTask and removed logging statements
Browse files Browse the repository at this point in the history
  • Loading branch information
MiranCZ committed Jul 11, 2024
1 parent b10aa08 commit 41c2bc2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<Entity> fireball) {
if (fireball.isEmpty())
return false;
Expand Down

0 comments on commit 41c2bc2

Please sign in to comment.