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


Java BlockRayHit类代码示例

本文整理汇总了Java中org.spongepowered.api.util.blockray.BlockRayHit的典型用法代码示例。如果您正苦于以下问题:Java BlockRayHit类的具体用法?Java BlockRayHit怎么用?Java BlockRayHit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BlockRayHit类属于org.spongepowered.api.util.blockray包,在下文中一共展示了BlockRayHit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: callback

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
protected ClickAction.ExecuteCallback callback(Chunk chunk) {
    return TextActions.executeCallback((commandSource -> {
        if (commandSource instanceof ConsoleSource) {
            commandSource.sendMessage(Text.of(TextColors.RED + "Silly console, you can't teleport."));
            return;
        }
        Player player = (Player) commandSource;
        Location<World> a = new Location<>(chunk.getWorld(), chunk.getPosition());
        Location<World> b = new Location<>(a.getExtent(), a.getX() * 16, a.getExtent().getBlockMax().getY(), a.getZ() * 16);
        Optional<BlockRayHit<World>> c = BlockRay.from(b).stopFilter(BlockRay.onlyAirFilter()).to(a.getPosition().sub(b.getX(), 1, b.getZ()))
                .end();

        if (c.isPresent()) {
            BlockRayHit<World> d = c.get();
            player.setLocation(d.getLocation());
        } else {
            commandSource.sendMessage(Text.of("Could not send you to: " + a.getX() + "," + a.getZ()));
        }
    }));
}
 
开发者ID:Time6628,项目名称:CatClearLag,代码行数:21,代码来源:LaggyChunksCommand.java

示例2: onRightClickBlock

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
@Listener
public void onRightClickBlock(InteractBlockEvent.Secondary evt, @Root Player player) {
    PlayerRightClicksBlockScriptEvent event = (PlayerRightClicksBlockScriptEvent) clone();
    event.internal = evt;
    event.player = new PlayerTag(player);
    if (evt.getTargetBlock().getLocation().isPresent()) {
        event.location = new LocationTag(evt.getTargetBlock().getLocation().get());
        event.precise_location = new LocationTag(evt.getInteractionPoint().get().add(evt.getTargetBlock().getPosition().toDouble()));
        event.precise_location.getInternal().world = event.location.getInternal().world;
        event.intersection_point = new LocationTag(evt.getInteractionPoint().get());
        event.impact_normal = new LocationTag(evt.getTargetSide().asOffset());
    }
    else {
        BlockRayHit<World> brh = BlockRay.from(player).distanceLimit(Utilities.getHandReach(player)).build().end().get();
        event.location = new LocationTag(brh.getLocation());
        event.precise_location = new LocationTag(brh.getPosition());
        event.precise_location.getInternal().world = event.location.getInternal().world;
        event.intersection_point = new LocationTag(brh.getPosition().sub(brh.getBlockPosition().toDouble()));
        event.impact_normal = new LocationTag(0, 0, 0);
    }
    event.hInternal = evt.getHandType();
    event.hand = new TextTag(Utilities.getIdWithoutDefaultPrefix(evt.getHandType().getId()));
    event.cancelled = evt.isCancelled();
    event.run();
    evt.setCancelled(event.cancelled);
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:27,代码来源:PlayerRightClicksBlockScriptEvent.java

示例3: getTarget

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
protected static <T extends Entity> T getTarget(Player player, int range, Collection<T> entities) {
	BlockRay iterator = BlockRay.from(player).blockLimit(range).build();
	while (iterator.hasNext()) {
		BlockRayHit block = iterator.next();
		for (T entity : entities) {
			int accuracy = 2;
			for (int offX = -accuracy; offX < accuracy; offX++) {
				for (int offY = -accuracy; offY < accuracy; offY++) {
					for (int offZ = -accuracy; offZ < accuracy; offZ++) {
						if (entity.getLocation().getBlockPosition().add(offX, offY, offZ)
								.equals(block.getLocation().getBlockPosition())) {
							return entity;
						}
					}
				}
			}
		}
	}
	return null;
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:21,代码来源:SpongeTargetUtils.java

示例4: invasion

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
@Command(desc = "Spawns a mob next to every player on the server")
public void invasion(CommandSource context, String mob)
{
    EntityType entityType = em.mob(mob, context.getLocale());
    if (entityType == null)
    {
        i18n.send(context, MessageType.NEGATIVE, "EntityType {input} not found", mob);
        return;
    }
    Sponge.getCauseStackManager().pushCause(context);
    for (Player player : Sponge.getServer().getOnlinePlayers())
    {
        Optional<BlockRayHit<World>> end =
            BlockRay.from(player).stopFilter(BlockRay.onlyAirFilter())
                .distanceLimit(module.getConfig().command.invasion.distance).build().end();
        if (end.isPresent())
        {
            Location<World> location = end.get().getLocation();
            Entity entity = location.getExtent().createEntity(entityType, location.getPosition());
            location.getExtent().spawnEntity(entity);
        }
    }
}
 
开发者ID:CubeEngine,项目名称:modules-extra,代码行数:24,代码来源:InvasionCommand.java

示例5: getLastTwoTargetBlocks

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
@Override
public List<Block> getLastTwoTargetBlocks(Set<Material> transparent, int maxDistance) {
    BlockRayHit<World> last = null;
    BlockRayHit<World> current = null;
    for (BlockRayHit<World> hit : getBlockRay(transparent, maxDistance)) {
        last = current;
        current = hit;
    }

    if (current == null) {
        return ImmutableList.of();
    } else if (last == null) {
        return ImmutableList.of(PoreBlock.of(current.getLocation()));
    } else {
        return ImmutableList.of(PoreBlock.of(last.getLocation()), PoreBlock.of(current.getLocation()));
    }
}
 
开发者ID:LapisBlue,项目名称:Pore,代码行数:18,代码来源:PoreLivingEntity.java

示例6: getViewBlock

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
/**
 * Retourne la position du block que le joueur regarde
 * @param limit La distance maximum du block
 * @return La position du block
 */
public Optional<Vector3i> getViewBlock(final double limit) {
	BlockRay<World> blocks = BlockRay.from(this.player).distanceLimit(limit).build();
	BlockRayHit<World> block = null;
	while(blocks.hasNext() && block == null) {
		BlockRayHit<World> tempoBlock = blocks.next();
		if (!this.getWorld().getBlockType(tempoBlock.getBlockPosition()).equals(BlockTypes.AIR)) {
			block = tempoBlock;
		}
	}
	if (block != null) {
		return Optional.of(block.getBlockPosition());
	}
	return Optional.empty();
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:20,代码来源:EPlayer.java

示例7: execute

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
	if (!(src instanceof Player)) {
		src.sendMessage(Messages.get("OnlyPlayersCanRunThis"));
		return CommandResult.empty();
	}
	
	final String kitName = args.<String>getOne("kit").get();
	
	if (!kitName.matches("[a-zA-Z0-9_-]+")) {
		src.sendMessage(Messages.get("KitNameInvalid"));
		return CommandResult.empty();
	}
	
	if (instance.getKit(kitName) != null) {
		src.sendMessage(Messages.get("KitAlreadyExist"));
		return CommandResult.empty();
	}

	BlockRay<World> blockRay = BlockRay.from(((Player)src)).distanceLimit(5).skipFilter(BlockRay.continueAfterFilter(BlockRay.onlyAirFilter(), 1)).build();
	Optional<BlockRayHit<World>> hitOpt = blockRay.end();
	if (hitOpt.isPresent() && instance.config().allowedChests.contains(hitOpt.get().getLocation().getBlock().getType())) {
	    instance.addKit(new Kit(kitName, hitOpt.get().getLocation()));
		try {
			instance.saveData();
			src.sendMessage(Text.of(TextColors.GREEN, "Kit created."));
		} catch (Exception e) {
			src.sendMessage(Text.of(TextColors.RED, "An error occurred while saving data."));
			e.printStackTrace();
		}
		
	} else {
		src.sendMessage(Messages.get("TargetBlockNotAllowed"));
	}
	
	return CommandResult.success();
}
 
开发者ID:KaiKikuchi,项目名称:BetterKits,代码行数:38,代码来源:CreateCommand.java

示例8: execute

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {

    if (!(src instanceof Player)) {
        return CommandResult.empty();
    }

    Player player = (Player) src;
    Location<World> location = null;
    Vector3d start = new Vector3d(player.getLocation().getPosition().getX(), 256, player.getLocation().getPosition().getZ());
    Vector3d end = new Vector3d(player.getLocation().getPosition().getX(), 0, player.getLocation().getPosition().getZ());
    BlockRay<World> blockRay = BlockRay.from(player.getWorld(), start).to(end)
            .skipFilter(BlockRay.continueAfterFilter(BlockRay.onlyAirFilter(), 5)).build();

    while (blockRay.hasNext() && location == null) {
        BlockRayHit<World> hit = blockRay.next();
        if (BlockUtil.isSolid(hit.getLocation())) {
            location = hit.getLocation();
        }
    }

    if (location != null && (location.getBlockY() != player.getLocation().getBlockY() - 1)) {
        Sponge.getGame().getEventManager().post(new PlayerTeleportPreEvent(player, player.getLocation(), player.getRotation()));
        Sponge.getGame().getEventManager().post(new PlayerTeleportTopEvent(player, location, player.getRotation()));
        return CommandResult.success();
    }

    player.sendMessage(MessagesUtil.error(player, "top.error"));
    return CommandResult.empty();
}
 
开发者ID:mmonkey,项目名称:Destinations,代码行数:31,代码来源:TopCommand.java

示例9: execute

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {

    if (!(src instanceof Player)) {
        return CommandResult.empty();
    }

    Player player = (Player) src;
    BlockRay<World> blockRay = BlockRay.from(player).skipFilter(BlockRay.continueAfterFilter(BlockRay.onlyAirFilter(), 5)).build();
    Location<World> location = null;

    while (blockRay.hasNext() && location == null) {
        BlockRayHit<World> hit = blockRay.next();
        if (BlockUtil.isSolid(hit.getLocation())) {
            location = hit.getLocation();
        }
    }

    if (location != null) {
        Sponge.getGame().getEventManager().post(new PlayerTeleportPreEvent(player, player.getLocation(), player.getRotation()));
        Sponge.getGame().getEventManager().post(new PlayerTeleportJumpEvent(player, location, player.getRotation()));
        return CommandResult.success();
    }

    player.sendMessage(MessagesUtil.error(player, "jump.error"));
    return CommandResult.empty();
}
 
开发者ID:mmonkey,项目名称:Destinations,代码行数:28,代码来源:JumpCommand.java

示例10: findNearbyClaim

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
private GPClaim findNearbyClaim(Player player) {
    int maxDistance = GriefPreventionPlugin.instance.maxInspectionDistance;
    BlockRay<World> blockRay = BlockRay.from(player).distanceLimit(maxDistance).build();
    GPPlayerData playerData = GriefPreventionPlugin.instance.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    GPClaim claim = null;
    int count = 0;
    while (blockRay.hasNext()) {
        BlockRayHit<World> blockRayHit = blockRay.next();
        Location<World> location = blockRayHit.getLocation();
        claim = this.dataStore.getClaimAt(location);
        if (claim != null && !claim.isWilderness() && (playerData.visualBlocks == null || (claim.id != playerData.visualClaimId))) {
            playerData.lastValidInspectLocation = location;
            return claim;
        }

        BlockType blockType = location.getBlockType();
        if (blockType != BlockTypes.AIR && blockType != BlockTypes.TALLGRASS) {
            break;
        }
        count++;
    }

    if (count == maxDistance) {
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.claimTooFar.toText());
    } else if (claim != null && claim.isWilderness()){
        GriefPreventionPlugin.sendMessage(player, GriefPreventionPlugin.instance.messageData.blockNotClaimed.toText());
    }

    return claim;
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:31,代码来源:PlayerEventHandler.java

示例11: getTargetBlock

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
public static Optional<Location<World>> getTargetBlock(Player player, GPPlayerData playerData, int maxDistance, boolean ignoreAir) throws IllegalStateException {
    BlockRay<World> blockRay = BlockRay.from(player).distanceLimit(maxDistance).build();
    GPClaim claim = null;
    if (playerData.visualClaimId != null) {
        claim = (GPClaim) GriefPreventionPlugin.instance.dataStore.getClaim(player.getWorld().getProperties(), playerData.visualClaimId);
    }

    while (blockRay.hasNext()) {
        BlockRayHit<World> blockRayHit = blockRay.next();
        if (claim != null) {
            for (Vector3i corner : claim.getVisualizer().getVisualCorners()) {
                if (corner.equals(blockRayHit.getBlockPosition())) {
                    return Optional.of(blockRayHit.getLocation());
                }
            }
        }
        if (ignoreAir) {
            if (blockRayHit.getLocation().getBlockType() != BlockTypes.TALLGRASS) {
                return Optional.of(blockRayHit.getLocation());
            }
        } else { 
            if (blockRayHit.getLocation().getBlockType() != BlockTypes.AIR &&
                    blockRayHit.getLocation().getBlockType() != BlockTypes.TALLGRASS) {
                return Optional.of(blockRayHit.getLocation());
            }
        }
    }

    return Optional.empty();
}
 
开发者ID:MinecraftPortCentral,项目名称:GriefPrevention,代码行数:31,代码来源:BlockUtils.java

示例12: parseValue

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
    String xStr;
    String yStr;
    String zStr;
    xStr = args.next();
    if (xStr.contains(",")) {
        String[] split = xStr.split(",");
        if (split.length != 3) {
            throw args.createError(t("Comma-separated location must have 3 elements, not %s", split.length));
        }
        xStr = split[0];
        yStr = split[1];
        zStr = split[2];
    } else if (xStr.equals("#target") && source instanceof Entity) {
        Optional<BlockRayHit<World>> hit = BlockRay.from(((Entity) source))
                .stopFilter(BlockRay.onlyAirFilter()).build().end();
        if (!hit.isPresent()) {
            throw args.createError(t("No target block is available! Stop stargazing!"));
        }
        return hit.get().getPosition();
    } else if (xStr.equalsIgnoreCase("#me") && source instanceof Locatable) {
        return ((Locatable) source).getLocation().getPosition();
    } else {
        yStr = args.next();
        zStr = args.next();
    }
    final RelativeDouble x = parseRelativeDouble(args, xStr);
    final RelativeDouble y = parseRelativeDouble(args, yStr);
    final RelativeDouble z = parseRelativeDouble(args, zStr);

    return new RelativeVector3d(x, y, z);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:34,代码来源:GenericArguments2.java

示例13: execute

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	if (src instanceof Player)
	{
		Player player = (Player) src;

		BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(5).build();
		BlockRayHit<World> finalHitRay = null;

		while (playerBlockRay.hasNext())
		{
			BlockRayHit<World> currentHitRay = playerBlockRay.next();

			if (!player.getWorld().getBlockType(currentHitRay.getBlockPosition()).equals(BlockTypes.AIR))
			{
				finalHitRay = currentHitRay;
				break;
			}
		}

		if (finalHitRay != null)
		{
			player.sendMessage(Text.of(TextColors.GOLD, "The name of the block you're looking at is: ", TextColors.GRAY, finalHitRay.getLocation().getBlock().getType().getTranslation().get()));
			player.sendMessage(Text.of(TextColors.GOLD, "The ID of the block you're looking at is: ", TextColors.GRAY, finalHitRay.getLocation().getBlock().getName()));
			Optional<Object> metaDataQuery = finalHitRay.getLocation().getBlock().toContainer().get(DataQuery.of("UnsafeMeta"));
			player.sendMessage(Text.of(TextColors.GOLD, "The meta of the block you're looking at is: ", TextColors.GRAY, metaDataQuery.isPresent() ? metaDataQuery.get().toString() : 0));
		}
		else
		{
			player.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You're not looking at any block within range."));
		}
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "You must be an in-game player to use this command."));
	}

	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:40,代码来源:BlockInfoExecutor.java

示例14: getSpawnLocFromPlayerLoc

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
public Location<World> getSpawnLocFromPlayerLoc(Player player)
{
	BlockRay<World> playerBlockRay = BlockRay.from(player).blockLimit(350).build();
	BlockRayHit<World> finalHitRay = null;

	while (playerBlockRay.hasNext())
	{
		BlockRayHit<World> currentHitRay = playerBlockRay.next();

		if (!player.getWorld().getBlockType(currentHitRay.getBlockPosition()).equals(BlockTypes.AIR))
		{
			finalHitRay = currentHitRay;
			break;
		}
	}

	Location<World> spawnLocation = null;

	if (finalHitRay == null)
	{
		spawnLocation = player.getLocation();
	}
	else
	{
		spawnLocation = finalHitRay.getLocation();
	}

	return spawnLocation;
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:30,代码来源:MobSpawnExecutor.java

示例15: getTargetBlock

import org.spongepowered.api.util.blockray.BlockRayHit; //导入依赖的package包/类
protected static Location getTargetBlock(Player player, int range) {
	BlockRay iterator = BlockRay.from(player).blockLimit(range).filter(new Predicate<BlockRayHit>() {
		@Override
		public boolean apply(BlockRayHit hit) {
			return hit.getExtent().getBlockType(hit.getBlockX(), hit.getBlockY(), hit.getBlockZ()) != BlockTypes.AIR;
		}
	}).build();
	return iterator.next().getLocation();
}
 
开发者ID:mcardy,项目名称:Zephyr,代码行数:10,代码来源:SpongeTargetUtils.java


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