Java Code Examples for net.minecraft.util.math.BlockPos.MutableBlockPos#toImmutable()
The following examples show how to use
net.minecraft.util.math.BlockPos.MutableBlockPos#toImmutable() .
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: EnergyNet.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
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; }
Example 2
Source File: FoamSprayerBehavior.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
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 3
Source File: FoamSprayerBehavior.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
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; }