LivingEntity¶
Inherits from: Entity
Represents a living entity in the game, inheriting from Entity and including attributes specific to living creatures, such as health, age state, and hostility.
Fields¶
baby: boolean — Read-Only¶
Indicates whether the entity is a baby.
health: number — Read/Write¶
The current health of the entity.
hostile: boolean — Read-Only¶
Indicates whether the entity behaves in a hostile manner toward players or other entities.
Methods¶
getEquipment(equipmentSlot: string) → item: Item|nil¶
Returns a copy of the item currently held in the specified equipment slot.
Example
local piglin = spell:summon("piglin_brute")
---@cast piglin LivingEntity
print(str(piglin:getEquipment("mainhand")))
Parameters
- equipmentSlot: string — The equipment slot; must be one of "mainhand","offhand","feet","legs","chest","head","body".
Returns
- item: Item|nil — A copy of the item in the specified equipment slot, or nil if the slot is empty.
getItemInHand(hand: string) → item: Item|nil¶
Returns a copy of the item currently held in the specified hand.
Example
local item = spell.owner:getItemInHand("MAIN_HAND")
if item then
print("Item in hand:", item.name)
end
Parameters
- hand: string — The hand to check; must be either "MAIN_HAND" or "OFF_HAND".
Returns
- item: Item|nil — A copy of the item held in the specified hand, or nil if the hand is empty.
setEquipment(equipmentSlot: string, item: Item|nil)¶
Places a copy of the given item into the specified equipment slot. The provided item is not consumed or modified.
Example
local zombie = spell:summon("zombie")
---@cast zombie LivingEntity
zombie:setEquipment("mainhand", Item:new("diamond_sword"))
zombie:setEquipment("head", Item:new("diamond_helmet"))
Parameters
- equipmentSlot: string — The equipment slot to equip; must be one of "mainhand","offhand","feet","legs","chest","head","body".
- item: Item|nil — The item to place in the specified slot, or nil to clear it.
setItemInHand(hand: string, item: Item|nil)¶
Places a copy of the given item into the specified hand. Pass nil to clear the hand. The provided item is not consumed or modified.
Example
local sword = Item:new("diamond_sword")
spell.owner:setItemInHand("MAIN_HAND", sword)
-- Clear the hand later:
spell.owner:setItemInHand("MAIN_HAND", nil)
Parameters
- hand: string — The hand to equip; must be either "MAIN_HAND" or "OFF_HAND".
- item: Item|nil — The item to place in the specified hand, or nil to clear it.