Commit 89935ff0 by Jonathan Thomas

- Added support for non path aware entities to FLEE (i.e. Ghast)

- Fixed a **crash with FLEE** when non-path aware entities (i.e. Ghast) attempted to flee.
parent fa3a5d72
Pipeline #12603 passed with stages
in 2 minutes 11 seconds
...@@ -4,6 +4,14 @@ All notable changes to **CreatureChat** are documented in this file. The format ...@@ -4,6 +4,14 @@ All notable changes to **CreatureChat** are documented in this file. The format
[Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
### Added
- Added support for non path aware entities to FLEE (i.e. Ghast)
### Changed
- Fixed a **crash with FLEE** when non-path aware entities (i.e. Ghast) attempted to flee.
## [1.0.7] - 2024-07-03 ## [1.0.7] - 2024-07-03
### Added ### Added
......
...@@ -43,7 +43,9 @@ public class FleePlayerGoal extends PlayerBaseGoal { ...@@ -43,7 +43,9 @@ public class FleePlayerGoal extends PlayerBaseGoal {
private void fleeFromPlayer() { private void fleeFromPlayer() {
int roundedFleeDistance = Math.round(fleeDistance); int roundedFleeDistance = Math.round(fleeDistance);
Vec3d fleeTarget = FuzzyTargeting.findFrom((PathAwareEntity)this.entity, roundedFleeDistance, if (this.entity instanceof PathAwareEntity) {
// Set random path away from player
Vec3d fleeTarget = FuzzyTargeting.findFrom((PathAwareEntity) this.entity, roundedFleeDistance,
roundedFleeDistance, this.targetEntity.getPos()); roundedFleeDistance, this.targetEntity.getPos());
if (fleeTarget != null) { if (fleeTarget != null) {
...@@ -52,6 +54,19 @@ public class FleePlayerGoal extends PlayerBaseGoal { ...@@ -52,6 +54,19 @@ public class FleePlayerGoal extends PlayerBaseGoal {
this.entity.getNavigation().startMovingAlong(path, this.speed); this.entity.getNavigation().startMovingAlong(path, this.speed);
} }
} }
} else {
// Move in the opposite direction from player (for non-path aware entities)
Vec3d playerPos = this.targetEntity.getPos();
Vec3d entityPos = this.entity.getPos();
// Calculate the direction away from the player
Vec3d fleeDirection = entityPos.subtract(playerPos).normalize();
// Apply movement with the entity's speed in the opposite direction
this.entity.setVelocity(fleeDirection.x * this.speed, this.entity.getVelocity().y, fleeDirection.z * this.speed);
this.entity.velocityModified = true;
}
} }
@Override @Override
......
...@@ -63,6 +63,9 @@ public class FollowPlayerGoal extends PlayerBaseGoal { ...@@ -63,6 +63,9 @@ public class FollowPlayerGoal extends PlayerBaseGoal {
} }
private Vec3d findTeleportPosition(int distance) { private Vec3d findTeleportPosition(int distance) {
return FuzzyTargeting.findTo((PathAwareEntity)this.entity, distance, distance, this.targetEntity.getPos()); if (this.entity instanceof PathAwareEntity) {
return FuzzyTargeting.findTo((PathAwareEntity) this.entity, distance, distance, this.targetEntity.getPos());
}
return null;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment