2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.util;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
2020-01-16 12:35:46 +01:00
|
|
|
import java.util.function.Predicate;
|
2019-01-20 00:07:59 +01:00
|
|
|
import java.util.stream.Stream;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
import javax.annotation.Nullable;
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2019-01-20 00:07:59 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.util.math.Box;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.util.math.Vec3d;
|
2019-01-20 00:07:59 +01:00
|
|
|
import net.minecraft.world.World;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2020-04-15 19:06:45 +02:00
|
|
|
public interface VecHelper {
|
|
|
|
static Stream<Entity> findAllEntitiesInRange(@Nullable Entity origin, World w, BlockPos pos, double radius) {
|
2020-09-22 15:11:20 +02:00
|
|
|
return w.getOtherEntities(origin, new Box(pos).expand(radius), e -> {
|
2020-05-04 00:41:22 +02:00
|
|
|
double dist = Math.sqrt(e.squaredDistanceTo(pos.getX(), pos.getY(), pos.getZ()));
|
|
|
|
double dist2 = Math.sqrt(e.squaredDistanceTo(pos.getX(), pos.getY() - e.getStandingEyeHeight(), pos.getZ()));
|
2019-01-20 00:07:59 +01:00
|
|
|
|
|
|
|
return dist <= radius || dist2 <= radius;
|
2020-05-03 19:20:51 +02:00
|
|
|
}).stream();
|
2019-01-20 00:07:59 +01:00
|
|
|
}
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
/**
|
|
|
|
* Gets all entities within a given range from the player.
|
|
|
|
*/
|
2020-09-27 20:07:55 +02:00
|
|
|
static List<Entity> getWithinReach(PlayerEntity player, double reach, @Nullable Predicate<? super Entity> predicate) {
|
2020-01-16 12:35:46 +01:00
|
|
|
Vec3d look = player.getCameraPosVec(1).multiply(reach);
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2020-09-22 15:11:20 +02:00
|
|
|
return player.world.getOtherEntities(player, player
|
2020-01-16 12:35:46 +01:00
|
|
|
.getBoundingBox()
|
2018-09-16 00:45:44 +02:00
|
|
|
.expand(look.x, look.y, look.z)
|
|
|
|
.expand(1, 1, 1), predicate);
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|