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

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

源代码1 项目: GregTech   文件: EnergyNet.java
public List<RoutePath> computePatches(BlockPos startPos) {
    ArrayList<RoutePath> readyPaths = new ArrayList<>();
    RoutePath currentPath = new RoutePath();
    Node<WireProperties> firstNode = getNodeAt(startPos);
    currentPath.path.put(startPos, firstNode.data);
    readyPaths.add(currentPath.cloneAndCompute(startPos));
    HashSet<BlockPos> observedSet = new HashSet<>();
    observedSet.add(startPos);
    MutableBlockPos currentPos = new MutableBlockPos(startPos);
    Stack<EnumFacing> moveStack = new Stack<>();
    main:
    while (true) {
        for (EnumFacing facing : EnumFacing.VALUES) {
            currentPos.move(facing);
            Node<WireProperties> secondNode = getNodeAt(currentPos);
            if (secondNode != null && canNodesConnect(firstNode, facing, secondNode, this) && !observedSet.contains(currentPos)) {
                BlockPos immutablePos = currentPos.toImmutable();
                observedSet.add(immutablePos);
                firstNode = secondNode;
                moveStack.push(facing.getOpposite());
                currentPath.path.put(immutablePos, getNodeAt(immutablePos).data);
                if (secondNode.isActive) {
                    //if we are on active node, this is end of our path
                    RoutePath finalizedPath = currentPath.cloneAndCompute(immutablePos);
                    readyPaths.add(finalizedPath);
                }
                continue main;
            } else {
                currentPos.move(facing.getOpposite());
            }
        }
        if (!moveStack.isEmpty()) {
            currentPos.move(moveStack.pop());
            //also remove already visited block from path
            currentPath.path.remove(currentPos);
        } else break;
    }
    return readyPaths;
}
 
源代码2 项目: 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;
}
 
源代码3 项目: 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;
}