vec.FastMathVec3DMixin

This commit is contained in:
Taiyou06
2024-07-09 00:09:04 +03:00
parent 123ffb0988
commit e9fd0a0363
2 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
package net.gensokyoreimagined.nitori.mixin.math.vec;
import net.minecraft.world.phys.Vec3;
import org.spongepowered.asm.mixin.*;
@Mixin(Vec3.class)
public class FastMathVec3DMixin {
@Mutable
@Shadow
@Final
public double x;
@Mutable
@Shadow @Final public double y;
@Mutable
@Shadow @Final public double z;
private Vec3 cachedNormalized;
/**
* @author QPCrummer
* @reason Cache normalized Vec
*/
@Overwrite
public Vec3 normalize() {
if (cachedNormalized == null) {
double squaredLength = x * x + y * y + z * z;
if (squaredLength < 1.0E-8) {
cachedNormalized = Vec3.ZERO;
} else {
double invLength = 1.0 / Math.sqrt(squaredLength);
cachedNormalized = new Vec3(x * invLength, y * invLength, z * invLength);
}
}
return cachedNormalized;
}
}

View File

@@ -44,6 +44,7 @@
"math.fast_util.AxisCycleDirectionMixin$ForwardMixin",
"math.fast_util.AxisCycleDirectionMixin$BackwardMixin",
"math.fast_util.DirectionMixin",
"math.vec.FastMathVec3DMixin",
"collections.entity_filtering.TypeFilterableListMixin",
"collections.entity_by_type.TypeFilterableListMixin",
"collections.chunk_tickets.SortedArraySetMixin",