本文整理汇总了Java中org.spongepowered.api.world.extent.EntityUniverse类的典型用法代码示例。如果您正苦于以下问题:Java EntityUniverse类的具体用法?Java EntityUniverse怎么用?Java EntityUniverse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityUniverse类属于org.spongepowered.api.world.extent包,在下文中一共展示了EntityUniverse类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: spawn
import org.spongepowered.api.world.extent.EntityUniverse; //导入依赖的package包/类
private Optional<Entity> spawn(EntityType entityType, Entity causeAndLocation) {
Location<World> location = causeAndLocation.getLocation();
EntityUniverse entityUniverse = location.getExtent();
Optional<Entity> optionalEntity = entityUniverse.createEntity(entityType, location.getPosition());
if (optionalEntity.isPresent()) {
Entity newEntity = optionalEntity.get();
Cause cause = Cause.source(EntitySpawnCause.builder().entity(causeAndLocation).type(SpawnTypes.PLUGIN).build()).build();
boolean isSpawned = entityUniverse.spawnEntity(newEntity, cause);
if (!isSpawned) {
logger.error("Could not spawn new Entity: " + entityType.getName());
return Optional.empty();
}
return Optional.of(newEntity);
} else {
logger.error("Could not create new Entity: " + entityType.getName());
return Optional.empty();
}
}
示例2: applyOnNearby
import org.spongepowered.api.world.extent.EntityUniverse; //导入依赖的package包/类
public static void applyOnNearby(IActiveCharacter character, int distance, Consumer<Entity> e) {
character.getPlayer().getWorld()
.getIntersectingEntities(character.getPlayer(), distance, hit -> hit.getEntity() != character.getPlayer())
.stream().map(EntityUniverse.EntityHit::getEntity)
.filter(Utils::isLivingEntity)
.forEach(e);
}
示例3: applyOnNearbyAndSelf
import org.spongepowered.api.world.extent.EntityUniverse; //导入依赖的package包/类
public static void applyOnNearbyAndSelf(IActiveCharacter character, int distance, Consumer<Entity> e) {
character.getPlayer().getWorld()
.getIntersectingEntities(character.getPlayer(), distance)
.stream().map(EntityUniverse.EntityHit::getEntity)
.filter(Utils::isLivingEntity)
.forEach(e);
}
示例4: getTargettedEntity
import org.spongepowered.api.world.extent.EntityUniverse; //导入依赖的package包/类
public static Living getTargettedEntity(IActiveCharacter character, int range) {
Player player = character.getPlayer();
Vector3d r = player.getRotation();
Vector3d dir = Quaterniond.fromAxesAnglesDeg(r.getX(), -r.getY(), r.getZ()).getDirection();
Vector3d vec3d = player.getProperty(EyeLocationProperty.class).get().getValue();
Optional<EntityUniverse.EntityHit> e = player
.getWorld()
.getIntersectingEntities(vec3d, dir, range, entityHit -> entityHit.getEntity() != character.getEntity() && isLivingEntity(entityHit.getEntity()))
.stream().reduce((a, b) -> a.getDistance() < b.getDistance() ? a : b);
if (e.isPresent()) {
Optional<BlockRayHit<World>> end = BlockRay.from(player)
.distanceLimit(range)
.stopFilter(SKILL_TARGET_BLOCK_FILTER)
.build()
.end();
if (!end.isPresent()) {
return (Living) e.get().getEntity();
} else {
Entity entity = e.get().getEntity();
Location<World> location = entity.getLocation();
if (end.get().getBlockPosition()
.distanceSquared(location.getBlockX(), location.getBlockZ(), location.getBlockZ()) <= 2) {
return (Living) e.get().getEntity();
}
}
}
return null;
}
示例5: spawn
import org.spongepowered.api.world.extent.EntityUniverse; //导入依赖的package包/类
public <T extends Entity> T spawn(Class<T> entityClass, Location<World> location) throws MinecraftHelperException {
EntityType entityType = getEntityType(entityClass);
EntityUniverse entityUniverse = location.getExtent();
Optional<Entity> optionalEntity = entityUniverse.createEntity(entityType, location.getPosition());
if (optionalEntity.isPresent()) {
@SuppressWarnings("unchecked") T newEntity = (T) optionalEntity.get();
boolean isSpawned = entityUniverse.spawnEntity(newEntity, null /* Cause.empty() */);
if (!isSpawned)
throw new MinecraftHelperException("Could not spawn new Entity: " + entityType.getName());
return newEntity;
} else {
throw new MinecraftHelperException("Could not create new Entity: " + entityType.getName());
}
}