use of org.lanternpowered.server.entity.LanternEntityType in project LanternServer by LanternPowered.
the class LanternWorld method createEntity.
public Entity createEntity(EntityType type, Vector3d position, Consumer<Entity> entityConsumer) {
checkNotNull(position, "position");
final LanternEntityType entityType = (LanternEntityType) checkNotNull(type, "type");
final LanternEntity entity = (LanternEntity) entityType.getEntityConstructor().apply(UUID.randomUUID());
entity.setPositionAndWorld(this, position);
entityConsumer.accept(entity);
final CauseStack causeStack = CauseStack.current();
// Only throw the post event, the pre event will
// only be called in specific cases.
final ConstructEntityEvent.Post event = SpongeEventFactory.createConstructEntityEventPost(causeStack.getCurrentCause(), entity, type, entity.getTransform());
Sponge.getEventManager().post(event);
return entity;
}
use of org.lanternpowered.server.entity.LanternEntityType in project LanternServer by LanternPowered.
the class LanternChunk method createEntity.
@SuppressWarnings("unchecked")
@Override
public Entity createEntity(EntityType type, Vector3d position) {
checkNotNull(position, "position");
final LanternEntityType entityType = (LanternEntityType) checkNotNull(type, "type");
checkVolumeBounds(position.getFloorX(), position.getFloorY(), position.getFloorZ());
// noinspection unchecked
final LanternEntity entity = (LanternEntity) entityType.getEntityConstructor().apply(UUID.randomUUID());
entity.setPositionAndWorld(this.world, position);
return entity;
}
use of org.lanternpowered.server.entity.LanternEntityType in project LanternServer by LanternPowered.
the class EntitySerializer method deserialize.
@Override
public LanternEntity deserialize(DataView dataView) throws InvalidDataException {
String id0 = dataView.getString(ID).get();
final String id;
// Fast fail if the data isn't old
if (dataView.getInt(DATA_VERSION).orElse(0) < 704) {
id = fixEntityId(dataView, id0);
} else {
id = id0;
}
dataView.remove(ID);
final LanternEntityType entityType = (LanternEntityType) Sponge.getRegistry().getType(EntityType.class, id).orElseThrow(() -> new InvalidDataException("Unknown entity id: " + id));
// noinspection unchecked
final ObjectStore<LanternEntity> store = (ObjectStore) ObjectStoreRegistry.get().get(entityType.getEntityClass()).get();
final UUID uniqueId;
if (store instanceof IdentifiableObjectStore) {
uniqueId = ((IdentifiableObjectStore) store).deserializeUniqueId(dataView);
} else {
uniqueId = UUID.randomUUID();
}
// noinspection unchecked
final LanternEntity entity = (LanternEntity) entityType.getEntityConstructor().apply(uniqueId);
store.deserialize(entity, dataView);
return entity;
}
Aggregations