Skip to content

Commit

Permalink
Improved effigy serach code
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksonhardaway committed Apr 6, 2021
1 parent 44d808b commit 2d8ca8c
Showing 1 changed file with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import net.minecraft.pathfinding.Path;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;

import java.util.EnumSet;
import java.util.stream.Stream;

public class SlabbyFindEffigyGoal extends Goal {
private final SlabfishEntity slabfish;
Expand All @@ -29,28 +29,22 @@ public boolean shouldExecute() {
return false;

AxisAlignedBB aabb = this.slabfish.getBoundingBox().grow(12.0D, 4.0D, 12.0D);
Iterable<BlockPos> blocks = BlockPos.getAllInBoxMutable(new BlockPos(MathHelper.floor(aabb.minX), MathHelper.floor(aabb.minY), MathHelper.floor(aabb.minZ)), new BlockPos(MathHelper.floor(aabb.maxX), MathHelper.floor(aabb.maxY), MathHelper.floor(aabb.maxZ)));
Stream<BlockPos> blocks = BlockPos.getAllInBox(aabb);

this.slabfish.getNavigator().clearPath();

BlockPos effigyPos = null;
double closest = Double.MAX_VALUE;
for (BlockPos pos : blocks) {
if (!(this.slabfish.world.getBlockState(pos).getBlock() instanceof SlabfishEffigyBlock))
continue;
double distance = this.slabfish.getDistanceSq(pos.getX(), pos.getY(), pos.getZ());
blocks.filter(pos -> this.slabfish.world.getBlockState(pos).getBlock() instanceof SlabfishEffigyBlock).forEach(pos -> {
double distance = this.slabfish.getDistanceSq(pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5);
double closest = this.effigyPos == null ? Double.MAX_VALUE : this.slabfish.getDistanceSq(this.effigyPos.getX() + 0.5, this.effigyPos.getY(), this.effigyPos.getZ() + 0.5);
if (distance < closest) {
closest = distance;
effigyPos = pos.toImmutable();
if (this.slabfish.getNavigator().getPathToPos(this.effigyPos, 0) == null)
return;

this.effigyPos = pos.toImmutable();
}
}
});

if (effigyPos == null)
return false;
else {
this.effigyPos = effigyPos;
return true;
}
return this.effigyPos != null;
}

@Override
Expand Down

0 comments on commit 2d8ca8c

Please sign in to comment.