package dF.Wirent.functions.impl.render;
import com.google.common.eventbus.Subscribe;
import dF.Wirent.events.EventDisplay;
import dF.Wirent.functions.api.Category;
import dF.Wirent.functions.api.Function;
import dF.Wirent.functions.api.FunctionRegister;
import dF.Wirent.functions.settings.impl.ModeSetting;
import dF.Wirent.utils.client.IMinecraft;
import dF.Wirent.utils.math.MathUtil;
import dF.Wirent.utils.projections.ProjectionUtil;
import dF.Wirent.utils.render.ColorUtils;
import dF.Wirent.utils.render.DisplayUtils;
import java.util.concurrent.CopyOnWriteArrayList;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.block.BlockState;
@FunctionRegister(name="RainbowRadiusTrails", type=Category.Render)
public class RainbowRadiusTrails extends Function {
private final ModeSetting setting = new ModeSetting("SXDpandora", "по доброте", "в дс отпишите если идеи будут"); //sxdpandora дс
private final CopyOnWriteArrayList<Particle> particles = new CopyOnWriteArrayList<>();
private final int maxParticles = 30;
private final int circleRadius = 3;
/* public RainbowRadiusTrails() {
this.addSettings(this.setting);
} */
@Subscribe
private void onDisplay(EventDisplay e) {
if (Minecraft.player == null || Minecraft.world == null || e.getType() != EventDisplay.Type.PRE) {
return;
}
if (this.particles.isEmpty()) {
for (int i = 0; i < maxParticles; i++) {
this.particles.add(new Particle(i, maxParticles));
}
}
for (Particle p : this.particles) {
p.updatePosition();
p.Sigmadampopechenyeslispizdishhuesosebanniyidisampihizhivotnoe();
p.smoothMove();
Vector2f pos = ProjectionUtil.project(p.currentPos.x, p.currentPos.y, p.currentPos.z);
switch ((String)this.setting.get()) {
case "Радужный круг": {
int color = ColorUtils.getColor(1);
//DisplayUtils.drawCircle(pos.x, pos.y, 5.0f, color);
DisplayUtils.drawStyledRect(pos.x - 2, pos.y - 3, 5, 5, 6);
break;
}
}
}
}
@Override
public void onDisable() {
this.particles.clear();
super.onDisable();
}
/* @Override
protected float[] rotations(PlayerEntity var1) {
return new float[0];
} */ //мои сломанные сурсы, ничего важного
private class Particle {
private Vector3d currentPos;
private Vector3d targetPos;
private Vector3d velocity = Vector3d.ZERO;
private final int index;
private final int totalParticles;
private float hue;
private long collisionTime = -1L;
public Particle(int index, int totalParticles) {
this.index = index;
this.totalParticles = totalParticles;
this.hue = (float) index / totalParticles;
updatePosition();
this.currentPos = this.targetPos;
}
public void updatePosition() {
double angle = 2 * Math.PI * index / totalParticles;
Vector3d playerPos = Minecraft.player.getPositionVec();
double xOffset = circleRadius * Math.cos(angle);
double zOffset = circleRadius * Math.sin(angle);
this.targetPos = playerPos.add(xOffset, 0, zOffset);
}
public void smoothMove() {
this.currentPos = MathUtil.fast(this.currentPos, this.targetPos, 10.1f);
}
private void Sigmadampopechenyeslispizdishhuesosebanniyidisampihizhivotnoe() {
if (this.collisionTime != -1L) {
long timeSinceCollision = System.currentTimeMillis() - this.collisionTime;
this.hue = Math.max(0.0f, 1.0f - (float) timeSinceCollision / 3000.0f);
}
this.velocity = this.velocity.add(0.0, -8.0E-4, 0.0);
Vector3d newPos = this.currentPos.add(this.velocity);
BlockPos particlePos = new BlockPos(newPos);
BlockState blockState = Minecraft.world.getBlockState(particlePos);
boolean collidedX = !Minecraft.world.getBlockState(new BlockPos(this.currentPos.x + this.velocity.x, this.currentPos.y, this.currentPos.z)).isAir();
boolean collidedY = !Minecraft.world.getBlockState(new BlockPos(this.currentPos.x, this.currentPos.y + this.velocity.y, this.currentPos.z)).isAir();
boolean collidedZ = !Minecraft.world.getBlockState(new BlockPos(this.currentPos.x, this.currentPos.y, this.currentPos.z + this.velocity.z)).isAir();
if (!blockState.isAir()) {
if (this.collisionTime == -1L) {
this.collisionTime = System.currentTimeMillis();
}
if (collidedX) {
this.velocity = new Vector3d(-this.velocity.x * 0.5, this.velocity.y * 0.8, this.velocity.z * 0.8);
this.currentPos = this.currentPos.add(-Math.signum(this.velocity.x) * 0.05, 0, 0);
}
if (collidedY && this.velocity.y < 0) {
this.velocity = new Vector3d(this.velocity.x * 0.8, 0, this.velocity.z * 0.8);
this.currentPos = this.currentPos.add(0, -Math.signum(this.velocity.y) * 0.05, 0);
}
if (collidedZ) {
this.velocity = new Vector3d(this.velocity.x * 0.8, this.velocity.y * 0.8, -this.velocity.z * 0.5);
this.currentPos = this.currentPos.add(0, 0, -Math.signum(this.velocity.z) * 0.05);
}
} else {
this.currentPos = newPos;
}
this.velocity = this.velocity.scale(0.95);
BlockPos currentBlockPos = new BlockPos(this.currentPos);
if (Minecraft.world.getBlockState(currentBlockPos).isSolid()) {
Vector3d playerPos = Minecraft.player.getPositionVec();
Vector3d directionToCenter = playerPos.subtract(this.currentPos).normalize();
this.currentPos = this.currentPos.add(directionToCenter.scale(0.05));
//this.velocity = directionToCenter.scale(-0.025);
}
}
public void update() {
this.hue += 0.01f;
if (this.hue > 1.0f) {
this.hue = 0.0f;
}
}
}
}