9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-30 12:29:15 +00:00

feat(entity): 为 EntityData 接口添加 entityDataAccessor 方法并实现

This commit is contained in:
jhqwqmc
2025-06-06 18:32:25 +08:00
parent b8483c00e8
commit 058b327612
2 changed files with 10 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ public interface EntityData<T> {
Object serializer();
int id();
T defaultValue();
Object entityDataAccessor();
default Object createEntityDataIfNotDefaultValue(T value) {
if (defaultValue().equals(value)) return null;

View File

@@ -1,14 +1,18 @@
package net.momirealms.craftengine.bukkit.entity.data;
import net.momirealms.craftengine.bukkit.nms.FastNMS;
public class SimpleEntityData<T> implements EntityData<T> {
private final int id;
private final Object serializer;
private final T defaultValue;
private final Object entityDataAccessor;
public SimpleEntityData(int id, Object serializer, T defaultValue) {
this.id = id;
this.serializer = serializer;
this.defaultValue = defaultValue;
this.entityDataAccessor = FastNMS.INSTANCE.constructor$EntityDataAccessor(id, serializer);
}
@Override
@@ -25,4 +29,9 @@ public class SimpleEntityData<T> implements EntityData<T> {
public T defaultValue() {
return defaultValue;
}
@Override
public Object entityDataAccessor() {
return entityDataAccessor;
}
}