73 lines
2.0 KiB
Java
73 lines
2.0 KiB
Java
package ru.nevetime.cheat.module.render;
|
|
|
|
import net.minecraft.client.gui.DrawContext;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.LivingEntity;
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
import ru.nevetime.cheat.module.Module;
|
|
|
|
public class TargetHUD extends Module {
|
|
private Entity currentTarget;
|
|
|
|
public TargetHUD() {
|
|
super("TargetHUD", Category.RENDER);
|
|
}
|
|
|
|
@Override
|
|
public void onTick() {
|
|
if (mc.player == null || mc.world == null) {
|
|
currentTarget = null;
|
|
return;
|
|
}
|
|
|
|
currentTarget = findTarget();
|
|
}
|
|
|
|
private Entity findTarget() {
|
|
Entity closest = null;
|
|
double closestDistance = 20.0;
|
|
|
|
for (Entity entity : mc.world.getEntities()) {
|
|
if (entity == mc.player) continue;
|
|
if (!(entity instanceof LivingEntity)) continue;
|
|
if (!entity.isAlive()) continue;
|
|
|
|
double distance = mc.player.distanceTo(entity);
|
|
if (distance < closestDistance) {
|
|
closest = entity;
|
|
closestDistance = distance;
|
|
}
|
|
}
|
|
|
|
return closest;
|
|
}
|
|
|
|
public void render(DrawContext context, int screenWidth, int screenHeight) {
|
|
if (!isEnabled() || currentTarget == null) return;
|
|
if (!(currentTarget instanceof LivingEntity living)) return;
|
|
|
|
int x = 10;
|
|
int y = 10;
|
|
|
|
String name = currentTarget.getName().getString();
|
|
float health = living.getHealth();
|
|
float maxHealth = living.getMaxHealth();
|
|
float distance = mc.player.distanceTo(currentTarget);
|
|
|
|
context.fill(x, y, x + 150, y + 50, 0x80000000);
|
|
|
|
context.drawText(mc.textRenderer, name, x + 5, y + 5, 0xFFFFFF, true);
|
|
context.drawText(mc.textRenderer, String.format("HP: %.1f/%.1f", health, maxHealth), x + 5, y + 20, 0xFF0000, true);
|
|
context.drawText(mc.textRenderer, String.format("Distance: %.1f", distance), x + 5, y + 35, 0xFFFFFF, true);
|
|
|
|
int barWidth = 140;
|
|
int healthBarWidth = (int) ((health / maxHealth) * barWidth);
|
|
context.fill(x + 5, y + 48, x + 5 + barWidth, y + 52, 0xFF333333);
|
|
context.fill(x + 5, y + 48, x + 5 + healthBarWidth, y + 52, 0xFF00FF00);
|
|
}
|
|
|
|
public Entity getCurrentTarget() {
|
|
return currentTarget;
|
|
}
|
|
}
|