cn.nukkit.entity.EntityIntelligent Maven / Gradle / Ivy
package cn.nukkit.entity;
import cn.nukkit.Player;
import cn.nukkit.Server;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.entity.ai.EntityAI;
import cn.nukkit.entity.ai.behaviorgroup.EmptyBehaviorGroup;
import cn.nukkit.entity.ai.behaviorgroup.IBehaviorGroup;
import cn.nukkit.entity.ai.controller.EntityControlUtils;
import cn.nukkit.entity.ai.evaluator.LogicalUtils;
import cn.nukkit.entity.ai.memory.CoreMemoryTypes;
import cn.nukkit.entity.ai.memory.IMemoryStorage;
import cn.nukkit.entity.ai.memory.MemoryType;
import cn.nukkit.event.entity.EntityDamageEvent;
import cn.nukkit.form.window.FormWindowSimple;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemID;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.math.Vector3;
import cn.nukkit.nbt.tag.CompoundTag;
import lombok.Getter;
import java.util.Objects;
/**
* {@code EntityIntelligent}抽象了一个具有行为组{@link IBehaviorGroup}(也就是具有AI)的实体
*/
@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public abstract class EntityIntelligent extends EntityPhysical implements LogicalUtils, EntityControlUtils {
public static final IBehaviorGroup EMPTY_BEHAVIOR_GROUP = new EmptyBehaviorGroup();
@Since("1.19.60-r1")
protected IBehaviorGroup behaviorGroup;
/**
* 是否为活跃实体,如果实体不活跃,就应当降低AI运行频率
*/
@Getter
protected boolean isActive = true;
public EntityIntelligent(FullChunk chunk, CompoundTag nbt) {
super(chunk, nbt);
this.behaviorGroup = requireBehaviorGroup();
var storage = getMemoryStorage();
if (storage != null) {
storage.put(CoreMemoryTypes.ENTITY_SPAWN_TIME, Server.getInstance().getTick());
MemoryType.getPersistentMemories().forEach(memory -> {
var mem = (MemoryType
© 2015 - 2025 Weber Informatics LLC | Privacy Policy