mirror of
https://github.com/Auxilor/EcoEnchants.git
synced 2024-12-25 20:17:38 +01:00
Added fast trig with lookup tables for artifacts.
This commit is contained in:
parent
242cb16ee6
commit
7e6265076e
@ -7,6 +7,7 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant;
|
||||
import com.willfp.ecoenchants.enchantments.EcoEnchants;
|
||||
import com.willfp.ecoenchants.enchantments.meta.EnchantmentType;
|
||||
import com.willfp.ecoenchants.enchantments.util.EnchantChecks;
|
||||
import com.willfp.ecoenchants.enchantments.util.FastTrig;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.block.Block;
|
||||
@ -140,8 +141,8 @@ public abstract class Artifact extends EcoEnchant {
|
||||
}
|
||||
yAtomic.addAndGet(yDelta);
|
||||
double y = yAtomic.get();
|
||||
double x = radius * Math.cos((y + offset) * radiusMultiplier);
|
||||
double z = radius * Math.sin((y + offset) * radiusMultiplier);
|
||||
double x = radius * FastTrig.cos((y + offset) * radiusMultiplier);
|
||||
double z = radius * FastTrig.sin((y + offset) * radiusMultiplier);
|
||||
Location particleLocation = victim.getLocation();
|
||||
particleLocation.add(x, y, z);
|
||||
victim.getWorld().spawnParticle(particle, particleLocation, 1, 0, 0, 0, 0, extra, false);
|
||||
|
@ -0,0 +1,52 @@
|
||||
package com.willfp.ecoenchants.enchantments.util;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
@UtilityClass
|
||||
public class FastTrig {
|
||||
/**
|
||||
* Precision.
|
||||
*/
|
||||
private static final int precision = 100;
|
||||
|
||||
/**
|
||||
* Modulus.
|
||||
*/
|
||||
private static final int modulus = 360 * precision;
|
||||
|
||||
/**
|
||||
* Sin lookup table.
|
||||
*/
|
||||
private static final double[] sin = new double[modulus];
|
||||
|
||||
private static double sinLookup(final int a) {
|
||||
return a >= 0 ? sin[a % modulus] : -sin[-a % modulus];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sin of a number.
|
||||
*
|
||||
* @param a The number.
|
||||
* @return The sin.
|
||||
*/
|
||||
public static double sin(final double a) {
|
||||
return sinLookup((int) (a * precision + 0.5f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cosine of a number.
|
||||
*
|
||||
* @param a The number.
|
||||
* @return The cosine.
|
||||
*/
|
||||
public static double cos(final double a) {
|
||||
return sinLookup((int) ((a + 90f) * precision + 0.5f));
|
||||
}
|
||||
|
||||
|
||||
static {
|
||||
for (int i = 0; i < sin.length; i++) {
|
||||
sin[i] = Math.sin((i * Math.PI) / (precision * 180));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user