當前位置: 首頁>>代碼示例>>Java>>正文


Java BlockIterator類代碼示例

本文整理匯總了Java中org.bukkit.util.BlockIterator的典型用法代碼示例。如果您正苦於以下問題:Java BlockIterator類的具體用法?Java BlockIterator怎麽用?Java BlockIterator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


BlockIterator類屬於org.bukkit.util包,在下文中一共展示了BlockIterator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isInLineOfSight

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
/**
 * @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;
}
 
開發者ID:davidm98,項目名稱:Crescent,代碼行數:25,代碼來源:KillauraB.java

示例2: getLineOfSight

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:26,代碼來源:CraftLivingEntity.java

示例3: getLineOfSight

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:CyberdyneCC,項目名稱:ThermosRebased,代碼行數:26,代碼來源:CraftLivingEntity.java

示例4: getTarget

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:mcardy,項目名稱:Zephyr,代碼行數:20,代碼來源:BukkitTargetUtils.java

示例5: getTarget

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:FabioZumbi12,項目名稱:RedProtect,代碼行數:21,代碼來源:RPPlayerListener.java

示例6: getTargetBlock

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:SupaHam,項目名稱:SupaCommons,代碼行數:23,代碼來源:TargetingUtils.java

示例7: getTargetEntity

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:mcardy,項目名稱:Zephyrus-II,代碼行數:22,代碼來源:OnlineUser.java

示例8: getTargetBlock

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:Gamegine,項目名稱:Gamegine,代碼行數:23,代碼來源:CmdSign.java

示例9: getLineOfSightNoTransparent

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:itsjoekent,項目名稱:SniperGamemode,代碼行數:25,代碼來源:Utils.java

示例10: getTargetBlock

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:JCThePants,項目名稱:NucleusFramework,代碼行數:28,代碼來源:PlayerUtils.java

示例11: getLineOfSight

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:WaywardRealms,項目名稱:Wayward,代碼行數:26,代碼來源:LineOfSightUtils.java

示例12: use

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
@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;
}
 
開發者ID:WaywardRealms,項目名稱:Wayward,代碼行數:17,代碼來源:QuickStepSkill.java

示例13: getLineOfSight

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:WaywardRealms,項目名稱:Wayward,代碼行數:17,代碼來源:PlayerInteractListener.java

示例14: getLineOfSight

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:WaywardRealms,項目名稱:Wayward,代碼行數:17,代碼來源:JumpCommand.java

示例15: getLineOfSight

import org.bukkit.util.BlockIterator; //導入依賴的package包/類
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;
}
 
開發者ID:WaywardRealms,項目名稱:Wayward,代碼行數:17,代碼來源:SpawnerCommand.java


注:本文中的org.bukkit.util.BlockIterator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。