Wojtek Beling

zrob mi moda do minecraft na wersje 1.21.4 fabric ze jak mam mniej niz 5 hp zdrowia to wyskakuje komunikat ze mam uciekac

Kodari AI
KodariOct 23 at 3:00 pm 1
LowHealthWarning
This Minecraft Fabric mod for version 1.21.4 adds a critical health warning system. When the player's health drops below 5 hit points (2.5 hearts), a prominent on-screen message appears, advising them to retreat and escape from danger. The warning is displayed as a large, red, centered notification with a pulsing animation to draw immediate attention. The mod checks the player's health continuously and displays the warning whenever the threshold is crossed, ensuring players are always aware of their critical state and encouraged to flee from combat or hazardous situations.
  1. Dodam clientowy mod Fabric 1.21.4 sprawdzający zdrowie gracza.

  2. Pokażę komunikat „Uciekaj!” po spadku poniżej 5 HP, bez spamowania co tick.

  3. Utworzę konfigurację projektu i pliki moda.

Gotowy mod Fabric 1.21.4: gdy zdrowie spadnie poniżej 5 HP, wyświetli na czacie „Masz mniej niż 5 HP! Uciekaj!”. Komunikat pojawi się raz, a ponownie dopiero po odzyskaniu co najmniej 5 HP i ponownym spadku.

Aby pobrać moda: kliknij Compile u góry, potem Compile w oknie kompilacji. Po udanym buildzie kliknij Download. Mod działa po stronie klienta.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 109
src/main/java/pl/kodari/escapewarning/EscapeWarningClient.java
package pl.kodari.escapewarning;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.text.Text;

public class EscapeWarningClient implements ClientModInitializer {
    private boolean warningSent;

    @Override
    public void onInitializeClient() {
        ClientTickEvents.END_CLIENT_TICK.register(client -> {
            if (client.player == null) {
                warningSent = false;
                return;
            }

            if (client.player.getHealth() < 5.0F) {
                if (!warningSent) {
                    client.player.sendMessage(Text.of("Masz mniej niż 5 HP! Uciekaj!"), false);
                    warningSent = true;
                }
            } else {
                warningSent = false;
            }
        });
    }
}