BlackCat13th

A client side minecraft mod that makes us /home when our health is low or any dangerous moment

Kodari AI
KodariOct 7 at 1:11 pm 1
AutoHomeEscape
AutoHomeEscape is a client-side Minecraft Fabric mod that automatically teleports the player home when their health drops to a critical level or when they encounter dangerous situations. The mod monitors player health, detecting when it falls below a configurable threshold, and instantly executes the /home command to escape danger. It also triggers on environmental hazards like drowning, burning, or falling, providing a safety net for players. Features include configurable health thresholds, danger detection for various damage sources, cooldown system to prevent spam, and seamless integration with existing home commands from popular mods or vanilla mechanics.
  1. Confirm the 26.2 client tick, player danger-state, and command-sending APIs.

  2. Create a client-only Fabric mod that sends /home once per danger episode, with a cooldown and health hysteresis.

  3. Add the Fabric 26.2 project metadata and build files.

Created Safely Home, a client-side Fabric mod. It sends /home when your health drops to 4 hearts or less, or when you’re burning, in lava, or critically low on air. It triggers once per danger episode, with a 30-second cooldown, and rearms after you recover.

The server must have a /home command available to your account.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 134
src/client/java/dev/kodari/safelyhome/SafeHomeClient.java
package dev.kodari.safelyhome;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.client.player.LocalPlayer;

public final class SafeHomeClient implements ClientModInitializer {
	private static final float LOW_HEALTH_THRESHOLD = 8.0f;
	private static final float RECOVERY_HEALTH_THRESHOLD = 10.0f;
	private static final int COOLDOWN_TICKS = 20 * 30;

	private static int cooldownTicks;
	private static boolean triggered;

	@Override
	public void onInitializeClient() {
		ClientTickEvents.END_CLIENT_TICK.register(SafeHomeClient::onClientTick);
	}

	private static void onClientTick(Minecraft client) {
		LocalPlayer player = client.player;
		ClientPacketListener connection = client.getConnection();
		if (player == null || connection == null) {
			triggered = false;
			cooldownTicks = 0;
			return;
		}

		if (cooldownTicks > 0) {
			cooldownTicks--;
		}

		int maxAir = player.getMaxAirSupply();
		int air = player.getAirSupply();
		boolean onFire = player.isOnFire();
		boolean inLava = player.isInLava();
		boolean lowAir = air <= maxAir / 4;
		boolean dangerous = player.getHealth() <= LOW_HEALTH_THRESHOLD || onFire || inLava || lowAir;
		boolean recovered = player.getHealth() > RECOVERY_HEALTH_THRESHOLD
				&& !onFire
				&& !inLava
				&& air > maxAir / 2;

		if (recovered && cooldownTicks == 0) {
			triggered = false;
		}

		if (dangerous && !triggered && cooldownTicks == 0) {
			connection.sendCommand("home");
			triggered = true;
			cooldownTicks = COOLDOWN_TICKS;
		}
	}
}