Skip to content

Commit

Permalink
optimize guiding bolt manager, fix close detection error
Browse files Browse the repository at this point in the history
address #651
  • Loading branch information
iron431 committed Oct 30, 2024
1 parent ba30b37 commit 003a711
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ public static void serverTick(LevelTickEvent.Post event) {
var dirtyProjectiles = INSTANCE.dirtyProjectiles.getOrDefault(serverLevel.dimension(), List.of());
for (int i = dirtyProjectiles.size() - 1; i >= 0; i--) {
var projectile = dirtyProjectiles.get(i);
if (projectile.isAddedToLevel()) {
if (projectile.isRemoved()) {
dirtyProjectiles.remove(i);
continue;
} else if (projectile.isAddedToLevel()) {
Vec3 start = projectile.position();
int searchRange = 48;
Vec3 end = Utils.raycastForBlock(serverLevel, start, projectile.getDeltaMovement().normalize().scale(searchRange).add(start), ClipContext.Fluid.NONE).getLocation();
Expand All @@ -107,7 +110,8 @@ public static void serverTick(LevelTickEvent.Post event) {
if (Math.abs(entity.getX() - projectile.getX()) > searchRange || Math.abs(entity.getY() - projectile.getY()) > searchRange || Math.abs(entity.getZ() - projectile.getZ()) > searchRange) {
continue;
}
if (Utils.checkEntityIntersecting(entity, start, end, 3.5f + Math.min(entity.getBbWidth() * .5f, 2)).getType() == HitResult.Type.ENTITY) {
float homeRadius = 3.5f + Math.min(entity.getBbWidth() * .5f, 2);
if (entity.getBoundingBox().inflate(homeRadius).contains(start) || Utils.checkEntityIntersecting(entity, start, end, homeRadius).getType() == HitResult.Type.ENTITY) {
updateTrackedProjectiles(entityToTrackedProjectiles.getValue(), projectile);
toSync.computeIfAbsent(entity, (key) -> new ArrayList<>()).add(projectile);
break;
Expand Down Expand Up @@ -157,7 +161,7 @@ public static void livingTick(EntityTickEvent.Pre event) {
Vec3 motion = projectile.getDeltaMovement();
float speed = (float) motion.length();
Vec3 home = livingEntity.getBoundingBox().getCenter().subtract(projectile.position()).normalize().scale(speed * .45f);
if (home.dot(motion) < 0) {
if (projectile.isRemoved() || home.dot(motion) < 0) {
//We have passed the entity
projectilesToRemove.add(projectile);
continue;
Expand Down

0 comments on commit 003a711

Please sign in to comment.