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

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

源代码1 项目: GregTech   文件: PipeNet.java
protected HashMap<BlockPos, Node<NodeDataType>> findAllConnectedBlocks(BlockPos startPos) {
    HashMap<BlockPos, Node<NodeDataType>> observedSet = new HashMap<>();
    observedSet.put(startPos, getNodeAt(startPos));
    Node<NodeDataType> firstNode = getNodeAt(startPos);
    MutableBlockPos currentPos = new MutableBlockPos(startPos);
    Stack<EnumFacing> moveStack = new Stack<>();
    main:
    while (true) {
        for (EnumFacing facing : EnumFacing.VALUES) {
            currentPos.move(facing);
            Node<NodeDataType> secondNode = getNodeAt(currentPos);
            //if there is node, and it can connect with previous node, add it to list, and set previous node as current
            if (secondNode != null && canNodesConnect(firstNode, facing, secondNode, this) && !observedSet.containsKey(currentPos)) {
                observedSet.put(currentPos.toImmutable(), getNodeAt(currentPos));
                firstNode = secondNode;
                moveStack.push(facing.getOpposite());
                continue main;
            } else currentPos.move(facing.getOpposite());
        }
        if (!moveStack.isEmpty()) {
            currentPos.move(moveStack.pop());
            firstNode = getNodeAt(currentPos);
        } else break;
    }
    return observedSet;
}
 
源代码2 项目: GregTech   文件: BlockFrame.java
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stackInHand = playerIn.getHeldItem(hand);
    if (stackInHand.isEmpty() || !(stackInHand.getItem() instanceof FrameItemBlock))
        return false;
    IBlockState blockState = ((FrameItemBlock) stackInHand.getItem()).getBlockState(stackInHand);
    if (blockState != worldIn.getBlockState(pos))
        return false;
    MutableBlockPos blockPos = new MutableBlockPos(pos);
    for (int i = 0; i < 32; i++) {
        IBlockState stateHere = worldIn.getBlockState(blockPos);
        if (stateHere == state) {
            blockPos.move(EnumFacing.UP);
            continue;
        }
        if (canPlaceBlockAt(worldIn, blockPos)) {
            worldIn.setBlockState(blockPos, blockState);
            if (!playerIn.capabilities.isCreativeMode)
                stackInHand.shrink(1);
            return true;
        } else {
            return false;
        }
    }
    return false;
}
 
源代码3 项目: BetterChests   文件: TreeHandler.java
@Override
public boolean handleHarvest(IBetterChest chest, IBlockState state, World world, BlockPos pos) {
	MutableBlockPos start = new MutableBlockPos(pos);
	while (canBreak(world, start)) {
		start.move(EnumFacing.UP);
	}
	start.move(EnumFacing.DOWN);

	if (start.getY() >= pos.getY()) {
		BlockPos target = search(world, pos);
		IBlockState targetState = world.getBlockState(target);
		targetState.getBlock().breakBlock(world, pos, state);
		PlantHarvestHelper.breakBlockHandleDrop(world, target, targetState, chest);
		return true;
	}
	return false;
}
 
源代码4 项目: GregTech   文件: MetaTileEntityTank.java
private static Map<BlockPos, MetaTileEntityTank> findConnectedTanks(MetaTileEntityTank tank, Set<BlockPos> visitedSet) {
    BlockPos startPos = tank.getPos();
    HashMap<BlockPos, MetaTileEntityTank> observedSet = new HashMap<>();
    if (visitedSet.contains(startPos)) {
        return observedSet;
    }
    observedSet.put(tank.getPos(), tank);
    visitedSet.add(startPos);
    MetaTileEntityTank firstNode = observedSet.get(startPos);
    MutableBlockPos currentPos = new MutableBlockPos(startPos);
    Stack<EnumFacing> moveStack = new Stack<>();
    int currentAmount = 0;
    int scanSizeLimit = tank.maxSizeHorizontal * tank.maxSizeHorizontal * tank.maxSizeVertical * 4;
    main: while (true) {
        if (currentAmount >= scanSizeLimit) {
            break;
        }
        for (EnumFacing facing : EnumFacing.VALUES) {
            currentPos.move(facing);
            MetaTileEntityTank metaTileEntity;
            if (!visitedSet.contains(currentPos) &&
                !observedSet.containsKey(currentPos) &&
                (metaTileEntity = tank.getTankTile(currentPos)) != null &&
                canTanksConnect(firstNode, metaTileEntity, facing)) {
                observedSet.put(metaTileEntity.getPos(), metaTileEntity);
                visitedSet.add(metaTileEntity.getPos());
                firstNode = metaTileEntity;
                moveStack.push(facing.getOpposite());
                currentAmount++;
                continue main;
            } else currentPos.move(facing.getOpposite());
        }
        if (!moveStack.isEmpty()) {
            currentPos.move(moveStack.pop());
            firstNode = observedSet.get(currentPos);
        } else break;
    }
    return observedSet;
}
 
源代码5 项目: GregTech   文件: BlockFrame.java
private boolean canFrameSupportVertical(World worldIn, BlockPos framePos) {
    MutableBlockPos blockPos = new MutableBlockPos(framePos);
    do {
        blockPos.move(EnumFacing.DOWN);
        IBlockState blockState = worldIn.getBlockState(blockPos);
        if (!(blockState.getBlock() instanceof BlockFrame)) {
            return blockState.getBlockFaceShape(worldIn, blockPos, EnumFacing.UP) == BlockFaceShape.SOLID;
        }
    } while (true);
}
 
源代码6 项目: 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;
}
 
源代码7 项目: 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;
}
 
源代码8 项目: 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;
}
 
源代码9 项目: BetterChests   文件: ReedHandler.java
@Override
public boolean handleHarvest(IBetterChest chest, IBlockState state, World world, BlockPos pos) {
	MutableBlockPos mut = new MutableBlockPos(pos);
	while (world.getBlockState(mut).getBlock() == state.getBlock()) {
		mut.move(EnumFacing.UP);
	}
	mut.move(EnumFacing.DOWN);
	if (mut.getY() != pos.getY()) {
		PlantHarvestHelper.breakBlockHandleDrop(world, mut, state, chest);
		return true;
	}
	return false;
}
 
源代码10 项目: 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;
}