Java Code Examples for net.minecraft.util.math.BlockPos.MutableBlockPos#distanceSq()

The following examples show how to use net.minecraft.util.math.BlockPos.MutableBlockPos#distanceSq() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FoamSprayerBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 2
Source File: FoamSprayerBehavior.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: BlockFrame.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
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;
}