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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user