
Out of Combat - Leaving Combat State
This modification introduces a convenient and customizable out-of-combat detection mechanic into Minecraft, helping to clearly track when a player ceases to participate in battles.
Supported Versions
The mod is compatible with most current Minecraft versions: 1.12.2, 1.16.1-1.16.5, 1.18-1.18.2, 1.20.1, and 1.20.6.
How the System Works
The mechanics are based on three independent time intervals (T1, T2, T3), measured in game ticks:
Tracking Phase: The system checks whether the player hasn't attacked for time T1 and hasn't taken damage for period T2.
Transition State: If both conditions are met, the countdown to leaving combat begins. Any attack or taking damage resets the corresponding timers.
Leaving Combat: When the accumulated inactivity time exceeds T3, the player is officially considered to have left the combat state.
Timer System
To implement this logic, four NBT tags stored in player data are used:
ForgeData: {
PlayerPersisted: {
out_of_combat: {
noAttackingTime: 0L // No attacks timer
noAttackedTime: 0L // No damage taken timer
stopOutOfCombatTimer: 0L // Countdown timer. While not reaching 0, the out-of-combat timer is paused
outOfCombatTime: 0L // Out-of-combat state timer
}
}
}
These tags are located in ForgeData/PlayerPersisted, allowing easy management of their values through mods, CraftTweaker or KubeJS scripts without the need for complex APIs or special integrations.
Additional Features
The mod includes an additional countdown timer that pauses the out-of-combat time counting without resetting it. This feature is useful for situations where the player activates abilities like "Invulnerability" - the system will wait for the ability effect to end before continuing the countdown.