Начинающий
- Статус
- Оффлайн
- Регистрация
- 27 Май 2024
- Сообщения
- 26
- Реакции
- 0
- Выберите загрузчик игры
- Fabric
моя первая работа слегка чат лгбт без хейта пж
java:
package fun.rich.addon.aura;
import fun.rich.utils.features.aura.rotations.constructor.RotateConstructor;
import fun.rich.utils.features.aura.utils.MathAngle;
import fun.rich.utils.features.aura.warp.Turns;
import fun.rich.utils.math.calc.Calculate;
import java.security.SecureRandom;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
public class FuntimeSnapAngle extends RotateConstructor {
private static final Vec3d DEFAULT_BODY_POINT = new Vec3d(0.5, 0.68, 0.5);
private final SecureRandom random = new SecureRandom();
private float lastYaw = Float.NaN;
private float lastPitch = Float.NaN;
private float shakeTime;
private int snapTicks;
private final float shakeSpeed = 1.05f;
private final float shakeIntensity = 0.75f;
private static Vec3d sharedBodyPoint = DEFAULT_BODY_POINT;
private static long sharedBodyPointUntil;
public FuntimeSnapAngle() {
super("FunTime");
}
@Override
public Turns limitAngleChange(Turns currentTurns, Turns targetTurns, Vec3d vec3d, Entity entity) {
if (Float.isNaN(this.lastYaw) || Float.isNaN(this.lastPitch)) {
this.lastYaw = currentTurns.getYaw();
this.lastPitch = currentTurns.getPitch();
}
long now = System.currentTimeMillis();
Turns desiredTurns = this.computeDesiredTurns(targetTurns, entity, now);
float deltaYaw = MathHelper.wrapDegrees(desiredTurns.getYaw() - this.lastYaw);
float deltaPitch = desiredTurns.getPitch() - this.lastPitch;
float absYaw = Math.abs(deltaYaw);
float absPitch = Math.abs(deltaPitch);
boolean shouldSnap = this.shouldSnap(absYaw, absPitch, now);
if (shouldSnap) {
this.snapTicks = Math.max(this.snapTicks, 2 + this.random.nextInt(3));
}
float yawFactor = this.snapTicks > 0 ? this.randomLerp(0.78f, 0.94f) : this.randomLerp(0.18f, 0.34f);
float pitchFactor = this.snapTicks > 0 ? this.randomLerp(0.72f, 0.9f) : this.randomLerp(0.12f, 0.24f);
float yawStep = deltaYaw * MathHelper.clamp(yawFactor, 0.0f, 1.0f);
float pitchStep = deltaPitch * MathHelper.clamp(pitchFactor, 0.0f, 1.0f);
float smooth = this.lastYaw + yawStep;
float newPitch = this.lastPitch + pitchStep;
float gcd = (float)Calculate.computeGcd();
smooth -= (smooth - this.lastYaw) % gcd;
newPitch -= (newPitch - this.lastPitch) % gcd;
this.shakeTime += this.shakeSpeed * 0.05f;
float intensity = this.snapTicks > 0 ? this.shakeIntensity : this.shakeIntensity * 0.45f;
float jitterYaw = this.randomLerp(-0.18f, 0.18f);
float jitterPitch = this.randomLerp(-0.1f, 0.1f);
float shakeYaw = (float)(Math.sin(this.shakeTime * 1.7f) * intensity * 0.5f);
float shakePitch = (float)(Math.sin(this.shakeTime * 2.3f + 1.0f) * intensity * 0.25f);
Turns snapTurns = new Turns(smooth + shakeYaw + jitterYaw, MathHelper.clamp(newPitch + shakePitch + jitterPitch, -89.0f, 89.0f));
this.lastYaw = smooth;
this.lastPitch = newPitch;
if (this.snapTicks > 0) {
--this.snapTicks;
}
return snapTurns;
}
@Override
public Vec3d randomValue() {
Vec3d bodyPoint = this.getBodyPoint(System.currentTimeMillis());
double xBias = (bodyPoint.x - 0.5) * 0.18;
double yBias = (bodyPoint.y - 0.5) * 0.24;
double zBias = (bodyPoint.z - 0.5) * 0.18;
return new Vec3d(
xBias + this.randomLerp(-0.028f, 0.028f),
yBias + this.randomLerp(-0.035f, 0.035f),
zBias + this.randomLerp(-0.028f, 0.028f)
);
}
private Turns computeDesiredTurns(Turns fallbackTurns, Entity entity, long now) {
if (entity == null) {
return fallbackTurns;
}
Box box = entity.getBoundingBox();
Vec3d bodyPoint = this.getBodyPoint(now);
double pointX = MathHelper.lerp(bodyPoint.x, box.minX + box.getLengthX() * 0.14, box.maxX - box.getLengthX() * 0.14);
double pointY = MathHelper.lerp(bodyPoint.y, box.minY + box.getLengthY() * 0.08, box.maxY - box.getLengthY() * 0.04);
double pointZ = MathHelper.lerp(bodyPoint.z, box.minZ + box.getLengthZ() * 0.14, box.maxZ - box.getLengthZ() * 0.14);
Vec3d targetPoint = new Vec3d(pointX, pointY, pointZ);
Turns pointTurns = MathAngle.calculateAngle(targetPoint);
pointTurns.setYaw(pointTurns.getYaw() + this.randomLerp(-0.45f, 0.45f));
pointTurns.setPitch(MathHelper.clamp(pointTurns.getPitch() + this.randomLerp(-0.22f, 0.22f), -89.0f, 89.0f));
return pointTurns;
}
private Vec3d getBodyPoint(long now) {
if (now < sharedBodyPointUntil) {
return sharedBodyPoint;
}
sharedBodyPoint = switch (this.random.nextInt(6)) {
case 0 -> this.createBodyPoint(0.5, 0.9, 0.5, 0.035, 0.035, 0.03);
case 1 -> this.createBodyPoint(0.5, 0.72, 0.5, 0.06, 0.05, 0.045);
case 2 -> this.createBodyPoint(0.5, 0.56, 0.5, 0.055, 0.05, 0.04);
case 3 -> this.createBodyPoint(0.33, 0.68, 0.47, 0.04, 0.05, 0.03);
case 4 -> this.createBodyPoint(0.67, 0.68, 0.53, 0.04, 0.05, 0.03);
default -> this.createBodyPoint(0.5, 0.42, 0.5, 0.05, 0.045, 0.035);
};
sharedBodyPointUntil = now + 120L + this.random.nextInt(150);
return sharedBodyPoint;
}
private Vec3d createBodyPoint(double x, double y, double z, double xSpread, double ySpread, double zSpread) {
double pointX = MathHelper.clamp(x + this.random.nextGaussian() * xSpread, 0.18, 0.82);
double pointY = MathHelper.clamp(y + this.random.nextGaussian() * ySpread, 0.1, 0.96);
double pointZ = MathHelper.clamp(z + this.random.nextGaussian() * zSpread, 0.18, 0.82);
return new Vec3d(pointX, pointY, pointZ);
}
private boolean shouldSnap(float absYaw, float absPitch, long now) {
return this.snapTicks > 0 || absYaw > this.randomLerp(8.0f, 18.0f) || absPitch > this.randomLerp(4.0f, 10.0f) || this.random.nextFloat() > 0.94f;
}
private float randomLerp(float min, float max) {
return MathHelper.lerp(this.random.nextFloat(), min, max);
}
}
