Skip to content

Instantly share code, notes, and snippets.

@dimitriye98
Last active August 29, 2015 14:24
Show Gist options
  • Save dimitriye98/78c76cd7f33cefcaecdd to your computer and use it in GitHub Desktop.
Save dimitriye98/78c76cd7f33cefcaecdd to your computer and use it in GitHub Desktop.
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