cn.nukkit.entity.ai.memory.codec.IMemoryCodec Maven / Gradle / Ivy
package cn.nukkit.entity.ai.memory.codec;
import cn.nukkit.api.PowerNukkitXOnly;
import cn.nukkit.api.Since;
import cn.nukkit.entity.EntityIntelligent;
import cn.nukkit.nbt.tag.CompoundTag;
import javax.annotation.Nullable;
import java.util.function.BiConsumer;
import java.util.function.Function;
/**
* 记忆编解码器
*/
@PowerNukkitXOnly
@Since("1.19.63-r1")
public interface IMemoryCodec {
/**
* 获取记忆解码器,用于从CompoundTag读取持久化数据写入到实体记忆中
*
* Obtain a memory decoder for reading persistent data from Compound Tag and writing it to entity memory
*
* @return the decoder
*/
Function getDecoder();
/**
* 获取记忆编码器,将实体记忆中的数据持久化进实体CompoundTag
*
* Get the memory encoder to persist the data in the entity memory into the entity Compound Tag
*
* @return the encoder
*/
BiConsumer getEncoder();
/**
* 从实体记忆初始化实体,可以用于初始化实体DataFlag.
*
* Initialize the entity from the entity memory, which can be used to initialize the entity Data Flag.
*
* @param data the data
* @param entity the entity
*/
void init(Data data, EntityIntelligent entity);
@Nullable
default Data decode(CompoundTag tag) {
return getDecoder().apply(tag);
}
default void encode(Data data, CompoundTag tag) {
getEncoder().accept(data, tag);
}
}