@FunctionAnnotation(name = "HpAlert", type = Category.Render)
public class HpAlert extends Function {
public SliderSetting intensivity = new SliderSetting("При скольки здоровье", 15f, 1f, 20f, 1f);
boolean hp;
float animation;
public HpAlert() {
super();
addSettings(intensivity);
}
@Override
public void onEvent(Event event) {
if (event instanceof EventRender eventRender) {
if (eventRender.isRender2D()) {
handle(eventRender);
}
}
}
private void handle(EventRender eventRender) {
final MatrixStack stack = eventRender.matrixStack;
final Minecraft mc = Minecraft.getInstance();
final float health = mc.player.getHealth();
final float threshold = Math.min(Math.max(intensivity.getValue().floatValue(), 1f), 20f);
if (health >= threshold) {
hp = true;
} else {
hp = false;
}
String message = "Внимание! Низкий уровень здоровья!";
animation = AnimationMath.fast(animation, hp ? 0 : 1, 4);
int screenWidth = mc.getMainWindow().getScaledWidth();
int screenHeight = mc.getMainWindow().getScaledHeight();
float heartWidth = 64f;
float heartHeight = 64f;
float heartPosX = screenWidth / 2f - heartWidth / 2f;
float heartPosY = screenHeight / 2f - heartHeight - 100;
float textWidth = 150f;
float textHeight = 20f;
float textPosX = screenWidth / 2f;
float textPosY = screenHeight / 2f - 85;
Fonts.sfsemibold[22].drawCenteredString(stack, message, textPosX, textPosY, RenderUtil.reAlphaInt(-1, (int) (255 * animkaxd)));
}
}