本文整理汇总了Java中cn.nukkit.utils.BlockIterator.next方法的典型用法代码示例。如果您正苦于以下问题:Java BlockIterator.next方法的具体用法?Java BlockIterator.next怎么用?Java BlockIterator.next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cn.nukkit.utils.BlockIterator
的用法示例。
在下文中一共展示了BlockIterator.next方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLineOfSight
import cn.nukkit.utils.BlockIterator; //导入方法依赖的package包/类
public Block[] getLineOfSight(int maxDistance, int maxLength, Integer[] transparent) {
if (maxDistance > 120) {
maxDistance = 120;
}
if (transparent != null && transparent.length == 0) {
transparent = null;
}
List<Block> blocks = new ArrayList<>();
BlockIterator itr = new BlockIterator(this.level, this.getPosition(), this.getDirectionVector(), this.getEyeHeight(), maxDistance);
while (itr.hasNext()) {
Block block = itr.next();
blocks.add(block);
if (maxLength != 0 && blocks.size() > maxLength) {
blocks.remove(0);
}
int id = block.getId();
if (transparent == null) {
if (id != 0) {
break;
}
} else {
if (Arrays.binarySearch(transparent, id) < 0) {
break;
}
}
}
return blocks.stream().toArray(Block[]::new);
}
示例2: getEntityPlayerLookingAt
import cn.nukkit.utils.BlockIterator; //导入方法依赖的package包/类
/**
* Returns the Entity the player is looking at currently
*
* @param maxDistance the maximum distance to check for entities
* @return Entity|null either NULL if no entity is found or an instance of the entity
*/
public EntityInteractable getEntityPlayerLookingAt(int maxDistance) {
timing.startTiming();
EntityInteractable entity = null;
// just a fix because player MAY not be fully initialized
if (temporalVector != null) {
Entity[] nearbyEntities = level.getNearbyEntities(boundingBox.grow(maxDistance, maxDistance, maxDistance), this);
// get all blocks in looking direction until the max interact distance is reached (it's possible that startblock isn't found!)
try {
BlockIterator itr = new BlockIterator(level, getPosition(), getDirectionVector(), getEyeHeight(), maxDistance);
if (itr.hasNext()) {
Block block;
while (itr.hasNext()) {
block = itr.next();
entity = getEntityAtPosition(nearbyEntities, block.getFloorX(), block.getFloorY(), block.getFloorZ());
if (entity != null) {
break;
}
}
}
} catch (Exception ex) {
// nothing to log here!
}
}
timing.stopTiming();
return entity;
}
示例3: getLineOfSight
import cn.nukkit.utils.BlockIterator; //导入方法依赖的package包/类
public Block[] getLineOfSight(int maxDistance, int maxLength, Map<Integer, Object> transparent) {
if (maxDistance > 120) {
maxDistance = 120;
}
if (transparent != null && transparent.isEmpty()) {
transparent = null;
}
List<Block> blocks = new ArrayList<>();
BlockIterator itr = new BlockIterator(this.level, this.getPosition(), this.getDirectionVector(), this.getEyeHeight(), maxDistance);
while (itr.hasNext()) {
Block block = itr.next();
blocks.add(block);
if (maxLength != 0 && blocks.size() > maxLength) {
blocks.remove(0);
}
int id = block.getId();
if (transparent == null) {
if (id != 0) {
break;
}
} else {
if (!transparent.containsKey(id)) {
break;
}
}
}
return blocks.stream().toArray(Block[]::new);
}