Java 类org.bukkit.util.BlockIterator 实例源码

项目:Crescent    文件:KillauraB.java   
/**
 * @param check
 *            The entity to check whether
 * @param distance
 *            The difference in distance to allow for.
 * @return
 */
private boolean isInLineOfSight(Entity check, double distance) {
    final Location entityLocation = check.getLocation();
    final BlockIterator iterator = new BlockIterator(profile.getPlayer().getEyeLocation(), 0.0, 7);

    while (iterator.hasNext()) {
        final Location current = iterator.next().getLocation();

        if (getLocationDifference(current, entityLocation, "X") < distance
                && getLocationDifference(current, entityLocation, "Y") < distance
                && getLocationDifference(current, entityLocation, "Z") < distance) {
            return true;
        }
    }

    // The entity has not been found in the player's line of sight.
    return false;
}
项目:Uranium    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        byte id = (byte)block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains(id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Uranium    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(Set<Material> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        Material material = block.getType();
        if (transparent == null) {
            if (!material.equals(Material.AIR)) {
                break;
            }
        } else {
            if (!transparent.contains(material)) {
                break;
            }
        }
    }
    return blocks;
}
项目:ThermosRebased    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Thermos    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:KCauldron    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:CauldronGit    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Cauldron-Old    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Cauldron-Reloaded    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Zephyr    文件:BukkitTargetUtils.java   
public static <T extends Entity> T getTarget(Player player, int range, Collection<T> entities) {
    BlockIterator iterator = new BlockIterator(player, range);
    while (iterator.hasNext()) {
        Block 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().getBlock().getRelative(offX, offY, offZ).equals(block)) {
                            return entity;
                        }
                    }
                }
            }
        }
    }
    return null;
}
项目:RedProtect    文件:RPPlayerListener.java   
private static Entity getTarget(final Player player) {
    try {
        BlockIterator iterator = new BlockIterator(player.getWorld(), player
                .getLocation().toVector(), player.getEyeLocation()
                .getDirection(), 0, 10);
        while (iterator.hasNext()) {
            Block item = iterator.next();
            for (Entity entity : player.getNearbyEntities(10, 10, 10)) {
                int acc = 2;
                for (int y = -acc; y < acc; y++){
                    if (entity.getLocation().getBlock()
                            .getRelative(0, y, 0).equals(item)) {
                        return entity;
                    }
                }
            }
        }
    } catch(IllegalStateException ignored){}
    return null;
}
项目:FFoKC    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:CraftBukkit    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:SupaCommons    文件:TargetingUtils.java   
public static Block getTargetBlock(@Nullable Set<Material> transparent, 
                                   @Nonnull Location location, int maxDistance) {
  Preconditions.checkNotNull(location, "location cannot be null.");
  if (maxDistance > 120) {
    maxDistance = 120;
  }

  Block result = null;
  BlockIterator itr = new BlockIterator(location, 0, maxDistance);
  while (itr.hasNext()) {
    result = itr.next();
    Material material = result.getType();
    if (transparent == null) {
      if (!material.equals(Material.AIR)) {
        break;
      }
    } else if (!transparent.contains(material)) {
      break;
    }
  }
  return result;
}
项目:Craftbukkit    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Craftbukkit    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(Set<Material> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        Material material = block.getType();
        if (transparent == null) {
            if (!material.equals(Material.AIR)) {
                break;
            }
        } else {
            if (!transparent.contains(material)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Almura-Server    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Zephyrus-II    文件:OnlineUser.java   
private LivingEntity getTargetEntity(int range) {
    BlockIterator iterator = new BlockIterator(player, range);
    while (iterator.hasNext()) {
        Block block = iterator.next();
        for (Entity entity : player.getNearbyEntities(range, range, range)) {
            if (entity instanceof LivingEntity) {
                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().getBlock().getRelative(offX, offY, offZ).equals(block)) {
                                return (LivingEntity) entity;
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
项目:Tweakkit-Server    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Cauldron    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Gamegine    文件:CmdSign.java   
private Block getTargetBlock(Player player) {
    BlockIterator iterator = new BlockIterator(player.getEyeLocation(), 0D, 10);
    Block block = null;
    while (iterator.hasNext()) {
        Block b = iterator.next();
        if (b != null && b.getType() != Material.AIR) {
            block = b;
            break;
        }
    }

    if (block == null) {
        plugin.getMessageManager().getMessage("errors.must_look_at_sign").sendTo(player);
        return null;
    }

    if (!(block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN)) {
        plugin.getMessageManager().getMessage("errors.block_not_sign").sendTo(player);
        return null;
    }
    return block;
}
项目:SniperGamemode    文件:Utils.java   
/**
 * Gets all blocks in a player line of sight including air
 * Modified from deprecated bukkit method by removing magic value usage
 * and including air.
 * @param entity Entity line of sight to get
 * @param maxDistance Maximum distance to get
 * @param maxLength Maximum length of the array, 0 to ignore this
 * @return List of blocks in the line of sight
 */
public static List<Block> getLineOfSightNoTransparent(LivingEntity entity, int maxDistance, int maxLength){
    if(maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(entity, maxDistance);
    while(itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if(maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
    }
    return blocks;
}
项目:NucleusFramework    文件:PlayerUtils.java   
/**
 * Iterates over blocks in the direction the player is looking until the
 * max distance is reached or a block that isn't {@link org.bukkit.Material#AIR}
 * is found.
 *
 * @param player       The {@link Player}.
 * @param maxDistance  The max distance to search.
 *
 * @return  The {@link Block} that was found or null if the max distance was reached.
 */
@Nullable
public static Block getTargetBlock(Player player, int maxDistance) {
    PreCon.notNull(player);
    PreCon.positiveNumber(maxDistance);

    BlockIterator bit = new BlockIterator(player, maxDistance);
    Block next;
    while(bit.hasNext())
    {
        next = bit.next();

        if (next != null && next.getType() != Material.AIR)
            return next;
    }

    return null;
}
项目:Wayward    文件:LineOfSightUtils.java   
private static List<Block> getLineOfSight(LivingEntity entity, Collection<Material> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<>();
    Iterator<Block> itr = new BlockIterator(entity, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        Material material = block.getType();
        if (transparent == null) {
            if (material != Material.AIR) {
                break;
            }
        } else {
            if (!transparent.contains(material)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Wayward    文件:QuickStepSkill.java   
@Override
public boolean use(Player player) {
    Iterator<Block> blockIterator = new BlockIterator(player, 6);
    Block block = player.getWorld().getBlockAt(player.getLocation());
    while (blockIterator.hasNext()) {
        Block next = blockIterator.next();
        if (next.getType().isSolid()) break;
        if (next.getLocation().distanceSquared(player.getLocation()) > 36) break;
        block = next;
    }
    float yaw = player.getLocation().getYaw();
    Location location = block.getLocation();
    location.setYaw(yaw);
    player.teleport(location);
    return true;
}
项目:Wayward    文件:PlayerInteractListener.java   
private List<Block> getLineOfSight(Player player, int maxDistance) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<>();
    Iterator<Block> iterator = new BlockIterator(player, maxDistance);
    while (iterator.hasNext()) {
        Block block = iterator.next();
        Material material = block.getType();
        if (material != Material.AIR) {
            blocks.add(block);
            break;
        }
    }
    return blocks;
}
项目:Wayward    文件:JumpCommand.java   
private List<Block> getLineOfSight(LivingEntity entity) {
    ArrayList<Block> blocks = new ArrayList<>();
    Iterator<Block> itr = new BlockIterator(entity, 64);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (blocks.size() > 1) {
            blocks.remove(0);
        }
        Material material = block.getType();
        if (material != Material.AIR) {
            break;
        }
    }
    return blocks;
}
项目:Wayward    文件:SpawnerCommand.java   
private List<Block> getLineOfSight(LivingEntity entity) {
    ArrayList<Block> blocks = new ArrayList<>();
    Iterator<Block> itr = new BlockIterator(entity, 32);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (blocks.size() > 1) {
            blocks.remove(0);
        }
        Material material = block.getType();
        if (material != Material.AIR) {
            break;
        }
    }
    return blocks;
}
项目:SpigotSource    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:SpigotSource    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(Set<Material> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        Material material = block.getType();
        if (transparent == null) {
            if (!material.equals(Material.AIR)) {
                break;
            }
        } else {
            if (!transparent.contains(material)) {
                break;
            }
        }
    }
    return blocks;
}
项目:GoldRushPlugin    文件:MineGenerator.java   
private void populateGold(World w, Integer numVeins, Integer veinLength) {

        //loops on number of veins specified
        for (int i = 0; i < numVeins; i++) {
            //uses a random set of vectors to get the points for the gold vein to be drew.
            Vector location = randomConstrainedVector(mineMin, mineMax);
            Vector newLocation = randomConstrainedVector(mineMin, mineMax);

            //limit the length of ore veins
            int distance = (int) Math.floor(location.distance(newLocation) - 1);
            if ((int) Math.floor(location.distance(newLocation) - 1) > veinLength) {
                distance = veinLength;
            }

            BlockIterator bli = new BlockIterator(w, location, new Vector(newLocation.getBlockX() - location.getBlockX(), newLocation.getBlockY() - location.getBlockY(), newLocation.getBlockZ() - location.getBlockZ()), 0, distance - 1);

            //BlockIterator draws lines of a block between two specified Vectors
            Location blockToAdd;
            while (bli.hasNext()) {
                blockToAdd = bli.next().getLocation();
                w.getBlockAt(new Location(blockToAdd.getWorld(), blockToAdd.getBlockX(), blockToAdd.getBlockY(), blockToAdd.getBlockZ())).setType(Material.GOLD_ORE);
            }
        }
    }
项目:GoldRushPlugin    文件:MineTool.java   
private void populateGold(World w, Player p, Integer numVeins, Integer veinLength) {

    //loops on number of veins specified
    for(int i = 0; i < numVeins; i++){
        //uses a random set of vectors to get the points for the gold vein to be drew.
        Vector location = randomConstrainedVector(MineLis.mineMin.get(p), MineLis.mineMax.get(p));
        Vector newLocation = randomConstrainedVector(MineLis.mineMin.get(p), MineLis.mineMax.get(p));

        //limit the length of ore veins
        int distance = (int) Math.floor(location.distance(newLocation) - 1);
        if((int) Math.floor(location.distance(newLocation) - 1) > veinLength) {
            distance = veinLength;
        }

        BlockIterator bli = new BlockIterator(w, location, new Vector(newLocation.getBlockX()-location.getBlockX(), newLocation.getBlockY()-location.getBlockY(), newLocation.getBlockZ()-location.getBlockZ()), 0, distance - 1);

        //BlockIterator draws lines of a block between two specified Vectors
        Location blockToAdd;
        while(bli.hasNext()) {
            blockToAdd = bli.next().getLocation();
            w.getBlockAt(new Location(blockToAdd.getWorld(), blockToAdd.getBlockX(), blockToAdd.getBlockY(), blockToAdd.getBlockZ())).setType(Material.GOLD_ORE);
        }
    }
}
项目:ReadySetJump    文件:ReadySetJumpPlugin.java   
@EventHandler
private void onPlayerMove(PlayerMoveEvent pme) {
  Location loc = pme.getTo().clone();
  Vector diff = loc.toVector().subtract(pme.getFrom().toVector());
  diff.multiply(2); // Magic value, should be playerPing * 20, but playerPing is as reliable as Math.random()
  if(diff.lengthSquared() < 1) {
    loc.subtract(0, .01, 0);
    if(loc.getY() < 0 || loc.getY() >= 256)
      return;
    launch(loc.getBlock(), pme.getPlayer());
  } else {
    if(loc.getY() < 0 || loc.getY() >= 256)
      return;
    BlockIterator iterator = new BlockIterator(loc.getWorld(), loc.toVector(), diff.clone().normalize(), -0.1, (int)Math.ceil(diff.length()));
    while (iterator.hasNext()) {
      if(launch(iterator.next(), pme.getPlayer()))
        return;
    }
  }
}
项目:NPlugins    文件:PlayerUtil.java   
/**
 * Gets all blocks along the living entity's line of sight.
 * <p>
 * This list contains all blocks from the living entity's eye position
 * to target inclusive.
 * <p>
 * This is a direct translation of the following deprecated method:
 * {@link LivingEntity#getLineOfSight(HashSet, int)}
 *
 * @param player      the player
 * @param transparent HashSet containing all transparent block IDs
 *                    (set to null for only air)
 * @param maxDistance this is the maximum distance to scan (may be
 *                    limited by server by at least 100 blocks, no less)
 * @param maxLength   maximum size of returned list
 *
 * @return list containing all blocks along the living entity's line
 * of sight
 */
public static List<Block> getLineOfSight(final Player player, final Set<Material> transparent, int maxDistance, final int maxLength) {
    if (maxDistance > LINEOFSIGHT_MAXDISTANCE) {
        maxDistance = LINEOFSIGHT_MAXDISTANCE;
    }
    final List<Block> blocks = new ArrayList<>();
    final Iterator<Block> itr = new BlockIterator(player, maxDistance);
    while (itr.hasNext()) {
        final Block b = itr.next();
        blocks.add(b);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        final Material m = b.getType();
        if (transparent == null) {
            if (m != Material.AIR) {
                break;
            }
        } else {
            if (!transparent.contains(m)) {
                break;
            }
        }
    }
    return blocks;
}
项目:NPlugins    文件:PlayerUtil.java   
/**
 * Gets the block that the living entity has targeted.
 * <p>
 * This is a direct translation of the following deprecated method:
 * {@link LivingEntity#getTargetBlock(HashSet, int)}
 *
 * @param player      the player
 * @param transparent HashSet containing all transparent block IDs
 *                    (set to null for only air)
 * @param maxDistance this is the maximum distance to scan (may be
 *                    limited by server by at least 100 blocks, no less)
 *
 * @return block that the living entity has targeted or null is only
 * transparent blocks in line of sight
 */
public static Block getTargetBlock(final Player player, final Set<Material> transparent, int maxDistance) {
    if (maxDistance > LINEOFSIGHT_MAXDISTANCE) {
        maxDistance = LINEOFSIGHT_MAXDISTANCE;
    }
    final Iterator<Block> itr = new BlockIterator(player, maxDistance);
    Block result = null;
    while (itr.hasNext()) {
        result = itr.next();
        final Material m = result.getType();
        if (transparent == null) {
            if (m != Material.AIR) {
                break;
            }
        } else {
            if (!transparent.contains(m)) {
                break;
            }
        }
    }
    return result;
}
项目:RodsTwo    文件:Pickpocket.java   
private Entity getTarget(Player player) {
    BlockIterator iterator = new BlockIterator(player.getWorld(), player
            .getLocation().toVector(), player.getEyeLocation()
            .getDirection(), 0, 100);
    Entity target = null;
    while (iterator.hasNext()) {
        Block item = iterator.next();
        for (Entity entity : player.getNearbyEntities(100, 100, 100)) {
            int acc = 2;
            for (int x = -acc; x < acc; x++)
                for (int z = -acc; z < acc; z++)
                    for (int y = -acc; y < acc; y++)
                        if (entity.getLocation().getBlock()
                                .getRelative(x, y, z).equals(item)) 
                            return target = entity;
        }
    }
    return target;
}
项目:RodsTwo    文件:Curse.java   
private Entity getTarget(Player player) {

        BlockIterator iterator = new BlockIterator(player.getWorld(), player
                .getLocation().toVector(), player.getEyeLocation()
                .getDirection(), 0, 100);
        Entity target = null;
        while (iterator.hasNext()) {
            Block item = iterator.next();
            for (Entity entity : player.getNearbyEntities(100, 100, 100)) {
                int acc = 2;
                for (int x = -acc; x < acc; x++)
                    for (int z = -acc; z < acc; z++)
                        for (int y = -acc; y < acc; y++)
                            if (entity.getLocation().getBlock()
                                    .getRelative(x, y, z).equals(item)) 
                                return target = entity;
            }
        }
        return target;
    }
项目:Craft-city    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:MCPBukkit    文件:CraftLivingEntity.java   
private List<Block> getLineOfSight(HashSet<Byte> transparent, int maxDistance, int maxLength) {
    if (maxDistance > 120) {
        maxDistance = 120;
    }
    ArrayList<Block> blocks = new ArrayList<Block>();
    Iterator<Block> itr = new BlockIterator(this, maxDistance);
    while (itr.hasNext()) {
        Block block = itr.next();
        blocks.add(block);
        if (maxLength != 0 && blocks.size() > maxLength) {
            blocks.remove(0);
        }
        int id = block.getTypeId();
        if (transparent == null) {
            if (id != 0) {
                break;
            }
        } else {
            if (!transparent.contains((byte) id)) {
                break;
            }
        }
    }
    return blocks;
}
项目:Zephyrus    文件:Spell.java   
/**
 * Gets the player's target entity
 * 
 * @param player
 *            The player to get the target of
 * @return Null if there is no target
 */
public Entity getTarget(Player player) {
    BlockIterator iterator = new BlockIterator(player.getWorld(), player.getLocation().toVector(), player
            .getEyeLocation().getDirection(), 0, 100);
    while (iterator.hasNext()) {
        Block item = iterator.next();
        for (Entity entity : player.getNearbyEntities(10, 10, 10)) {
            int acc = 2;
            for (int x = -acc; x < acc; x++) {
                for (int z = -acc; z < acc; z++) {
                    for (int y = -acc; y < acc; y++) {
                        if (entity.getLocation().getBlock().getRelative(x, y, z).equals(item)) {
                            return entity;
                        }
                    }
                }
            }
        }
    }
    return null;
}