import { Entity } from "@minecraft/server"
import { EntityComponents } from "../utils/entityComponents"

export const CREEPER = {
    _familyType: "creeper",
    _chargedMarkKey: "charged",

    /**
     * 
     * @param {Entity} entity 
     */
    isChargedCreeper(entity) {
        const familyType = EntityComponents.getFamilyType(entity)
        const isCharged = EntityComponents.getIsCharged(entity)
        return familyType.hasTypeFamily(this._familyType) && isCharged
    },

    /**
     * 
     * @param {Entity} entity 
     */
    markAsCharged(entity) {
        entity[this._chargedMarkKey] = true
    },

    /**
     * 
     * @param {Entity} entity 
     */
    isMarkedAsCharged(entity) {
        try {
            return entity[this._chargedMarkKey]
        } catch {
            return false
        }
    }
}