-
-
Save dimitriye98/78c76cd7f33cefcaecdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<BlockPos> getNeighborPipeBlocks(BlockPos pos, World world) { | |
List<BlockPos> result = Lists.newArrayList(); | |
for (int i = 0; i < EnumFacing.VALUES.length; i++) { | |
BlockPos p1 = pos.offset(EnumFacing.VALUES[i]); | |
if (world.getBlockState(p1).getBlock() == BlockReference.fluidPipe) | |
result.add(p1); | |
} | |
return result; | |
} | |
public Optional<BlockPos> findOutput(BlockPos pos, World world) { | |
// NOTE: If you ever add teserects, you'll need to track BlockPos-World pairs. | |
LinkedList<BlockPos> queue = Lists.newLinkedList(); | |
List<BlockPos> checked = Lists.newArrayList(); | |
queue.add(pos); | |
while (!queue.isEmpty()) { | |
BlockPos current = queue.pop(); | |
@SuppressWarnings("unchecked") //safe because we only get the positions of fluid pipes | |
TileFluidNode currentPipe = (TileFluidNode) world.getTileEntity(current) | |
if (currentPipe.isOutput(pos, world)) | |
return Optional.of(current) | |
checked.add(current) | |
for (BlockPos pos: currentPipe.getNeighborPipes(pos, world)) { | |
if (!checked.contains(pos)) | |
queue.add(pos) | |
} | |
} | |
return Optional.absent<BlockPos>(); | |
} | |
public boolean isOutput(BlockPos pos, World world) { | |
// logic here | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment