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


Java BlockIterator类代码示例

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


BlockIterator类属于cn.nukkit.utils包,在下文中一共展示了BlockIterator类的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);
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:37,代码来源:EntityLiving.java

示例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;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:38,代码来源:Player.java

示例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);
}
 
开发者ID:PrismarineMC,项目名称:MagmaBlock,代码行数:37,代码来源:EntityLiving.java


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