當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。