mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-06-30 17:58:27 +00:00
Cleaning up code, new Aim C
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
package dev.brighten.ac.utils;
|
||||
|
||||
import lombok.Data;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
public class KLocation implements Cloneable {
|
||||
public double x, y, z;
|
||||
public float yaw, pitch;
|
||||
public long timeStamp;
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
private long timeStamp;
|
||||
|
||||
public KLocation(double x, double y, double z, float yaw, float pitch, long timeStamp) {
|
||||
this.x = x;
|
||||
|
||||
@@ -90,13 +90,13 @@ public class MathUtils {
|
||||
}
|
||||
|
||||
public static double getDistanceWithoutRoot(KLocation one, KLocation two) {
|
||||
double deltaX = one.x - two.x, deltaY = one.y - two.y, deltaZ = one.z - two.z;
|
||||
double deltaX = one.getX() - two.getX(), deltaY = one.getY() - two.getY(), deltaZ = one.getZ() - two.getZ();
|
||||
|
||||
return (deltaX * deltaX) + (deltaY * deltaY) + (deltaZ * deltaZ);
|
||||
}
|
||||
|
||||
public static boolean isSameLocation(KLocation one, KLocation two) {
|
||||
return one.x == two.x && one.y == two.y && one.z == two.z;
|
||||
return one.getX() == two.getX() && one.getY() == two.getY() && one.getZ() == two.getZ();
|
||||
}
|
||||
|
||||
|
||||
@@ -509,8 +509,8 @@ public class MathUtils {
|
||||
/* Stolen from Bukkit */
|
||||
public static Vector getDirection(KLocation loc) {
|
||||
Vector vector = new Vector();
|
||||
double rotX = loc.yaw;
|
||||
double rotY = loc.pitch;
|
||||
double rotX = loc.getYaw();
|
||||
double rotY = loc.getPitch();
|
||||
vector.setY(-Math.sin(Math.toRadians(rotY)));
|
||||
double xz = Math.cos(Math.toRadians(rotY));
|
||||
vector.setX(-xz * Math.sin(Math.toRadians(rotX)));
|
||||
@@ -892,9 +892,9 @@ public class MathUtils {
|
||||
}
|
||||
|
||||
public static float[] getRotation(KLocation one, KLocation two) {
|
||||
double diffX = two.x - one.x;
|
||||
double diffZ = two.z - one.z;
|
||||
double diffY = two.y - one.y;
|
||||
double diffX = two.getX() - one.getX();
|
||||
double diffZ = two.getZ() - one.getZ();
|
||||
double diffY = two.getY() - one.getY();
|
||||
double dist = Math.sqrt(diffX * diffX + diffZ * diffZ);
|
||||
float yaw = (float) (FastTrig.fast_atan2(diffZ, diffX) * 180.0 / 3.141592653589793) - 90.0f;
|
||||
float pitch = (float) (-FastTrig.fast_atan2(diffY, dist) * 180.0 / 3.141592653589793);
|
||||
@@ -926,5 +926,13 @@ public class MathUtils {
|
||||
double pitchOffset = Math.abs(pitch - one.getPitch());
|
||||
return new double[]{yawOffset, pitchOffset};
|
||||
}
|
||||
|
||||
public static double[] getOffsetFromLocation(KLocation one, KLocation two) {
|
||||
double yaw = MathUtils.getRotation(one, two)[0];
|
||||
double pitch = MathUtils.getRotation(one, two)[1];
|
||||
double yawOffset = Math.abs(yaw - MathUtils.yawTo180F(one.getYaw()));
|
||||
double pitchOffset = Math.abs(pitch - one.getPitch());
|
||||
return new double[]{yawOffset, pitchOffset};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package dev.brighten.ac.utils.objects.evicting;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class EvictingSet<E> extends AbstractSet<E> implements Set<E>, Cloneable {
|
||||
|
||||
@Getter
|
||||
private final int fixedSize;
|
||||
private transient EvictingMap<E, Object> map;
|
||||
|
||||
public EvictingSet(int fixedSize) {
|
||||
this.fixedSize = fixedSize;
|
||||
this.map = new EvictingMap<>(fixedSize);
|
||||
}
|
||||
private static final Object PRESENT = new Object();
|
||||
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return map.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(Object o) {
|
||||
return map.containsKey(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return map.keySet().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] toArray() {
|
||||
return map.keySet().toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T[] toArray(T[] a) {
|
||||
return map.keySet().toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean add(E k) {
|
||||
return map.put(k, PRESENT) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object o) {
|
||||
return map.remove(o) == PRESENT;
|
||||
}
|
||||
|
||||
public Object clone() {
|
||||
try {
|
||||
EvictingSet<E> newSet = (EvictingSet<E>) super.clone();
|
||||
newSet.map = (EvictingMap<E, Object>) map.clone();
|
||||
return newSet;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
throw new InternalError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user