Search in sources :

Example 1 with DisconnectedScreen

use of net.minecraft.client.gui.screen.DisconnectedScreen in project tweakermore by Fallen-Breath.

the class SafeAfkHelper method onHealthUpdate.

public static void onHealthUpdate(MinecraftClient mc) {
    if (TweakerMoreConfigs.TWEAKM_SAFE_AFK.getBooleanValue()) {
        if (mc.player != null && mc.world != null && hasRecord()) {
            float health = mc.player.getHealth();
            float maxHealth = mc.player.getMaximumHealth();
            if (maxHealth > 0 && health < TweakerMoreConfigs.SAFE_AFK_HEALTH_THRESHOLD.getDoubleValue()) {
                String title = TweakerMoreMod.MOD_NAME + " " + TweakerMoreConfigs.TWEAKM_SAFE_AFK.getPrettyName();
                BaseText reason = new TranslatableText("tweakermore.config.tweakmSafeAfk.received_damage", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), String.format("%.1f / %.1f (%.0f%%)", health, maxHealth, health / maxHealth * 100));
                resetHurtTime();
                mc.execute(() -> {
                    mc.world.disconnect();
                    mc.disconnect();
                    mc.openScreen(new DisconnectedScreen(new MultiplayerScreen(new TitleScreen()), title, reason));
                });
            }
        }
    }
}
Also used : BaseText(net.minecraft.text.BaseText) TranslatableText(net.minecraft.text.TranslatableText) MultiplayerScreen(net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen) DisconnectedScreen(net.minecraft.client.gui.screen.DisconnectedScreen) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) TitleScreen(net.minecraft.client.gui.screen.TitleScreen)

Aggregations

SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 DisconnectedScreen (net.minecraft.client.gui.screen.DisconnectedScreen)1 TitleScreen (net.minecraft.client.gui.screen.TitleScreen)1 MultiplayerScreen (net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen)1 BaseText (net.minecraft.text.BaseText)1 TranslatableText (net.minecraft.text.TranslatableText)1