package tech.neverbels.functions.impl.render;
import com.google.common.eventbus.Subscribe;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import lombok.Getter;
import net.minecraft.client.renderer.WorldVertexBufferUploader;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.vector.Vector3d;
import net.optifine.shaders.Shaders;
import org.lwjgl.opengl.GL11;
import tech.neverbels.events.EventDisplay;
import tech.neverbels.events.WorldEvent;
import tech.neverbels.functions.api.Category;
import tech.neverbels.functions.api.Function;
import tech.neverbels.functions.api.FunctionRegister;
import tech.neverbels.functions.impl.combat.KillAura;
import tech.neverbels.functions.settings.impl.ModeSetting;
import tech.neverbels.functions.settings.impl.SliderSetting;
import tech.neverbels.utils.math.Vector4i;
import tech.neverbels.utils.projections.ProjectionUtil;
import tech.neverbels.utils.render.ColorUtils;
import tech.neverbels.utils.render.DisplayUtils;
import static com.mojang.blaze3d.systems.RenderSystem.depthMask;
@FunctionRegister(name = "TargetESP", type = Category.Render)
public class TargetESP extends Function {
private final ModeSetting type = new ModeSetting("Тип", "Дефолт", "Дефолт", "Новая","Круг","Призраки");
public SliderSetting speed = new SliderSetting("Скорость", 2.0F, 0.7F, 9.0F, 1.0F);
public SliderSetting size = new SliderSetting("Размер", 75.0F, 5.0F, 140.0F, 1.0F);
public SliderSetting bright = new SliderSetting("Яркость", 255.0F, 1.0F, 255.0F, 1.0F);
[USER=270918]@Getter[/USER]
public static LivingEntity target = null;
private final KillAura killAura;
public TargetESP(KillAura killAura) {
this.killAura = killAura;
addSettings(type);
}
public static long startTime = System.currentTimeMillis();
@Subscribe
private void onWorldEvent(WorldEvent e) {
if (this.type.is("Круг")) {
EntityRendererManager rm = mc.getRenderManager();
if (killAura.isState() && killAura.getTarget() != null) {
double x = killAura.getTarget().lastTickPosX + (killAura.getTarget().getPosX() - killAura.getTarget().lastTickPosX) * (double) e.getPartialTicks() - rm.info.getProjectedView().getX();
double y = killAura.getTarget().lastTickPosY + (killAura.getTarget().getPosY() - killAura.getTarget().lastTickPosY) * (double) e.getPartialTicks() - rm.info.getProjectedView().getY();
double z = killAura.getTarget().lastTickPosZ + (killAura.getTarget().getPosZ() - killAura.getTarget().lastTickPosZ) * (double) e.getPartialTicks() - rm.info.getProjectedView().getZ();
float height = killAura.getTarget().getHeight();
double duration = 1500.0;
double elapsed = (double) System.currentTimeMillis() % duration;
boolean side = elapsed > duration / 2.0;
double progress = elapsed / (duration / 2.0);
progress = side ? --progress : 1.0 - progress;
progress = progress < 0.5 ? 2.0 * progress * progress : 1.0 - Math.pow(-2.0 * progress + 2.0, 2.0) / 2.0;
double eased = (double) (height / 2.0F) * (progress > 0.5 ? 1.0 - progress : progress) * (double) (side ? -1 : 1);
RenderSystem.pushMatrix();
GL11.glDepthMask(false);
GL11.glEnable(2848);
GL11.glHint(3154, 4354);
RenderSystem.disableTexture();
RenderSystem.enableBlend();
RenderSystem.disableAlphaTest();
RenderSystem.shadeModel(7425);
RenderSystem.disableCull();
RenderSystem.lineWidth(1.5F);
RenderSystem.color4f(-1.0F, -1.0F, -1.0F, -1.0F);
buffer.begin(8, DefaultVertexFormats.POSITION_COLOR);
float[] colors = null;
int i;
for (i = 0; i <= 360; ++i) {
colors = DisplayUtils.IntColor.rgb(HUD.getColor(0));
buffer.pos(x + Math.cos(Math.toRadians((double) i)) * (double) this.killAura.getTarget().getWidth() * 0.85, y + (double) height * progress, z + Math.sin(Math.toRadians((double) i)) * (double) this.killAura.getTarget().getWidth() * 0.85).color(colors[0], colors[1], colors[2], 0.5F).endVertex();
buffer.pos(x + Math.cos(Math.toRadians((double) i)) * (double) this.killAura.getTarget().getWidth() * 0.85, y + (double) height * progress + eased * 1.5, z + Math.sin(Math.toRadians((double) i)) * (double) this.killAura.getTarget().getWidth() * 0.85).color(colors[0], colors[1], colors[2], 0.2F).endVertex();
}
buffer.finishDrawing();
WorldVertexBufferUploader.draw(buffer);
RenderSystem.color4f(-1.0F, -1.0F, -1.0F, -1.0F);
buffer.begin(2, DefaultVertexFormats.POSITION_COLOR);
for (i = 0; i <= 360; ++i) {
buffer.pos(x + Math.cos(Math.toRadians((double) i)) * (double) this.killAura.getTarget().getWidth() * 0.85, y + (double) height * progress, z + Math.sin(Math.toRadians((double) i)) * (double) this.killAura.getTarget().getWidth() * 0.85).color(colors[0], colors[1], colors[2], 0.2F).endVertex();
}
buffer.finishDrawing();
WorldVertexBufferUploader.draw(buffer);
RenderSystem.enableCull();
RenderSystem.disableBlend();
RenderSystem.enableTexture();
RenderSystem.enableAlphaTest();
GL11.glDepthMask(true);
GL11.glDisable(2848);
GL11.glHint(3154, 4354);
RenderSystem.shadeModel(7424);
RenderSystem.popMatrix();
} else {
}
}
if (type.is("Призраки")) {
if (killAura.isState() && killAura.getTarget() != null) {
MatrixStack stack = new MatrixStack();
EntityRendererManager rm = mc.getRenderManager();
float c = (float) ((((System.currentTimeMillis() - startTime) / 1300F)) + (Math.sin((((System.currentTimeMillis() - startTime) / 1500F))) / 10f));
double x = killAura.getTarget().lastTickPosX + (killAura.getTarget().getPosX() - killAura.getTarget().lastTickPosX) * (double) e.getPartialTicks() - rm.info.getProjectedView().getX();
double y = killAura.getTarget().lastTickPosY + (killAura.getTarget().getPosY() - killAura.getTarget().lastTickPosY) * (double) e.getPartialTicks() - rm.info.getProjectedView().getY();
double z = killAura.getTarget().lastTickPosZ + (killAura.getTarget().getPosZ() - killAura.getTarget().lastTickPosZ) * (double) e.getPartialTicks() - rm.info.getProjectedView().getZ();
float alpha = Shaders.shaderPackLoaded ? 1f : 0.5f;
alpha *= 0.1F;
float pl = 0;
boolean fa = true;
for (int b = 0; b < 3; b++) {
for (float i = c * 360; i < c * 360 + 90; i += 2) {
float cur = i;
float max = c * 360 + 90;
float dc = MathHelper.normalize(cur, c * 360 - 45, max);
float degrees = i;
int color = ColorUtils.getColor(0);
int color2 = ColorUtils.getColor(90);
float rf = 0.7f;
double radians = Math.toRadians(degrees);
double plY = pl + Math.sin(radians * 1.2f) * 0.1f;
stack.push();
stack.translate(x, y, z);
stack.rotate(mc.getRenderManager().info.getRotation());
GL11.glDepthMask(false);
float q = (!fa ? 0.15f : 0.15f) * (Math.max(fa ? 0.15f : 0.15f, fa ? dc : (1f - -(0.4f - dc)) / 2f) + 0.45f);
float w = q * (1.5f + ((0.5f - -alpha) * 2));
DisplayUtils.drawImage1(stack, new ResourceLocation("Tech/images/glow.png"), Math.cos(radians) * rf - w / 2f, plY + 1 - 0.7f, Math.sin(radians) * rf - w / 2f, w, w, color, color2, color2, color);
GL11.glEnable(GL11.GL_DEPTH_TEST);
depthMask(true);
stack.pop();
}
c *= -1.025f;
fa = !fa;
pl += 0.45f;
}
}
}else {
}
}
@Subscribe
private void onDisplay(EventDisplay e) {
if (e.getType() != EventDisplay.Type.PRE) {
return;
}
if (killAura.isState() && killAura.getTarget() != null) {
double sin = Math.sin(System.currentTimeMillis() / 1000.0);
float size = 90.0F;
Vector3d interpolated = killAura.getTarget().getPositon(e.getPartialTicks());
Vector2f pos = ProjectionUtil.project(interpolated.x, interpolated.y + killAura.getTarget().getHeight() / 2f, interpolated.z);
GlStateManager.pushMatrix();
GlStateManager.translatef(pos.x, pos.y, 0);
GlStateManager.rotatef((float) sin * 360, 0, 0, 1);
GlStateManager.translatef(-pos.x, -pos.y, 0);
if (type.is("Дефолт")) {
DisplayUtils.drawImage(new ResourceLocation("Tech/images/target.png"), pos.x - size / 2f, pos.y - size / 2f, size, size, new Vector4i(ColorUtils.setAlpha(HUD.getColor(0, 1), 220), ColorUtils.setAlpha(HUD.getColor(90, 1), 220), ColorUtils.setAlpha(HUD.getColor(180, 1), 220), ColorUtils.setAlpha(HUD.getColor(270, 1), 220)));
}
if (type.is("Новая")) {
DisplayUtils.drawImage(new ResourceLocation("Tech/images/target1.png"), pos.x - size / 2f, pos.y - size / 2f, size, size, new Vector4i(ColorUtils.setAlpha(HUD.getColor(0, 1), 220), ColorUtils.setAlpha(HUD.getColor(90, 1), 220), ColorUtils.setAlpha(HUD.getColor(180, 1), 220), ColorUtils.setAlpha(HUD.getColor(270, 1), 220)));
}
GlStateManager.popMatrix();
}
}
}