package com.minelittlepony.unicopia.util; import java.util.List; import java.util.function.Predicate; import javax.annotation.Nullable; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; public interface VecHelper { static Predicate inRange(BlockPos center, double range) { double rad = Math.pow(range, 2); return e -> { return e.squaredDistanceTo(center.getX(), center.getY(), center.getZ()) <= rad || e.squaredDistanceTo(center.getX(), center.getY() - e.getStandingEyeHeight(), center.getZ()) <= rad; }; } static List findInRange(@Nullable Entity origin, World w, BlockPos pos, double radius, @Nullable Predicate predicate) { return w.getOtherEntities(origin, new Box(pos).expand(radius), predicate == null ? inRange(pos, radius) : inRange(pos, radius).and(predicate)); } /** * Gets all entities within a given range from the player. */ static List findInReach(PlayerEntity player, double reach, @Nullable Predicate predicate) { Vec3d look = player.getCameraPosVec(1).multiply(reach); return player.world.getOtherEntities(player, player .getBoundingBox() .expand(look.x, look.y, look.z) .expand(1, 1, 1), predicate); } }