本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}