Class in @minecraft/server
Extends EntityComponent
An entity’s health.
import { EntityHealthComponent } from '@minecraft/server';Example
Section titled “Example”import { world, type EntityHealthComponent } from '@minecraft/server';
for (const player of world.getAllPlayers()) { const component: EntityHealthComponent | undefined = player.getComponent('minecraft:health'); if (component) { console.log(player.name, component.currentValue); }}import { world } from '@minecraft/server';
for (const player of world.getAllPlayers()) { const component = player.getComponent('minecraft:health'); if (component) { console.log(player.name, component.currentValue); }}Properties
Section titled “Properties”typeId
Section titled “typeId”read-only
readonly typeId: "minecraft:health";entity
Section titled “entity”read-only
readonly entity: Entity;Types
isValid
Section titled “isValid”read-only
readonly isValid: boolean;currentValue
Section titled “currentValue”read-only
readonly currentValue: number;effectiveMax
Section titled “effectiveMax”read-only
readonly effectiveMax: number;effectiveMin
Section titled “effectiveMin”read-only
readonly effectiveMin: number;defaultValue
Section titled “defaultValue”read-only
readonly defaultValue: number;The maximum, in Basalt.
Methods
Section titled “Methods”setCurrentValue
Section titled “setCurrentValue”setCurrentValue(value: number): boolean;Sets the health, within the maximum; zero kills.
Parameters
valuenumber
Returns
booleanresetToMaxValue
Section titled “resetToMaxValue”resetToMaxValue(): void;resetToDefaultValue
Section titled “resetToDefaultValue”resetToDefaultValue(): void;resetToMinValue
Section titled “resetToMinValue”resetToMinValue(): void;Used by
Section titled “Used by”EntityComponentTypeMap.minecraft:health, EntityComponentTypeMap.health