当前位置: 首页>>代码示例>>Java>>正文


Java EntityUniverse类代码示例

本文整理汇总了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();
	}
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:19,代码来源:LearningPlugin.java

示例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);
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:8,代码来源:Utils.java

示例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);
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:8,代码来源:Utils.java

示例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;
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:31,代码来源:Utils.java

示例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());
	}
}
 
开发者ID:vorburger,项目名称:SwissKnightMinecraft,代码行数:15,代码来源:SpawnHelper.java


注:本文中的org.spongepowered.api.world.extent.EntityUniverse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。