Search in sources :

Example 1 with CustomEntityDescriptor

use of net.glowstone.entity.CustomEntityDescriptor in project Glowstone by GlowstoneMC.

the class GlowWorld method spawnCustomEntity.

/**
 * Spawn a custom entity at the given {@link Location}, with the given {@link SpawnReason}.
 *
 * @param location the {@link Location} to spawn the entity at
 * @param id       the id of the custom entity
 * @param reason   the reason for the spawning of the entity
 * @param <T>      the class of the {@link Entity} to spawn
 * @return an instance of the spawned {@link Entity}
 */
@SuppressWarnings("unchecked")
public <T extends Entity> T spawnCustomEntity(Location location, String id, SpawnReason reason) throws IllegalArgumentException {
    checkNotNull(location);
    checkNotNull(id);
    CustomEntityDescriptor descriptor = EntityRegistry.getCustomEntityDescriptor(id);
    if (descriptor == null) {
        throw new IllegalArgumentException("Could not find a custom entity descriptor for the given id '" + id + "'");
    }
    return (T) spawn(location, descriptor.getEntityClass(), reason);
}
Also used : CustomEntityDescriptor(net.glowstone.entity.CustomEntityDescriptor)

Aggregations

CustomEntityDescriptor (net.glowstone.entity.CustomEntityDescriptor)1