All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.entity.ai.executor.LookAtTargetExecutor Maven / Gradle / Ivy

package cn.nukkit.entity.ai.executor;

import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.entity.EntityIntelligent;
import cn.nukkit.entity.ai.memory.Vector3Memory;
import cn.nukkit.math.Vector3;
import org.jetbrains.annotations.NotNull;

@PowerNukkitXOnly
@Since("1.6.0.0-PNX")
public class LookAtTargetExecutor implements IBehaviorExecutor {

    //指示执行器应该从哪个Memory获取目标位置
    protected Class> memoryClazz;
    protected int duration;
    protected int currentTick;

    public LookAtTargetExecutor(Class> memoryClazz, int duration) {
        this.memoryClazz = memoryClazz;
        this.duration = duration;
    }

    @Override
    public boolean execute(EntityIntelligent entity) {
        currentTick++;
        if (!entity.isEnablePitch()) entity.setEnablePitch(true);
        Vector3Memory vector3Memory = entity.getMemoryStorage().get(memoryClazz);
        if (vector3Memory.hasData()) {
            setLookTarget(entity, vector3Memory.getData());
        }
        if (currentTick <= duration) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void onInterrupt(EntityIntelligent entity) {
        currentTick = 0;
        entity.setEnablePitch(false);
    }

    @Override
    public void onStop(EntityIntelligent entity) {
        currentTick = 0;
        entity.setEnablePitch(false);
    }

    protected void setLookTarget(@NotNull EntityIntelligent entity, Vector3 vector3) {
        entity.setLookTarget(vector3);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy