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));
});
}
}
}
}
Aggregations