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;
|
2021-12-23 18:46:25 +01:00
|
|
|
import java.util.function.DoubleSupplier;
|
2020-01-16 12:35:46 +01:00
|
|
|
import java.util.function.Predicate;
|
2023-08-05 16:45:36 +02:00
|
|
|
import java.util.function.Supplier;
|
|
|
|
|
2021-08-04 15:38:03 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2018-09-16 00:45:44 +02:00
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
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;
|
2023-08-05 16:45:36 +02:00
|
|
|
import net.minecraft.util.math.random.Random;
|
2022-10-03 23:44:30 +02:00
|
|
|
import net.minecraft.world.EntityView;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2020-04-15 19:06:45 +02:00
|
|
|
public interface VecHelper {
|
2019-01-20 00:07:59 +01:00
|
|
|
|
2022-10-08 10:57:16 +02:00
|
|
|
static Vec3d divide(Vec3d one, Vec3d two) {
|
|
|
|
return new Vec3d(one.x / two.x, one.y / two.y, one.z / two.z);
|
|
|
|
}
|
|
|
|
|
2021-12-23 18:46:25 +01:00
|
|
|
static Vec3d supply(DoubleSupplier rng) {
|
|
|
|
return new Vec3d(rng.getAsDouble(), rng.getAsDouble(), rng.getAsDouble());
|
|
|
|
}
|
|
|
|
|
2023-08-05 16:45:36 +02:00
|
|
|
static Supplier<Vec3d> supplier(DoubleSupplier rng) {
|
|
|
|
return () -> supply(rng);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Supplier<Vec3d> sphere(Random rng) {
|
|
|
|
return sphere(rng, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Supplier<Vec3d> sphere(Random rng, double radius) {
|
|
|
|
return supplier(() -> (rng.nextGaussian() - 0.5) * radius);
|
|
|
|
}
|
|
|
|
|
2021-01-29 17:37:41 +01:00
|
|
|
static Predicate<Entity> inRange(Vec3d center, double range) {
|
2020-10-04 12:58:01 +02:00
|
|
|
double rad = Math.pow(range, 2);
|
|
|
|
return e -> {
|
2021-01-29 17:37:41 +01:00
|
|
|
return e.squaredDistanceTo(center) <= rad
|
|
|
|
|| e.squaredDistanceTo(center.getX(), center.getY() - e.getStandingEyeHeight(), center.getZ()) <= rad;
|
2020-10-04 12:58:01 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-03 23:44:30 +02:00
|
|
|
static List<Entity> findInRange(@Nullable Entity origin, EntityView w, Vec3d pos, double radius, @Nullable Predicate<Entity> predicate) {
|
2021-08-04 15:38:03 +02:00
|
|
|
double diameter = radius * 2;
|
|
|
|
return w.getOtherEntities(origin, Box.of(pos, diameter, diameter, diameter), predicate == null ? inRange(pos, radius) : inRange(pos, radius).and(predicate));
|
2019-01-20 00:07:59 +01:00
|
|
|
}
|
2023-01-09 11:38:32 +01:00
|
|
|
|
|
|
|
static List<Entity> findInRange(@Nullable Entity origin, EntityView w, Vec3d pos, double radius) {
|
|
|
|
double diameter = radius * 2;
|
|
|
|
return w.getOtherEntities(origin, Box.of(pos, diameter, diameter, diameter), inRange(pos, radius));
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|