net.minecraft.util.math.BlockPos.MutableBlockPos#distanceSq ( )源码实例Demo

下面列出了net.minecraft.util.math.BlockPos.MutableBlockPos#distanceSq ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: GregTech   文件: FoamSprayerBehavior.java
private static List<BlockPos> gatherReplacableBlocks(World worldIn, BlockPos centerPos, int maxRadiusSq) {
    HashSet<BlockPos> observedSet = new HashSet<>();
    ArrayList<BlockPos> resultAirBlocks = new ArrayList<>();
    observedSet.add(centerPos);
    resultAirBlocks.add(centerPos);
    Stack<EnumFacing> moveStack = new Stack<>();
    MutableBlockPos currentPos = new MutableBlockPos(centerPos);
    main:
    while (true) {
        for (EnumFacing facing : EnumFacing.VALUES) {
            currentPos.move(facing);
            IBlockState blockStateHere = worldIn.getBlockState(currentPos);
            //if there is node, and it can connect with previous node, add it to list, and set previous node as current
            if (blockStateHere.getBlock().isReplaceable(worldIn, currentPos) &&
                currentPos.distanceSq(centerPos) <= maxRadiusSq && !observedSet.contains(currentPos)) {
                BlockPos immutablePos = currentPos.toImmutable();
                observedSet.add(immutablePos);
                resultAirBlocks.add(immutablePos);
                moveStack.push(facing.getOpposite());
                continue main;
            } else currentPos.move(facing.getOpposite());
        }
        if (!moveStack.isEmpty()) {
            currentPos.move(moveStack.pop());
        } else break;
    }
    resultAirBlocks.sort(Comparator.comparing(it -> it.distanceSq(centerPos)));
    return resultAirBlocks;
}
 
源代码2 项目: GregTech   文件: FoamSprayerBehavior.java
private static List<BlockPos> gatherFrameBlocks(World worldIn, BlockPos centerPos, int maxRadiusSq) {
    HashSet<BlockPos> observedSet = new HashSet<>();
    ArrayList<BlockPos> resultFrameBlocks = new ArrayList<>();
    observedSet.add(centerPos);
    resultFrameBlocks.add(centerPos);
    IBlockState frameState = null;
    Stack<EnumFacing> moveStack = new Stack<>();
    MutableBlockPos currentPos = new MutableBlockPos(centerPos);
    main:
    while (true) {
        for (EnumFacing facing : EnumFacing.VALUES) {
            currentPos.move(facing);
            IBlockState blockStateHere = worldIn.getBlockState(currentPos);
            //if there is node, and it can connect with previous node, add it to list, and set previous node as current
            if (blockStateHere.getBlock() instanceof BlockFrame &&
                currentPos.distanceSq(centerPos) <= maxRadiusSq &&
                (frameState == null || frameState == blockStateHere) && !observedSet.contains(currentPos)) {
                BlockPos immutablePos = currentPos.toImmutable();
                observedSet.add(immutablePos);
                resultFrameBlocks.add(immutablePos);
                moveStack.push(facing.getOpposite());
                frameState = blockStateHere;
                continue main;
            } else currentPos.move(facing.getOpposite());
        }
        if (!moveStack.isEmpty()) {
            currentPos.move(moveStack.pop());
        } else break;
    }
    resultFrameBlocks.sort(Comparator.comparing(it -> it.distanceSq(centerPos)));
    return resultFrameBlocks;
}
 
源代码3 项目: GregTech   文件: BlockFrame.java
protected boolean canBlockStay(World worldIn, BlockPos pos) {
    MutableBlockPos currentPos = new MutableBlockPos(pos);
    currentPos.move(EnumFacing.DOWN);
    IBlockState downState = worldIn.getBlockState(currentPos);
    if (downState.getBlock() instanceof BlockFrame) {
        if (canFrameSupportVertical(worldIn, currentPos)) {
            return true;
        }
    } else if (downState.getBlockFaceShape(worldIn, currentPos, EnumFacing.UP) == BlockFaceShape.SOLID) {
        return true;
    }
    currentPos.move(EnumFacing.UP);
    HashSet<BlockPos> observedSet = new HashSet<>();
    Stack<EnumFacing> moveStack = new Stack<>();
    main:
    while (true) {
        for (EnumFacing facing : EnumFacing.HORIZONTALS) {
            currentPos.move(facing);
            IBlockState blockStateHere = worldIn.getBlockState(currentPos);
            //if there is node, and it can connect with previous node, add it to list, and set previous node as current
            if (blockStateHere.getBlock() instanceof BlockFrame && currentPos.distanceSq(pos) <= SCAFFOLD_PILLAR_RADIUS_SQ && !observedSet.contains(currentPos)) {
                observedSet.add(currentPos.toImmutable());
                currentPos.move(EnumFacing.DOWN);
                downState = worldIn.getBlockState(currentPos);
                if (downState.getBlock() instanceof BlockFrame) {
                    if (canFrameSupportVertical(worldIn, currentPos)) {
                        return true;
                    }
                } else if (downState.getBlockFaceShape(worldIn, currentPos, EnumFacing.UP) == BlockFaceShape.SOLID) {
                    return true;
                }
                currentPos.move(EnumFacing.UP);
                moveStack.push(facing.getOpposite());
                continue main;
            } else currentPos.move(facing.getOpposite());
        }
        if (!moveStack.isEmpty()) {
            currentPos.move(moveStack.pop());
        } else break;
    }
    return false;
}